mirror of https://github.com/status-im/evmc.git
Add names table for each EVM revision
This commit is contained in:
parent
94bb5fbec9
commit
cb9ebb7c82
|
@ -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
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||
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<evmc_revision>(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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue