Execution Context

When the EVM executes a smart contract, a context is created for it. The context consists of the following.

  • The Code

    • The contract bytecode which is immutable, it is stored on-chain and referenced using a contract address.

  • The Stack

    • The call stack, an empty stack is initialised for each EVM contract execution.

  • The Memory

    • The contract memory, a clean memory is initialised for each EVM contract execution.

  • The Storage

    • The contract storage which is persisted across executions, it is stored on-chain and is referenced via a contract address and its storage slot.

  • The Call Data

    • The input data for a transaction.

  • The Return Data

    • The data returned from a contract function call.

CALL vs. DELEGATECALL

CALL executes a function in the context of the contract it was defined, while DELEGATECALL inherits the execution context, meaning that the function will behave as it was defined in the contract that’s using DELEGATECALL

For DELEGATECALL we have the following input variables;

  • gas: amount of gas to send to the sub context to execute. The gas that is not used by the sub context is returned to this one.

  • address: the account which context to execute.

  • argsOffset: byte offset in the memory in bytes, the calldata of the sub context.

  • argsSize: byte size to copy (size of the calldata).

  • retOffset: byte offset in the memory in bytes, where to store the return data of the sub context.

  • retSize: byte size to copy (size of the return data).

CALL has exactly the same input variables with one additional value.

  • value: value in wei to send to the account. (CALL only)

References:

https://www.evm.codes/about

Last updated