Ethereum  PoC-8
The C++ Implementation of Ethereum
Instruction.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #pragma once
19 
20 #include <cstdint>
21 
22 namespace dev
23 {
24 namespace eth
25 {
26 
28 enum class Instruction : uint8_t
29 {
30  STOP = 0x00,
31  ADD,
32  MUL,
33  SUB,
34  DIV,
35  SDIV,
36  MOD,
37  SMOD,
38  ADDMOD,
39  MULMOD,
40  EXP,
41  SIGNEXTEND,
42 
43  LT = 0x10,
44  GT,
45  SLT,
46  SGT,
47  EQ,
48  ISZERO,
49  AND,
50  OR,
51  XOR,
52  NOT,
53  BYTE,
54  SHL,
55  SHR,
56  SAR,
57 
58  SHA3 = 0x20,
59 
60  ADDRESS = 0x30,
61  BALANCE,
62  ORIGIN,
63  CALLER,
64  CALLVALUE,
65  CALLDATALOAD,
67  CALLDATASIZE,
68  CALLDATACOPY,
69  CODESIZE,
70  CODECOPY,
71  GASPRICE,
72  EXTCODESIZE,
73  EXTCODECOPY,
74  RETURNDATASIZE = 0x3d,
75  RETURNDATACOPY = 0x3e,
76  EXTCODEHASH = 0x3f,
77 
78  BLOCKHASH = 0x40,
79  COINBASE,
80  TIMESTAMP,
81  NUMBER,
82  DIFFICULTY,
83  GASLIMIT,
84 
85  POP = 0x50,
86  MLOAD,
87  MSTORE,
88  MSTORE8,
89  SLOAD,
90  SSTORE,
91  JUMP,
92  JUMPI,
93  PC,
94  MSIZE,
95  GAS,
96  JUMPDEST,
97 
98  PUSH1 = 0x60,
99  PUSH2,
100  PUSH3,
101  PUSH4,
102  PUSH5,
103  PUSH6,
104  PUSH7,
105  PUSH8,
106  PUSH9,
107  PUSH10,
108  PUSH11,
109  PUSH12,
110  PUSH13,
111  PUSH14,
112  PUSH15,
113  PUSH16,
114  PUSH17,
115  PUSH18,
116  PUSH19,
117  PUSH20,
118  PUSH21,
119  PUSH22,
120  PUSH23,
121  PUSH24,
122  PUSH25,
123  PUSH26,
124  PUSH27,
125  PUSH28,
126  PUSH29,
127  PUSH30,
128  PUSH31,
129  PUSH32,
130 
131  DUP1 = 0x80,
132  DUP2,
133  DUP3,
134  DUP4,
135  DUP5,
136  DUP6,
137  DUP7,
138  DUP8,
139  DUP9,
140  DUP10,
141  DUP11,
142  DUP12,
143  DUP13,
144  DUP14,
145  DUP15,
146  DUP16,
147 
148  SWAP1 = 0x90,
149  SWAP2,
150  SWAP3,
151  SWAP4,
152  SWAP5,
153  SWAP6,
154  SWAP7,
155  SWAP8,
156  SWAP9,
157  SWAP10,
158  SWAP11,
159  SWAP12,
160  SWAP13,
161  SWAP14,
162  SWAP15,
163  SWAP16,
164 
165  LOG0 = 0xa0,
166  LOG1,
167  LOG2,
168  LOG3,
169  LOG4,
170 
171  // these are generated by the interpreter - should never be in user code
172  PUSHC = 0xac,
173  JUMPC,
174  JUMPCI,
175 
176  JUMPTO = 0xb0,
177  JUMPIF,
178  JUMPSUB,
179  JUMPV,
180  JUMPSUBV,
181  BEGINSUB,
182  BEGINDATA,
183  RETURNSUB,
184  PUTLOCAL,
185  GETLOCAL,
186 
187  XADD = 0xc1,
188  XMUL,
189  XSUB,
190  XDIV,
191  XSDIV,
192  XMOD,
193  XSMOD,
194  XLT = 0xd0,
195  XGT,
196  XSLT,
197  XSGT,
198  XEQ,
199  XISZERO,
200  XAND,
201  XOOR,
202  XXOR,
203  XNOT,
204  XSHL = 0xdb,
205  XSHR,
206  XSAR,
207  XROL,
208  XROR,
209  XPUSH = 0xe0,
210  XMLOAD,
211  XMSTORE,
212  XSLOAD = 0xe4,
213  XSSTORE,
214  XVTOWIDE,
215  XWIDETOV,
216  XGET,
217  XPUT,
218  XSWIZZLE,
219  XSHUFFLE,
220 
221  CREATE = 0xf0,
222  CALL,
223  CALLCODE,
224  RETURN,
225  DELEGATECALL,
226  CREATE2 = 0xf5,
227  STATICCALL = 0xfa,
228  REVERT = 0xfd,
230  INVALID = 0xfe,
231  SUICIDE = 0xff
232 };
233 
234 enum class Tier : unsigned
235 {
236  Zero = 0, // 0, Zero
237  Base, // 2, Quick
238  VeryLow, // 3, Fastest
239  Low, // 5, Fast
240  Mid, // 8, Mid
241  High, // 10, Slow
242  Ext, // 20, Ext
243  Special, // multiparam or otherwise special
244  Invalid // Invalid.
245 };
246 
249 {
250  char const* const name;
251  int const args;
252  int const ret;
254 };
255 
257 {
259  int args;
260  int ret;
261 };
262 
265 
266 }
267 }
dev::eth::Instruction::PUSH9
@ PUSH9
place 9 byte item on stack
dev::eth::Instruction::XSHR
@ XSHR
shift right opertation
dev::eth::Instruction::JUMPCI
@ JUMPCI
conditionally alter the program counter - pre-verified
dev::eth::Instruction::XSHL
@ XSHL
shift left opertation
dev::eth::Instruction::LOG0
@ LOG0
Makes a log entry; no topics.
dev::eth::Instruction::LOG3
@ LOG3
Makes a log entry; 3 topics.
dev::eth::Instruction::LOG4
@ LOG4
Makes a log entry; 4 topics.
dev::eth::Tier::Low
@ Low
dev::eth::Instruction::ADDRESS
@ ADDRESS
get address of currently executing account
dev::eth::Instruction::DIFFICULTY
@ DIFFICULTY
get the block's difficulty
dev::eth::Instruction::PUSH3
@ PUSH3
place 3 byte item on stack
dev::eth::Instruction::DUP16
@ DUP16
copies the 16th highest item in the stack to the top of the stack
dev::eth::Instruction::SLOAD
@ SLOAD
load word from storage
dev::eth::Instruction::XSHUFFLE
@ XSHUFFLE
permute data in two vectors
dev::eth::Tier
Tier
Definition: Instruction.h:235
dev::eth::Instruction::PUSH8
@ PUSH8
place 8 byte item on stack
dev::eth::Instruction::XMLOAD
@ XMLOAD
load vector from memory
dev::eth::Instruction::PUSH29
@ PUSH29
place 29 byte item on stack
dev::eth::Instruction::DUP10
@ DUP10
copies the 10th highest item in the stack to the top of the stack
dev::eth::Instruction::SWAP7
@ SWAP7
swaps the highest and 8th highest value on the stack
dev::eth::Instruction::SIGNEXTEND
@ SIGNEXTEND
extend length of signed integer
dev::eth::Instruction::CREATE
@ CREATE
create a new account with associated code
dev::eth::Instruction::POP
@ POP
remove item from stack
dev::eth::Instruction::CALLER
@ CALLER
get caller address
dev::eth::Instruction::XOR
@ XOR
bitwise XOR operation
dev::eth::Instruction::PUSH15
@ PUSH15
place 15 byte item on stack
dev::eth::Instruction::RETURNDATACOPY
@ RETURNDATACOPY
copy data returned from previous call to memory
dev::eth::Instruction::JUMPV
@ JUMPV
alter the program counter to a jumpdest
dev::eth::Instruction::DELEGATECALL
@ DELEGATECALL
like CALLCODE but keeps caller's value and sender
dev::eth::Instruction::SSTORE
@ SSTORE
save word to storage
dev::eth::Instruction::SWAP15
@ SWAP15
swaps the highest and 16th highest value on the stack
dev::eth::Instruction::LT
@ LT
less-than comparision
dev::eth::Instruction::PUSH18
@ PUSH18
place 18 byte item on stack
dev::eth::Instruction::DUP11
@ DUP11
copies the 11th highest item in the stack to the top of the stack
dev::eth::Instruction::XROR
@ XROR
rotate right opertation
dev::eth::Instruction::RETURN
@ RETURN
halt execution returning output data
dev::eth::Instruction::XLT
@ XLT
less-than comparision
dev::eth::Instruction::XXOR
@ XXOR
bitwise XOR operation
dev::eth::Instruction::PUSH11
@ PUSH11
place 11 byte item on stack
dev::eth::Instruction::AND
@ AND
bitwise AND operation
dev::eth::Instruction::OR
@ OR
bitwise OR operation
dev::eth::Instruction::LOG1
@ LOG1
Makes a log entry; 1 topic.
dev::eth::Instruction::SWAP13
@ SWAP13
swaps the highest and 14th highest value on the stack
dev::eth::Instruction::SAR
@ SAR
arithmetic shift right operation
dev::eth::Instruction::PUSH10
@ PUSH10
place 10 byte item on stack
dev::eth::Tier::Mid
@ Mid
dev::eth::Instruction::PUSHC
@ PUSHC
push value from constant pool
dev::eth::Instruction::PUSH21
@ PUSH21
place 21 byte item on stack
dev::eth::Instruction::XMOD
@ XMOD
modulo remainder operation
dev::eth::Instruction::STATICCALL
@ STATICCALL
dev::eth::InstructionInfo::ret
int const ret
Number of items placed (back) on the stack by this instruction, assuming args items were removed.
Definition: Instruction.h:252
dev::eth::Instruction::XSMOD
@ XSMOD
signed modulo remainder operation
dev::eth::Instruction::XSGT
@ XSGT
signed greater-than comparision
dev::eth::Instruction::BALANCE
@ BALANCE
get balance of the given account
dev::eth::Instruction::PUSH32
@ PUSH32
place 32 byte item on stack
dev::eth::Instruction::DUP1
@ DUP1
copies the highest item in the stack to the top of the stack
dev::eth::Instruction::CALLCODE
@ CALLCODE
message-call with another account's code only
dev::eth::Instruction::PUSH22
@ PUSH22
place 22 byte item on stack
dev::eth::Instruction::SWAP9
@ SWAP9
swaps the highest and 10th highest value on the stack
dev::eth::Instruction::SUB
@ SUB
subtraction operation
dev::eth::Instruction::DUP8
@ DUP8
copies the 8th highest item in the stack to the top of the stack
dev::eth::Instruction::MLOAD
@ MLOAD
load word from memory
dev::eth::Instruction::SHR
@ SHR
logical shift right operation
dev::eth::Instruction::XAND
@ XAND
bitwise AND operation
dev::eth::Instruction::CALLDATACOPY
@ CALLDATACOPY
copy input data in current environment to memory
dev::eth::Instruction::PUSH28
@ PUSH28
place 28 byte item on stack
dev::eth::Instruction::XPUT
@ XPUT
put data in vector
dev::eth::Instruction::RETURNSUB
@ RETURNSUB
return to subroutine jumped from
dev::eth::Tier::High
@ High
dev::eth::InstructionInfo::args
int const args
Number of items required on the stack for this instruction (and, for the purposes of ret,...
Definition: Instruction.h:251
dev::eth::Instruction::SWAP11
@ SWAP11
swaps the highest and 12th highest value on the stack
dev::eth::Tier::Base
@ Base
dev::eth::Instruction::MOD
@ MOD
modulo remainder operation
dev::eth::Instruction::JUMP
@ JUMP
alter the program counter to a jumpdest
dev::eth::Instruction::PUSH24
@ PUSH24
place 24 byte item on stack
dev::eth::Instruction::XSSTORE
@ XSSTORE
save vector to storage
dev::eth::Instruction::STOP
@ STOP
halts execution
dev::eth::InstructionMetric::ret
int ret
Definition: Instruction.h:260
dev::eth::Instruction::SWAP1
@ SWAP1
swaps the highest and second highest value on the stack
dev::eth::Instruction::SWAP4
@ SWAP4
swaps the highest and 5th highest value on the stack
dev::eth::Instruction::SMOD
@ SMOD
signed modulo remainder operation
dev::eth::Instruction::MUL
@ MUL
mulitplication operation
dev::eth::Instruction::DUP12
@ DUP12
copies the 12th highest item in the stack to the top of the stack
dev::eth::Instruction::DUP7
@ DUP7
copies the 7th highest item in the stack to the top of the stack
dev::eth::Instruction::XGT
@ XGT
greater-than comparision
dev::eth::Instruction::DUP5
@ DUP5
copies the 5th highest item in the stack to the top of the stack
dev::eth::Instruction::SUICIDE
@ SUICIDE
halt execution and register account for later deletion
dev::eth::Instruction::XWIDETOV
@ XWIDETOV
convert wide integer to vector
dev::eth::Instruction::GAS
@ GAS
get the amount of available gas
dev::eth::Instruction::PUSH19
@ PUSH19
place 19 byte item on stack
dev::eth::Instruction::SWAP14
@ SWAP14
swaps the highest and 15th highest value on the stack
dev::eth::Instruction::XPUSH
@ XPUSH
push vector to stack
dev::eth::Instruction::XGET
@ XGET
get data from vector
dev::eth::Instruction::PUSH27
@ PUSH27
place 27 byte item on stack
dev::eth::Instruction::JUMPI
@ JUMPI
conditionally alter the program counter
dev::eth::Instruction::SWAP8
@ SWAP8
swaps the highest and 9th highest value on the stack
dev::eth::Instruction::XMSTORE
@ XMSTORE
save vector to memory
dev::eth::Instruction::PUSH4
@ PUSH4
place 4 byte item on stack
dev::eth::Instruction::SWAP6
@ SWAP6
swaps the highest and 7th highest value on the stack
dev::eth::InstructionInfo
Information structure for a particular instruction.
Definition: Instruction.h:249
dev::eth::Instruction::SWAP5
@ SWAP5
swaps the highest and 6th highest value on the stack
dev::eth::Instruction::INVALID
@ INVALID
dedicated invalid instruction
dev::eth::Instruction::XMUL
@ XMUL
mulitplication operation
dev::eth::Instruction::JUMPC
@ JUMPC
alter the program counter - pre-verified
dev::eth::Instruction::MSTORE
@ MSTORE
save word to memory
dev::eth::Instruction::XROL
@ XROL
rotate left opertation
dev::eth::Instruction::DUP6
@ DUP6
copies the 6th highest item in the stack to the top of the stack
dev::eth::Tier::Ext
@ Ext
dev::eth::Instruction::JUMPTO
@ JUMPTO
alter the program counter to a jumpdest
dev::eth::Instruction::PUSH25
@ PUSH25
place 25 byte item on stack
dev::eth::Instruction::LOG2
@ LOG2
Makes a log entry; 2 topics.
dev::eth::Instruction::SDIV
@ SDIV
signed integer division operation
dev::eth::Instruction::PUSH7
@ PUSH7
place 7 byte item on stack
dev::eth::Instruction::COINBASE
@ COINBASE
get the block's coinbase address
dev::eth::Instruction::BEGINSUB
@ BEGINSUB
set a potential jumpsub destination
dev::eth::InstructionMetric::gasPriceTier
Tier gasPriceTier
Definition: Instruction.h:258
dev::eth::Instruction::XSLT
@ XSLT
signed less-than comparision
dev::eth::Instruction::DIV
@ DIV
integer division operation
dev::eth::Instruction::SWAP3
@ SWAP3
swaps the highest and 4th highest value on the stack
dev::eth::Instruction::GT
@ GT
greater-than comparision
dev::eth::Instruction::ISZERO
@ ISZERO
simple not operator
dev::eth::Instruction::NOT
@ NOT
bitwise NOT operation
dev::eth::Instruction::PUSH14
@ PUSH14
place 14 byte item on stack
dev::eth::Instruction::PUSH30
@ PUSH30
place 30 byte item on stack
dev::eth::InstructionInfo::gasPriceTier
Tier const gasPriceTier
Tier for gas pricing.
Definition: Instruction.h:253
dev::eth::Instruction::PUSH12
@ PUSH12
place 12 byte item on stack
dev::eth::Instruction::CALL
@ CALL
message-call into an account
dev::eth::Instruction::XADD
@ XADD
addition operation
dev::eth::Tier::Zero
@ Zero
dev::eth::Instruction::XSDIV
@ XSDIV
signed integer division operation
dev::eth::Instruction::EQ
@ EQ
equality comparision
dev::eth::Instruction::BEGINDATA
@ BEGINDATA
begine the data section
dev::eth::InstructionInfo::name
char const *const name
The name of the instruction.
Definition: Instruction.h:250
dev::eth::Instruction::XEQ
@ XEQ
equality comparision
dev::eth::Instruction::BLOCKHASH
@ BLOCKHASH
get hash of most recent complete block
dev::eth::InstructionMetric::args
int args
Definition: Instruction.h:259
dev::eth::Instruction
Instruction
Virtual machine bytecode instruction.
Definition: Instruction.h:29
dev::eth::Instruction::EXTCODESIZE
@ EXTCODESIZE
get external code size (from another contract)
dev::eth::Instruction::XSWIZZLE
@ XSWIZZLE
permute data in vector
dev::eth::Tier::VeryLow
@ VeryLow
dev::eth::Instruction::DUP9
@ DUP9
copies the 9th highest item in the stack to the top of the stack
dev::eth::Instruction::ADDMOD
@ ADDMOD
unsigned modular addition
dev::eth::Instruction::REVERT
@ REVERT
stop execution and revert state changes, without consuming all provided gas
dev::eth::Instruction::ADD
@ ADD
addition operation
dev::eth::Instruction::XSAR
@ XSAR
shift arithmetic right opertation
dev::eth::Instruction::CALLDATALOAD
@ CALLDATALOAD
get input data of current environment
dev::eth::Instruction::PUSH20
@ PUSH20
place 20 byte item on stack
dev::eth::Instruction::XNOT
@ XNOT
bitwise NOT opertation
dev::eth::Instruction::PUSH26
@ PUSH26
place 26 byte item on stack
dev::eth::Instruction::SHL
@ SHL
logical shift left operation
dev::eth::Instruction::EXP
@ EXP
exponential operation
dev::eth::Instruction::PUSH5
@ PUSH5
place 5 byte item on stack
dev::eth::Instruction::SGT
@ SGT
signed greater-than comparision
dev::eth::Instruction::DUP14
@ DUP14
copies the 14th highest item in the stack to the top of the stack
dev::eth::Instruction::PUSH2
@ PUSH2
place 2 byte item on stack
dev::eth::Instruction::SWAP10
@ SWAP10
swaps the highest and 11th highest value on the stack
dev::eth::Instruction::SWAP12
@ SWAP12
swaps the highest and 13th highest value on the stack
dev::eth::Instruction::SWAP2
@ SWAP2
swaps the highest and third highest value on the stack
dev::eth::Instruction::PUSH13
@ PUSH13
place 13 byte item on stack
dev::eth::Instruction::NUMBER
@ NUMBER
get the block's number
dev::eth::Instruction::XSUB
@ XSUB
subtraction operation
dev::eth::Instruction::CALLDATASIZE
@ CALLDATASIZE
get size of input data in current environment
dev::eth::Instruction::PUSH1
@ PUSH1
place 1 byte item on stack
dev::eth::Instruction::CODESIZE
@ CODESIZE
get size of code running in current environment
dev::eth::Instruction::XISZERO
@ XISZERO
simple not operator
dev::eth::Instruction::MULMOD
@ MULMOD
unsigned modular multiplication
dev
Definition: Address.cpp:21
dev::eth::Instruction::XSLOAD
@ XSLOAD
load vector from storage
dev::eth::Instruction::BYTE
@ BYTE
retrieve single byte from word
dev::eth::Instruction::DUP13
@ DUP13
copies the 13th highest item in the stack to the top of the stack
dev::eth::Instruction::PUSH31
@ PUSH31
place 31 byte item on stack
dev::eth::Instruction::GASPRICE
@ GASPRICE
get price of gas in current environment
dev::eth::Instruction::DUP2
@ DUP2
copies the second highest item in the stack to the top of the stack
dev::eth::Instruction::TIMESTAMP
@ TIMESTAMP
get the block's timestamp
dev::eth::Instruction::ORIGIN
@ ORIGIN
get execution origination address
dev::eth::Instruction::CODECOPY
@ CODECOPY
copy code running in current environment to memory
dev::eth::Instruction::PUSH17
@ PUSH17
place 17 byte item on stack
dev::eth::Tier::Invalid
@ Invalid
dev::eth::Instruction::SHA3
@ SHA3
compute SHA3-256 hash
dev::eth::Instruction::DUP3
@ DUP3
copies the third highest item in the stack to the top of the stack
dev::eth::instructionInfo
InstructionInfo instructionInfo(Instruction _inst)
Information on all the instructions.
Definition: Instruction.cpp:220
dev::eth::Instruction::XVTOWIDE
@ XVTOWIDE
convert vector to wide integer
dev::eth::Instruction::JUMPSUBV
@ JUMPSUBV
alter the program counter to a beginsub
dev::eth::InstructionMetric
Definition: Instruction.h:257
dev::eth::Instruction::MSTORE8
@ MSTORE8
save byte to memory
dev::eth::Instruction::RETURNDATASIZE
@ RETURNDATASIZE
size of data returned from previous call
dev::eth::Instruction::PUSH23
@ PUSH23
place 23 byte item on stack
dev::eth::Instruction::EXTCODEHASH
@ EXTCODEHASH
get external code hash
dev::eth::Instruction::PUSH16
@ PUSH16
place 16 byte item on stack
dev::eth::Instruction::JUMPIF
@ JUMPIF
conditionally alter the program counter
dev::eth::Instruction::PUSH6
@ PUSH6
place 6 byte item on stack
dev::eth::Instruction::MSIZE
@ MSIZE
get the size of active memory
dev::eth::Instruction::XDIV
@ XDIV
integer division operation
dev::eth::Instruction::JUMPDEST
@ JUMPDEST
set a potential jump destination
dev::eth::Instruction::GASLIMIT
@ GASLIMIT
get the block's gas limit
dev::eth::Instruction::SWAP16
@ SWAP16
swaps the highest and 17th highest value on the stack
dev::eth::Instruction::PUTLOCAL
@ PUTLOCAL
pop top of stack to local variable
dev::eth::Instruction::DUP4
@ DUP4
copies the 4th highest item in the stack to the top of the stack
dev::eth::Tier::Special
@ Special
dev::eth::Instruction::XOOR
@ XOOR
bitwise OR operation
dev::eth::Instruction::EXTCODECOPY
@ EXTCODECOPY
copy external code (from another contract)
dev::eth::Instruction::JUMPSUB
@ JUMPSUB
alter the program counter to a beginsub
dev::eth::Instruction::GETLOCAL
@ GETLOCAL
push local variable to top of stack
dev::eth::Instruction::SLT
@ SLT
signed less-than comparision
dev::eth::Instruction::CREATE2
@ CREATE2
create a new account with associated code. sha3((sender + salt + code)
dev::eth::Instruction::PC
@ PC
get the program counter
dev::eth::Instruction::DUP15
@ DUP15
copies the 15th highest item in the stack to the top of the stack
dev::eth::Instruction::CALLVALUE
@ CALLVALUE