# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://thryec.gitbook.io/dev-compedium/ethereum/solidity/execution-context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
