> For the complete documentation index, see [llms.txt](https://thryec.gitbook.io/dev-compedium/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thryec.gitbook.io/dev-compedium/ethereum/solidity/execution-context.md).

# Execution Context

When the EVM executes a smart contract, a [context](https://www.evm.codes/about) 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`&#x20;

For DELEGATECALL we have the following input variables;

* `gas`: amount of gas to send to the sub [context](https://www.evm.codes/about) to execute. The gas that is not used by the sub context is returned to this one.
* `address`: the account which [context](https://www.evm.codes/about) to execute.
* `argsOffset`: byte offset in the [memory](https://www.evm.codes/about) in bytes, the [calldata](https://www.evm.codes/about) of the sub [context](https://www.evm.codes/about).
* `argsSize`: byte size to copy (size of the [calldata](https://www.evm.codes/about)).
* `retOffset`: byte offset in the [memory](https://www.evm.codes/about) in bytes, where to store the [return data](https://www.evm.codes/about) of the sub [context](https://www.evm.codes/about).
* `retSize`: byte size to copy (size of the [return data](https://www.evm.codes/about)).

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

* `value`: [value](https://www.evm.codes/#34) in [wei](https://www.investopedia.com/terms/w/wei.asp) to send to the account. (CALL only)

References:

<https://www.evm.codes/about>
