Fabcoin Core  0.16.2
P2P Digital Currency
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 */
22 #include "Instruction.h"
23 
24 #include <functional>
25 #include <libdevcore/Common.h>
26 #include <libdevcore/CommonIO.h>
27 #include <libdevcore/Log.h>
28 using namespace std;
29 using namespace dev;
30 using namespace dev::eth;
31 
32 const std::map<std::string, Instruction> dev::eth::c_instructions =
33 {
34  { "STOP", Instruction::STOP },
35  { "ADD", Instruction::ADD },
36  { "SUB", Instruction::SUB },
37  { "MUL", Instruction::MUL },
38  { "DIV", Instruction::DIV },
39  { "SDIV", Instruction::SDIV },
40  { "MOD", Instruction::MOD },
41  { "SMOD", Instruction::SMOD },
42  { "EXP", Instruction::EXP },
43  { "BNOT", Instruction::NOT },
44  { "LT", Instruction::LT },
45  { "GT", Instruction::GT },
46  { "SLT", Instruction::SLT },
47  { "SGT", Instruction::SGT },
48  { "EQ", Instruction::EQ },
49  { "NOT", Instruction::ISZERO },
50  { "AND", Instruction::AND },
51  { "OR", Instruction::OR },
52  { "XOR", Instruction::XOR },
53  { "BYTE", Instruction::BYTE },
54  { "ADDMOD", Instruction::ADDMOD },
55  { "MULMOD", Instruction::MULMOD },
56  { "SIGNEXTEND", Instruction::SIGNEXTEND },
57  { "SHA3", Instruction::SHA3 },
58  { "ADDRESS", Instruction::ADDRESS },
59  { "BALANCE", Instruction::BALANCE },
60  { "ORIGIN", Instruction::ORIGIN },
61  { "CALLER", Instruction::CALLER },
62  { "CALLVALUE", Instruction::CALLVALUE },
63  { "CALLDATALOAD", Instruction::CALLDATALOAD },
64  { "CALLDATASIZE", Instruction::CALLDATASIZE },
65  { "CALLDATACOPY", Instruction::CALLDATACOPY },
66  { "CODESIZE", Instruction::CODESIZE },
67  { "CODECOPY", Instruction::CODECOPY },
68  { "GASPRICE", Instruction::GASPRICE },
69  { "EXTCODESIZE", Instruction::EXTCODESIZE },
70  { "EXTCODECOPY", Instruction::EXTCODECOPY },
71  { "BLOCKHASH", Instruction::BLOCKHASH },
72  { "COINBASE", Instruction::COINBASE },
73  { "TIMESTAMP", Instruction::TIMESTAMP },
74  { "NUMBER", Instruction::NUMBER },
75  { "DIFFICULTY", Instruction::DIFFICULTY },
76  { "GASLIMIT", Instruction::GASLIMIT },
77  { "JUMPTO", Instruction::JUMPTO },
78  { "JUMPIF", Instruction::JUMPTO },
79  { "JUMPSUB", Instruction::JUMPSUB },
80  { "JUMPV", Instruction::JUMPV },
81  { "JUMPSUBV", Instruction::JUMPSUBV },
82  { "RETURNSUB", Instruction::RETURNSUB },
83  { "POP", Instruction::POP },
84  { "MLOAD", Instruction::MLOAD },
85  { "MSTORE", Instruction::MSTORE },
86  { "MSTORE8", Instruction::MSTORE8 },
87  { "SLOAD", Instruction::SLOAD },
88  { "SSTORE", Instruction::SSTORE },
89  { "JUMP", Instruction::JUMP },
90  { "JUMPI", Instruction::JUMPI },
91  { "PC", Instruction::PC },
92  { "MSIZE", Instruction::MSIZE },
93  { "GAS", Instruction::GAS },
94  { "BEGIN", Instruction::JUMPDEST },
95  { "JUMPDEST", Instruction::JUMPDEST },
96  { "BEGINDATA", Instruction::BEGINDATA },
97  { "BEGINSUB", Instruction::BEGINSUB },
98  { "PUSH1", Instruction::PUSH1 },
99  { "PUSH2", Instruction::PUSH2 },
100  { "PUSH3", Instruction::PUSH3 },
101  { "PUSH4", Instruction::PUSH4 },
102  { "PUSH5", Instruction::PUSH5 },
103  { "PUSH6", Instruction::PUSH6 },
104  { "PUSH7", Instruction::PUSH7 },
105  { "PUSH8", Instruction::PUSH8 },
106  { "PUSH9", Instruction::PUSH9 },
107  { "PUSH10", Instruction::PUSH10 },
108  { "PUSH11", Instruction::PUSH11 },
109  { "PUSH12", Instruction::PUSH12 },
110  { "PUSH13", Instruction::PUSH13 },
111  { "PUSH14", Instruction::PUSH14 },
112  { "PUSH15", Instruction::PUSH15 },
113  { "PUSH16", Instruction::PUSH16 },
114  { "PUSH17", Instruction::PUSH17 },
115  { "PUSH18", Instruction::PUSH18 },
116  { "PUSH19", Instruction::PUSH19 },
117  { "PUSH20", Instruction::PUSH20 },
118  { "PUSH21", Instruction::PUSH21 },
119  { "PUSH22", Instruction::PUSH22 },
120  { "PUSH23", Instruction::PUSH23 },
121  { "PUSH24", Instruction::PUSH24 },
122  { "PUSH25", Instruction::PUSH25 },
123  { "PUSH26", Instruction::PUSH26 },
124  { "PUSH27", Instruction::PUSH27 },
125  { "PUSH28", Instruction::PUSH28 },
126  { "PUSH29", Instruction::PUSH29 },
127  { "PUSH30", Instruction::PUSH30 },
128  { "PUSH31", Instruction::PUSH31 },
129  { "PUSH32", Instruction::PUSH32 },
130  { "DUP1", Instruction::DUP1 },
131  { "DUP2", Instruction::DUP2 },
132  { "DUP3", Instruction::DUP3 },
133  { "DUP4", Instruction::DUP4 },
134  { "DUP5", Instruction::DUP5 },
135  { "DUP6", Instruction::DUP6 },
136  { "DUP7", Instruction::DUP7 },
137  { "DUP8", Instruction::DUP8 },
138  { "DUP9", Instruction::DUP9 },
139  { "DUP10", Instruction::DUP10 },
140  { "DUP11", Instruction::DUP11 },
141  { "DUP12", Instruction::DUP12 },
142  { "DUP13", Instruction::DUP13 },
143  { "DUP14", Instruction::DUP14 },
144  { "DUP15", Instruction::DUP15 },
145  { "DUP16", Instruction::DUP16 },
146  { "SWAP1", Instruction::SWAP1 },
147  { "SWAP2", Instruction::SWAP2 },
148  { "SWAP3", Instruction::SWAP3 },
149  { "SWAP4", Instruction::SWAP4 },
150  { "SWAP5", Instruction::SWAP5 },
151  { "SWAP6", Instruction::SWAP6 },
152  { "SWAP7", Instruction::SWAP7 },
153  { "SWAP8", Instruction::SWAP8 },
154  { "SWAP9", Instruction::SWAP9 },
155  { "SWAP10", Instruction::SWAP10 },
156  { "SWAP11", Instruction::SWAP11 },
157  { "SWAP12", Instruction::SWAP12 },
158  { "SWAP13", Instruction::SWAP13 },
159  { "SWAP14", Instruction::SWAP14 },
160  { "SWAP15", Instruction::SWAP15 },
161  { "SWAP16", Instruction::SWAP16 },
162  { "LOG0", Instruction::LOG0 },
163  { "LOG1", Instruction::LOG1 },
164  { "LOG2", Instruction::LOG2 },
165  { "LOG3", Instruction::LOG3 },
166  { "LOG4", Instruction::LOG4 },
167  { "CREATE", Instruction::CREATE },
168  { "CALL", Instruction::CALL },
169  { "CALLCODE", Instruction::CALLCODE },
170  { "RETURN", Instruction::RETURN },
171  { "DELEGATECALL", Instruction::DELEGATECALL },
172  { "SUICIDE", Instruction::SUICIDE },
173 
174  // these are generated by the interpreter - should never be in user code
175  { "PUSHC", Instruction::PUSHC },
176  { "JUMPC", Instruction::JUMPC },
177  { "JUMPCI", Instruction::JUMPCI }
178 };
179 
180 static const std::map<Instruction, InstructionInfo> c_instructionInfo =
181 { // Add, Args, Ret, SideEffects, GasPriceTier
182  { Instruction::STOP, { "STOP", 0, 0, 0, true, Tier::Zero } },
183  { Instruction::ADD, { "ADD", 0, 2, 1, false, Tier::VeryLow } },
184  { Instruction::SUB, { "SUB", 0, 2, 1, false, Tier::VeryLow } },
185  { Instruction::MUL, { "MUL", 0, 2, 1, false, Tier::Low } },
186  { Instruction::DIV, { "DIV", 0, 2, 1, false, Tier::Low } },
187  { Instruction::SDIV, { "SDIV", 0, 2, 1, false, Tier::Low } },
188  { Instruction::MOD, { "MOD", 0, 2, 1, false, Tier::Low } },
189  { Instruction::SMOD, { "SMOD", 0, 2, 1, false, Tier::Low } },
190  { Instruction::EXP, { "EXP", 0, 2, 1, false, Tier::Special } },
191  { Instruction::NOT, { "NOT", 0, 1, 1, false, Tier::VeryLow } },
192  { Instruction::LT, { "LT", 0, 2, 1, false, Tier::VeryLow } },
193  { Instruction::GT, { "GT", 0, 2, 1, false, Tier::VeryLow } },
194  { Instruction::SLT, { "SLT", 0, 2, 1, false, Tier::VeryLow } },
195  { Instruction::SGT, { "SGT", 0, 2, 1, false, Tier::VeryLow } },
196  { Instruction::EQ, { "EQ", 0, 2, 1, false, Tier::VeryLow } },
197  { Instruction::ISZERO, { "ISZERO", 0, 1, 1, false, Tier::VeryLow } },
198  { Instruction::AND, { "AND", 0, 2, 1, false, Tier::VeryLow } },
199  { Instruction::OR, { "OR", 0, 2, 1, false, Tier::VeryLow } },
200  { Instruction::XOR, { "XOR", 0, 2, 1, false, Tier::VeryLow } },
201  { Instruction::BYTE, { "BYTE", 0, 2, 1, false, Tier::VeryLow } },
202  { Instruction::ADDMOD, { "ADDMOD", 0, 3, 1, false, Tier::Mid } },
203  { Instruction::MULMOD, { "MULMOD", 0, 3, 1, false, Tier::Mid } },
204  { Instruction::SIGNEXTEND, { "SIGNEXTEND", 0, 2, 1, false, Tier::Low } },
205  { Instruction::SHA3, { "SHA3", 0, 2, 1, false, Tier::Special } },
206  { Instruction::ADDRESS, { "ADDRESS", 0, 0, 1, false, Tier::Base } },
207  { Instruction::BALANCE, { "BALANCE", 0, 1, 1, false, Tier::Special } },
208  { Instruction::ORIGIN, { "ORIGIN", 0, 0, 1, false, Tier::Base } },
209  { Instruction::CALLER, { "CALLER", 0, 0, 1, false, Tier::Base } },
210  { Instruction::CALLVALUE, { "CALLVALUE", 0, 0, 1, false, Tier::Base } },
211  { Instruction::CALLDATALOAD, { "CALLDATALOAD", 0, 1, 1, false, Tier::VeryLow } },
212  { Instruction::CALLDATASIZE, { "CALLDATASIZE", 0, 0, 1, false, Tier::Base } },
213  { Instruction::CALLDATACOPY, { "CALLDATACOPY", 0, 3, 0, true, Tier::VeryLow } },
214  { Instruction::CODESIZE, { "CODESIZE", 0, 0, 1, false, Tier::Base } },
215  { Instruction::CODECOPY, { "CODECOPY", 0, 3, 0, true, Tier::VeryLow } },
216  { Instruction::GASPRICE, { "GASPRICE", 0, 0, 1, false, Tier::Base } },
217  { Instruction::EXTCODESIZE, { "EXTCODESIZE", 0, 1, 1, false, Tier::Special } },
218  { Instruction::EXTCODECOPY, { "EXTCODECOPY", 0, 4, 0, true, Tier::Special } },
219  { Instruction::BLOCKHASH, { "BLOCKHASH", 0, 1, 1, false, Tier::Ext } },
220  { Instruction::COINBASE, { "COINBASE", 0, 0, 1, false, Tier::Base } },
221  { Instruction::TIMESTAMP, { "TIMESTAMP", 0, 0, 1, false, Tier::Base } },
222  { Instruction::NUMBER, { "NUMBER", 0, 0, 1, false, Tier::Base } },
223  { Instruction::DIFFICULTY, { "DIFFICULTY", 0, 0, 1, false, Tier::Base } },
224  { Instruction::GASLIMIT, { "GASLIMIT", 0, 0, 1, false, Tier::Base } },
225  { Instruction::JUMPTO, { "JUMPTO", 4, 1, 0, true, Tier::VeryLow } },
226  { Instruction::JUMPIF, { "JUMPIF", 4, 2, 0, true, Tier::Low } },
227  { Instruction::JUMPV, { "JUMPV", 4, 1, 0, true, Tier::Mid } },
228  { Instruction::JUMPSUB, { "JUMPSUB", 4, 1, 0, true, Tier::Low } },
229  { Instruction::JUMPSUBV, { "JUMPSUBV", 4, 1, 0, true, Tier::Mid } },
230  { Instruction::RETURNSUB, { "RETURNSUB", 0, 1, 0, true, Tier::Mid } },
231  { Instruction::POP, { "POP", 0, 1, 0, false, Tier::Base } },
232  { Instruction::MLOAD, { "MLOAD", 0, 1, 1, false, Tier::VeryLow } },
233  { Instruction::MSTORE, { "MSTORE", 0, 2, 0, true, Tier::VeryLow } },
234  { Instruction::MSTORE8, { "MSTORE8", 0, 2, 0, true, Tier::VeryLow } },
235  { Instruction::SLOAD, { "SLOAD", 0, 1, 1, false, Tier::Special } },
236  { Instruction::SSTORE, { "SSTORE", 0, 2, 0, true, Tier::Special } },
237  { Instruction::JUMP, { "JUMP", 0, 1, 0, true, Tier::Mid } },
238  { Instruction::JUMPI, { "JUMPI", 0, 2, 0, true, Tier::High } },
239  { Instruction::PC, { "PC", 0, 0, 1, false, Tier::Base } },
240  { Instruction::MSIZE, { "MSIZE", 0, 0, 1, false, Tier::Base } },
241  { Instruction::GAS, { "GAS", 0, 0, 1, false, Tier::Base } },
242  { Instruction::JUMPDEST, { "JUMPDEST", 0, 0, 0, true, Tier::Special } },
243  { Instruction::BEGINDATA, { "BEGINDATA", 0, 0, 0, true, Tier::Special } },
244  { Instruction::BEGINSUB, { "BEGINSUB", 0, 0, 0, true, Tier::Special } },
245  { Instruction::PUSH1, { "PUSH1", 1, 0, 1, false, Tier::VeryLow } },
246  { Instruction::PUSH2, { "PUSH2", 2, 0, 1, false, Tier::VeryLow } },
247  { Instruction::PUSH3, { "PUSH3", 3, 0, 1, false, Tier::VeryLow } },
248  { Instruction::PUSH4, { "PUSH4", 4, 0, 1, false, Tier::VeryLow } },
249  { Instruction::PUSH5, { "PUSH5", 5, 0, 1, false, Tier::VeryLow } },
250  { Instruction::PUSH6, { "PUSH6", 6, 0, 1, false, Tier::VeryLow } },
251  { Instruction::PUSH7, { "PUSH7", 7, 0, 1, false, Tier::VeryLow } },
252  { Instruction::PUSH8, { "PUSH8", 8, 0, 1, false, Tier::VeryLow } },
253  { Instruction::PUSH9, { "PUSH9", 9, 0, 1, false, Tier::VeryLow } },
254  { Instruction::PUSH10, { "PUSH10", 10, 0, 1, false, Tier::VeryLow } },
255  { Instruction::PUSH11, { "PUSH11", 11, 0, 1, false, Tier::VeryLow } },
256  { Instruction::PUSH12, { "PUSH12", 12, 0, 1, false, Tier::VeryLow } },
257  { Instruction::PUSH13, { "PUSH13", 13, 0, 1, false, Tier::VeryLow } },
258  { Instruction::PUSH14, { "PUSH14", 14, 0, 1, false, Tier::VeryLow } },
259  { Instruction::PUSH15, { "PUSH15", 15, 0, 1, false, Tier::VeryLow } },
260  { Instruction::PUSH16, { "PUSH16", 16, 0, 1, false, Tier::VeryLow } },
261  { Instruction::PUSH17, { "PUSH17", 17, 0, 1, false, Tier::VeryLow } },
262  { Instruction::PUSH18, { "PUSH18", 18, 0, 1, false, Tier::VeryLow } },
263  { Instruction::PUSH19, { "PUSH19", 19, 0, 1, false, Tier::VeryLow } },
264  { Instruction::PUSH20, { "PUSH20", 20, 0, 1, false, Tier::VeryLow } },
265  { Instruction::PUSH21, { "PUSH21", 21, 0, 1, false, Tier::VeryLow } },
266  { Instruction::PUSH22, { "PUSH22", 22, 0, 1, false, Tier::VeryLow } },
267  { Instruction::PUSH23, { "PUSH23", 23, 0, 1, false, Tier::VeryLow } },
268  { Instruction::PUSH24, { "PUSH24", 24, 0, 1, false, Tier::VeryLow } },
269  { Instruction::PUSH25, { "PUSH25", 25, 0, 1, false, Tier::VeryLow } },
270  { Instruction::PUSH26, { "PUSH26", 26, 0, 1, false, Tier::VeryLow } },
271  { Instruction::PUSH27, { "PUSH27", 27, 0, 1, false, Tier::VeryLow } },
272  { Instruction::PUSH28, { "PUSH28", 28, 0, 1, false, Tier::VeryLow } },
273  { Instruction::PUSH29, { "PUSH29", 29, 0, 1, false, Tier::VeryLow } },
274  { Instruction::PUSH30, { "PUSH30", 30, 0, 1, false, Tier::VeryLow } },
275  { Instruction::PUSH31, { "PUSH31", 31, 0, 1, false, Tier::VeryLow } },
276  { Instruction::PUSH32, { "PUSH32", 32, 0, 1, false, Tier::VeryLow } },
277  { Instruction::DUP1, { "DUP1", 0, 1, 2, false, Tier::VeryLow } },
278  { Instruction::DUP2, { "DUP2", 0, 2, 3, false, Tier::VeryLow } },
279  { Instruction::DUP3, { "DUP3", 0, 3, 4, false, Tier::VeryLow } },
280  { Instruction::DUP4, { "DUP4", 0, 4, 5, false, Tier::VeryLow } },
281  { Instruction::DUP5, { "DUP5", 0, 5, 6, false, Tier::VeryLow } },
282  { Instruction::DUP6, { "DUP6", 0, 6, 7, false, Tier::VeryLow } },
283  { Instruction::DUP7, { "DUP7", 0, 7, 8, false, Tier::VeryLow } },
284  { Instruction::DUP8, { "DUP8", 0, 8, 9, false, Tier::VeryLow } },
285  { Instruction::DUP9, { "DUP9", 0, 9, 10, false, Tier::VeryLow } },
286  { Instruction::DUP10, { "DUP10", 0, 10, 11, false, Tier::VeryLow } },
287  { Instruction::DUP11, { "DUP11", 0, 11, 12, false, Tier::VeryLow } },
288  { Instruction::DUP12, { "DUP12", 0, 12, 13, false, Tier::VeryLow } },
289  { Instruction::DUP13, { "DUP13", 0, 13, 14, false, Tier::VeryLow } },
290  { Instruction::DUP14, { "DUP14", 0, 14, 15, false, Tier::VeryLow } },
291  { Instruction::DUP15, { "DUP15", 0, 15, 16, false, Tier::VeryLow } },
292  { Instruction::DUP16, { "DUP16", 0, 16, 17, false, Tier::VeryLow } },
293  { Instruction::SWAP1, { "SWAP1", 0, 2, 2, false, Tier::VeryLow } },
294  { Instruction::SWAP2, { "SWAP2", 0, 3, 3, false, Tier::VeryLow } },
295  { Instruction::SWAP3, { "SWAP3", 0, 4, 4, false, Tier::VeryLow } },
296  { Instruction::SWAP4, { "SWAP4", 0, 5, 5, false, Tier::VeryLow } },
297  { Instruction::SWAP5, { "SWAP5", 0, 6, 6, false, Tier::VeryLow } },
298  { Instruction::SWAP6, { "SWAP6", 0, 7, 7, false, Tier::VeryLow } },
299  { Instruction::SWAP7, { "SWAP7", 0, 8, 8, false, Tier::VeryLow } },
300  { Instruction::SWAP8, { "SWAP8", 0, 9, 9, false, Tier::VeryLow } },
301  { Instruction::SWAP9, { "SWAP9", 0, 10, 10, false, Tier::VeryLow } },
302  { Instruction::SWAP10, { "SWAP10", 0, 11, 11, false, Tier::VeryLow } },
303  { Instruction::SWAP11, { "SWAP11", 0, 12, 12, false, Tier::VeryLow } },
304  { Instruction::SWAP12, { "SWAP12", 0, 13, 13, false, Tier::VeryLow } },
305  { Instruction::SWAP13, { "SWAP13", 0, 14, 14, false, Tier::VeryLow } },
306  { Instruction::SWAP14, { "SWAP14", 0, 15, 15, false, Tier::VeryLow } },
307  { Instruction::SWAP15, { "SWAP15", 0, 16, 16, false, Tier::VeryLow } },
308  { Instruction::SWAP16, { "SWAP16", 0, 17, 17, false, Tier::VeryLow } },
309  { Instruction::LOG0, { "LOG0", 0, 2, 0, true, Tier::Special } },
310  { Instruction::LOG1, { "LOG1", 0, 3, 0, true, Tier::Special } },
311  { Instruction::LOG2, { "LOG2", 0, 4, 0, true, Tier::Special } },
312  { Instruction::LOG3, { "LOG3", 0, 5, 0, true, Tier::Special } },
313  { Instruction::LOG4, { "LOG4", 0, 6, 0, true, Tier::Special } },
314  { Instruction::CREATE, { "CREATE", 0, 3, 1, true, Tier::Special } },
315  { Instruction::CALL, { "CALL", 0, 7, 1, true, Tier::Special } },
316  { Instruction::CALLCODE, { "CALLCODE", 0, 7, 1, true, Tier::Special } },
317  { Instruction::RETURN, { "RETURN", 0, 2, 0, true, Tier::Zero } },
318  { Instruction::DELEGATECALL,{ "DELEGATECALL", 0, 6, 1, true, Tier::Special } },
319  { Instruction::SUICIDE, { "SUICIDE", 0, 1, 0, true, Tier::Special } },
320 
321  // these are generated by the interpreter - should never be in user code
322  { Instruction::PUSHC, { "PUSHC", 2, 0 , 1, false, Tier::VeryLow } },
323  { Instruction::JUMPC, { "JUMPC", 0, 1, 0, true, Tier::Mid } },
324  { Instruction::JUMPCI, { "JUMPCI", 0, 1, 0, true, Tier::High } },
325  { Instruction::STOP, { "BAD", 0, 0, 0, true, Tier::Zero } },
326 };
327 
329  bytes const& _mem,
330  function<void(Instruction,u256 const&)> const& _onInstruction
331 )
332 {
333  for (auto it = _mem.begin(); it < _mem.end(); ++it)
334  {
335  Instruction instr = Instruction(*it);
336  size_t additional = 0;
337  if (isValidInstruction(instr))
338  additional = instructionInfo(instr).additional;
339  u256 data;
340  for (size_t i = 0; i < additional; ++i)
341  {
342  data <<= 8;
343  if (++it < _mem.end())
344  data |= *it;
345  }
346  _onInstruction(instr, data);
347  }
348 }
349 
350 string dev::eth::disassemble(bytes const& _mem)
351 {
352  stringstream ret;
353  eachInstruction(_mem, [&](Instruction _instr, u256 const& _data) {
354  if (!isValidInstruction(_instr))
355  ret << "0x" << hex << int(_instr) << " ";
356  else
357  {
358  InstructionInfo info = instructionInfo(_instr);
359  ret << info.name << " ";
360  if (info.additional)
361  ret << "0x" << hex << _data << " ";
362  }
363  });
364  return ret.str();
365 }
366 
368 {
369  auto it = c_instructionInfo.find(_inst);
370  if (it != c_instructionInfo.end())
371  return it->second;
372  return InstructionInfo({{}, 0, 0, 0, false, Tier::Invalid});
373 }
374 
376 {
377  return !!c_instructionInfo.count(_inst);
378 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
void eachInstruction(bytes const &_mem, std::function< void(Instruction, u256 const &)> const &_onInstruction)
Iterate through EVM code and call a function on each instruction.
#define OR
Definition: lubyrack.h:61
#define MUL(a, b)
Definition: idea.cpp:154
std::hash for asio::adress
Definition: Common.h:323
Instruction
Virtual machine bytecode instruction.
Definition: Instruction.h:16
#define LT(i, a, b, c, d, e)
Definition: serpentp.h:6
InstructionInfo instructionInfo(Instruction _inst)
Information on all the instructions.
bool isValidInstruction(Instruction _inst)
check whether instructions exists
std::string name
The name of the instruction.
Definition: Instruction.h:260
#define MSIZE
Definition: lockedpool.cpp:14
std::vector< byte > bytes
Definition: Common.h:75
const std::map< std::string, Instruction > c_instructions
Convert from string mnemonic to Instruction type.
Definition: Instruction.cpp:32
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
Instruction
Virtual machine bytecode instruction.
Definition: Instruction.h:39
Information structure for a particular instruction.
Definition: Instruction.h:258
int additional
Additional items required in memory for this instructions (only for PUSH).
Definition: Instruction.h:261
#define EXP(x)
Definition: safer.cpp:50
uint8_t const * data
Definition: sha3.h:19
std::string disassemble(bytes const &_mem)
Convert from EVM code to simple EVM assembly language.