Storage, Memory, Stack
EVM data locations.
Where Data Lives in the EVM
The EVM has several distinct places to keep data, each with different costs and lifetimes.
The three core data locations are the stack, memory, and storage. Choosing the right one is key to writing efficient contracts.
The Stack
The stack is the EVM's scratchpad for computation. It holds up to 1024 values of 256 bits each.
Opcodes push and pop from the top of the stack. It is extremely cheap but tiny and temporary.
PUSH1 0x02 // [2]
PUSH1 0x04 // [2, 4]
MUL // [8]
// stack vanishes when the call endsAll lessons in this course
- The Ethereum Virtual Machine
- Storage, Memory, Stack
- Opcodes
- Accounts and State