Skip to content

Commit

Permalink
fix initial nonce in homestad, improve evm methods
Browse files Browse the repository at this point in the history
Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon committed Sep 23, 2023
1 parent b3b2259 commit b320710
Showing 1 changed file with 181 additions and 34 deletions.
215 changes: 181 additions & 34 deletions evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,24 @@ public static EVMExecutor evm(
final EvmSpecVersion fork,
final BigInteger chainId,
final EvmConfiguration evmConfiguration) {
return new EVMExecutor(
switch (fork) {
case FRONTIER -> MainnetEVMs.frontier(evmConfiguration);
case HOMESTEAD -> MainnetEVMs.homestead(evmConfiguration);
case BYZANTIUM -> MainnetEVMs.byzantium(evmConfiguration);
case CONSTANTINOPLE -> MainnetEVMs.constantinople(evmConfiguration);
case PETERSBURG -> MainnetEVMs.petersburg(evmConfiguration);
case ISTANBUL -> MainnetEVMs.istanbul(chainId, evmConfiguration);
case BERLIN -> MainnetEVMs.berlin(chainId, evmConfiguration);
case LONDON -> MainnetEVMs.london(chainId, evmConfiguration);
case PARIS -> MainnetEVMs.paris(chainId, evmConfiguration);
case SHANGHAI -> MainnetEVMs.shanghai(chainId, evmConfiguration);
case CANCUN -> MainnetEVMs.cancun(chainId, evmConfiguration);
case PRAGUE -> MainnetEVMs.prague(chainId, evmConfiguration);
case OSAKA -> MainnetEVMs.osaka(chainId, evmConfiguration);
case BOGOTA -> MainnetEVMs.bogota(chainId, evmConfiguration);
case FUTURE_EIPS -> MainnetEVMs.futureEips(chainId, evmConfiguration);
case EXPERIMENTAL_EIPS -> MainnetEVMs.experimentalEips(chainId, evmConfiguration);
});
return switch (fork) {
case FRONTIER -> frontier(evmConfiguration);
case HOMESTEAD -> homestead(evmConfiguration);
case BYZANTIUM -> byzantium(evmConfiguration);
case CONSTANTINOPLE -> constantinople(evmConfiguration);
case PETERSBURG -> petersburg(evmConfiguration);
case ISTANBUL -> istanbul(chainId, evmConfiguration);
case BERLIN -> berlin(chainId, evmConfiguration);
case LONDON -> london(chainId, evmConfiguration);
case PARIS -> paris(chainId, evmConfiguration);
case SHANGHAI -> shanghai(chainId, evmConfiguration);
case CANCUN -> cancun(chainId, evmConfiguration);
case PRAGUE -> prague(chainId, evmConfiguration);
case OSAKA -> osaka(chainId, evmConfiguration);
case BOGOTA -> bogota(chainId, evmConfiguration);
case FUTURE_EIPS -> futureEips(chainId, evmConfiguration);
case EXPERIMENTAL_EIPS -> experimentalEips(chainId, evmConfiguration);
};
}

/**
Expand All @@ -187,6 +186,7 @@ public static EVMExecutor frontier(final EvmConfiguration evmConfiguration) {
executor.contractValidationRules = List.of();
executor.requireDeposit = false;
executor.forceCommitAddresses = List.of();
executor.initialNonce = 0;
return executor;
}

Expand All @@ -202,31 +202,33 @@ public static EVMExecutor homestead(final EvmConfiguration evmConfiguration) {
MainnetPrecompiledContracts.frontier(executor.evm.getGasCalculator());
executor.contractValidationRules = List.of();
executor.forceCommitAddresses = List.of();
executor.initialNonce = 0;
return executor;
}

/**
* Instantiate Spurious dragon evm executor.
* Instantiate Tangerine whistle evm executor.
*
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor spuriousDragon(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.spuriousDragon(evmConfiguration));
public static EVMExecutor tangerineWhistle(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.tangerineWhistle(evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.frontier(executor.evm.getGasCalculator());
executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000));
executor.initialNonce = 0;
return executor;
}

/**
* Instantiate Tangerine whistle evm executor.
* Instantiate Spurious dragon evm executor.
*
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor tangerineWhistle(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.tangerineWhistle(evmConfiguration));
public static EVMExecutor spuriousDragon(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.spuriousDragon(evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.frontier(executor.evm.getGasCalculator());
executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000));
Expand Down Expand Up @@ -282,7 +284,19 @@ public static EVMExecutor petersburg(final EvmConfiguration evmConfiguration) {
* @return the evm executor
*/
public static EVMExecutor istanbul(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.istanbul(evmConfiguration));
return istanbul(BigInteger.ONE, evmConfiguration);
}

/**
* Instantiate Istanbul evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor istanbul(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.istanbul(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.istanbul(executor.evm.getGasCalculator());
executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000));
Expand All @@ -296,7 +310,19 @@ public static EVMExecutor istanbul(final EvmConfiguration evmConfiguration) {
* @return the evm executor
*/
public static EVMExecutor berlin(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.berlin(evmConfiguration));
return berlin(BigInteger.ONE, evmConfiguration);
}

/**
* Instantiate berlin evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor berlin(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.berlin(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.istanbul(executor.evm.getGasCalculator());
executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000));
Expand All @@ -310,7 +336,19 @@ public static EVMExecutor berlin(final EvmConfiguration evmConfiguration) {
* @return the evm executor
*/
public static EVMExecutor london(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.london(evmConfiguration));
return london(BigInteger.ONE, evmConfiguration);
}

/**
* Instantiate London evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor london(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.london(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.istanbul(executor.evm.getGasCalculator());
return executor;
Expand All @@ -322,8 +360,20 @@ public static EVMExecutor london(final EvmConfiguration evmConfiguration) {
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor paris(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.paris(evmConfiguration));
public static EVMExecutor Paris(final EvmConfiguration evmConfiguration) {
return paris(BigInteger.ONE, evmConfiguration);
}

/**
* Instantiate Paris evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor paris(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.paris(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.istanbul(executor.evm.getGasCalculator());
return executor;
Expand All @@ -336,7 +386,19 @@ public static EVMExecutor paris(final EvmConfiguration evmConfiguration) {
* @return the evm executor
*/
public static EVMExecutor shanghai(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.shanghai(evmConfiguration));
return shanghai(BigInteger.ONE, evmConfiguration);
}

/**
* Instantiate Shanghai evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor shanghai(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.shanghai(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.istanbul(executor.evm.getGasCalculator());
return executor;
Expand All @@ -349,20 +411,105 @@ public static EVMExecutor shanghai(final EvmConfiguration evmConfiguration) {
* @return the evm executor
*/
public static EVMExecutor cancun(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.cancun(evmConfiguration));
return cancun(BigInteger.ONE, evmConfiguration);
}

/**
* Instantiate Cancun evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor cancun(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.cancun(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.cancun(executor.evm.getGasCalculator());
return executor;
}

/**
* Instantiate Prague evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor prague(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.prague(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.cancun(executor.evm.getGasCalculator());
return executor;
}

/**
* Instantiate Osaka evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor osaka(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.osaka(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.cancun(executor.evm.getGasCalculator());
return executor;
}

/**
* Instantiate Bogota evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor bogota(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.bogota(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.cancun(executor.evm.getGasCalculator());
return executor;
}

/**
* Instantiate Future EIPs evm executor.
*
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor futureEips(final EvmConfiguration evmConfiguration) {
return futureEips(BigInteger.ONE, evmConfiguration);
}

/**
* Instantiate Future EIPs evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor futureEips(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.futureEips(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.futureEIPs(executor.evm.getGasCalculator());
return executor;
}

/**
* Instantiate Experimental EIPs evm executor.
*
* @param chainId the chain ID
* @param evmConfiguration the evm configuration
* @return the evm executor
*/
public static EVMExecutor futureEIPs(final EvmConfiguration evmConfiguration) {
final EVMExecutor executor = new EVMExecutor(MainnetEVMs.cancun(evmConfiguration));
public static EVMExecutor experimentalEips(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
final EVMExecutor executor =
new EVMExecutor(MainnetEVMs.experimentalEips(chainId, evmConfiguration));
executor.precompileContractRegistry =
MainnetPrecompiledContracts.futureEIPs(executor.evm.getGasCalculator());
return executor;
Expand Down

0 comments on commit b320710

Please sign in to comment.