#
The EVM Execution Environment
The environment in which bytecode is executed is the collection of resources that bytecode has access to.
Specifically, bytecode has access to:
- The stack
- Memory
- Contract storage
- A finite amount of gas
- Various fields of information about the running transaction, including calldata, the running contract, and its caller.
In the following chapters, we will go over the first three in greater detail.
#
Three Worlds of Data
The stack is not the only data location you have to work with. Specifically, you have access to:
- The stack. Push, pop, dupe, and swap are the base operations you have access to.
- Memory. A location to read/write data that will only last as long as a function call
- This is an EVM function call, to be clear; Solidity sometimes has a different definition of a function call, as we'll learn in ⚙️ Internal Function Calls
(coming soon).
- Storage. A location to read/write data that will persist across function calls and transactions.
And that's it. These three data locations make up the execution environment that all contracts run in on-chain.
In the following chapters, we’ll discuss the details of working with each one.
#
Function Call Environments
Generally speaking, each function call gets its own, isolated execution environment. Namely:
- A new, empty stack.
- New, empty memory.
- Access to the running contract address’s storage.
- A finite amount of gas to run.
The details of how function calls work is described in ☎️ How EVM Function Calls Work
(coming soon). For now, just keep in mind that function calls do not share stack nor memory.