Ethereum VM (EVM) Opcodes and Instruction Reference

This reference consolidates EVM opcode information from the yellow paper, stack exchange, solidity source, parity source, evm-opcode-gas-costs and Manticore.

Notes

The size of a "word" in EVM is 256 bits.

The gas information is a work in progress. If an asterisk is in the Gas column, the base cost is shown but may vary based on the opcode arguments.

Table

OpcodeNameDescriptionExtra InfoGas
0x00STOPHalts execution-0
0x01ADDAddition operation-3
0x02MULMultiplication operation-5
0x03SUBSubtraction operation-3
0x04DIVInteger division operation-5
0x05SDIVSigned integer division operation (truncated)-5
0x06MODModulo remainder operation-5
0x07SMODSigned modulo remainder operation-5
0x08ADDMODModulo addition operation-8
0x09MULMODModulo multiplication operation-8
0x0aEXPExponential operation-10*
0x0bSIGNEXTENDExtend length of two's complement signed integer-5
0x0c - 0x0fUnusedUnused-
0x10LTLess-than comparison-3
0x11GTGreater-than comparison-3
0x12SLTSigned less-than comparison-3
0x13SGTSigned greater-than comparison-3
0x14EQEquality comparison-3
0x15ISZEROSimple not operator-3
0x16ANDBitwise AND operation-3
0x17ORBitwise OR operation-3
0x18XORBitwise XOR operation-3
0x19NOTBitwise NOT operation-3
0x1aBYTERetrieve single byte from word-3
0x1bSHLShift LeftEIP1453
0x1cSHRLogical Shift RightEIP1453
0x1dSARArithmetic Shift RightEIP1453
0x20KECCAK256Compute Keccak-256 hash-30*
0x21 - 0x2fUnusedUnused
0x30ADDRESSGet address of currently executing account-2
0x31BALANCEGet balance of the given account-700
0x32ORIGINGet execution origination address-2
0x33CALLERGet caller address-2
0x34CALLVALUEGet deposited value by the instruction/transaction responsible for this execution-2
0x35CALLDATALOADGet input data of current environment-3
0x36CALLDATASIZEGet size of input data in current environment-2*
0x37CALLDATACOPYCopy input data in current environment to memory-3
0x38CODESIZEGet size of code running in current environment-2
0x39CODECOPYCopy code running in current environment to memory-3*
0x3aGASPRICEGet price of gas in current environment-2
0x3bEXTCODESIZEGet size of an account's code-700
0x3cEXTCODECOPYCopy an account's code to memory-700*
0x3dRETURNDATASIZEPushes the size of the return data buffer onto the stackEIP 2112
0x3eRETURNDATACOPYCopies data from the return data buffer to memoryEIP 2113
0x3fEXTCODEHASHReturns the keccak256 hash of a contract's codeEIP 1052700
0x40BLOCKHASHGet the hash of one of the 256 most recent complete blocks-20
0x41COINBASEGet the block's beneficiary address-2
0x42TIMESTAMPGet the block's timestamp-2
0x43NUMBERGet the block's number-2
0x44DIFFICULTYGet the block's difficulty-2
0x45GASLIMITGet the block's gas limit-2
0x46CHAINIDReturns the current chain’s EIP-155 unique identifierEIP 13442
0x47 - 0x4fUnused-
0x48BASEFEEReturns the value of the base fee of the current block it is executing in.EIP 31982
0x50POPRemove word from stack-2
0x51MLOADLoad word from memory-3*
0x52MSTORESave word to memory-3*
0x53MSTORE8Save byte to memory-3
0x54SLOADLoad word from storage-800
0x55SSTORESave word to storage-20000**
0x56JUMPAlter the program counter-8
0x57JUMPIConditionally alter the program counter-10
0x58PCGet the value of the program counter prior to the increment-2
0x59MSIZEGet the size of active memory in bytes-2
0x5aGASGet the amount of available gas, including the corresponding reduction for the cost of this instruction-2
0x5bJUMPDESTMark a valid destination for jumps-1
0x5c - 0x5eUnused-
0x5fPUSH0Place the constant value 0 on stackEIP-38552
0x60PUSH1Place 1 byte item on stack-3
0x61PUSH2Place 2-byte item on stack-3
0x62PUSH3Place 3-byte item on stack-3
0x63PUSH4Place 4-byte item on stack-3
0x64PUSH5Place 5-byte item on stack-3
0x65PUSH6Place 6-byte item on stack-3
0x66PUSH7Place 7-byte item on stack-3
0x67PUSH8Place 8-byte item on stack-3
0x68PUSH9Place 9-byte item on stack-3
0x69PUSH10Place 10-byte item on stack-3
0x6aPUSH11Place 11-byte item on stack-3
0x6bPUSH12Place 12-byte item on stack-3
0x6cPUSH13Place 13-byte item on stack-3
0x6dPUSH14Place 14-byte item on stack-3
0x6ePUSH15Place 15-byte item on stack-3
0x6fPUSH16Place 16-byte item on stack-3
0x70PUSH17Place 17-byte item on stack-3
0x71PUSH18Place 18-byte item on stack-3
0x72PUSH19Place 19-byte item on stack-3
0x73PUSH20Place 20-byte item on stack-3
0x74PUSH21Place 21-byte item on stack-3
0x75PUSH22Place 22-byte item on stack-3
0x76PUSH23Place 23-byte item on stack-3
0x77PUSH24Place 24-byte item on stack-3
0x78PUSH25Place 25-byte item on stack-3
0x79PUSH26Place 26-byte item on stack-3
0x7aPUSH27Place 27-byte item on stack-3
0x7bPUSH28Place 28-byte item on stack-3
0x7cPUSH29Place 29-byte item on stack-3
0x7dPUSH30Place 30-byte item on stack-3
0x7ePUSH31Place 31-byte item on stack-3
0x7fPUSH32Place 32-byte (full word) item on stack-3
0x80DUP1Duplicate 1st stack item-3
0x81DUP2Duplicate 2nd stack item-3
0x82DUP3Duplicate 3rd stack item-3
0x83DUP4Duplicate 4th stack item-3
0x84DUP5Duplicate 5th stack item-3
0x85DUP6Duplicate 6th stack item-3
0x86DUP7Duplicate 7th stack item-3
0x87DUP8Duplicate 8th stack item-3
0x88DUP9Duplicate 9th stack item-3
0x89DUP10Duplicate 10th stack item-3
0x8aDUP11Duplicate 11th stack item-3
0x8bDUP12Duplicate 12th stack item-3
0x8cDUP13Duplicate 13th stack item-3
0x8dDUP14Duplicate 14th stack item-3
0x8eDUP15Duplicate 15th stack item-3
0x8fDUP16Duplicate 16th stack item-3
0x90SWAP1Exchange 1st and 2nd stack items-3
0x91SWAP2Exchange 1st and 3rd stack items-3
0x92SWAP3Exchange 1st and 4th stack items-3
0x93SWAP4Exchange 1st and 5th stack items-3
0x94SWAP5Exchange 1st and 6th stack items-3
0x95SWAP6Exchange 1st and 7th stack items-3
0x96SWAP7Exchange 1st and 8th stack items-3
0x97SWAP8Exchange 1st and 9th stack items-3
0x98SWAP9Exchange 1st and 10th stack items-3
0x99SWAP10Exchange 1st and 11th stack items-3
0x9aSWAP11Exchange 1st and 12th stack items-3
0x9bSWAP12Exchange 1st and 13th stack items-3
0x9cSWAP13Exchange 1st and 14th stack items-3
0x9dSWAP14Exchange 1st and 15th stack items-3
0x9eSWAP15Exchange 1st and 16th stack items-3
0x9fSWAP16Exchange 1st and 17th stack items-3
0xa0LOG0Append log record with no topics-375
0xa1LOG1Append log record with one topic-750
0xa2LOG2Append log record with two topics-1125
0xa3LOG3Append log record with three topics-1500
0xa4LOG4Append log record with four topics-1875
0xa5 - 0xafUnused-
0xb0JUMPTOTentative libevmasm has different numbersEIP 615
0xb1JUMPIFTentativeEIP 615
0xb2JUMPSUBTentativeEIP 615
0xb4JUMPSUBVTentativeEIP 615
0xb5BEGINSUBTentativeEIP 615
0xb6BEGINDATATentativeEIP 615
0xb8RETURNSUBTentativeEIP 615
0xb9PUTLOCALTentativeEIP 615
0xbaGETLOCALTentativeEIP 615
0xbb - 0xe0Unused-
0xe1SLOADBYTESOnly referenced in pyethereum--
0xe2SSTOREBYTESOnly referenced in pyethereum--
0xe3SSIZEOnly referenced in pyethereum--
0xe4 - 0xefUnused-
0xf0CREATECreate a new account with associated code-32000
0xf1CALLMessage-call into an account-Complicated
0xf2CALLCODEMessage-call into this account with alternative account's code-Complicated
0xf3RETURNHalt execution returning output data-0
0xf4DELEGATECALLMessage-call into this account with an alternative account's code, but persisting into this account with an alternative account's code-Complicated
0xf5CREATE2Create a new account and set creation address to sha3(sender + sha3(init code)) % 2**160-
0xf6 - 0xf9Unused--
0xfaSTATICCALLSimilar to CALL, but does not modify state-40
0xfbUnused--
0xfdREVERTStop execution and revert state changes, without consuming all provided gas and providing a reason-0
0xfeINVALIDDesignated invalid instruction-0
0xffSELFDESTRUCTHalt execution and register account for later deletion-5000*

Instruction Details


STOP

0x00

() => ()

halts execution


ADD

0x01

Takes two words from stack, adds them, then pushes the result onto the stack.

(a, b) => (c)

c = a + b


MUL

0x02

(a, b) => (c)

c = a * b


SUB

0x03

(a, b) => (c)

c = a - b


DIV

0x04

(a, b) => (c)

c = a / b


SDIV

0x05

(a: int256, b: int256) => (c: int256)

c = a / b


MOD

0x06

(a, b) => (c)

c = a % b


SMOD

0x07

(a: int256, b: int256) => (c: int256)

c = a % b


ADDMOD

0x08

(a, b, m) => (c)

c = (a + b) % m


MULMOD

0x09

(a, b, m) => (c)

c = (a * b) % m


EXP

0x0a

(a, b, m) => (c)

c = (a * b) % m


SIGNEXTEND

0x0b

(b, x) => (y)

y = SIGNEXTEND(x, b)

sign extends x from (b + 1) * 8 bits to 256 bits.


LT

0x10

(a, b) => (c)

c = a < b

all values interpreted as uint256


GT

0x11

(a, b) => (c)

c = a > b

all values interpreted as uint256


SLT

0x12

(a, b) => (c)

c = a < b

all values interpreted as int256


SGT

0x13

(a, b) => (c)

c = a > b

all values interpreted as int256


EQ

0x14

Pops 2 elements off the stack and pushes the value 1 to the stack in case they're equal, otherwise the value 0.

(a, b) => (c)

c = a == b


ISZERO

0x15

(a) => (c)

c = a == 0


AND

0x16

(a, b) => (c)

c = a & b


OR

0x17

(a, b) => (c)

c = a | b


XOR

0x18

(a, b) => (c)

c = a ^ b


NOT

0x19

(a) => (c)

c = ~a


BYTE

0x1a

(i, x) => (y)

y = (x >> (248 - i * 8) & 0xff


SHL

0x1b

Pops 2 elements from the stack and pushes the second element onto the stack shifted left by the shift amount (first element).

(shift, value) => (res)

res = value << shift


SHR

0x1c

Pops 2 elements from the stack and pushes the second element onto the stack shifted right by the shift amount (first element).

(shift, value) => (res)

res = value >> shift


SAR

0x1d

(shift, value) => (res)

res = value >> shift

value: int256


KECCAK256

0x20

(offset, len) => (hash)

hash = keccak256(memory[offset:offset+len])


ADDRESS

0x30

() => (address(this))


BALANCE

0x31

() => (address(this).balance)


ORIGIN

0x32

() => (tx.origin)


CALLER

0x33

() => (msg.sender)


CALLVALUE

0x34

() => (msg.value)


CALLDATALOAD

0x35

(index) => (msg.data[index:index+32])


CALLDATASIZE

0x36

() => (msg.data.size)


CALLDATACOPY

0x37

(memOffset, offset, length) => ()

memory[memOffset:memOffset+len] = msg.data[offset:offset+len]


CODESIZE

0x38

() => (address(this).code.size)


CODECOPY

0x39

(memOffset, codeOffset, len) => ()

memory[memOffset:memOffset+len] = address(this).code[codeOffset:codeOffset+len]


GASPRICE

0x3a

() => (tx.gasprice)


EXTCODESIZE

0x3b

(addr) => (address(addr).code.size)


EXTCODECOPY

0x3c

(addr, memOffset, offset, length) => ()

memory[memOffset:memOffset+len] = address(addr).code[codeOffset:codeOffset+len]


RETURNDATASIZE

0x3d

() => (size)

size = RETURNDATASIZE()

The number of bytes that were returned from the last ext call


RETURNDATACOPY

0x3e

(memOffset, offset, length) => ()

memory[memOffset:memOffset+len] = RETURNDATA[codeOffset:codeOffset+len]

RETURNDATA is the data returned from the last external call


EXTCODEHASH

0x3f

(addr) => (hash)

hash = address(addr).exists ? keccak256(address(addr).code) : 0


BLOCKHASH

0x40

(number) => (hash)

hash = block.blockHash(number)


COINBASE

0x41

() => (block.coinbase)


TIMESTAMP

0x42

() => (block.timestamp)


NUMBER

0x43

() => (block.number)


DIFFICULTY

0x44

() => (block.difficulty)


GASLIMIT

0x45

() => (block.gaslimit)


CHAINID

0x46

() => (chainid)

where chainid = 1 for mainnet & some other value for other networks


SELFBALANCE

0x47

() => (address(this).balance)


BASEFEE

0x48

() => (block.basefee)

current block's base fee (related to EIP1559)


POP

0x50

(a) => ()

discards the top stack item


MLOAD

0x51

(offset) => (value)

value = memory[offset:offset+32]


MSTORE

0x52

Saves a word to the EVM memory. Pops 2 elements from stack - the first element being the word memory address where the saved value (second element popped from stack) will be stored.

(offset, value) => ()

memory[offset:offset+32] = value


MSTORE8

0x53

(offset, value) => ()

memory[offset:offset+32] = value & 0xff


SLOAD

0x54

Pops 1 element off the stack, that being the key which is the storage slot and returns the read value stored there.

(key) => (value)

value = storage[key]


SSTORE

0x55

Pops 2 elements off the stack, the first element being the key and the second being the value which is then stored at the storage slot represented from the first element (key).

(key, value) => ()

storage[key] = value


JUMP

0x56

(dest) => ()

pc = dest


JUMPI

0x57

Conditional - Pops 2 elements from the stack, the first element being the jump location and the second being the value 0 (false) or 1 (true). If the value’s 1 the PC will be altered and the jump executed. Otherwise, the value will be 0 and the PC will remain the same and execution unaltered.

(dest, cond) => ()

pc = cond ? dest : pc + 1


PC

0x58

() => (pc)


MSIZE

0x59

() => (memory.size)


GAS

0x5a

() => (gasRemaining)

not including the gas required for this opcode


JUMPDEST

0x5b

() => ()

noop, marks a valid jump destination


PUSH0

0x5f

The constant value 0 is pushed onto the stack.

() => (0)


PUSH1

0x60

The following byte is read from PC, placed into a word, then this word is pushed onto the stack.

() => (address(this).code[pc+1:pc+2])


PUSH2

0x61

() => (address(this).code[pc+2:pc+3])


PUSH3

0x62

() => (address(this).code[pc+3:pc+4])


PUSH4

0x63

() => (address(this).code[pc+4:pc+5])


PUSH5

0x64

() => (address(this).code[pc+5:pc+6])


PUSH6

0x65

() => (address(this).code[pc+6:pc+7])


PUSH7

0x66

() => (address(this).code[pc+7:pc+8])


PUSH8

0x67

() => (address(this).code[pc+8:pc+9])


PUSH9

0x68

() => (address(this).code[pc+9:pc+10])


PUSH10

0x69

() => (address(this).code[pc+10:pc+11])


PUSH11

0x6a

() => (address(this).code[pc+11:pc+12])


PUSH12

0x6b

() => (address(this).code[pc+12:pc+13])


PUSH13

0x6c

() => (address(this).code[pc+13:pc+14])


PUSH14

0x6d

() => (address(this).code[pc+14:pc+15])


PUSH15

0x6e

() => (address(this).code[pc+15:pc+16])


PUSH16

0x6f

() => (address(this).code[pc+16:pc+17])


PUSH17

0x70

() => (address(this).code[pc+17:pc+18])


PUSH18

0x71

() => (address(this).code[pc+18:pc+19])


PUSH19

0x72

() => (address(this).code[pc+19:pc+20])


PUSH20

0x73

() => (address(this).code[pc+20:pc+21])


PUSH21

0x74

() => (address(this).code[pc+21:pc+22])


PUSH22

0x75

() => (address(this).code[pc+22:pc+23])


PUSH23

0x76

() => (address(this).code[pc+23:pc+24])


PUSH24

0x77

() => (address(this).code[pc+24:pc+25])


PUSH25

0x78

() => (address(this).code[pc+25:pc+26])


PUSH26

0x79

() => (address(this).code[pc+26:pc+27])


PUSH27

0x7a

() => (address(this).code[pc+27:pc+28])


PUSH28

0x7b

() => (address(this).code[pc+28:pc+29])


PUSH29

0x7c

() => (address(this).code[pc+29:pc+30])


PUSH30

0x7d

() => (address(this).code[pc+30:pc+31])


PUSH31

0x7e

() => (address(this).code[pc+31:pc+32])


PUSH32

0x7f

() => (address(this).code[pc+32:pc+33])


DUP1

0x80

(1) => (1, 1)


DUP2

0x81

(1, 2) => (2, 1, 2)


DUP3

0x82

(1, 2, 3) => (3, 1, 2, 3)


DUP4

0x83

(1, ..., 4) => (4, 1, ..., 4)


DUP5

0x84

(1, ..., 5) => (5, 1, ..., 5)


DUP6

0x85

(1, ..., 6) => (6, 1, ..., 6)


DUP7

0x86

(1, ..., 7) => (7, 1, ..., 7)


DUP8

0x87

(1, ..., 8) => (8, 1, ..., 8)


DUP9

0x88

(1, ..., 9) => (9, 1, ..., 9)


DUP10

0x89

(1, ..., 10) => (10, 1, ..., 10)


DUP11

0x8a

(1, ..., 11) => (11, 1, ..., 11)


DUP12

0x8b

(1, ..., 12) => (12, 1, ..., 12)


DUP13

0x8c

(1, ..., 13) => (13, 1, ..., 13)


DUP14

0x8d

(1, ..., 14) => (14, 1, ..., 14)


DUP15

0x8e

(1, ..., 15) => (15, 1, ..., 15)


DUP16

0x8f

(1, ..., 16) => (16, 1, ..., 16)


SWAP1

0x90

(1, 2) => (2, 1)


SWAP2

0x91

(1, 2, 3) => (3, 2, 1)


SWAP3

0x92

(1, ..., 4) => (4, ..., 1)


SWAP4

0x93

(1, ..., 5) => (5, ..., 1)


SWAP5

0x94

(1, ..., 6) => (6, ..., 1)


SWAP6

0x95

(1, ..., 7) => (7, ..., 1)


SWAP7

0x96

(1, ..., 8) => (8, ..., 1)


SWAP8

0x97

(1, ..., 9) => (9, ..., 1)


SWAP9

0x98

(1, ..., 10) => (10, ..., 1)


SWAP10

0x99

(1, ..., 11) => (11, ..., 1)


SWAP11

0x9a

(1, ..., 12) => (12, ..., 1)


SWAP12

0x9b

(1, ..., 13) => (13, ..., 1)


SWAP13

0x9c

(1, ..., 14) => (14, ..., 1)


SWAP14

0x9d

(1, ..., 15) => (15, ..., 1)


SWAP15

0x9e

(1, ..., 16) => (16, ..., 1)


SWAP16

0x9f

(1, ..., 17) => (17, ..., 1)


LOG0

0xa0

(offset, length) => ()

emit(memory[offset:offset+length])


LOG1

0xa1

(offset, length, topic0) => ()

emit(memory[offset:offset+length], topic0)


LOG2

0xa2

(offset, length, topic0, topic1) => ()

emit(memory[offset:offset+length], topic0, topic1)


LOG3

0xa3

(offset, length, topic0, topic1, topic2) => ()

emit(memory[offset:offset+length], topic0, topic1, topic2)


LOG4

0xa4

(offset, length, topic0, topic1, topic2, topic3) => ()

emit(memory[offset:offset+length], topic0, topic1, topic2, topic3)


CREATE

0xf0

(value, offset, length) => (addr)

addr = keccak256(rlp([address(this), this.nonce]))[12:] addr.code = exec(memory[offset:offset+length]) addr.balance += value this.balance -= value this.nonce += 1


CALL

0xf1

(gas, addr, value, argsOffset, argsLength, retOffset, retLength) => (success)

memory[retOffset:retOffset+retLength] = address(addr).callcode.gas(gas).value(value)(memory[argsOffset:argsOffset+argsLength]) success = true (unless the prev call reverted)


CALLCODE

0xf2

(gas, addr, value, argsOffset, argsLength, retOffset, retLength) => (success)

memory[retOffset:retOffset+retLength] = address(addr).callcode.gas(gas).value(value)(memory[argsOffset:argsOffset+argsLength]) success = true (unless the prev call reverted)

TODO: what's the difference between this & CALL?


RETURN

0xf3

(offset, length) => ()

return memory[offset:offset+length]


DELEGATECALL

0xf4

(gas, addr, argsOffset, argsLength, retOffset, retLength) => (success)

memory[retOffset:retOffset+retLength] = address(addr).delegatecall.gas(gas)(memory[argsOffset:argsOffset+argsLength]) success = true (unless the prev call reverted)


CREATE2

0xf5

(value, offset, length, salt) => (addr)

initCode = memory[offset:offset+length] addr = keccak256(0xff ++ address(this) ++ salt ++ keccak256(initCode))[12:] address(addr).code = exec(initCode)


STATICCALL

0xfa

(gas, addr, argsOffset, argsLength, retOffset, retLength) => (success)

memory[retOffset:retOffset+retLength] = address(addr).delegatecall.gas(gas)(memory[argsOffset:argsOffset+argsLength]) success = true (unless the prev call reverted)

TODO: what's the difference between this & DELEGATECALL?


REVERT

0xfd

(offset, length) => ()

revert(memory[offset:offset+length])


SELFDESTRUCT

0xff

(addr) => ()

address(addr).send(address(this).balance) this.code = 0