Skip to content

Commit

Permalink
Add CALLF and RETF instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Aug 10, 2022
1 parent f2715da commit 1b66b3a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/evmc/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ enum evmc_opcode
OP_CREATE2 = 0xf5,

OP_STATICCALL = 0xfa,

OP_CALLF = 0xfb,
OP_RETF = 0xfc,
OP_REVERT = 0xfd,
OP_INVALID = 0xfe,
OP_SELFDESTRUCT = 0xff
Expand Down
4 changes: 2 additions & 2 deletions lib/instructions/instruction_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ static struct evmc_instruction_metrics cancun_metrics[256] = {
/* = 0xf8 */ {UNDEFINED, 0, 0},
/* = 0xf9 */ {UNDEFINED, 0, 0},
/* STATICCALL = 0xfa */ {WARM_STORAGE_READ_COST, 6, -5},
/* = 0xfb */ {UNDEFINED, 0, 0},
/* = 0xfc */ {UNDEFINED, 0, 0},
/* CALLF = 0xfb */ {MID, 0, 0},
/* RETF = 0xfc */ {MID, 0, 0},
/* REVERT = 0xfd */ {ZERO, 2, -2},
/* INVALID = 0xfe */ {ZERO, 0, 0},
/* SELFDESTRUCT = 0xff */ {5000, 1, -1},
Expand Down
4 changes: 2 additions & 2 deletions lib/instructions/instruction_names.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ static const char* cancun_names[256] = {
/* 0xf8 */ NULL,
/* 0xf9 */ NULL,
/* 0xfa */ "STATICCALL",
/* 0xfb */ NULL,
/* 0xfc */ NULL,
/* 0xfb */ "CALLF",
/* 0xfc */ "RETF",
/* 0xfd */ "REVERT",
/* 0xfe */ "INVALID",
/* 0xff */ "SELFDESTRUCT",
Expand Down
16 changes: 15 additions & 1 deletion test/unittests/instructions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ TEST(instructions, cancun_hard_fork)

for (int op = 0x00; op <= 0xff; ++op)
{
if (op == OP_RJUMP || op == OP_RJUMPI)
if (op == OP_RJUMP || op == OP_RJUMPI || op == OP_CALLF || op == OP_RETF)
continue;
EXPECT_EQ(c[op], s[op]) << op;
EXPECT_STREQ(cn[op], sn[op]) << op;
Expand All @@ -423,4 +423,18 @@ TEST(instructions, cancun_hard_fork)
EXPECT_EQ(s[OP_RJUMPI].gas_cost, 0);
EXPECT_EQ(cn[OP_RJUMPI], std::string{"RJUMPI"});
EXPECT_TRUE(sn[OP_RJUMPI] == nullptr);

// EIP-4750: EOF Functions
EXPECT_EQ(c[OP_CALLF].gas_cost, 8);
EXPECT_EQ(c[OP_CALLF].stack_height_required, 0);
EXPECT_EQ(c[OP_CALLF].stack_height_change, 0);
EXPECT_EQ(s[OP_CALLF].gas_cost, 0);
EXPECT_EQ(cn[OP_CALLF], std::string{"CALLF"});
EXPECT_TRUE(sn[OP_CALLF] == nullptr);
EXPECT_EQ(c[OP_RETF].gas_cost, 8);
EXPECT_EQ(c[OP_RETF].stack_height_required, 0);
EXPECT_EQ(c[OP_RETF].stack_height_change, 0);
EXPECT_EQ(s[OP_RETF].gas_cost, 0);
EXPECT_EQ(cn[OP_RETF], std::string{"RETF"});
EXPECT_TRUE(sn[OP_RETF] == nullptr);
}

0 comments on commit 1b66b3a

Please sign in to comment.