From 6f1f961f85040a6e4a87f8810ea93fdfb3385495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 11 Jun 2018 17:11:09 +0200 Subject: [PATCH 1/7] Use name prefix for EVM opcode enum items --- include/evmc/instructions.h | 300 +++++++++++++-------------- test/unittests/test_instructions.cpp | 32 +-- 2 files changed, 165 insertions(+), 167 deletions(-) diff --git a/include/evmc/instructions.h b/include/evmc/instructions.h index 71756d40c..1f39eb03e 100644 --- a/include/evmc/instructions.h +++ b/include/evmc/instructions.h @@ -14,159 +14,157 @@ extern "C" { #endif /** - * The list of EVM 1 instructions from every EVM revision. + * The list of EVM 1 opcodes from every EVM revision. */ -enum evmc_instruction +enum evmc_opcode { - STOP = 0x00, - ADD, - MUL, - SUB, - DIV, - SDIV, - MOD, - SMOD, - ADDMOD, - MULMOD, - EXP, - SIGNEXTEND, - - LT = 0x10, - GT, - SLT, - SGT, - EQ, - ISZERO, - AND, - OR, - XOR, - NOT, - BYTE, - SHL, - SHR, - SAR, - - SHA3 = 0x20, - - ADDRESS = 0x30, - BALANCE, - ORIGIN, - CALLER, - CALLVALUE, - CALLDATALOAD, - CALLDATASIZE, - CALLDATACOPY, - CODESIZE, - CODECOPY, - GASPRICE, - EXTCODESIZE, - EXTCODECOPY, - RETURNDATASIZE = 0x3d, - RETURNDATACOPY = 0x3e, - - BLOCKHASH = 0x40, - COINBASE, - TIMESTAMP, - NUMBER, - DIFFICULTY, - GASLIMIT, - - POP = 0x50, - MLOAD, - MSTORE, - MSTORE8, - SLOAD, - SSTORE, - JUMP, - JUMPI, - PC, - MSIZE, - GAS, - JUMPDEST, - - PUSH1 = 0x60, - PUSH2, - PUSH3, - PUSH4, - PUSH5, - PUSH6, - PUSH7, - PUSH8, - PUSH9, - PUSH10, - PUSH11, - PUSH12, - PUSH13, - PUSH14, - PUSH15, - PUSH16, - PUSH17, - PUSH18, - PUSH19, - PUSH20, - PUSH21, - PUSH22, - PUSH23, - PUSH24, - PUSH25, - PUSH26, - PUSH27, - PUSH28, - PUSH29, - PUSH30, - PUSH31, - PUSH32, - - DUP1 = 0x80, - DUP2, - DUP3, - DUP4, - DUP5, - DUP6, - DUP7, - DUP8, - DUP9, - DUP10, - DUP11, - DUP12, - DUP13, - DUP14, - DUP15, - DUP16, - - SWAP1 = 0x90, - SWAP2, - SWAP3, - SWAP4, - SWAP5, - SWAP6, - SWAP7, - SWAP8, - SWAP9, - SWAP10, - SWAP11, - SWAP12, - SWAP13, - SWAP14, - SWAP15, - SWAP16, - - LOG0 = 0xa0, - LOG1, - LOG2, - LOG3, - LOG4, - - CREATE = 0xf0, - CALL, - CALLCODE, - RETURN, - DELEGATECALL, - STATICCALL = 0xfa, - - REVERT = 0xfd, - INVALID = 0xfe, - SELFDESTRUCT = 0xff, + OP_STOP = 0x00, + OP_ADD = 0x01, + OP_MUL = 0x02, + OP_SUB = 0x03, + OP_DIV = 0x04, + OP_SDIV = 0x05, + OP_MOD = 0x06, + OP_SMOD = 0x07, + OP_ADDMOD = 0x08, + OP_MULMOD = 0x09, + OP_EXP = 0x0a, + OP_SIGNEXTEND = 0x0b, + + OP_LT = 0x10, + OP_GT = 0x11, + OP_SLT = 0x12, + OP_SGT = 0x13, + OP_EQ = 0x14, + OP_ISZERO = 0x15, + OP_AND = 0x16, + OP_OR = 0x17, + OP_XOR = 0x18, + OP_NOT = 0x19, + OP_BYTE = 0x1a, + OP_SHL = 0x1b, + OP_SHR = 0x1c, + OP_SAR = 0x1d, + + OP_SHA3 = 0x20, + + OP_ADDRESS = 0x30, + OP_BALANCE = 0x31, + OP_ORIGIN = 0x32, + OP_CALLER = 0x33, + OP_CALLVALUE = 0x34, + OP_CALLDATALOAD = 0x35, + OP_CALLDATASIZE = 0x36, + OP_CALLDATACOPY = 0x37, + OP_CODESIZE = 0x38, + OP_CODECOPY = 0x39, + OP_GASPRICE = 0x3a, + OP_EXTCODESIZE = 0x3b, + OP_EXTCODECOPY = 0x3c, + OP_RETURNDATASIZE = 0x3d, + OP_RETURNDATACOPY = 0x3e, + + OP_BLOCKHASH = 0x40, + OP_COINBASE = 0x41, + OP_TIMESTAMP = 0x42, + OP_NUMBER = 0x43, + OP_DIFFICULTY = 0x44, + OP_GASLIMIT = 0x45, + + OP_POP = 0x50, + OP_MLOAD = 0x51, + OP_MSTORE = 0x52, + OP_MSTORE8 = 0x53, + OP_SLOAD = 0x54, + OP_SSTORE = 0x55, + OP_JUMP = 0x56, + OP_JUMPI = 0x57, + OP_PC = 0x58, + OP_MSIZE = 0x59, + OP_GAS = 0x5a, + OP_JUMPDEST = 0x5b, + + OP_PUSH1 = 0x60, + OP_PUSH2 = 0x61, + OP_PUSH3 = 0x62, + OP_PUSH4 = 0x63, + OP_PUSH5 = 0x64, + OP_PUSH6 = 0x65, + OP_PUSH7 = 0x66, + OP_PUSH8 = 0x67, + OP_PUSH9 = 0x68, + OP_PUSH10 = 0x69, + OP_PUSH11 = 0x6a, + OP_PUSH12 = 0x6b, + OP_PUSH13 = 0x6c, + OP_PUSH14 = 0x6d, + OP_PUSH15 = 0x6e, + OP_PUSH16 = 0x6f, + OP_PUSH17 = 0x70, + OP_PUSH18 = 0x71, + OP_PUSH19 = 0x72, + OP_PUSH20 = 0x73, + OP_PUSH21 = 0x74, + OP_PUSH22 = 0x75, + OP_PUSH23 = 0x76, + OP_PUSH24 = 0x77, + OP_PUSH25 = 0x78, + OP_PUSH26 = 0x79, + OP_PUSH27 = 0x7a, + OP_PUSH28 = 0x7b, + OP_PUSH29 = 0x7c, + OP_PUSH30 = 0x7d, + OP_PUSH31 = 0x7e, + OP_PUSH32 = 0x7f, + OP_DUP1 = 0x80, + OP_DUP2 = 0x81, + OP_DUP3 = 0x82, + OP_DUP4 = 0x83, + OP_DUP5 = 0x84, + OP_DUP6 = 0x85, + OP_DUP7 = 0x86, + OP_DUP8 = 0x87, + OP_DUP9 = 0x88, + OP_DUP10 = 0x89, + OP_DUP11 = 0x8a, + OP_DUP12 = 0x8b, + OP_DUP13 = 0x8c, + OP_DUP14 = 0x8d, + OP_DUP15 = 0x8e, + OP_DUP16 = 0x8f, + OP_SWAP1 = 0x90, + OP_SWAP2 = 0x91, + OP_SWAP3 = 0x92, + OP_SWAP4 = 0x93, + OP_SWAP5 = 0x94, + OP_SWAP6 = 0x95, + OP_SWAP7 = 0x96, + OP_SWAP8 = 0x97, + OP_SWAP9 = 0x98, + OP_SWAP10 = 0x99, + OP_SWAP11 = 0x9a, + OP_SWAP12 = 0x9b, + OP_SWAP13 = 0x9c, + OP_SWAP14 = 0x9d, + OP_SWAP15 = 0x9e, + OP_SWAP16 = 0x9f, + OP_LOG0 = 0xa0, + OP_LOG1 = 0xa1, + OP_LOG2 = 0xa2, + OP_LOG3 = 0xa3, + OP_LOG4 = 0xa4, + + OP_CREATE = 0xf0, + OP_CALL = 0xf1, + OP_CALLCODE = 0xf2, + OP_RETURN = 0xf3, + OP_DELEGATECALL = 0xf4, + + OP_STATICCALL = 0xfa, + + OP_REVERT = 0xfd, + OP_INVALID = 0xfe, + OP_SELFDESTRUCT = 0xff, }; /** diff --git a/test/unittests/test_instructions.cpp b/test/unittests/test_instructions.cpp index 0f6858d81..5facae463 100644 --- a/test/unittests/test_instructions.cpp +++ b/test/unittests/test_instructions.cpp @@ -11,27 +11,27 @@ TEST(instructions, tangerine_whistle_hard_fork) const auto h = evmc_get_instruction_metrics_table(EVMC_HOMESTEAD); const auto tw = evmc_get_instruction_metrics_table(EVMC_TANGERINE_WHISTLE); - EXPECT_EQ(h[EXTCODESIZE].gas_cost, 20); - EXPECT_EQ(tw[EXTCODESIZE].gas_cost, 700); + EXPECT_EQ(h[OP_EXTCODESIZE].gas_cost, 20); + EXPECT_EQ(tw[OP_EXTCODESIZE].gas_cost, 700); - EXPECT_EQ(h[EXTCODECOPY].gas_cost, 20); - EXPECT_EQ(tw[EXTCODECOPY].gas_cost, 700); + EXPECT_EQ(h[OP_EXTCODECOPY].gas_cost, 20); + EXPECT_EQ(tw[OP_EXTCODECOPY].gas_cost, 700); - EXPECT_EQ(h[BALANCE].gas_cost, 20); - EXPECT_EQ(tw[BALANCE].gas_cost, 400); + EXPECT_EQ(h[OP_BALANCE].gas_cost, 20); + EXPECT_EQ(tw[OP_BALANCE].gas_cost, 400); - EXPECT_EQ(h[SLOAD].gas_cost, 50); - EXPECT_EQ(tw[SLOAD].gas_cost, 200); + EXPECT_EQ(h[OP_SLOAD].gas_cost, 50); + EXPECT_EQ(tw[OP_SLOAD].gas_cost, 200); - EXPECT_EQ(h[CALL].gas_cost, 40); - EXPECT_EQ(tw[CALL].gas_cost, 700); + EXPECT_EQ(h[OP_CALL].gas_cost, 40); + EXPECT_EQ(tw[OP_CALL].gas_cost, 700); - EXPECT_EQ(h[CALLCODE].gas_cost, 40); - EXPECT_EQ(tw[CALLCODE].gas_cost, 700); + EXPECT_EQ(h[OP_CALLCODE].gas_cost, 40); + EXPECT_EQ(tw[OP_CALLCODE].gas_cost, 700); - EXPECT_EQ(h[DELEGATECALL].gas_cost, 40); - EXPECT_EQ(tw[DELEGATECALL].gas_cost, 700); + EXPECT_EQ(h[OP_DELEGATECALL].gas_cost, 40); + EXPECT_EQ(tw[OP_DELEGATECALL].gas_cost, 700); - EXPECT_EQ(h[SELFDESTRUCT].gas_cost, 0); - EXPECT_EQ(tw[SELFDESTRUCT].gas_cost, 5000); + EXPECT_EQ(h[OP_SELFDESTRUCT].gas_cost, 0); + EXPECT_EQ(tw[OP_SELFDESTRUCT].gas_cost, 5000); } \ No newline at end of file From bfa5c5bf0601ea6b9dcd639680bcc73f5ff51c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 11 Jun 2018 18:06:36 +0200 Subject: [PATCH 2/7] Add more tests for instruction tables --- include/evmc/instructions.h | 2 +- test/unittests/test_instructions.cpp | 38 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/evmc/instructions.h b/include/evmc/instructions.h index 1f39eb03e..c025f63a9 100644 --- a/include/evmc/instructions.h +++ b/include/evmc/instructions.h @@ -174,7 +174,7 @@ enum evmc_opcode */ struct evmc_instruction_metrics { - /** The instruction gas cost. Value -1 indicates undefined instruction. */ + /** The instruction gas cost. Value -1 indicates an undefined instruction. */ int16_t gas_cost; /** The number of items the instruction pops from the EVM stack before execution. */ diff --git a/test/unittests/test_instructions.cpp b/test/unittests/test_instructions.cpp index 5facae463..35ca97cbc 100644 --- a/test/unittests/test_instructions.cpp +++ b/test/unittests/test_instructions.cpp @@ -6,6 +6,15 @@ #include +TEST(instructions, homestead_hard_fork) +{ + const auto f = evmc_get_instruction_metrics_table(EVMC_FRONTIER); + const auto h = evmc_get_instruction_metrics_table(EVMC_HOMESTEAD); + + EXPECT_EQ(f[OP_DELEGATECALL].gas_cost, -1); + EXPECT_EQ(h[OP_DELEGATECALL].gas_cost, 40); +} + TEST(instructions, tangerine_whistle_hard_fork) { const auto h = evmc_get_instruction_metrics_table(EVMC_HOMESTEAD); @@ -34,4 +43,33 @@ TEST(instructions, tangerine_whistle_hard_fork) EXPECT_EQ(h[OP_SELFDESTRUCT].gas_cost, 0); EXPECT_EQ(tw[OP_SELFDESTRUCT].gas_cost, 5000); +} + +TEST(instructions, spurious_dragon_hard_fork) +{ + const auto sd = evmc_get_instruction_metrics_table(EVMC_SPURIOUS_DRAGON); + const auto tw = evmc_get_instruction_metrics_table(EVMC_TANGERINE_WHISTLE); + + EXPECT_EQ(sd[OP_EXP].gas_cost, 10); + EXPECT_EQ(tw[OP_EXP].gas_cost, 10); +} + +TEST(instructions, byzantium_hard_fork) +{ + const auto b = evmc_get_instruction_metrics_table(EVMC_BYZANTIUM); + const auto sd = evmc_get_instruction_metrics_table(EVMC_SPURIOUS_DRAGON); + + EXPECT_EQ(b[OP_REVERT].gas_cost, 0); + EXPECT_EQ(b[OP_REVERT].num_stack_arguments, 2); + EXPECT_EQ(b[OP_REVERT].num_stack_returned_items, 0); + EXPECT_EQ(sd[OP_REVERT].gas_cost, -1); + + EXPECT_EQ(b[OP_RETURNDATACOPY].gas_cost, 3); + EXPECT_EQ(sd[OP_RETURNDATACOPY].gas_cost, -1); + + EXPECT_EQ(b[OP_RETURNDATASIZE].gas_cost, 2); + EXPECT_EQ(sd[OP_RETURNDATASIZE].gas_cost, -1); + + EXPECT_EQ(b[OP_STATICCALL].gas_cost, 700); + EXPECT_EQ(sd[OP_STATICCALL].gas_cost, -1); } \ No newline at end of file From 2c83269f627e41bd46175575b10804e73184ba44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 11 Jun 2018 18:09:26 +0200 Subject: [PATCH 3/7] Set OP_EXP cost to HIGH --- lib/instructions/instructions.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/instructions/instructions.c b/lib/instructions/instructions.c index 1ea217788..927007562 100644 --- a/lib/instructions/instructions.c +++ b/lib/instructions/instructions.c @@ -32,7 +32,7 @@ static struct evmc_instruction_metrics constantinople_metrics[256] = { /* SMOD = 0x07 */ {LOW, 2, 1}, /* ADDMOD = 0x08 */ {MID, 3, 1}, /* MULMOD = 0x09 */ {MID, 3, 1}, - /* EXP = 0x0a */ {10, 2, 1}, + /* EXP = 0x0a */ {HIGH, 2, 1}, /* SIGNEXTEND = 0x0b */ {LOW, 2, 1}, /* = 0x0c */ {UNDEFINED, 0, 0}, /* = 0x0d */ {UNDEFINED, 0, 0}, @@ -291,7 +291,7 @@ static struct evmc_instruction_metrics byzantium_metrics[256] = { /* SMOD = 0x07 */ {LOW, 2, 1}, /* ADDMOD = 0x08 */ {MID, 3, 1}, /* MULMOD = 0x09 */ {MID, 3, 1}, - /* EXP = 0x0a */ {10, 2, 1}, + /* EXP = 0x0a */ {HIGH, 2, 1}, /* SIGNEXTEND = 0x0b */ {LOW, 2, 1}, /* = 0x0c */ {UNDEFINED, 0, 0}, /* = 0x0d */ {UNDEFINED, 0, 0}, @@ -550,7 +550,7 @@ static struct evmc_instruction_metrics tangerine_whistle_metrics[256] = { /* SMOD = 0x07 */ {LOW, 2, 1}, /* ADDMOD = 0x08 */ {MID, 3, 1}, /* MULMOD = 0x09 */ {MID, 3, 1}, - /* EXP = 0x0a */ {10, 2, 1}, + /* EXP = 0x0a */ {HIGH, 2, 1}, /* SIGNEXTEND = 0x0b */ {LOW, 2, 1}, /* = 0x0c */ {UNDEFINED, 0, 0}, /* = 0x0d */ {UNDEFINED, 0, 0}, @@ -809,7 +809,7 @@ static struct evmc_instruction_metrics homestead_metrics[256] = { /* SMOD = 0x07 */ {LOW, 2, 1}, /* ADDMOD = 0x08 */ {MID, 3, 1}, /* MULMOD = 0x09 */ {MID, 3, 1}, - /* EXP = 0x0a */ {10, 2, 1}, + /* EXP = 0x0a */ {HIGH, 2, 1}, /* SIGNEXTEND = 0x0b */ {LOW, 2, 1}, /* = 0x0c */ {UNDEFINED, 0, 0}, /* = 0x0d */ {UNDEFINED, 0, 0}, @@ -1068,7 +1068,7 @@ static struct evmc_instruction_metrics frontier_metrics[256] = { /* SMOD = 0x07 */ {LOW, 2, 1}, /* ADDMOD = 0x08 */ {MID, 3, 1}, /* MULMOD = 0x09 */ {MID, 3, 1}, - /* EXP = 0x0a */ {10, 2, 1}, + /* EXP = 0x0a */ {HIGH, 2, 1}, /* SIGNEXTEND = 0x0b */ {LOW, 2, 1}, /* = 0x0c */ {UNDEFINED, 0, 0}, /* = 0x0d */ {UNDEFINED, 0, 0}, From 8a9ebd49667d7032d14d677fba68f62fa65d8936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 11 Jun 2018 18:14:36 +0200 Subject: [PATCH 4/7] Rename instructions.c to instruction_metrics.c --- lib/instructions/CMakeLists.txt | 7 ++++++- lib/instructions/{instructions.c => instruction_metrics.c} | 0 2 files changed, 6 insertions(+), 1 deletion(-) rename lib/instructions/{instructions.c => instruction_metrics.c} (100%) diff --git a/lib/instructions/CMakeLists.txt b/lib/instructions/CMakeLists.txt index fafed2c99..25aea117c 100644 --- a/lib/instructions/CMakeLists.txt +++ b/lib/instructions/CMakeLists.txt @@ -2,7 +2,12 @@ # Copyright 2018 Pawel Bylica. # Licensed under the MIT License. See the LICENSE file. -add_library(instructions ${include_dir}/evmc/instructions.h instructions.c) +add_library( + instructions + ${include_dir}/evmc/instructions.h + instruction_metrics.c +) + add_library(evmc::instructions ALIAS instructions) target_include_directories(instructions PUBLIC ${include_dir}) diff --git a/lib/instructions/instructions.c b/lib/instructions/instruction_metrics.c similarity index 100% rename from lib/instructions/instructions.c rename to lib/instructions/instruction_metrics.c From 94bb5fbec96a8e1f498ee5941ba8c0b3f66ad023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 11 Jun 2018 18:17:20 +0200 Subject: [PATCH 5/7] Separate instruction names from metrics --- lib/instructions/CMakeLists.txt | 1 + lib/instructions/instruction_metrics.c | 265 ------------------------ lib/instructions/instruction_names.c | 270 +++++++++++++++++++++++++ 3 files changed, 271 insertions(+), 265 deletions(-) create mode 100644 lib/instructions/instruction_names.c diff --git a/lib/instructions/CMakeLists.txt b/lib/instructions/CMakeLists.txt index 25aea117c..4d9905e5f 100644 --- a/lib/instructions/CMakeLists.txt +++ b/lib/instructions/CMakeLists.txt @@ -6,6 +6,7 @@ add_library( instructions ${include_dir}/evmc/instructions.h instruction_metrics.c + instruction_names.c ) add_library(evmc::instructions ALIAS instructions) diff --git a/lib/instructions/instruction_metrics.c b/lib/instructions/instruction_metrics.c index 927007562..a1f0a9e47 100644 --- a/lib/instructions/instruction_metrics.c +++ b/lib/instructions/instruction_metrics.c @@ -1335,268 +1335,3 @@ const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table( } return NULL; } - - -static const char* names[256] = { - "STOP", - "ADD", - "MUL", - "SUB", - "DIV", - "SDIV", - "MOD", - "SMOD", - "ADDMOD", - "MULMOD", - "EXP", - "SIGNEXTEND", - NULL, - NULL, - NULL, - NULL, - "LT", - "GT", - "SLT", - "SGT", - "EQ", - "ISZERO", - "AND", - "OR", - "XOR", - "NOT", - "BYTE", - "SHL", - "SHR", - "SAR", - NULL, - NULL, - "SHA3", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - "ADDRESS", - "BALANCE", - "ORIGIN", - "CALLER", - "CALLVALUE", - "CALLDATALOAD", - "CALLDATASIZE", - "CALLDATACOPY", - "CODESIZE", - "CODECOPY", - "GASPRICE", - "EXTCODESIZE", - "EXTCODECOPY", - "RETURNDATASIZE", - "RETURNDATACOPY", - NULL, - "BLOCKHASH", - "COINBASE", - "TIMESTAMP", - "NUMBER", - "DIFFICULTY", - "GASLIMIT", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - "POP", - "MLOAD", - "MSTORE", - "MSTORE8", - "SLOAD", - "SSTORE", - "JUMP", - "JUMPI", - "PC", - "MSIZE", - "GAS", - "JUMPDEST", - NULL, - NULL, - NULL, - NULL, - "PUSH1", - "PUSH2", - "PUSH3", - "PUSH4", - "PUSH5", - "PUSH6", - "PUSH7", - "PUSH8", - "PUSH9", - "PUSH10", - "PUSH11", - "PUSH12", - "PUSH13", - "PUSH14", - "PUSH15", - "PUSH16", - "PUSH17", - "PUSH18", - "PUSH19", - "PUSH20", - "PUSH21", - "PUSH22", - "PUSH23", - "PUSH24", - "PUSH25", - "PUSH26", - "PUSH27", - "PUSH28", - "PUSH29", - "PUSH30", - "PUSH31", - "PUSH32", - "DUP1", - "DUP2", - "DUP3", - "DUP4", - "DUP5", - "DUP6", - "DUP7", - "DUP8", - "DUP9", - "DUP10", - "DUP11", - "DUP12", - "DUP13", - "DUP14", - "DUP15", - "DUP16", - "SWAP1", - "SWAP2", - "SWAP3", - "SWAP4", - "SWAP5", - "SWAP6", - "SWAP7", - "SWAP8", - "SWAP9", - "SWAP10", - "SWAP11", - "SWAP12", - "SWAP13", - "SWAP14", - "SWAP15", - "SWAP16", - "LOG0", - "LOG1", - "LOG2", - "LOG3", - "LOG4", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - "CREATE", - "CALL", - "CALLCODE", - "RETURN", - "DELEGATECALL", - NULL, - NULL, - NULL, - NULL, - NULL, - "STATICCALL", - NULL, - NULL, - "REVERT", - "INVALID", - "SUICIDE", -}; - -const char* const* evmc_get_instruction_name_table() -{ - return names; -} diff --git a/lib/instructions/instruction_names.c b/lib/instructions/instruction_names.c new file mode 100644 index 000000000..0e83606c6 --- /dev/null +++ b/lib/instructions/instruction_names.c @@ -0,0 +1,270 @@ +/* EVMC: Ethereum Client-VM Connector API. + * Copyright 2018 Pawel Bylica. + * Licensed under the MIT License. See the LICENSE file. + */ + +#include + +static const char* names[256] = { + "STOP", + "ADD", + "MUL", + "SUB", + "DIV", + "SDIV", + "MOD", + "SMOD", + "ADDMOD", + "MULMOD", + "EXP", + "SIGNEXTEND", + NULL, + NULL, + NULL, + NULL, + "LT", + "GT", + "SLT", + "SGT", + "EQ", + "ISZERO", + "AND", + "OR", + "XOR", + "NOT", + "BYTE", + "SHL", + "SHR", + "SAR", + NULL, + NULL, + "SHA3", + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + "ADDRESS", + "BALANCE", + "ORIGIN", + "CALLER", + "CALLVALUE", + "CALLDATALOAD", + "CALLDATASIZE", + "CALLDATACOPY", + "CODESIZE", + "CODECOPY", + "GASPRICE", + "EXTCODESIZE", + "EXTCODECOPY", + "RETURNDATASIZE", + "RETURNDATACOPY", + NULL, + "BLOCKHASH", + "COINBASE", + "TIMESTAMP", + "NUMBER", + "DIFFICULTY", + "GASLIMIT", + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + "POP", + "MLOAD", + "MSTORE", + "MSTORE8", + "SLOAD", + "SSTORE", + "JUMP", + "JUMPI", + "PC", + "MSIZE", + "GAS", + "JUMPDEST", + NULL, + NULL, + NULL, + NULL, + "PUSH1", + "PUSH2", + "PUSH3", + "PUSH4", + "PUSH5", + "PUSH6", + "PUSH7", + "PUSH8", + "PUSH9", + "PUSH10", + "PUSH11", + "PUSH12", + "PUSH13", + "PUSH14", + "PUSH15", + "PUSH16", + "PUSH17", + "PUSH18", + "PUSH19", + "PUSH20", + "PUSH21", + "PUSH22", + "PUSH23", + "PUSH24", + "PUSH25", + "PUSH26", + "PUSH27", + "PUSH28", + "PUSH29", + "PUSH30", + "PUSH31", + "PUSH32", + "DUP1", + "DUP2", + "DUP3", + "DUP4", + "DUP5", + "DUP6", + "DUP7", + "DUP8", + "DUP9", + "DUP10", + "DUP11", + "DUP12", + "DUP13", + "DUP14", + "DUP15", + "DUP16", + "SWAP1", + "SWAP2", + "SWAP3", + "SWAP4", + "SWAP5", + "SWAP6", + "SWAP7", + "SWAP8", + "SWAP9", + "SWAP10", + "SWAP11", + "SWAP12", + "SWAP13", + "SWAP14", + "SWAP15", + "SWAP16", + "LOG0", + "LOG1", + "LOG2", + "LOG3", + "LOG4", + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + "CREATE", + "CALL", + "CALLCODE", + "RETURN", + "DELEGATECALL", + NULL, + NULL, + NULL, + NULL, + NULL, + "STATICCALL", + NULL, + NULL, + "REVERT", + "INVALID", + "SUICIDE", +}; + +const char* const* evmc_get_instruction_name_table() +{ + return names; +} From cb9ebb7c826263f07fe35e53afe05a04b5375f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 11 Jun 2018 19:32:18 +0200 Subject: [PATCH 6/7] Add names table for each EVM revision --- include/evmc/instructions.h | 13 +- lib/instructions/instruction_names.c | 1308 +++++++++++++++++++++----- test/unittests/test_instructions.cpp | 37 +- 3 files changed, 1091 insertions(+), 267 deletions(-) diff --git a/include/evmc/instructions.h b/include/evmc/instructions.h index c025f63a9..449242712 100644 --- a/include/evmc/instructions.h +++ b/include/evmc/instructions.h @@ -188,7 +188,8 @@ struct evmc_instruction_metrics * Get the table of the EVM 1 instructions metrics. * * @param revision The EVM revision. - * @return The pointer to the array of 256 instruction metrics. + * @return The pointer to the array of 256 instruction metrics. Null pointer in case + * an invalid EVM revision provided. */ const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table( enum evmc_revision revision); @@ -196,15 +197,13 @@ const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table( /** * Get the table of the EVM 1 instruction names. * - * This table is EVM revision independent and contains the superset of the names of the instructions - * from all EVM revisions. Use evmc_get_instruction_metrics_table() to know if an instruction - * is present in the given EVM revision. - * * The entries for undefined instructions contain null pointers. * - * @return The pointer to the array of 256 instruction names. + * @param revision The EVM revision. + * @return The pointer to the array of 256 instruction names. Null pointer in case + * an invalid EVM revision provided. */ -const char* const* evmc_get_instruction_name_table(); +const char* const* evmc_get_instruction_names_table(enum evmc_revision revision); #if __cplusplus } diff --git a/lib/instructions/instruction_names.c b/lib/instructions/instruction_names.c index 0e83606c6..d2b29ea9c 100644 --- a/lib/instructions/instruction_names.c +++ b/lib/instructions/instruction_names.c @@ -5,266 +5,1056 @@ #include -static const char* names[256] = { - "STOP", - "ADD", - "MUL", - "SUB", - "DIV", - "SDIV", - "MOD", - "SMOD", - "ADDMOD", - "MULMOD", - "EXP", - "SIGNEXTEND", - NULL, - NULL, - NULL, - NULL, - "LT", - "GT", - "SLT", - "SGT", - "EQ", - "ISZERO", - "AND", - "OR", - "XOR", - "NOT", - "BYTE", - "SHL", - "SHR", - "SAR", - NULL, - NULL, - "SHA3", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - "ADDRESS", - "BALANCE", - "ORIGIN", - "CALLER", - "CALLVALUE", - "CALLDATALOAD", - "CALLDATASIZE", - "CALLDATACOPY", - "CODESIZE", - "CODECOPY", - "GASPRICE", - "EXTCODESIZE", - "EXTCODECOPY", - "RETURNDATASIZE", - "RETURNDATACOPY", - NULL, - "BLOCKHASH", - "COINBASE", - "TIMESTAMP", - "NUMBER", - "DIFFICULTY", - "GASLIMIT", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - "POP", - "MLOAD", - "MSTORE", - "MSTORE8", - "SLOAD", - "SSTORE", - "JUMP", - "JUMPI", - "PC", - "MSIZE", - "GAS", - "JUMPDEST", - NULL, - NULL, - NULL, - NULL, - "PUSH1", - "PUSH2", - "PUSH3", - "PUSH4", - "PUSH5", - "PUSH6", - "PUSH7", - "PUSH8", - "PUSH9", - "PUSH10", - "PUSH11", - "PUSH12", - "PUSH13", - "PUSH14", - "PUSH15", - "PUSH16", - "PUSH17", - "PUSH18", - "PUSH19", - "PUSH20", - "PUSH21", - "PUSH22", - "PUSH23", - "PUSH24", - "PUSH25", - "PUSH26", - "PUSH27", - "PUSH28", - "PUSH29", - "PUSH30", - "PUSH31", - "PUSH32", - "DUP1", - "DUP2", - "DUP3", - "DUP4", - "DUP5", - "DUP6", - "DUP7", - "DUP8", - "DUP9", - "DUP10", - "DUP11", - "DUP12", - "DUP13", - "DUP14", - "DUP15", - "DUP16", - "SWAP1", - "SWAP2", - "SWAP3", - "SWAP4", - "SWAP5", - "SWAP6", - "SWAP7", - "SWAP8", - "SWAP9", - "SWAP10", - "SWAP11", - "SWAP12", - "SWAP13", - "SWAP14", - "SWAP15", - "SWAP16", - "LOG0", - "LOG1", - "LOG2", - "LOG3", - "LOG4", - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - "CREATE", - "CALL", - "CALLCODE", - "RETURN", - "DELEGATECALL", - NULL, - NULL, - NULL, - NULL, - NULL, - "STATICCALL", - NULL, - NULL, - "REVERT", - "INVALID", - "SUICIDE", +static const char* constantinople_names[256] = { + /* 0x00 */ "STOP", + /* 0x01 */ "ADD", + /* 0x02 */ "MUL", + /* 0x03 */ "SUB", + /* 0x04 */ "DIV", + /* 0x05 */ "SDIV", + /* 0x06 */ "MOD", + /* 0x07 */ "SMOD", + /* 0x08 */ "ADDMOD", + /* 0x09 */ "MULMOD", + /* 0x0a */ "EXP", + /* 0x0b */ "SIGNEXTEND", + /* 0x0c */ NULL, + /* 0x0d */ NULL, + /* 0x0e */ NULL, + /* 0x0f */ NULL, + /* 0x10 */ "LT", + /* 0x11 */ "GT", + /* 0x12 */ "SLT", + /* 0x13 */ "SGT", + /* 0x14 */ "EQ", + /* 0x15 */ "ISZERO", + /* 0x16 */ "AND", + /* 0x17 */ "OR", + /* 0x18 */ "XOR", + /* 0x19 */ "NOT", + /* 0x1a */ "BYTE", + /* 0x1b */ "SHL", + /* 0x1c */ "SHR", + /* 0x1d */ "SAR", + /* 0x1e */ NULL, + /* 0x1f */ NULL, + /* 0x20 */ "SHA3", + /* 0x21 */ NULL, + /* 0x22 */ NULL, + /* 0x23 */ NULL, + /* 0x24 */ NULL, + /* 0x25 */ NULL, + /* 0x26 */ NULL, + /* 0x27 */ NULL, + /* 0x28 */ NULL, + /* 0x29 */ NULL, + /* 0x2a */ NULL, + /* 0x2b */ NULL, + /* 0x2c */ NULL, + /* 0x2d */ NULL, + /* 0x2e */ NULL, + /* 0x2f */ NULL, + /* 0x30 */ "ADDRESS", + /* 0x31 */ "BALANCE", + /* 0x32 */ "ORIGIN", + /* 0x33 */ "CALLER", + /* 0x34 */ "CALLVALUE", + /* 0x35 */ "CALLDATALOAD", + /* 0x36 */ "CALLDATASIZE", + /* 0x37 */ "CALLDATACOPY", + /* 0x38 */ "CODESIZE", + /* 0x39 */ "CODECOPY", + /* 0x3a */ "GASPRICE", + /* 0x3b */ "EXTCODESIZE", + /* 0x3c */ "EXTCODECOPY", + /* 0x3d */ "RETURNDATASIZE", + /* 0x3e */ "RETURNDATACOPY", + /* 0x3f */ NULL, + /* 0x40 */ "BLOCKHASH", + /* 0x41 */ "COINBASE", + /* 0x42 */ "TIMESTAMP", + /* 0x43 */ "NUMBER", + /* 0x44 */ "DIFFICULTY", + /* 0x45 */ "GASLIMIT", + /* 0x46 */ NULL, + /* 0x47 */ NULL, + /* 0x48 */ NULL, + /* 0x49 */ NULL, + /* 0x4a */ NULL, + /* 0x4b */ NULL, + /* 0x4c */ NULL, + /* 0x4d */ NULL, + /* 0x4e */ NULL, + /* 0x4f */ NULL, + /* 0x50 */ "POP", + /* 0x51 */ "MLOAD", + /* 0x52 */ "MSTORE", + /* 0x53 */ "MSTORE8", + /* 0x54 */ "SLOAD", + /* 0x55 */ "SSTORE", + /* 0x56 */ "JUMP", + /* 0x57 */ "JUMPI", + /* 0x58 */ "PC", + /* 0x59 */ "MSIZE", + /* 0x5a */ "GAS", + /* 0x5b */ "JUMPDEST", + /* 0x5c */ NULL, + /* 0x5d */ NULL, + /* 0x5e */ NULL, + /* 0x5f */ NULL, + /* 0x60 */ "PUSH1", + /* 0x61 */ "PUSH2", + /* 0x62 */ "PUSH3", + /* 0x63 */ "PUSH4", + /* 0x64 */ "PUSH5", + /* 0x65 */ "PUSH6", + /* 0x66 */ "PUSH7", + /* 0x67 */ "PUSH8", + /* 0x68 */ "PUSH9", + /* 0x69 */ "PUSH10", + /* 0x6a */ "PUSH11", + /* 0x6b */ "PUSH12", + /* 0x6c */ "PUSH13", + /* 0x6d */ "PUSH14", + /* 0x6e */ "PUSH15", + /* 0x6f */ "PUSH16", + /* 0x70 */ "PUSH17", + /* 0x71 */ "PUSH18", + /* 0x72 */ "PUSH19", + /* 0x73 */ "PUSH20", + /* 0x74 */ "PUSH21", + /* 0x75 */ "PUSH22", + /* 0x76 */ "PUSH23", + /* 0x77 */ "PUSH24", + /* 0x78 */ "PUSH25", + /* 0x79 */ "PUSH26", + /* 0x7a */ "PUSH27", + /* 0x7b */ "PUSH28", + /* 0x7c */ "PUSH29", + /* 0x7d */ "PUSH30", + /* 0x7e */ "PUSH31", + /* 0x7f */ "PUSH32", + /* 0x80 */ "DUP1", + /* 0x81 */ "DUP2", + /* 0x82 */ "DUP3", + /* 0x83 */ "DUP4", + /* 0x84 */ "DUP5", + /* 0x85 */ "DUP6", + /* 0x86 */ "DUP7", + /* 0x87 */ "DUP8", + /* 0x88 */ "DUP9", + /* 0x89 */ "DUP10", + /* 0x8a */ "DUP11", + /* 0x8b */ "DUP12", + /* 0x8c */ "DUP13", + /* 0x8d */ "DUP14", + /* 0x8e */ "DUP15", + /* 0x8f */ "DUP16", + /* 0x90 */ "SWAP1", + /* 0x91 */ "SWAP2", + /* 0x92 */ "SWAP3", + /* 0x93 */ "SWAP4", + /* 0x94 */ "SWAP5", + /* 0x95 */ "SWAP6", + /* 0x96 */ "SWAP7", + /* 0x97 */ "SWAP8", + /* 0x98 */ "SWAP9", + /* 0x99 */ "SWAP10", + /* 0x9a */ "SWAP11", + /* 0x9b */ "SWAP12", + /* 0x9c */ "SWAP13", + /* 0x9d */ "SWAP14", + /* 0x9e */ "SWAP15", + /* 0x9f */ "SWAP16", + /* 0xa0 */ "LOG0", + /* 0xa1 */ "LOG1", + /* 0xa2 */ "LOG2", + /* 0xa3 */ "LOG3", + /* 0xa4 */ "LOG4", + /* 0xa5 */ NULL, + /* 0xa6 */ NULL, + /* 0xa7 */ NULL, + /* 0xa8 */ NULL, + /* 0xa9 */ NULL, + /* 0xaa */ NULL, + /* 0xab */ NULL, + /* 0xac */ NULL, + /* 0xad */ NULL, + /* 0xae */ NULL, + /* 0xaf */ NULL, + /* 0xb0 */ NULL, + /* 0xb1 */ NULL, + /* 0xb2 */ NULL, + /* 0xb3 */ NULL, + /* 0xb4 */ NULL, + /* 0xb5 */ NULL, + /* 0xb6 */ NULL, + /* 0xb7 */ NULL, + /* 0xb8 */ NULL, + /* 0xb9 */ NULL, + /* 0xba */ NULL, + /* 0xbb */ NULL, + /* 0xbc */ NULL, + /* 0xbd */ NULL, + /* 0xbe */ NULL, + /* 0xbf */ NULL, + /* 0xc0 */ NULL, + /* 0xc1 */ NULL, + /* 0xc2 */ NULL, + /* 0xc3 */ NULL, + /* 0xc4 */ NULL, + /* 0xc5 */ NULL, + /* 0xc6 */ NULL, + /* 0xc7 */ NULL, + /* 0xc8 */ NULL, + /* 0xc9 */ NULL, + /* 0xca */ NULL, + /* 0xcb */ NULL, + /* 0xcc */ NULL, + /* 0xcd */ NULL, + /* 0xce */ NULL, + /* 0xcf */ NULL, + /* 0xd0 */ NULL, + /* 0xd1 */ NULL, + /* 0xd2 */ NULL, + /* 0xd3 */ NULL, + /* 0xd4 */ NULL, + /* 0xd5 */ NULL, + /* 0xd6 */ NULL, + /* 0xd7 */ NULL, + /* 0xd8 */ NULL, + /* 0xd9 */ NULL, + /* 0xda */ NULL, + /* 0xdb */ NULL, + /* 0xdc */ NULL, + /* 0xdd */ NULL, + /* 0xde */ NULL, + /* 0xdf */ NULL, + /* 0xe0 */ NULL, + /* 0xe1 */ NULL, + /* 0xe2 */ NULL, + /* 0xe3 */ NULL, + /* 0xe4 */ NULL, + /* 0xe5 */ NULL, + /* 0xe6 */ NULL, + /* 0xe7 */ NULL, + /* 0xe8 */ NULL, + /* 0xe9 */ NULL, + /* 0xea */ NULL, + /* 0xeb */ NULL, + /* 0xec */ NULL, + /* 0xed */ NULL, + /* 0xee */ NULL, + /* 0xef */ NULL, + /* 0xf0 */ "CREATE", + /* 0xf1 */ "CALL", + /* 0xf2 */ "CALLCODE", + /* 0xf3 */ "RETURN", + /* 0xf4 */ "DELEGATECALL", + /* 0xf5 */ NULL, + /* 0xf6 */ NULL, + /* 0xf7 */ NULL, + /* 0xf8 */ NULL, + /* 0xf9 */ NULL, + /* 0xfa */ "STATICCALL", + /* 0xfb */ NULL, + /* 0xfc */ NULL, + /* 0xfd */ "REVERT", + /* 0xfe */ "INVALID", + /* 0xff */ "SELFDESTRUCT", }; -const char* const* evmc_get_instruction_name_table() +static const char* byzantium_names[256] = { + /* 0x00 */ "STOP", + /* 0x01 */ "ADD", + /* 0x02 */ "MUL", + /* 0x03 */ "SUB", + /* 0x04 */ "DIV", + /* 0x05 */ "SDIV", + /* 0x06 */ "MOD", + /* 0x07 */ "SMOD", + /* 0x08 */ "ADDMOD", + /* 0x09 */ "MULMOD", + /* 0x0a */ "EXP", + /* 0x0b */ "SIGNEXTEND", + /* 0x0c */ NULL, + /* 0x0d */ NULL, + /* 0x0e */ NULL, + /* 0x0f */ NULL, + /* 0x10 */ "LT", + /* 0x11 */ "GT", + /* 0x12 */ "SLT", + /* 0x13 */ "SGT", + /* 0x14 */ "EQ", + /* 0x15 */ "ISZERO", + /* 0x16 */ "AND", + /* 0x17 */ "OR", + /* 0x18 */ "XOR", + /* 0x19 */ "NOT", + /* 0x1a */ "BYTE", + /* 0x1b */ NULL, + /* 0x1c */ NULL, + /* 0x1d */ NULL, + /* 0x1e */ NULL, + /* 0x1f */ NULL, + /* 0x20 */ "SHA3", + /* 0x21 */ NULL, + /* 0x22 */ NULL, + /* 0x23 */ NULL, + /* 0x24 */ NULL, + /* 0x25 */ NULL, + /* 0x26 */ NULL, + /* 0x27 */ NULL, + /* 0x28 */ NULL, + /* 0x29 */ NULL, + /* 0x2a */ NULL, + /* 0x2b */ NULL, + /* 0x2c */ NULL, + /* 0x2d */ NULL, + /* 0x2e */ NULL, + /* 0x2f */ NULL, + /* 0x30 */ "ADDRESS", + /* 0x31 */ "BALANCE", + /* 0x32 */ "ORIGIN", + /* 0x33 */ "CALLER", + /* 0x34 */ "CALLVALUE", + /* 0x35 */ "CALLDATALOAD", + /* 0x36 */ "CALLDATASIZE", + /* 0x37 */ "CALLDATACOPY", + /* 0x38 */ "CODESIZE", + /* 0x39 */ "CODECOPY", + /* 0x3a */ "GASPRICE", + /* 0x3b */ "EXTCODESIZE", + /* 0x3c */ "EXTCODECOPY", + /* 0x3d */ "RETURNDATASIZE", + /* 0x3e */ "RETURNDATACOPY", + /* 0x3f */ NULL, + /* 0x40 */ "BLOCKHASH", + /* 0x41 */ "COINBASE", + /* 0x42 */ "TIMESTAMP", + /* 0x43 */ "NUMBER", + /* 0x44 */ "DIFFICULTY", + /* 0x45 */ "GASLIMIT", + /* 0x46 */ NULL, + /* 0x47 */ NULL, + /* 0x48 */ NULL, + /* 0x49 */ NULL, + /* 0x4a */ NULL, + /* 0x4b */ NULL, + /* 0x4c */ NULL, + /* 0x4d */ NULL, + /* 0x4e */ NULL, + /* 0x4f */ NULL, + /* 0x50 */ "POP", + /* 0x51 */ "MLOAD", + /* 0x52 */ "MSTORE", + /* 0x53 */ "MSTORE8", + /* 0x54 */ "SLOAD", + /* 0x55 */ "SSTORE", + /* 0x56 */ "JUMP", + /* 0x57 */ "JUMPI", + /* 0x58 */ "PC", + /* 0x59 */ "MSIZE", + /* 0x5a */ "GAS", + /* 0x5b */ "JUMPDEST", + /* 0x5c */ NULL, + /* 0x5d */ NULL, + /* 0x5e */ NULL, + /* 0x5f */ NULL, + /* 0x60 */ "PUSH1", + /* 0x61 */ "PUSH2", + /* 0x62 */ "PUSH3", + /* 0x63 */ "PUSH4", + /* 0x64 */ "PUSH5", + /* 0x65 */ "PUSH6", + /* 0x66 */ "PUSH7", + /* 0x67 */ "PUSH8", + /* 0x68 */ "PUSH9", + /* 0x69 */ "PUSH10", + /* 0x6a */ "PUSH11", + /* 0x6b */ "PUSH12", + /* 0x6c */ "PUSH13", + /* 0x6d */ "PUSH14", + /* 0x6e */ "PUSH15", + /* 0x6f */ "PUSH16", + /* 0x70 */ "PUSH17", + /* 0x71 */ "PUSH18", + /* 0x72 */ "PUSH19", + /* 0x73 */ "PUSH20", + /* 0x74 */ "PUSH21", + /* 0x75 */ "PUSH22", + /* 0x76 */ "PUSH23", + /* 0x77 */ "PUSH24", + /* 0x78 */ "PUSH25", + /* 0x79 */ "PUSH26", + /* 0x7a */ "PUSH27", + /* 0x7b */ "PUSH28", + /* 0x7c */ "PUSH29", + /* 0x7d */ "PUSH30", + /* 0x7e */ "PUSH31", + /* 0x7f */ "PUSH32", + /* 0x80 */ "DUP1", + /* 0x81 */ "DUP2", + /* 0x82 */ "DUP3", + /* 0x83 */ "DUP4", + /* 0x84 */ "DUP5", + /* 0x85 */ "DUP6", + /* 0x86 */ "DUP7", + /* 0x87 */ "DUP8", + /* 0x88 */ "DUP9", + /* 0x89 */ "DUP10", + /* 0x8a */ "DUP11", + /* 0x8b */ "DUP12", + /* 0x8c */ "DUP13", + /* 0x8d */ "DUP14", + /* 0x8e */ "DUP15", + /* 0x8f */ "DUP16", + /* 0x90 */ "SWAP1", + /* 0x91 */ "SWAP2", + /* 0x92 */ "SWAP3", + /* 0x93 */ "SWAP4", + /* 0x94 */ "SWAP5", + /* 0x95 */ "SWAP6", + /* 0x96 */ "SWAP7", + /* 0x97 */ "SWAP8", + /* 0x98 */ "SWAP9", + /* 0x99 */ "SWAP10", + /* 0x9a */ "SWAP11", + /* 0x9b */ "SWAP12", + /* 0x9c */ "SWAP13", + /* 0x9d */ "SWAP14", + /* 0x9e */ "SWAP15", + /* 0x9f */ "SWAP16", + /* 0xa0 */ "LOG0", + /* 0xa1 */ "LOG1", + /* 0xa2 */ "LOG2", + /* 0xa3 */ "LOG3", + /* 0xa4 */ "LOG4", + /* 0xa5 */ NULL, + /* 0xa6 */ NULL, + /* 0xa7 */ NULL, + /* 0xa8 */ NULL, + /* 0xa9 */ NULL, + /* 0xaa */ NULL, + /* 0xab */ NULL, + /* 0xac */ NULL, + /* 0xad */ NULL, + /* 0xae */ NULL, + /* 0xaf */ NULL, + /* 0xb0 */ NULL, + /* 0xb1 */ NULL, + /* 0xb2 */ NULL, + /* 0xb3 */ NULL, + /* 0xb4 */ NULL, + /* 0xb5 */ NULL, + /* 0xb6 */ NULL, + /* 0xb7 */ NULL, + /* 0xb8 */ NULL, + /* 0xb9 */ NULL, + /* 0xba */ NULL, + /* 0xbb */ NULL, + /* 0xbc */ NULL, + /* 0xbd */ NULL, + /* 0xbe */ NULL, + /* 0xbf */ NULL, + /* 0xc0 */ NULL, + /* 0xc1 */ NULL, + /* 0xc2 */ NULL, + /* 0xc3 */ NULL, + /* 0xc4 */ NULL, + /* 0xc5 */ NULL, + /* 0xc6 */ NULL, + /* 0xc7 */ NULL, + /* 0xc8 */ NULL, + /* 0xc9 */ NULL, + /* 0xca */ NULL, + /* 0xcb */ NULL, + /* 0xcc */ NULL, + /* 0xcd */ NULL, + /* 0xce */ NULL, + /* 0xcf */ NULL, + /* 0xd0 */ NULL, + /* 0xd1 */ NULL, + /* 0xd2 */ NULL, + /* 0xd3 */ NULL, + /* 0xd4 */ NULL, + /* 0xd5 */ NULL, + /* 0xd6 */ NULL, + /* 0xd7 */ NULL, + /* 0xd8 */ NULL, + /* 0xd9 */ NULL, + /* 0xda */ NULL, + /* 0xdb */ NULL, + /* 0xdc */ NULL, + /* 0xdd */ NULL, + /* 0xde */ NULL, + /* 0xdf */ NULL, + /* 0xe0 */ NULL, + /* 0xe1 */ NULL, + /* 0xe2 */ NULL, + /* 0xe3 */ NULL, + /* 0xe4 */ NULL, + /* 0xe5 */ NULL, + /* 0xe6 */ NULL, + /* 0xe7 */ NULL, + /* 0xe8 */ NULL, + /* 0xe9 */ NULL, + /* 0xea */ NULL, + /* 0xeb */ NULL, + /* 0xec */ NULL, + /* 0xed */ NULL, + /* 0xee */ NULL, + /* 0xef */ NULL, + /* 0xf0 */ "CREATE", + /* 0xf1 */ "CALL", + /* 0xf2 */ "CALLCODE", + /* 0xf3 */ "RETURN", + /* 0xf4 */ "DELEGATECALL", + /* 0xf5 */ NULL, + /* 0xf6 */ NULL, + /* 0xf7 */ NULL, + /* 0xf8 */ NULL, + /* 0xf9 */ NULL, + /* 0xfa */ "STATICCALL", + /* 0xfb */ NULL, + /* 0xfc */ NULL, + /* 0xfd */ "REVERT", + /* 0xfe */ "INVALID", + /* 0xff */ "SELFDESTRUCT", +}; + +static const char* homestead_names[256] = { + /* 0x00 */ "STOP", + /* 0x01 */ "ADD", + /* 0x02 */ "MUL", + /* 0x03 */ "SUB", + /* 0x04 */ "DIV", + /* 0x05 */ "SDIV", + /* 0x06 */ "MOD", + /* 0x07 */ "SMOD", + /* 0x08 */ "ADDMOD", + /* 0x09 */ "MULMOD", + /* 0x0a */ "EXP", + /* 0x0b */ "SIGNEXTEND", + /* 0x0c */ NULL, + /* 0x0d */ NULL, + /* 0x0e */ NULL, + /* 0x0f */ NULL, + /* 0x10 */ "LT", + /* 0x11 */ "GT", + /* 0x12 */ "SLT", + /* 0x13 */ "SGT", + /* 0x14 */ "EQ", + /* 0x15 */ "ISZERO", + /* 0x16 */ "AND", + /* 0x17 */ "OR", + /* 0x18 */ "XOR", + /* 0x19 */ "NOT", + /* 0x1a */ "BYTE", + /* 0x1b */ NULL, + /* 0x1c */ NULL, + /* 0x1d */ NULL, + /* 0x1e */ NULL, + /* 0x1f */ NULL, + /* 0x20 */ "SHA3", + /* 0x21 */ NULL, + /* 0x22 */ NULL, + /* 0x23 */ NULL, + /* 0x24 */ NULL, + /* 0x25 */ NULL, + /* 0x26 */ NULL, + /* 0x27 */ NULL, + /* 0x28 */ NULL, + /* 0x29 */ NULL, + /* 0x2a */ NULL, + /* 0x2b */ NULL, + /* 0x2c */ NULL, + /* 0x2d */ NULL, + /* 0x2e */ NULL, + /* 0x2f */ NULL, + /* 0x30 */ "ADDRESS", + /* 0x31 */ "BALANCE", + /* 0x32 */ "ORIGIN", + /* 0x33 */ "CALLER", + /* 0x34 */ "CALLVALUE", + /* 0x35 */ "CALLDATALOAD", + /* 0x36 */ "CALLDATASIZE", + /* 0x37 */ "CALLDATACOPY", + /* 0x38 */ "CODESIZE", + /* 0x39 */ "CODECOPY", + /* 0x3a */ "GASPRICE", + /* 0x3b */ "EXTCODESIZE", + /* 0x3c */ "EXTCODECOPY", + /* 0x3d */ NULL, + /* 0x3e */ NULL, + /* 0x3f */ NULL, + /* 0x40 */ "BLOCKHASH", + /* 0x41 */ "COINBASE", + /* 0x42 */ "TIMESTAMP", + /* 0x43 */ "NUMBER", + /* 0x44 */ "DIFFICULTY", + /* 0x45 */ "GASLIMIT", + /* 0x46 */ NULL, + /* 0x47 */ NULL, + /* 0x48 */ NULL, + /* 0x49 */ NULL, + /* 0x4a */ NULL, + /* 0x4b */ NULL, + /* 0x4c */ NULL, + /* 0x4d */ NULL, + /* 0x4e */ NULL, + /* 0x4f */ NULL, + /* 0x50 */ "POP", + /* 0x51 */ "MLOAD", + /* 0x52 */ "MSTORE", + /* 0x53 */ "MSTORE8", + /* 0x54 */ "SLOAD", + /* 0x55 */ "SSTORE", + /* 0x56 */ "JUMP", + /* 0x57 */ "JUMPI", + /* 0x58 */ "PC", + /* 0x59 */ "MSIZE", + /* 0x5a */ "GAS", + /* 0x5b */ "JUMPDEST", + /* 0x5c */ NULL, + /* 0x5d */ NULL, + /* 0x5e */ NULL, + /* 0x5f */ NULL, + /* 0x60 */ "PUSH1", + /* 0x61 */ "PUSH2", + /* 0x62 */ "PUSH3", + /* 0x63 */ "PUSH4", + /* 0x64 */ "PUSH5", + /* 0x65 */ "PUSH6", + /* 0x66 */ "PUSH7", + /* 0x67 */ "PUSH8", + /* 0x68 */ "PUSH9", + /* 0x69 */ "PUSH10", + /* 0x6a */ "PUSH11", + /* 0x6b */ "PUSH12", + /* 0x6c */ "PUSH13", + /* 0x6d */ "PUSH14", + /* 0x6e */ "PUSH15", + /* 0x6f */ "PUSH16", + /* 0x70 */ "PUSH17", + /* 0x71 */ "PUSH18", + /* 0x72 */ "PUSH19", + /* 0x73 */ "PUSH20", + /* 0x74 */ "PUSH21", + /* 0x75 */ "PUSH22", + /* 0x76 */ "PUSH23", + /* 0x77 */ "PUSH24", + /* 0x78 */ "PUSH25", + /* 0x79 */ "PUSH26", + /* 0x7a */ "PUSH27", + /* 0x7b */ "PUSH28", + /* 0x7c */ "PUSH29", + /* 0x7d */ "PUSH30", + /* 0x7e */ "PUSH31", + /* 0x7f */ "PUSH32", + /* 0x80 */ "DUP1", + /* 0x81 */ "DUP2", + /* 0x82 */ "DUP3", + /* 0x83 */ "DUP4", + /* 0x84 */ "DUP5", + /* 0x85 */ "DUP6", + /* 0x86 */ "DUP7", + /* 0x87 */ "DUP8", + /* 0x88 */ "DUP9", + /* 0x89 */ "DUP10", + /* 0x8a */ "DUP11", + /* 0x8b */ "DUP12", + /* 0x8c */ "DUP13", + /* 0x8d */ "DUP14", + /* 0x8e */ "DUP15", + /* 0x8f */ "DUP16", + /* 0x90 */ "SWAP1", + /* 0x91 */ "SWAP2", + /* 0x92 */ "SWAP3", + /* 0x93 */ "SWAP4", + /* 0x94 */ "SWAP5", + /* 0x95 */ "SWAP6", + /* 0x96 */ "SWAP7", + /* 0x97 */ "SWAP8", + /* 0x98 */ "SWAP9", + /* 0x99 */ "SWAP10", + /* 0x9a */ "SWAP11", + /* 0x9b */ "SWAP12", + /* 0x9c */ "SWAP13", + /* 0x9d */ "SWAP14", + /* 0x9e */ "SWAP15", + /* 0x9f */ "SWAP16", + /* 0xa0 */ "LOG0", + /* 0xa1 */ "LOG1", + /* 0xa2 */ "LOG2", + /* 0xa3 */ "LOG3", + /* 0xa4 */ "LOG4", + /* 0xa5 */ NULL, + /* 0xa6 */ NULL, + /* 0xa7 */ NULL, + /* 0xa8 */ NULL, + /* 0xa9 */ NULL, + /* 0xaa */ NULL, + /* 0xab */ NULL, + /* 0xac */ NULL, + /* 0xad */ NULL, + /* 0xae */ NULL, + /* 0xaf */ NULL, + /* 0xb0 */ NULL, + /* 0xb1 */ NULL, + /* 0xb2 */ NULL, + /* 0xb3 */ NULL, + /* 0xb4 */ NULL, + /* 0xb5 */ NULL, + /* 0xb6 */ NULL, + /* 0xb7 */ NULL, + /* 0xb8 */ NULL, + /* 0xb9 */ NULL, + /* 0xba */ NULL, + /* 0xbb */ NULL, + /* 0xbc */ NULL, + /* 0xbd */ NULL, + /* 0xbe */ NULL, + /* 0xbf */ NULL, + /* 0xc0 */ NULL, + /* 0xc1 */ NULL, + /* 0xc2 */ NULL, + /* 0xc3 */ NULL, + /* 0xc4 */ NULL, + /* 0xc5 */ NULL, + /* 0xc6 */ NULL, + /* 0xc7 */ NULL, + /* 0xc8 */ NULL, + /* 0xc9 */ NULL, + /* 0xca */ NULL, + /* 0xcb */ NULL, + /* 0xcc */ NULL, + /* 0xcd */ NULL, + /* 0xce */ NULL, + /* 0xcf */ NULL, + /* 0xd0 */ NULL, + /* 0xd1 */ NULL, + /* 0xd2 */ NULL, + /* 0xd3 */ NULL, + /* 0xd4 */ NULL, + /* 0xd5 */ NULL, + /* 0xd6 */ NULL, + /* 0xd7 */ NULL, + /* 0xd8 */ NULL, + /* 0xd9 */ NULL, + /* 0xda */ NULL, + /* 0xdb */ NULL, + /* 0xdc */ NULL, + /* 0xdd */ NULL, + /* 0xde */ NULL, + /* 0xdf */ NULL, + /* 0xe0 */ NULL, + /* 0xe1 */ NULL, + /* 0xe2 */ NULL, + /* 0xe3 */ NULL, + /* 0xe4 */ NULL, + /* 0xe5 */ NULL, + /* 0xe6 */ NULL, + /* 0xe7 */ NULL, + /* 0xe8 */ NULL, + /* 0xe9 */ NULL, + /* 0xea */ NULL, + /* 0xeb */ NULL, + /* 0xec */ NULL, + /* 0xed */ NULL, + /* 0xee */ NULL, + /* 0xef */ NULL, + /* 0xf0 */ "CREATE", + /* 0xf1 */ "CALL", + /* 0xf2 */ "CALLCODE", + /* 0xf3 */ "RETURN", + /* 0xf4 */ "DELEGATECALL", + /* 0xf5 */ NULL, + /* 0xf6 */ NULL, + /* 0xf7 */ NULL, + /* 0xf8 */ NULL, + /* 0xf9 */ NULL, + /* 0xfa */ NULL, + /* 0xfb */ NULL, + /* 0xfc */ NULL, + /* 0xfd */ NULL, + /* 0xfe */ "INVALID", + /* 0xff */ "SELFDESTRUCT", +}; + +static const char* frontier_names[256] = { + /* 0x00 */ "STOP", + /* 0x01 */ "ADD", + /* 0x02 */ "MUL", + /* 0x03 */ "SUB", + /* 0x04 */ "DIV", + /* 0x05 */ "SDIV", + /* 0x06 */ "MOD", + /* 0x07 */ "SMOD", + /* 0x08 */ "ADDMOD", + /* 0x09 */ "MULMOD", + /* 0x0a */ "EXP", + /* 0x0b */ "SIGNEXTEND", + /* 0x0c */ NULL, + /* 0x0d */ NULL, + /* 0x0e */ NULL, + /* 0x0f */ NULL, + /* 0x10 */ "LT", + /* 0x11 */ "GT", + /* 0x12 */ "SLT", + /* 0x13 */ "SGT", + /* 0x14 */ "EQ", + /* 0x15 */ "ISZERO", + /* 0x16 */ "AND", + /* 0x17 */ "OR", + /* 0x18 */ "XOR", + /* 0x19 */ "NOT", + /* 0x1a */ "BYTE", + /* 0x1b */ NULL, + /* 0x1c */ NULL, + /* 0x1d */ NULL, + /* 0x1e */ NULL, + /* 0x1f */ NULL, + /* 0x20 */ "SHA3", + /* 0x21 */ NULL, + /* 0x22 */ NULL, + /* 0x23 */ NULL, + /* 0x24 */ NULL, + /* 0x25 */ NULL, + /* 0x26 */ NULL, + /* 0x27 */ NULL, + /* 0x28 */ NULL, + /* 0x29 */ NULL, + /* 0x2a */ NULL, + /* 0x2b */ NULL, + /* 0x2c */ NULL, + /* 0x2d */ NULL, + /* 0x2e */ NULL, + /* 0x2f */ NULL, + /* 0x30 */ "ADDRESS", + /* 0x31 */ "BALANCE", + /* 0x32 */ "ORIGIN", + /* 0x33 */ "CALLER", + /* 0x34 */ "CALLVALUE", + /* 0x35 */ "CALLDATALOAD", + /* 0x36 */ "CALLDATASIZE", + /* 0x37 */ "CALLDATACOPY", + /* 0x38 */ "CODESIZE", + /* 0x39 */ "CODECOPY", + /* 0x3a */ "GASPRICE", + /* 0x3b */ "EXTCODESIZE", + /* 0x3c */ "EXTCODECOPY", + /* 0x3d */ NULL, + /* 0x3e */ NULL, + /* 0x3f */ NULL, + /* 0x40 */ "BLOCKHASH", + /* 0x41 */ "COINBASE", + /* 0x42 */ "TIMESTAMP", + /* 0x43 */ "NUMBER", + /* 0x44 */ "DIFFICULTY", + /* 0x45 */ "GASLIMIT", + /* 0x46 */ NULL, + /* 0x47 */ NULL, + /* 0x48 */ NULL, + /* 0x49 */ NULL, + /* 0x4a */ NULL, + /* 0x4b */ NULL, + /* 0x4c */ NULL, + /* 0x4d */ NULL, + /* 0x4e */ NULL, + /* 0x4f */ NULL, + /* 0x50 */ "POP", + /* 0x51 */ "MLOAD", + /* 0x52 */ "MSTORE", + /* 0x53 */ "MSTORE8", + /* 0x54 */ "SLOAD", + /* 0x55 */ "SSTORE", + /* 0x56 */ "JUMP", + /* 0x57 */ "JUMPI", + /* 0x58 */ "PC", + /* 0x59 */ "MSIZE", + /* 0x5a */ "GAS", + /* 0x5b */ "JUMPDEST", + /* 0x5c */ NULL, + /* 0x5d */ NULL, + /* 0x5e */ NULL, + /* 0x5f */ NULL, + /* 0x60 */ "PUSH1", + /* 0x61 */ "PUSH2", + /* 0x62 */ "PUSH3", + /* 0x63 */ "PUSH4", + /* 0x64 */ "PUSH5", + /* 0x65 */ "PUSH6", + /* 0x66 */ "PUSH7", + /* 0x67 */ "PUSH8", + /* 0x68 */ "PUSH9", + /* 0x69 */ "PUSH10", + /* 0x6a */ "PUSH11", + /* 0x6b */ "PUSH12", + /* 0x6c */ "PUSH13", + /* 0x6d */ "PUSH14", + /* 0x6e */ "PUSH15", + /* 0x6f */ "PUSH16", + /* 0x70 */ "PUSH17", + /* 0x71 */ "PUSH18", + /* 0x72 */ "PUSH19", + /* 0x73 */ "PUSH20", + /* 0x74 */ "PUSH21", + /* 0x75 */ "PUSH22", + /* 0x76 */ "PUSH23", + /* 0x77 */ "PUSH24", + /* 0x78 */ "PUSH25", + /* 0x79 */ "PUSH26", + /* 0x7a */ "PUSH27", + /* 0x7b */ "PUSH28", + /* 0x7c */ "PUSH29", + /* 0x7d */ "PUSH30", + /* 0x7e */ "PUSH31", + /* 0x7f */ "PUSH32", + /* 0x80 */ "DUP1", + /* 0x81 */ "DUP2", + /* 0x82 */ "DUP3", + /* 0x83 */ "DUP4", + /* 0x84 */ "DUP5", + /* 0x85 */ "DUP6", + /* 0x86 */ "DUP7", + /* 0x87 */ "DUP8", + /* 0x88 */ "DUP9", + /* 0x89 */ "DUP10", + /* 0x8a */ "DUP11", + /* 0x8b */ "DUP12", + /* 0x8c */ "DUP13", + /* 0x8d */ "DUP14", + /* 0x8e */ "DUP15", + /* 0x8f */ "DUP16", + /* 0x90 */ "SWAP1", + /* 0x91 */ "SWAP2", + /* 0x92 */ "SWAP3", + /* 0x93 */ "SWAP4", + /* 0x94 */ "SWAP5", + /* 0x95 */ "SWAP6", + /* 0x96 */ "SWAP7", + /* 0x97 */ "SWAP8", + /* 0x98 */ "SWAP9", + /* 0x99 */ "SWAP10", + /* 0x9a */ "SWAP11", + /* 0x9b */ "SWAP12", + /* 0x9c */ "SWAP13", + /* 0x9d */ "SWAP14", + /* 0x9e */ "SWAP15", + /* 0x9f */ "SWAP16", + /* 0xa0 */ "LOG0", + /* 0xa1 */ "LOG1", + /* 0xa2 */ "LOG2", + /* 0xa3 */ "LOG3", + /* 0xa4 */ "LOG4", + /* 0xa5 */ NULL, + /* 0xa6 */ NULL, + /* 0xa7 */ NULL, + /* 0xa8 */ NULL, + /* 0xa9 */ NULL, + /* 0xaa */ NULL, + /* 0xab */ NULL, + /* 0xac */ NULL, + /* 0xad */ NULL, + /* 0xae */ NULL, + /* 0xaf */ NULL, + /* 0xb0 */ NULL, + /* 0xb1 */ NULL, + /* 0xb2 */ NULL, + /* 0xb3 */ NULL, + /* 0xb4 */ NULL, + /* 0xb5 */ NULL, + /* 0xb6 */ NULL, + /* 0xb7 */ NULL, + /* 0xb8 */ NULL, + /* 0xb9 */ NULL, + /* 0xba */ NULL, + /* 0xbb */ NULL, + /* 0xbc */ NULL, + /* 0xbd */ NULL, + /* 0xbe */ NULL, + /* 0xbf */ NULL, + /* 0xc0 */ NULL, + /* 0xc1 */ NULL, + /* 0xc2 */ NULL, + /* 0xc3 */ NULL, + /* 0xc4 */ NULL, + /* 0xc5 */ NULL, + /* 0xc6 */ NULL, + /* 0xc7 */ NULL, + /* 0xc8 */ NULL, + /* 0xc9 */ NULL, + /* 0xca */ NULL, + /* 0xcb */ NULL, + /* 0xcc */ NULL, + /* 0xcd */ NULL, + /* 0xce */ NULL, + /* 0xcf */ NULL, + /* 0xd0 */ NULL, + /* 0xd1 */ NULL, + /* 0xd2 */ NULL, + /* 0xd3 */ NULL, + /* 0xd4 */ NULL, + /* 0xd5 */ NULL, + /* 0xd6 */ NULL, + /* 0xd7 */ NULL, + /* 0xd8 */ NULL, + /* 0xd9 */ NULL, + /* 0xda */ NULL, + /* 0xdb */ NULL, + /* 0xdc */ NULL, + /* 0xdd */ NULL, + /* 0xde */ NULL, + /* 0xdf */ NULL, + /* 0xe0 */ NULL, + /* 0xe1 */ NULL, + /* 0xe2 */ NULL, + /* 0xe3 */ NULL, + /* 0xe4 */ NULL, + /* 0xe5 */ NULL, + /* 0xe6 */ NULL, + /* 0xe7 */ NULL, + /* 0xe8 */ NULL, + /* 0xe9 */ NULL, + /* 0xea */ NULL, + /* 0xeb */ NULL, + /* 0xec */ NULL, + /* 0xed */ NULL, + /* 0xee */ NULL, + /* 0xef */ NULL, + /* 0xf0 */ "CREATE", + /* 0xf1 */ "CALL", + /* 0xf2 */ "CALLCODE", + /* 0xf3 */ "RETURN", + /* 0xf4 */ NULL, + /* 0xf5 */ NULL, + /* 0xf6 */ NULL, + /* 0xf7 */ NULL, + /* 0xf8 */ NULL, + /* 0xf9 */ NULL, + /* 0xfa */ NULL, + /* 0xfb */ NULL, + /* 0xfc */ NULL, + /* 0xfd */ NULL, + /* 0xfe */ "INVALID", + /* 0xff */ "SELFDESTRUCT", +}; + +const char* const* evmc_get_instruction_names_table(enum evmc_revision revision) { - return names; + switch (revision) + { + case EVMC_CONSTANTINOPLE: + return constantinople_names; + case EVMC_BYZANTIUM: + return byzantium_names; + case EVMC_SPURIOUS_DRAGON: + case EVMC_TANGERINE_WHISTLE: + case EVMC_HOMESTEAD: + return homestead_names; + case EVMC_FRONTIER: + return frontier_names; + } + return NULL; } diff --git a/test/unittests/test_instructions.cpp b/test/unittests/test_instructions.cpp index 35ca97cbc..23c8f9f05 100644 --- a/test/unittests/test_instructions.cpp +++ b/test/unittests/test_instructions.cpp @@ -10,9 +10,13 @@ TEST(instructions, homestead_hard_fork) { const auto f = evmc_get_instruction_metrics_table(EVMC_FRONTIER); const auto h = evmc_get_instruction_metrics_table(EVMC_HOMESTEAD); + const auto fn = evmc_get_instruction_names_table(EVMC_FRONTIER); + const auto hn = evmc_get_instruction_names_table(EVMC_HOMESTEAD); EXPECT_EQ(f[OP_DELEGATECALL].gas_cost, -1); EXPECT_EQ(h[OP_DELEGATECALL].gas_cost, 40); + EXPECT_EQ(fn[OP_DELEGATECALL], nullptr); + EXPECT_EQ(hn[OP_DELEGATECALL], std::string{"DELEGATECALL"}); } TEST(instructions, tangerine_whistle_hard_fork) @@ -58,18 +62,49 @@ TEST(instructions, byzantium_hard_fork) { const auto b = evmc_get_instruction_metrics_table(EVMC_BYZANTIUM); const auto sd = evmc_get_instruction_metrics_table(EVMC_SPURIOUS_DRAGON); + const auto bn = evmc_get_instruction_names_table(EVMC_BYZANTIUM); + const auto sdn = evmc_get_instruction_names_table(EVMC_SPURIOUS_DRAGON); EXPECT_EQ(b[OP_REVERT].gas_cost, 0); EXPECT_EQ(b[OP_REVERT].num_stack_arguments, 2); EXPECT_EQ(b[OP_REVERT].num_stack_returned_items, 0); EXPECT_EQ(sd[OP_REVERT].gas_cost, -1); + EXPECT_EQ(bn[OP_REVERT], std::string{"REVERT"}); + EXPECT_EQ(sdn[OP_REVERT], nullptr); EXPECT_EQ(b[OP_RETURNDATACOPY].gas_cost, 3); EXPECT_EQ(sd[OP_RETURNDATACOPY].gas_cost, -1); + EXPECT_EQ(bn[OP_RETURNDATACOPY], std::string{"RETURNDATACOPY"}); + EXPECT_EQ(sdn[OP_RETURNDATACOPY], nullptr); EXPECT_EQ(b[OP_RETURNDATASIZE].gas_cost, 2); EXPECT_EQ(sd[OP_RETURNDATASIZE].gas_cost, -1); + EXPECT_EQ(bn[OP_RETURNDATASIZE], std::string{"RETURNDATASIZE"}); + EXPECT_EQ(sdn[OP_RETURNDATASIZE], nullptr); EXPECT_EQ(b[OP_STATICCALL].gas_cost, 700); EXPECT_EQ(sd[OP_STATICCALL].gas_cost, -1); -} \ No newline at end of file + EXPECT_EQ(bn[OP_STATICCALL], std::string{"STATICCALL"}); + EXPECT_EQ(sdn[OP_STATICCALL], nullptr); +} + +TEST(instructions, name_gas_cost_equivalence) +{ + for (auto rev = EVMC_FRONTIER; rev <= EVMC_CONSTANTINOPLE; + rev = static_cast(rev + 1)) + { + const auto names = evmc_get_instruction_names_table(rev); + const auto metrics = evmc_get_instruction_metrics_table(rev); + + for (int i = 0; i < 256; ++i) + { + auto name = names[i]; + auto gas_cost = metrics[i].gas_cost; + + if (name != nullptr) + EXPECT_GE(gas_cost, 0); + else + EXPECT_EQ(gas_cost, -1); + } + } +} From 41b3501b5efef58f78f9285548511ea92248ae06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 11 Jun 2018 19:35:16 +0200 Subject: [PATCH 7/7] Add EVMC_LATEST_REVISON as an alias for latest EVM revision --- include/evmc/evmc.h | 4 +++- test/unittests/test_instructions.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index 08db5e702..d8f8cab0b 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -659,7 +659,9 @@ enum evmc_revision EVMC_TANGERINE_WHISTLE = 2, EVMC_SPURIOUS_DRAGON = 3, EVMC_BYZANTIUM = 4, - EVMC_CONSTANTINOPLE = 5 + EVMC_CONSTANTINOPLE = 5, + + EVMC_LATEST_REVISION = EVMC_CONSTANTINOPLE }; diff --git a/test/unittests/test_instructions.cpp b/test/unittests/test_instructions.cpp index 23c8f9f05..3a8691689 100644 --- a/test/unittests/test_instructions.cpp +++ b/test/unittests/test_instructions.cpp @@ -90,7 +90,7 @@ TEST(instructions, byzantium_hard_fork) TEST(instructions, name_gas_cost_equivalence) { - for (auto rev = EVMC_FRONTIER; rev <= EVMC_CONSTANTINOPLE; + for (auto rev = EVMC_FRONTIER; rev <= EVMC_LATEST_REVISION; rev = static_cast(rev + 1)) { const auto names = evmc_get_instruction_names_table(rev);