Ethereum  PoC-8
The C++ Implementation of Ethereum
Instruction.cpp
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 #include "Instruction.h"
19 #include <map>
20 
21 namespace dev
22 {
23 namespace eth
24 {
25 
26 static const std::map<Instruction, InstructionInfo> c_instructionInfo =
27 { // Args, Ret, GasPriceTier
28  { Instruction::STOP, { "STOP", 0, 0, Tier::Zero } },
29  { Instruction::ADD, { "ADD", 2, 1, Tier::VeryLow } },
30  { Instruction::SUB, { "SUB", 2, 1, Tier::VeryLow } },
31  { Instruction::MUL, { "MUL", 2, 1, Tier::Low } },
32  { Instruction::DIV, { "DIV", 2, 1, Tier::Low } },
33  { Instruction::SDIV, { "SDIV", 2, 1, Tier::Low } },
34  { Instruction::MOD, { "MOD", 2, 1, Tier::Low } },
35  { Instruction::SMOD, { "SMOD", 2, 1, Tier::Low } },
36  { Instruction::EXP, { "EXP", 2, 1, Tier::Special } },
37  { Instruction::NOT, { "NOT", 1, 1, Tier::VeryLow } },
38  { Instruction::LT, { "LT", 2, 1, Tier::VeryLow } },
39  { Instruction::GT, { "GT", 2, 1, Tier::VeryLow } },
40  { Instruction::SLT, { "SLT", 2, 1, Tier::VeryLow } },
41  { Instruction::SGT, { "SGT", 2, 1, Tier::VeryLow } },
42  { Instruction::EQ, { "EQ", 2, 1, Tier::VeryLow } },
43  { Instruction::ISZERO, { "ISZERO", 1, 1, Tier::VeryLow } },
44  { Instruction::AND, { "AND", 2, 1, Tier::VeryLow } },
45  { Instruction::OR, { "OR", 2, 1, Tier::VeryLow } },
46  { Instruction::XOR, { "XOR", 2, 1, Tier::VeryLow } },
47  { Instruction::BYTE, { "BYTE", 2, 1, Tier::VeryLow } },
48  { Instruction::SHL, { "SHL", 2, 1, Tier::VeryLow } },
49  { Instruction::SHR, { "SHR", 2, 1, Tier::VeryLow } },
50  { Instruction::SAR, { "SAR", 2, 1, Tier::VeryLow } },
51  { Instruction::ADDMOD, { "ADDMOD", 3, 1, Tier::Mid } },
52  { Instruction::MULMOD, { "MULMOD", 3, 1, Tier::Mid } },
53  { Instruction::SIGNEXTEND, { "SIGNEXTEND", 2, 1, Tier::Low } },
54  { Instruction::SHA3, { "SHA3", 2, 1, Tier::Special } },
55  { Instruction::ADDRESS, { "ADDRESS", 0, 1, Tier::Base } },
56  { Instruction::BALANCE, { "BALANCE", 1, 1, Tier::Special } },
57  { Instruction::ORIGIN, { "ORIGIN", 0, 1, Tier::Base } },
58  { Instruction::CALLER, { "CALLER", 0, 1, Tier::Base } },
59  { Instruction::CALLVALUE, { "CALLVALUE", 0, 1, Tier::Base } },
60  { Instruction::CALLDATALOAD, { "CALLDATALOAD", 1, 1, Tier::VeryLow } },
61  { Instruction::CALLDATASIZE, { "CALLDATASIZE", 0, 1, Tier::Base } },
62  { Instruction::CALLDATACOPY, { "CALLDATACOPY", 3, 0, Tier::VeryLow } },
63  { Instruction::CODESIZE, { "CODESIZE", 0, 1, Tier::Base } },
64  { Instruction::CODECOPY, { "CODECOPY", 3, 0, Tier::VeryLow } },
65  { Instruction::GASPRICE, { "GASPRICE", 0, 1, Tier::Base } },
66  { Instruction::EXTCODESIZE, { "EXTCODESIZE", 1, 1, Tier::Special } },
67  { Instruction::EXTCODECOPY, { "EXTCODECOPY", 4, 0, Tier::Special } },
68  { Instruction::RETURNDATASIZE,{"RETURNDATASIZE", 0, 1, Tier::Base } },
69  { Instruction::RETURNDATACOPY,{"RETURNDATACOPY", 3, 0, Tier::VeryLow } },
70  { Instruction::EXTCODEHASH, { "EXTCODEHASH", 1, 1, Tier::Special }},
71  { Instruction::BLOCKHASH, { "BLOCKHASH", 1, 1, Tier::Special } },
72  { Instruction::COINBASE, { "COINBASE", 0, 1, Tier::Base } },
73  { Instruction::TIMESTAMP, { "TIMESTAMP", 0, 1, Tier::Base } },
74  { Instruction::NUMBER, { "NUMBER", 0, 1, Tier::Base } },
75  { Instruction::DIFFICULTY, { "DIFFICULTY", 0, 1, Tier::Base } },
76  { Instruction::GASLIMIT, { "GASLIMIT", 0, 1, Tier::Base } },
77  { Instruction::POP, { "POP", 1, 0, Tier::Base } },
78  { Instruction::MLOAD, { "MLOAD", 1, 1, Tier::VeryLow } },
79  { Instruction::MSTORE, { "MSTORE", 2, 0, Tier::VeryLow } },
80  { Instruction::MSTORE8, { "MSTORE8", 2, 0, Tier::VeryLow } },
81  { Instruction::SLOAD, { "SLOAD", 1, 1, Tier::Special } },
82  { Instruction::SSTORE, { "SSTORE", 2, 0, Tier::Special } },
83  { Instruction::JUMP, { "JUMP", 1, 0, Tier::Mid } },
84  { Instruction::JUMPI, { "JUMPI", 2, 0, Tier::High } },
85  { Instruction::PC, { "PC", 0, 1, Tier::Base } },
86  { Instruction::MSIZE, { "MSIZE", 0, 1, Tier::Base } },
87  { Instruction::GAS, { "GAS", 0, 1, Tier::Base } },
88  { Instruction::JUMPDEST, { "JUMPDEST", 0, 0, Tier::Special } },
89  { Instruction::PUSH1, { "PUSH1", 0, 1, Tier::VeryLow } },
90  { Instruction::PUSH2, { "PUSH2", 0, 1, Tier::VeryLow } },
91  { Instruction::PUSH3, { "PUSH3", 0, 1, Tier::VeryLow } },
92  { Instruction::PUSH4, { "PUSH4", 0, 1, Tier::VeryLow } },
93  { Instruction::PUSH5, { "PUSH5", 0, 1, Tier::VeryLow } },
94  { Instruction::PUSH6, { "PUSH6", 0, 1, Tier::VeryLow } },
95  { Instruction::PUSH7, { "PUSH7", 0, 1, Tier::VeryLow } },
96  { Instruction::PUSH8, { "PUSH8", 0, 1, Tier::VeryLow } },
97  { Instruction::PUSH9, { "PUSH9", 0, 1, Tier::VeryLow } },
98  { Instruction::PUSH10, { "PUSH10", 0, 1, Tier::VeryLow } },
99  { Instruction::PUSH11, { "PUSH11", 0, 1, Tier::VeryLow } },
100  { Instruction::PUSH12, { "PUSH12", 0, 1, Tier::VeryLow } },
101  { Instruction::PUSH13, { "PUSH13", 0, 1, Tier::VeryLow } },
102  { Instruction::PUSH14, { "PUSH14", 0, 1, Tier::VeryLow } },
103  { Instruction::PUSH15, { "PUSH15", 0, 1, Tier::VeryLow } },
104  { Instruction::PUSH16, { "PUSH16", 0, 1, Tier::VeryLow } },
105  { Instruction::PUSH17, { "PUSH17", 0, 1, Tier::VeryLow } },
106  { Instruction::PUSH18, { "PUSH18", 0, 1, Tier::VeryLow } },
107  { Instruction::PUSH19, { "PUSH19", 0, 1, Tier::VeryLow } },
108  { Instruction::PUSH20, { "PUSH20", 0, 1, Tier::VeryLow } },
109  { Instruction::PUSH21, { "PUSH21", 0, 1, Tier::VeryLow } },
110  { Instruction::PUSH22, { "PUSH22", 0, 1, Tier::VeryLow } },
111  { Instruction::PUSH23, { "PUSH23", 0, 1, Tier::VeryLow } },
112  { Instruction::PUSH24, { "PUSH24", 0, 1, Tier::VeryLow } },
113  { Instruction::PUSH25, { "PUSH25", 0, 1, Tier::VeryLow } },
114  { Instruction::PUSH26, { "PUSH26", 0, 1, Tier::VeryLow } },
115  { Instruction::PUSH27, { "PUSH27", 0, 1, Tier::VeryLow } },
116  { Instruction::PUSH28, { "PUSH28", 0, 1, Tier::VeryLow } },
117  { Instruction::PUSH29, { "PUSH29", 0, 1, Tier::VeryLow } },
118  { Instruction::PUSH30, { "PUSH30", 0, 1, Tier::VeryLow } },
119  { Instruction::PUSH31, { "PUSH31", 0, 1, Tier::VeryLow } },
120  { Instruction::PUSH32, { "PUSH32", 0, 1, Tier::VeryLow } },
121  { Instruction::DUP1, { "DUP1", 1, 2, Tier::VeryLow } },
122  { Instruction::DUP2, { "DUP2", 2, 3, Tier::VeryLow } },
123  { Instruction::DUP3, { "DUP3", 3, 4, Tier::VeryLow } },
124  { Instruction::DUP4, { "DUP4", 4, 5, Tier::VeryLow } },
125  { Instruction::DUP5, { "DUP5", 5, 6, Tier::VeryLow } },
126  { Instruction::DUP6, { "DUP6", 6, 7, Tier::VeryLow } },
127  { Instruction::DUP7, { "DUP7", 7, 8, Tier::VeryLow } },
128  { Instruction::DUP8, { "DUP8", 8, 9, Tier::VeryLow } },
129  { Instruction::DUP9, { "DUP9", 9, 10, Tier::VeryLow } },
130  { Instruction::DUP10, { "DUP10", 10, 11, Tier::VeryLow } },
131  { Instruction::DUP11, { "DUP11", 11, 12, Tier::VeryLow } },
132  { Instruction::DUP12, { "DUP12", 12, 13, Tier::VeryLow } },
133  { Instruction::DUP13, { "DUP13", 13, 14, Tier::VeryLow } },
134  { Instruction::DUP14, { "DUP14", 14, 15, Tier::VeryLow } },
135  { Instruction::DUP15, { "DUP15", 15, 16, Tier::VeryLow } },
136  { Instruction::DUP16, { "DUP16", 16, 17, Tier::VeryLow } },
137  { Instruction::SWAP1, { "SWAP1", 2, 2, Tier::VeryLow } },
138  { Instruction::SWAP2, { "SWAP2", 3, 3, Tier::VeryLow } },
139  { Instruction::SWAP3, { "SWAP3", 4, 4, Tier::VeryLow } },
140  { Instruction::SWAP4, { "SWAP4", 5, 5, Tier::VeryLow } },
141  { Instruction::SWAP5, { "SWAP5", 6, 6, Tier::VeryLow } },
142  { Instruction::SWAP6, { "SWAP6", 7, 7, Tier::VeryLow } },
143  { Instruction::SWAP7, { "SWAP7", 8, 8, Tier::VeryLow } },
144  { Instruction::SWAP8, { "SWAP8", 9, 9, Tier::VeryLow } },
145  { Instruction::SWAP9, { "SWAP9", 10, 10, Tier::VeryLow } },
146  { Instruction::SWAP10, { "SWAP10", 11, 11, Tier::VeryLow } },
147  { Instruction::SWAP11, { "SWAP11", 12, 12, Tier::VeryLow } },
148  { Instruction::SWAP12, { "SWAP12", 13, 13, Tier::VeryLow } },
149  { Instruction::SWAP13, { "SWAP13", 14, 14, Tier::VeryLow } },
150  { Instruction::SWAP14, { "SWAP14", 15, 15, Tier::VeryLow } },
151  { Instruction::SWAP15, { "SWAP15", 16, 16, Tier::VeryLow } },
152  { Instruction::SWAP16, { "SWAP16", 17, 17, Tier::VeryLow } },
153  { Instruction::LOG0, { "LOG0", 2, 0, Tier::Special } },
154  { Instruction::LOG1, { "LOG1", 3, 0, Tier::Special } },
155  { Instruction::LOG2, { "LOG2", 4, 0, Tier::Special } },
156  { Instruction::LOG3, { "LOG3", 5, 0, Tier::Special } },
157  { Instruction::LOG4, { "LOG4", 6, 0, Tier::Special } },
158 
159  { Instruction::JUMPTO, { "JUMPTO", 1, 0, Tier::VeryLow } },
160  { Instruction::JUMPIF, { "JUMPIF", 2, 0, Tier::Low } },
161  { Instruction::JUMPV, { "JUMPV", 1, 0, Tier::Mid } },
162  { Instruction::JUMPSUB, { "JUMPSUB", 1, 0, Tier::Low } },
163  { Instruction::JUMPSUBV, { "JUMPSUBV", 1, 0, Tier::Mid } },
164  { Instruction::BEGINSUB, { "BEGINSUB", 0, 0, Tier::Special } },
165  { Instruction::BEGINDATA, { "BEGINDATA", 0, 0, Tier::Special } },
166  { Instruction::RETURNSUB, { "RETURNSUB", 1, 0, Tier::Mid } },
167  { Instruction::PUTLOCAL, { "PUTLOCAL", 1, 0, Tier::VeryLow } },
168  { Instruction::GETLOCAL, { "GETLOCAL", 0, 1, Tier::VeryLow } },
169 
170  { Instruction::XADD, { "XADD", 0, 0, Tier::Special } },
171  { Instruction::XMUL, { "XMUL", 2, 1, Tier::Special } },
172  { Instruction::XSUB, { "XSUB", 2, 1, Tier::Special } },
173  { Instruction::XDIV, { "XDIV", 2, 1, Tier::Special } },
174  { Instruction::XSDIV, { "XSDIV", 2, 1, Tier::Special } },
175  { Instruction::XMOD, { "XMOD", 2, 1, Tier::Special } },
176  { Instruction::XSMOD, { "XSMOD", 2, 1, Tier::Special } },
177  { Instruction::XLT, { "XLT", 2, 1, Tier::Special } },
178  { Instruction::XGT, { "XGT", 2, 1, Tier::Special } },
179  { Instruction::XSLT, { "XSLT", 2, 1, Tier::Special } },
180  { Instruction::XSGT, { "XSGT", 2, 1, Tier::Special } },
181  { Instruction::XEQ, { "XEQ", 2, 1, Tier::Special } },
182  { Instruction::XISZERO, { "XISZERO", 2, 1, Tier::Special } },
183  { Instruction::XAND, { "XAND", 1, 1, Tier::Special } },
184  { Instruction::XOOR, { "XOOR", 2, 1, Tier::Special } },
185  { Instruction::XXOR, { "XXOR", 2, 1, Tier::Special } },
186  { Instruction::XNOT, { "XNOT", 2, 1, Tier::Special } },
187  { Instruction::XSHL, { "XSHL", 2, 1, Tier::Special } },
188  { Instruction::XSHR, { "XSHR", 2, 1, Tier::Special } },
189  { Instruction::XSAR, { "XSAR", 2, 1, Tier::Special } },
190  { Instruction::XROL, { "XROL", 2, 1, Tier::Special } },
191  { Instruction::XROR, { "XROR", 2, 1, Tier::Special } },
192  { Instruction::XPUSH, { "XPUSH", 1, 1, Tier::VeryLow } },
193  { Instruction::XMLOAD, { "XMLOAD", 1, 1, Tier::VeryLow } },
194  { Instruction::XMSTORE, { "XMSTORE", 2, 0, Tier::VeryLow } },
195  { Instruction::XSLOAD, { "XSLOAD", 1, 1, Tier::Special } },
196  { Instruction::XSSTORE, { "XSSTORE", 2, 0, Tier::Special } },
197  { Instruction::XVTOWIDE, { "XVTOWIDE", 1, 1, Tier::VeryLow } },
198  { Instruction::XWIDETOV, { "XWIDETOV", 1, 1, Tier::VeryLow } },
199  { Instruction::XPUT, { "XPUT", 3, 1, Tier::Special } },
200  { Instruction::XGET, { "XGET", 2, 1, Tier::Special } },
201  { Instruction::XSWIZZLE, { "XSWIZZLE", 2, 1, Tier::Special } },
202  { Instruction::XSHUFFLE, { "XSHUFFLE", 3, 1, Tier::Special } },
203  { Instruction::CREATE, { "CREATE", 3, 1, Tier::Special } },
204  { Instruction::CREATE2, { "CREATE2", 4, 1, Tier::Special } },
205  { Instruction::CALL, { "CALL", 7, 1, Tier::Special } },
206  { Instruction::CALLCODE, { "CALLCODE", 7, 1, Tier::Special } },
207  { Instruction::RETURN, { "RETURN", 2, 0, Tier::Zero } },
208  { Instruction::STATICCALL, { "STATICCALL", 6, 1, Tier::Special } },
209  { Instruction::DELEGATECALL, { "DELEGATECALL", 6, 1, Tier::Special } },
210  { Instruction::REVERT, { "REVERT", 2, 0, Tier::Special } },
211  { Instruction::INVALID, { "INVALID", 0, 0, Tier::Zero } },
212  { Instruction::SUICIDE, { "SUICIDE", 1, 0, Tier::Special } },
213 
214  // these are generated by the interpreter - should never be in user code
215  { Instruction::PUSHC, { "PUSHC", 0, 1, Tier::VeryLow } },
216  { Instruction::JUMPC, { "JUMPC", 1, 0, Tier::Mid } },
217  { Instruction::JUMPCI, { "JUMPCI", 2, 0, Tier::High } },
218 };
219 
221 {
222  auto it = c_instructionInfo.find(_inst);
223  if (it != c_instructionInfo.end())
224  return it->second;
225  return InstructionInfo{{}, 0, 0, Tier::Invalid};
226 }
227 
228 
229 }
230 }
signed greater-than comparision
set a potential jumpsub destination
bitwise XOR operation
place 17 byte item on stack
bitwise OR operation
Definition: Address.cpp:20
exponential operation
unsigned modular addition
place 10 byte item on stack
copies the 14th highest item in the stack to the top of the stack
get external code size (from another contract)
place 28 byte item on stack
return to subroutine jumped from
place 19 byte item on stack
unsigned modular multiplication
get the block&#39;s timestamp
place 1 byte item on stack
modulo remainder operation
place 27 byte item on stack
place 31 byte item on stack
dedicated invalid instruction
conditionally alter the program counter
place 13 byte item on stack
convert vector to wide integer
alter the program counter to a beginsub
copy input data in current environment to memory
conditionally alter the program counter
place 2 byte item on stack
addition operation
retrieve single byte from word
get external code hash
shift arithmetic right opertation
arithmetic shift right operation
place 6 byte item on stack
place 20 byte item on stack
load vector from storage
signed modulo remainder operation
swaps the highest and 6th highest value on the stack
swaps the highest and 9th highest value on the stack
get execution origination address
shift left opertation
create a new account with associated code. sha3((sender + salt + code)
Makes a log entry; 4 topics.
get the block&#39;s number
swaps the highest and 15th highest value on the stack
equality comparision
swaps the highest and 11th highest value on the stack
swaps the highest and 13th highest value on the stack
integer division operation
copies the 9th highest item in the stack to the top of the stack
swaps the highest and 17th highest value on the stack
get the block&#39;s coinbase address
simple not operator
set a potential jump destination
push local variable to top of stack
swaps the highest and 7th highest value on the stack
get input data of current environment
signed less-than comparision
bitwise OR operation
place 30 byte item on stack
place 12 byte item on stack
save byte to memory
greater-than comparision
addition operation
copies the 5th highest item in the stack to the top of the stack
halt execution and register account for later deletion
place 8 byte item on stack
swaps the highest and third highest value on the stack
signed integer division operation
load word from storage
swaps the highest and 4th highest value on the stack
save vector to memory
copies the 16th highest item in the stack to the top of the stack
place 29 byte item on stack
signed less-than comparision
InstructionInfo instructionInfo(Instruction _inst)
Information on all the instructions.
halt execution returning output data
conditionally alter the program counter - pre-verified
copies the 10th highest item in the stack to the top of the stack
get address of currently executing account
place 25 byte item on stack
place 26 byte item on stack
remove item from stack
get hash of most recent complete block
alter the program counter - pre-verified
get the program counter
copies the 6th highest item in the stack to the top of the stack
copies the third highest item in the stack to the top of the stack
swaps the highest and 14th highest value on the stack
greater-than comparision
get size of code running in current environment
rotate right opertation
place 16 byte item on stack
copies the highest item in the stack to the top of the stack
Makes a log entry; no topics.
get the size of active memory
copies the 8th highest item in the stack to the top of the stack
copies the second highest item in the stack to the top of the stack
get the block&#39;s gas limit
place 3 byte item on stack
copy data returned from previous call to memory
place 11 byte item on stack
get balance of the given account
save word to storage
message-call with another account&#39;s code only
less-than comparision
load vector from memory
equality comparision
permute data in two vectors
compute SHA3-256 hash
get size of input data in current environment
extend length of signed integer
permute data in vector
place 18 byte item on stack
copy code running in current environment to memory
logical shift left operation
place 15 byte item on stack
bitwise AND operation
copies the 11th highest item in the stack to the top of the stack
signed modulo remainder operation
subtraction operation
mulitplication operation
swaps the highest and 10th highest value on the stack
swaps the highest and 5th highest value on the stack
like CALLCODE but keeps caller&#39;s value and sender
swaps the highest and 16th highest value on the stack
place 23 byte item on stack
size of data returned from previous call
Instruction
Virtual machine bytecode instruction.
Definition: Instruction.h:28
get the amount of available gas
swaps the highest and 12th highest value on the stack
bitwise AND operation
copies the 4th highest item in the stack to the top of the stack
put data in vector
get data from vector
copy external code (from another contract)
alter the program counter to a beginsub
Information structure for a particular instruction.
Definition: Instruction.h:248
signed greater-than comparision
swaps the highest and 8th highest value on the stack
integer division operation
place 32 byte item on stack
place 22 byte item on stack
place 9 byte item on stack
get price of gas in current environment
logical shift right operation
alter the program counter to a jumpdest
swaps the highest and second highest value on the stack
convert wide integer to vector
Makes a log entry; 1 topic.
bitwise XOR operation
copies the 15th highest item in the stack to the top of the stack
place 14 byte item on stack
push vector to stack
message-call into an account
pop top of stack to local variable
get the block&#39;s difficulty
rotate left opertation
save word to memory
alter the program counter to a jumpdest
shift right opertation
stop execution and revert state changes, without consuming all provided gas
place 24 byte item on stack
place 7 byte item on stack
bitwise NOT opertation
save vector to storage
Makes a log entry; 3 topics.
less-than comparision
signed integer division operation
alter the program counter to a jumpdest
push value from constant pool
place 5 byte item on stack
copies the 12th highest item in the stack to the top of the stack
copies the 7th highest item in the stack to the top of the stack
begine the data section
load word from memory
subtraction operation
simple not operator
place 4 byte item on stack
bitwise NOT operation
modulo remainder operation
copies the 13th highest item in the stack to the top of the stack
place 21 byte item on stack
mulitplication operation
create a new account with associated code
Makes a log entry; 2 topics.