diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index a3b8fb4..40730e0 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -153,6 +153,7 @@ struct evmc_tx_context int64_t block_timestamp; /**< The block timestamp. */ int64_t block_gas_limit; /**< The block gas limit. */ evmc_uint256be block_difficulty; /**< The block difficulty. */ + evmc_uint256be chain_id; /**< The blockchain's ChainID. */ }; struct evmc_context; diff --git a/include/evmc/evmc.hpp b/include/evmc/evmc.hpp index ff486a2..4806e04 100644 --- a/include/evmc/evmc.hpp +++ b/include/evmc/evmc.hpp @@ -640,8 +640,7 @@ inline void emit_log(evmc_context* h, constexpr evmc_host_interface interface{ account_exists, get_storage, set_storage, get_balance, get_code_size, get_code_hash, - copy_code, selfdestruct, call, get_tx_context, get_block_hash, emit_log, -}; + copy_code, selfdestruct, call, get_tx_context, get_block_hash, emit_log}; } // namespace internal inline Host::Host() noexcept : evmc_context{&evmc::internal::interface} {} diff --git a/include/evmc/instructions.h b/include/evmc/instructions.h index 557fce7..84e9cbe 100644 --- a/include/evmc/instructions.h +++ b/include/evmc/instructions.h @@ -78,6 +78,7 @@ enum evmc_opcode OP_NUMBER = 0x43, OP_DIFFICULTY = 0x44, OP_GASLIMIT = 0x45, + OP_CHAINID = 0x46, OP_POP = 0x50, OP_MLOAD = 0x51, diff --git a/lib/instructions/instruction_metrics.c b/lib/instructions/instruction_metrics.c index 178c591..03a494f 100644 --- a/lib/instructions/instruction_metrics.c +++ b/lib/instructions/instruction_metrics.c @@ -92,7 +92,7 @@ static struct evmc_instruction_metrics istanbul_metrics[256] = { /* NUMBER = 0x43 */ {BASE, 0, 1}, /* DIFFICULTY = 0x44 */ {BASE, 0, 1}, /* GASLIMIT = 0x45 */ {BASE, 0, 1}, - /* = 0x46 */ {UNDEFINED, 0, 0}, + /* CHAINID = 0x46 */ {BASE, 0, 1}, /* = 0x47 */ {UNDEFINED, 0, 0}, /* = 0x48 */ {UNDEFINED, 0, 0}, /* = 0x49 */ {UNDEFINED, 0, 0}, diff --git a/lib/instructions/instruction_names.c b/lib/instructions/instruction_names.c index 2f08fc1..361cfc8 100644 --- a/lib/instructions/instruction_names.c +++ b/lib/instructions/instruction_names.c @@ -76,7 +76,7 @@ static const char* istanbul_names[256] = { /* 0x43 */ "NUMBER", /* 0x44 */ "DIFFICULTY", /* 0x45 */ "GASLIMIT", - /* 0x46 */ NULL, + /* 0x46 */ "CHAINID", /* 0x47 */ NULL, /* 0x48 */ NULL, /* 0x49 */ NULL, diff --git a/test/unittests/test_instructions.cpp b/test/unittests/test_instructions.cpp index 0925c28..f60f910 100644 --- a/test/unittests/test_instructions.cpp +++ b/test/unittests/test_instructions.cpp @@ -251,7 +251,21 @@ TEST(instructions, istanbul_hard_fork) for (int op{OP_STOP}; op <= OP_SELFDESTRUCT; ++op) { - EXPECT_EQ(i[op], p[op]) << op; - EXPECT_STREQ(in[op], pn[op]) << op; + switch (op) + { + case OP_CHAINID: + continue; + default: + EXPECT_EQ(i[op], p[op]) << op; + EXPECT_STREQ(in[op], pn[op]) << op; + break; + } } + + EXPECT_EQ(i[OP_CHAINID].gas_cost, 2); + EXPECT_EQ(i[OP_CHAINID].num_stack_arguments, 0); + EXPECT_EQ(i[OP_CHAINID].num_stack_returned_items, 1); + EXPECT_EQ(p[OP_CHAINID].gas_cost, -1); + EXPECT_EQ(in[OP_CHAINID], std::string{"CHAINID"}); + EXPECT_TRUE(pn[OP_CHAINID] == nullptr); }