@ -14,6 +14,8 @@
* /
* /
package org.hyperledger.besu.evm.fluent ;
package org.hyperledger.besu.evm.fluent ;
import static com.google.common.base.Preconditions.checkNotNull ;
import org.hyperledger.besu.datatypes.Address ;
import org.hyperledger.besu.datatypes.Address ;
import org.hyperledger.besu.datatypes.Hash ;
import org.hyperledger.besu.datatypes.Hash ;
import org.hyperledger.besu.datatypes.Wei ;
import org.hyperledger.besu.datatypes.Wei ;
@ -48,8 +50,8 @@ import org.apache.tuweni.bytes.Bytes32;
public class EVMExecutor {
public class EVMExecutor {
private final EVM evm ;
private PrecompileContractRegistry precompileContractRegistry ;
private PrecompileContractRegistry precompileContractRegistry ;
private EVM evm ;
private boolean commitWorldState = false ;
private boolean commitWorldState = false ;
private WorldUpdater worldUpdater = new SimpleWorld ( ) ;
private WorldUpdater worldUpdater = new SimpleWorld ( ) ;
private Gas gas = Gas . MAX_VALUE ;
private Gas gas = Gas . MAX_VALUE ;
@ -58,7 +60,7 @@ public class EVMExecutor {
private Wei gasPriceGWei = Wei . ZERO ;
private Wei gasPriceGWei = Wei . ZERO ;
private Bytes callData = Bytes . EMPTY ;
private Bytes callData = Bytes . EMPTY ;
private Wei ethValue = Wei . ZERO ;
private Wei ethValue = Wei . ZERO ;
private Code code = new Code ( Bytes . EMPTY , Hash . EMPTY ) ;
private Code code = Code . EMPTY_CODE ;
private BlockValues blockValues = new SimpleBlockValues ( ) ;
private BlockValues blockValues = new SimpleBlockValues ( ) ;
private OperationTracer tracer = OperationTracer . NO_TRACING ;
private OperationTracer tracer = OperationTracer . NO_TRACING ;
private boolean requireDeposit = true ;
private boolean requireDeposit = true ;
@ -71,15 +73,17 @@ public class EVMExecutor {
private MessageCallProcessor messageCallProcessor = null ;
private MessageCallProcessor messageCallProcessor = null ;
private ContractCreationProcessor contractCreationProcessor = null ;
private ContractCreationProcessor contractCreationProcessor = null ;
private EVMExecutor ( final EVM evm ) {
checkNotNull ( evm , "evm must not be null" ) ;
this . evm = evm ;
}
public static EVMExecutor evm ( final EVM evm ) {
public static EVMExecutor evm ( final EVM evm ) {
EVMExecutor executor = new EVMExecutor ( ) ;
return new EVMExecutor ( evm ) ;
executor . evm = evm ;
return executor ;
}
}
public static EVMExecutor frontier ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor frontier ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . frontier ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . frontier ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . frontier ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . frontier ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( ) ;
executor . contractValidationRules = List . of ( ) ;
@ -89,8 +93,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor homestead ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor homestead ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . homestead ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . homestead ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . frontier ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . frontier ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( ) ;
executor . contractValidationRules = List . of ( ) ;
@ -99,8 +102,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor spuriousDragon ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor spuriousDragon ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . spuriousDragon ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . spuriousDragon ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . frontier ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . frontier ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
@ -108,8 +110,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor tangerineWhistle ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor tangerineWhistle ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . tangerineWhistle ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . tangerineWhistle ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . frontier ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . frontier ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
@ -117,8 +118,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor byzantium ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor byzantium ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . byzantium ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . byzantium ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . byzantium ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . byzantium ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
@ -126,8 +126,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor constantinople ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor constantinople ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . constantinople ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . constantinople ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . byzantium ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . byzantium ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
@ -135,8 +134,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor petersburg ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor petersburg ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . petersburg ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . petersburg ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . byzantium ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . byzantium ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
@ -144,8 +142,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor istanbul ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor istanbul ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . istanbul ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . istanbul ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . istanbul ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . istanbul ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
@ -153,8 +150,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor berlin ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor berlin ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . berlin ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . berlin ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . istanbul ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . istanbul ( executor . evm . getGasCalculator ( ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
executor . contractValidationRules = List . of ( MaxCodeSizeRule . of ( 0x6000 ) ) ;
@ -162,8 +158,7 @@ public class EVMExecutor {
}
}
public static EVMExecutor london ( final EvmConfiguration evmConfiguration ) {
public static EVMExecutor london ( final EvmConfiguration evmConfiguration ) {
EVMExecutor executor = new EVMExecutor ( ) ;
final EVMExecutor executor = new EVMExecutor ( MainnetEVMs . london ( evmConfiguration ) ) ;
executor . evm = MainnetEVMs . istanbul ( evmConfiguration ) ;
executor . precompileContractRegistry =
executor . precompileContractRegistry =
MainnetPrecompiledContracts . istanbul ( executor . evm . getGasCalculator ( ) ) ;
MainnetPrecompiledContracts . istanbul ( executor . evm . getGasCalculator ( ) ) ;
return executor ;
return executor ;
@ -198,7 +193,7 @@ public class EVMExecutor {
public Bytes execute (
public Bytes execute (
final Bytes codeBytes , final Bytes inputData , final Wei value , final Address receiver ) {
final Bytes codeBytes , final Bytes inputData , final Wei value , final Address receiver ) {
this . code = new Code ( codeBytes , Hash . EMPTY ) ;
this . code = evm . getCode ( Hash . hash ( codeBytes ) , codeBytes ) ;
this . callData = inputData ;
this . callData = inputData ;
this . ethValue = value ;
this . ethValue = value ;
this . receiver = receiver ;
this . receiver = receiver ;
@ -206,10 +201,10 @@ public class EVMExecutor {
}
}
public Bytes execute ( ) {
public Bytes execute ( ) {
MessageCallProcessor mcp = thisMessageCallProcessor ( ) ;
final MessageCallProcessor mcp = thisMessageCallProcessor ( ) ;
ContractCreationProcessor ccp = thisContractCreationProcessor ( ) ;
final ContractCreationProcessor ccp = thisContractCreationProcessor ( ) ;
final Deque < MessageFrame > messageFrameStack = new ArrayDeque < > ( ) ;
final Deque < MessageFrame > messageFrameStack = new ArrayDeque < > ( ) ;
MessageFrame initialMessageFrame =
final MessageFrame initialMessageFrame =
MessageFrame . builder ( )
MessageFrame . builder ( )
. type ( MessageFrame . Type . MESSAGE_CALL )
. type ( MessageFrame . Type . MESSAGE_CALL )
. messageFrameStack ( messageFrameStack )
. messageFrameStack ( messageFrameStack )
@ -302,7 +297,7 @@ public class EVMExecutor {
}
}
public EVMExecutor code ( final Bytes codeBytes , final Hash hash ) {
public EVMExecutor code ( final Bytes codeBytes , final Hash hash ) {
this . code = new Code ( codeBytes , hash ) ;
this . code = evm . getCode ( hash , codeBytes ) ;
return this ;
return this ;
}
}