Skip to content

Commit

Permalink
Add PUSH0 instruction (EIP-3855)
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Feb 10, 2022
1 parent 839ab88 commit 5c6e2d6
Show file tree
Hide file tree
Showing 4 changed files with 13 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 @@ -94,6 +94,7 @@ enum evmc_opcode
OP_GAS = 0x5a,
OP_JUMPDEST = 0x5b,

OP_PUSH0 = 0x5f,
OP_PUSH1 = 0x60,
OP_PUSH2 = 0x61,
OP_PUSH3 = 0x62,
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 @@ -128,7 +128,7 @@ static struct evmc_instruction_metrics shanghai_metrics[256] = {
/* = 0x5c */ {UNDEFINED, 0, 0},
/* = 0x5d */ {UNDEFINED, 0, 0},
/* = 0x5e */ {UNDEFINED, 0, 0},
/* = 0x5f */ {UNDEFINED, 0, 0},
/* PUSH0 = 0x5f */ {BASE, 0, 1},
/* PUSH1 = 0x60 */ {VERYLOW, 0, 1},
/* PUSH2 = 0x61 */ {VERYLOW, 0, 1},
/* PUSH3 = 0x62 */ {VERYLOW, 0, 1},
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 @@ -100,7 +100,7 @@ static const char* shanghai_names[256] = {
/* 0x5c */ NULL,
/* 0x5d */ NULL,
/* 0x5e */ NULL,
/* 0x5f */ NULL,
/* 0x5f */ "PUSH0",
/* 0x60 */ "PUSH1",
/* 0x61 */ "PUSH2",
/* 0x62 */ "PUSH3",
Expand Down
10 changes: 10 additions & 0 deletions test/unittests/instructions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,17 @@ TEST(instructions, shanghai_hard_fork)

for (int op = 0x00; op <= 0xff; ++op)
{
if (op == OP_PUSH0)
continue;
EXPECT_EQ(s[op], m[op]) << op;
EXPECT_STREQ(sn[op], mn[op]) << op;
}

// EIP-3855: PUSH0 instruction
EXPECT_EQ(s[OP_PUSH0].gas_cost, 2);
EXPECT_EQ(s[OP_PUSH0].stack_height_required, 0);
EXPECT_EQ(s[OP_PUSH0].stack_height_change, 1);
EXPECT_EQ(m[OP_PUSH0].gas_cost, 0);
EXPECT_EQ(sn[OP_PUSH0], std::string{"PUSH0"});
EXPECT_TRUE(mn[OP_PUSH0] == nullptr);
}

0 comments on commit 5c6e2d6

Please sign in to comment.