The Host trait provides an interface that allows the EVM to interact with the external world. It contains methods to access environmental information, manipulate account balances, and interact with contract code and storage.
The EVMImpl struct implements this Host trait.
-
step&step_endThese methods are used to control the interpreter's execution. They move the interpreter forward one step, allowing the user to inspect the state of the interpreter after each individual operation. These control the execution of the interpreter, allowing step-by-step execution and inspection.
-
envThis method returns a mutable reference to the environment information that the EVM uses for its execution. The
Envstruct contains details about the current block, such as the timestamp, block number, difficulty, and gas limit. -
block_hashThis method retrieves the hash of a block given its number. It's typically used within smart contracts for actions like random number generation.
-
load_accountThis method loads the account associated with a given address and returns information about the account's existence and if it's a contract.
-
balanceThis method retrieves the balance of an Ethereum account given its address. It returns a tuple containing the balance and a boolean indicating whether the account was "cold" (accessed for the first time in the current transaction).
-
codeThis method retrieves the bytecode of a given address. It returns a tuple containing the bytecode and a boolean indicating whether the account was "cold".
-
code_hashThis method retrieves the code_hash at a given address. It returns a tuple containing the hash and a boolean indicating whether the account was "cold".
-
sload&sstoreThese methods interact with the contract storage. The
sloadmethod retrieves a value from contract storage, whilesstoresets a value in contract storage. -
tload&tstoreAs defined in EIP1153, for transiant storage reads and writes.
-
logThis method is used to create log entries, which are a way for contracts to produce output that external observers (like dapps or the frontend of a blockchain explorer) can listen for and react to.
-
selfdestructThe selfdestruct method attempts to terminate the specified address, transferring its remaining balance to a given target address. If the INSPECT constant is true, the self-destruction event is observed or logged via an inspector. The method returns an Option, encapsulating the outcome of the operation: Some(SelfDestructResult) on success and None if an error occurs, with the error being stored internally for later reference.
-
createThe create method initiates the creation of a contract with the provided CreateInputs. If the INSPECT constant is true, the creation process is observed or logged using an inspector, both at the start and end of the creation. The method returns a tuple consisting of the operation's result (InstructionResult), the optional address (Option) of the newly created contract, the amount of gas consumed (Gas), and the output data (Bytes). If the inspector intervenes and determines the instruction shouldn't continue, an early return occurs with the observed outcomes.
-
callThe call method manages a contract invocation using the provided CallInputs. If the INSPECT constant is active, the call event is observed or logged via an inspector before execution. The method yields a tuple representing the outcome of the call: the result status (InstructionResult), the consumed gas (Gas), and the output data (Bytes). If the inspector suggests early termination, the method returns immediately with the observed results. Otherwise, the main call execution is processed, and the outcomes, either raw or observed, are returned accordingly.