Skip to content

Commit

Permalink
Add Shandong gas calculator to support EIP-3860
Browse files Browse the repository at this point in the history
Signed-off-by: Diego López León <[email protected]>
Signed-off-by: Diego López León <[email protected]>
  • Loading branch information
diega committed Nov 23, 2022
1 parent 9fb5e69 commit f0fb504
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator;
import org.hyperledger.besu.evm.gascalculator.LondonGasCalculator;
import org.hyperledger.besu.evm.gascalculator.PetersburgGasCalculator;
import org.hyperledger.besu.evm.gascalculator.ShandongGasCalculator;
import org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator;
import org.hyperledger.besu.evm.gascalculator.TangerineWhistleGasCalculator;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
Expand Down Expand Up @@ -79,6 +80,7 @@ public abstract class MainnetProtocolSpecs {
public static final int FRONTIER_CONTRACT_SIZE_LIMIT = Integer.MAX_VALUE;

public static final int SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT = 24576;
public static final int SHANDONG_CONTRACT_SIZE_LIMIT = 2 * SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT;

private static final Address RIPEMD160_PRECOMPILE =
Address.fromHexString("0x0000000000000000000000000000000000000003");
Expand Down Expand Up @@ -649,8 +651,7 @@ static ProtocolSpecBuilder shandongDefinition(
genesisConfigOptions.isZeroBaseFee()
? FeeMarket.zeroBaseFee(londonForkBlockNumber)
: FeeMarket.london(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas());
final int contractSizeLimit =
configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
final int contractSizeLimit = configContractSizeLimit.orElse(SHANDONG_CONTRACT_SIZE_LIMIT);

return parisDefinition(
chainId,
Expand All @@ -660,6 +661,7 @@ static ProtocolSpecBuilder shandongDefinition(
genesisConfigOptions,
quorumCompatibilityMode,
evmConfiguration)
.gasCalculator(ShandongGasCalculator::new)
.evmBuilder(
(gasCalculator, jdCacheConfig) ->
MainnetEVMs.shandong(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.hyperledger.besu.evm.gascalculator;

import org.apache.tuweni.bytes.Bytes;

public class ShandongGasCalculator extends LondonGasCalculator {

private static final long INIT_CODE_COST = 2L;

@Override
public long transactionIntrinsicGasCost(final Bytes payload, final boolean isContractCreation) {
long intrinsicGasCost = super.transactionIntrinsicGasCost(payload, isContractCreation);
if (isContractCreation) {
final int dataLength = (int) Math.ceil((double) payload.size() / 32.0);
final long initCodeCost = dataLength * INIT_CODE_COST;
return intrinsicGasCost + initCodeCost;
} else {
return intrinsicGasCost;
}
}
}

0 comments on commit f0fb504

Please sign in to comment.