Skip to content

Commit

Permalink
Add PUSH0 instruction (EIP-3855)
Browse files Browse the repository at this point in the history
Add information about PUSH0 instruction introduced by EIP-3855
for the Shanghai revision.

https://eips.ethereum.org/EIPS/eip-3855
  • Loading branch information
chfast committed Feb 12, 2022
1 parent e2378fe commit 20a9a00
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning].

### Added

- Information about `PUSH0` instruction from [EIP-3855](https://eips.ethereum.org/EIPS/eip-3855)
for Shanghai revision.
[#628](https://github.com/ethereum/evmc/pull/628)
- The [Merge](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/merge.md)
EVM revision.
[#627](https://github.com/ethereum/evmc/pull/627)
Expand Down
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 @@ -127,7 +127,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 20a9a00

Please sign in to comment.