Skip to content

Commit

Permalink
CREATE2 support in instructions lib
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jul 25, 2018
1 parent bc17468 commit cac4f6f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/evmc/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ enum evmc_opcode
OP_CALLCODE = 0xf2,
OP_RETURN = 0xf3,
OP_DELEGATECALL = 0xf4,
OP_CREATE2 = 0xf5,

OP_STATICCALL = 0xfa,

Expand Down
2 changes: 1 addition & 1 deletion lib/instructions/instruction_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static struct evmc_instruction_metrics constantinople_metrics[256] = {
/* CALLCODE = 0xf2 */ {700, 7, 1},
/* RETURN = 0xf3 */ {ZERO, 2, 0},
/* DELEGATECALL = 0xf4 */ {700, 6, 1},
/* = 0xf5 */ {UNDEFINED, 0, 0},
/* CREATE2 = 0xf5 */ {32000, 4, 1},
/* = 0xf6 */ {UNDEFINED, 0, 0},
/* = 0xf7 */ {UNDEFINED, 0, 0},
/* = 0xf8 */ {UNDEFINED, 0, 0},
Expand Down
2 changes: 1 addition & 1 deletion lib/instructions/instruction_names.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static const char* constantinople_names[256] = {
/* 0xf2 */ "CALLCODE",
/* 0xf3 */ "RETURN",
/* 0xf4 */ "DELEGATECALL",
/* 0xf5 */ NULL,
/* 0xf5 */ "CREATE2",
/* 0xf6 */ NULL,
/* 0xf7 */ NULL,
/* 0xf8 */ NULL,
Expand Down
16 changes: 16 additions & 0 deletions test/unittests/test_instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ TEST(instructions, byzantium_hard_fork)
EXPECT_EQ(sdn[OP_STATICCALL], nullptr);
}

TEST(instructions, constantinople_hard_fork)
{
const auto c = evmc_get_instruction_metrics_table(EVMC_CONSTANTINOPLE);
const auto b = evmc_get_instruction_metrics_table(EVMC_BYZANTIUM);
const auto cn = evmc_get_instruction_names_table(EVMC_CONSTANTINOPLE);
const auto bn = evmc_get_instruction_names_table(EVMC_BYZANTIUM);

EXPECT_EQ(c[OP_CREATE2].gas_cost, 32000);
EXPECT_EQ(c[OP_CREATE2].num_stack_arguments, 4);
EXPECT_EQ(c[OP_CREATE2].num_stack_returned_items, 1);
EXPECT_EQ(b[OP_CREATE2].gas_cost, -1);
EXPECT_EQ(cn[OP_CREATE2], std::string{"CREATE2"});
EXPECT_EQ(bn[OP_CREATE2], nullptr);
}


TEST(instructions, name_gas_cost_equivalence)
{
for (auto rev = EVMC_FRONTIER; rev <= EVMC_LATEST_REVISION;
Expand Down

0 comments on commit cac4f6f

Please sign in to comment.