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] 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 c025f63..4492427 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 0e83606..d2b29ea 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 35ca97c..23c8f9f 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); + } + } +}