Skip to content

Commit

Permalink
Reconfigure how Protocol Specs are created WRT EVM condiguration (hyp…
Browse files Browse the repository at this point in the history
…erledger#7245)

Make the max code size and max initcode size a part of the EVM
configuration. As part of the change we need to move the tasks
CodeFactory once handled as a static class and move it into the EVM.
This has a nice follow on effect that we don't need to pass in max EOF
versions or max code sizes anymore.

Signed-off-by: Danno Ferrin <danno@numisight.com>
  • Loading branch information
shemnon authored and daniellehrner committed Jul 16, 2024
1 parent 31e0dcf commit 4e5b309
Show file tree
Hide file tree
Showing 57 changed files with 881 additions and 1,118 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Reduce lock contention on transaction pool when building a block [#7180](https://github.com/hyperledger/besu/pull/7180)
- Update Docker base image to Ubuntu 24.04 [#7251](https://github.com/hyperledger/besu/pull/7251)
- Add LUKSO as predefined network name [#7223](https://github.com/hyperledger/besu/pull/7223)
- Refactored how code, initcode, and max stack size are configured in forks. [#7245](https://github.com/hyperledger/besu/pull/7245)
- Added EIP-7702 [#7237](https://github.com/hyperledger/besu/pull/7237)

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.hyperledger.besu.evm.MainnetEVMs;
import org.hyperledger.besu.evm.contractvalidation.MaxCodeSizeRule;
import org.hyperledger.besu.evm.contractvalidation.PrefixCodeRule;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator;
import org.hyperledger.besu.evm.gascalculator.DieHardGasCalculator;
import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator;
Expand All @@ -44,7 +43,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Set;

Expand All @@ -56,50 +54,38 @@ private ClassicProtocolSpecs() {
}

public static ProtocolSpecBuilder classicRecoveryInitDefinition(
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final EvmConfiguration evmConfiguration) {
return MainnetProtocolSpecs.homesteadDefinition(
contractSizeLimit, configStackSizeLimit, evmConfiguration)
return MainnetProtocolSpecs.homesteadDefinition(evmConfiguration)
.blockHeaderValidatorBuilder(
feeMarket -> MainnetBlockHeaderValidator.createClassicValidator())
.name("ClassicRecoveryInit");
}

public static ProtocolSpecBuilder tangerineWhistleDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final EvmConfiguration evmConfiguration) {
return MainnetProtocolSpecs.homesteadDefinition(
contractSizeLimit, configStackSizeLimit, evmConfiguration)
final Optional<BigInteger> chainId, final EvmConfiguration evmConfiguration) {
return MainnetProtocolSpecs.homesteadDefinition(evmConfiguration)
.isReplayProtectionSupported(true)
.gasCalculator(TangerineWhistleGasCalculator::new)
.transactionValidatorFactoryBuilder(
(gasCalculator, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(gasCalculator, gasLimitCalculator, true, chainId))
(evm, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(
evm.getGasCalculator(), gasLimitCalculator, true, chainId))
.name("ClassicTangerineWhistle");
}

public static ProtocolSpecBuilder dieHardDefinition(
final Optional<BigInteger> chainId,
final OptionalInt ignoredConfigContractSizeLimit,
final OptionalInt configStackSizeLimit,
final EvmConfiguration evmConfiguration) {
return tangerineWhistleDefinition(
chainId, OptionalInt.empty(), configStackSizeLimit, evmConfiguration)
final Optional<BigInteger> chainId, final EvmConfiguration evmConfiguration) {
return tangerineWhistleDefinition(chainId, evmConfiguration)
.gasCalculator(DieHardGasCalculator::new)
.difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_PAUSED)
.name("DieHard");
}

public static ProtocolSpecBuilder gothamDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return dieHardDefinition(chainId, contractSizeLimit, configStackSizeLimit, evmConfiguration)
return dieHardDefinition(chainId, evmConfiguration)
.blockReward(MAX_BLOCK_REWARD)
.difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_DELAYED)
.blockProcessorBuilder(
Expand All @@ -122,35 +108,23 @@ public static ProtocolSpecBuilder gothamDefinition(

public static ProtocolSpecBuilder defuseDifficultyBombDefinition(
final Optional<BigInteger> chainId,
final OptionalInt contractSizeLimit,
final OptionalInt configStackSizeLimit,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return gothamDefinition(
chainId, contractSizeLimit, configStackSizeLimit, ecip1017EraRounds, evmConfiguration)
return gothamDefinition(chainId, ecip1017EraRounds, evmConfiguration)
.difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_REMOVED)
.transactionValidatorFactoryBuilder(
(gasCalculator, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(gasCalculator, gasLimitCalculator, true, chainId))
(evm, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(
evm.getGasCalculator(), gasLimitCalculator, true, chainId))
.name("DefuseDifficultyBomb");
}

public static ProtocolSpecBuilder atlantisDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
final int contractSizeLimit =
configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
return gothamDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
ecip1017EraRounds,
evmConfiguration)
return gothamDefinition(chainId, ecip1017EraRounds, evmConfiguration)
.evmBuilder(MainnetEVMs::byzantium)
.evmConfiguration(evmConfiguration)
.gasCalculator(SpuriousDragonGasCalculator::new)
Expand All @@ -163,13 +137,9 @@ public static ProtocolSpecBuilder atlantisDefinition(
? ClassicProtocolSpecs::byzantiumTransactionReceiptFactoryWithReasonEnabled
: ClassicProtocolSpecs::byzantiumTransactionReceiptFactory)
.contractCreationProcessorBuilder(
(gasCalculator, evm) ->
evm ->
new ContractCreationProcessor(
gasCalculator,
evm,
true,
Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)),
1))
evm, true, Collections.singletonList(MaxCodeSizeRule.from(evm)), 1))
.transactionProcessorBuilder(
(gasCalculator,
feeMarket,
Expand All @@ -183,7 +153,7 @@ public static ProtocolSpecBuilder atlantisDefinition(
messageCallProcessor,
true,
false,
stackSizeLimit,
evmConfiguration.evmStackSize(),
feeMarket,
CoinbaseFeePriceCalculator.frontier(),
new SetCodeTransactionProcessor(chainId.orElse(BigInteger.ZERO))))
Expand All @@ -192,18 +162,10 @@ public static ProtocolSpecBuilder atlantisDefinition(

public static ProtocolSpecBuilder aghartaDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return atlantisDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return atlantisDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.evmBuilder(MainnetEVMs::constantinople)
.gasCalculator(PetersburgGasCalculator::new)
.evmBuilder(MainnetEVMs::constantinople)
Expand All @@ -213,18 +175,10 @@ public static ProtocolSpecBuilder aghartaDefinition(

public static ProtocolSpecBuilder phoenixDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return aghartaDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return aghartaDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.gasCalculator(IstanbulGasCalculator::new)
.evmBuilder(
(gasCalculator, evmConfig) ->
Expand All @@ -236,18 +190,10 @@ public static ProtocolSpecBuilder phoenixDefinition(

public static ProtocolSpecBuilder thanosDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return phoenixDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return phoenixDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.blockHeaderValidatorBuilder(
feeMarket ->
MainnetBlockHeaderValidator.createPgaBlockHeaderValidator(
Expand Down Expand Up @@ -281,23 +227,15 @@ private static TransactionReceipt byzantiumTransactionReceiptFactoryWithReasonEn

public static ProtocolSpecBuilder magnetoDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return thanosDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return thanosDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.gasCalculator(BerlinGasCalculator::new)
.transactionValidatorFactoryBuilder(
(gasCalculator, gasLimitCalculator, feeMarket) ->
(evm, gasLimitCalculator, feeMarket) ->
new TransactionValidatorFactory(
gasCalculator,
evm.getGasCalculator(),
gasLimitCalculator,
true,
chainId,
Expand All @@ -311,47 +249,24 @@ public static ProtocolSpecBuilder magnetoDefinition(

public static ProtocolSpecBuilder mystiqueDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
final int contractSizeLimit =
configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
return magnetoDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return magnetoDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
.gasCalculator(LondonGasCalculator::new)
.contractCreationProcessorBuilder(
(gasCalculator, evm) ->
evm ->
new ContractCreationProcessor(
gasCalculator,
evm,
true,
List.of(MaxCodeSizeRule.of(contractSizeLimit), PrefixCodeRule.of()),
1))
evm, true, List.of(MaxCodeSizeRule.from(evm), PrefixCodeRule.of()), 1))
.name("Mystique");
}

public static ProtocolSpecBuilder spiralDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
return mystiqueDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
return mystiqueDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration)
// EIP-3860
.gasCalculator(ShanghaiGasCalculator::new)
// EIP-3855
Expand All @@ -373,7 +288,7 @@ public static ProtocolSpecBuilder spiralDefinition(
messageCallProcessor,
true,
true,
stackSizeLimit,
evmConfiguration.evmStackSize(),
feeMarket,
CoinbaseFeePriceCalculator.frontier(),
new SetCodeTransactionProcessor(chainId.orElse(BigInteger.ZERO))))
Expand Down
Loading

0 comments on commit 4e5b309

Please sign in to comment.