Support for CHAINID opcode
MODIFY
include/evmc/evmc.h
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;

MODIFY
include/evmc/evmc.hpp
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} {}

MODIFY
include/evmc/instructions.h
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,

MODIFY
lib/instructions/instruction_metrics.c
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},

MODIFY
lib/instructions/instruction_names.c
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,

MODIFY
test/unittests/test_instructions.cpp
test/unittests/test_instructions.cpp
@@ -251,7 +251,21 @@ TEST(instructions, istanbul_hard_fork)
for (int op{OP_STOP}; op <= OP_SELFDESTRUCT; ++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);
}

Support for EIP-1344 CHAINID opcode