EVM
Definition
Turing-complete virtual machine that executes smart contracts on the Ethereum blockchain.
State
Ethereum is a distributed state machine;
The machine state (or simply "state") is a data structure that keeps a record of all changes made to the blockchain like all accounts balances, all contracts, etc;
State is stored in a modified Merkle Patricia Trie (MPT);
State can change from block to block.
Rules for state changes are defined by the EVM.
Storage
Key-value permanent store that is part of the state;
Key-value pairs = "slots";
Values = 256 bits words or items;
Keys = Keccak256 hashes of their contract's address & the word;
If a transaction tries to add an item that is too big, the transaction will be reverted;
Data types smaller than 256 bits can be packed into a single slot. For this, developers must order the same data types from the smallest to the biggest:
Mappings & dynamic arrays values are stored in different slots but contiguous;
Strings have 1 storage slot for the length, then 1 slot for each 32 bytes of the string;
A struct is stored in a single slot if it fits, otherwise it is stored in multiple contiguous slots;
Smart contracts have no storage size limit.
Opcode
STATICCALL
STATICCALLSimilar to
CALLbut does not allow state modifications;Used for
view&purefunctions.
DELEGATECALL
DELEGATECALLCalls another contract's function using the current contract's context (storage, caller, value);
Used in proxy contracts.
References
Last updated