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
JUMPDEST
position 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 0x0
Push index0
of read-only memory onto stack. -
ORIGIN
(0x32
):READROM 0x1
Push index1
of read-only memory onto stack. -
CALLER
(0x33
):READROM 0x3
Push index2
of read-only memory onto stack. -
CALLVALUE
(0x34
):READROM 0x4
Push index3
of read-only memory onto stack. -
GASPRICE
(0x3a
):READROM 0x5
Push index4
of read-only memory onto stack. -
COINBASE
(0x41
):READROM 0x6
Push index5
of read-only memory onto stack. -
TIMESTAMP
(0x42
):READROM 0x7
Push index6
of read-only memory onto stack. -
NUMBER
(0x43
):READROM 0x8
Push index7
of read-only memory onto stack. -
DIFFICULTY
(0x44
):READROM 0x9
Push index8
of read-only memory onto stack. -
GASLIMIT
(0x45
):READROM 0xa
Push index9
of read-only memory onto stack. -
CHAINID
(0x46
):READROM 0xb
Push index10
of read-only memory onto stack. -
SELFBALANCE
(0x47
):READROM 0xc
Push index11
of 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.