Table of contents
Ethereum Virtual Machine
This provides a definition of Ethereum Virtual Machine that is modular. This enables reusing the EVM definition for projects outside of Ethereum-like blockchains.
Modules
EVM Core
EVM Core defines the base layer of execution. The VM has access to the following information:
-
Data: a bytearray defining the input of the VM.
-
Code: a bytearray defining the code being executed.
-
Program Counter: an integer, pointing to the position of the next instruction being executed.
-
Jump Validity Map: a boolean list the same size as the code bytearray. It is generated in the beginning of the program execution, and sets all valid
JUMPDESTposition to true. -
Memory: A linear memory of bytes, of given limit.
-
Stack: A stack, containing values of 256-bit.
Valid instructions of EVM Core are:
-
Stop and Arithmetic:
STOP,ADD,MUL,SUB,DIV,SDIV,MOD,SMOD,ADDMOD,MULMOD,EXP,SIGNEXTEND. -
Comparison and Bitwise Logic:
LT,GT,SLT,SGT,EQ,ISZERO,AND,OR,XOR,NOT,BYTE,SHL,SHR,SAR. -
Code and Data Access:
CALLDATALOAD,CALLDATASIZE,CALLDATACOPY,CODESIZE,CODECOPY. -
Stack, Memory and Flow Control:
POP,PUSHn,DUPn,SWAPn,MLOAD,MSTORE,MSTORE8,JUMP,JUMPI,PC,MSIZE,JUMPDEST,RETURN,REVERT,INVALID.
EVM ROM
The EVM ROM layer can be built on top of EVM Core to provide access to a range of read-only memory. We define the following structure:
-
Read-only Memory: A range of read-only memory that can be accessed by specific opcodes.
We redefine the following opcodes to be access of read-only memory. Here we define read-only memory to have index every 32 bytes.
-
ADDRESS(0x30):READROM 0x0Push index0of read-only memory onto stack. -
ORIGIN(0x32):READROM 0x1Push index1of read-only memory onto stack. -
CALLER(0x33):READROM 0x3Push index2of read-only memory onto stack. -
CALLVALUE(0x34):READROM 0x4Push index3of read-only memory onto stack. -
GASPRICE(0x3a):READROM 0x5Push index4of read-only memory onto stack. -
COINBASE(0x41):READROM 0x6Push index5of read-only memory onto stack. -
TIMESTAMP(0x42):READROM 0x7Push index6of read-only memory onto stack. -
NUMBER(0x43):READROM 0x8Push index7of read-only memory onto stack. -
DIFFICULTY(0x44):READROM 0x9Push index8of read-only memory onto stack. -
GASLIMIT(0x45):READROM 0xaPush index9of read-only memory onto stack. -
CHAINID(0x46):READROM 0xbPush index10of read-only memory onto stack. -
SELFBALANCE(0x47):READROM 0xcPush index11of read-only memory onto stack.
EVM Storage
The EVM Storage layer provides opcodes for access of a persistent storage:
-
Storage: External storage that can be read or write by the contract.
Opcodes SLOAD and SSTORE are defined in this layer.