Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 56ea037

Browse files
committed
Add RJUMP and RJUMPI instructions
1 parent 8eeb892 commit 56ea037

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

include/evmc/instructions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ enum evmc_opcode
9393
OP_MSIZE = 0x59,
9494
OP_GAS = 0x5a,
9595
OP_JUMPDEST = 0x5b,
96+
OP_RJUMP = 0x5c,
97+
OP_RJUMPI = 0x5d,
98+
// OP_RJUMPTABLE = 0x5e,
9699

97100
OP_PUSH0 = 0x5f,
98101
OP_PUSH1 = 0x60,

lib/instructions/instruction_metrics.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ static struct evmc_instruction_metrics cancun_metrics[256] = {
124124
/* MSIZE = 0x59 */ {BASE, 0, 1},
125125
/* GAS = 0x5a */ {BASE, 0, 1},
126126
/* JUMPDEST = 0x5b */ {1, 0, 0},
127-
/* = 0x5c */ {UNDEFINED, 0, 0},
128-
/* = 0x5d */ {UNDEFINED, 0, 0},
127+
/* RJUMP = 0x5c */ {LOW, 0, 0},
128+
/* RJUMPI = 0x5d */ {7, 1, -1},
129129
/* = 0x5e */ {UNDEFINED, 0, 0},
130130
/* PUSH0 = 0x5f */ {BASE, 0, 1},
131131
/* PUSH1 = 0x60 */ {VERYLOW, 0, 1},

lib/instructions/instruction_names.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ static const char* cancun_names[256] = {
9797
/* 0x59 */ "MSIZE",
9898
/* 0x5a */ "GAS",
9999
/* 0x5b */ "JUMPDEST",
100-
/* 0x5c */ NULL,
101-
/* 0x5d */ NULL,
100+
/* 0x5c */ "RJUMP",
101+
/* 0x5d */ "RJUMPI",
102102
/* 0x5e */ NULL,
103103
/* 0x5f */ "PUSH0",
104104
/* 0x60 */ "PUSH1",

test/unittests/instructions_test.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,33 @@ TEST(instructions, shanghai_hard_fork)
394394
EXPECT_EQ(sn[OP_PUSH0], std::string{"PUSH0"});
395395
EXPECT_TRUE(pn[OP_PUSH0] == nullptr);
396396
}
397+
398+
TEST(instructions, cancun_hard_fork)
399+
{
400+
const auto c = evmc_get_instruction_metrics_table(EVMC_CANCUN);
401+
const auto s = evmc_get_instruction_metrics_table(EVMC_SHANGHAI);
402+
const auto cn = evmc_get_instruction_names_table(EVMC_CANCUN);
403+
const auto sn = evmc_get_instruction_names_table(EVMC_SHANGHAI);
404+
405+
for (int op = 0x00; op <= 0xff; ++op)
406+
{
407+
if (op == OP_RJUMP || op == OP_RJUMPI)
408+
continue;
409+
EXPECT_EQ(c[op], s[op]) << op;
410+
EXPECT_STREQ(cn[op], sn[op]) << op;
411+
}
412+
413+
// EIP-4200: Static relative jumps
414+
EXPECT_EQ(c[OP_RJUMP].gas_cost, 5);
415+
EXPECT_EQ(c[OP_RJUMP].stack_height_required, 0);
416+
EXPECT_EQ(c[OP_RJUMP].stack_height_change, 0);
417+
EXPECT_EQ(s[OP_RJUMP].gas_cost, 0);
418+
EXPECT_EQ(cn[OP_RJUMP], std::string{"RJUMP"});
419+
EXPECT_TRUE(sn[OP_RJUMP] == nullptr);
420+
EXPECT_EQ(c[OP_RJUMPI].gas_cost, 7);
421+
EXPECT_EQ(c[OP_RJUMPI].stack_height_required, 1);
422+
EXPECT_EQ(c[OP_RJUMPI].stack_height_change, -1);
423+
EXPECT_EQ(s[OP_RJUMPI].gas_cost, 0);
424+
EXPECT_EQ(cn[OP_RJUMPI], std::string{"RJUMPI"});
425+
EXPECT_TRUE(sn[OP_RJUMPI] == nullptr);
426+
}

0 commit comments

Comments
 (0)