Support for EIP-1344 CHAINID opcode

This commit is contained in:
Andrei Maiboroda 2019-07-30 16:57:41 +02:00 committed by Paweł Bylica
parent 279d6dad25
commit cd93feaf9f
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
6 changed files with 21 additions and 6 deletions

View File

@ -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;

View File

@ -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} {}

View File

@ -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,

View File

@ -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},

View File

@ -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,

View File

@ -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);
}