Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instructions: add SELFBALANCE from EIP-1884 #372

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ and this project adheres to [Semantic Versioning].

### Added

- Support for Istanbul CHAINID opcode. `chain_id` added to `evmc_tx_context` struct.
- Support for Istanbul EIP-1344 (CHAINID opcode). `chain_id` added to `evmc_tx_context` struct.
[[#375](https://github.com/ethereum/evmc/pull/375)]
- Support for Istanbul EIP-1884 (Repricing for trie-size-dependent opcodes).
[[#372](https://github.com/ethereum/evmc/pull/372)]
- The **Berlin** EVM revision has been added.
[[#407](https://github.com/ethereum/evmc/pull/407)]

Expand Down
1 change: 1 addition & 0 deletions include/evmc/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enum evmc_opcode
OP_DIFFICULTY = 0x44,
OP_GASLIMIT = 0x45,
OP_CHAINID = 0x46,
OP_SELFBALANCE = 0x47,
axic marked this conversation as resolved.
Show resolved Hide resolved

OP_POP = 0x50,
OP_MLOAD = 0x51,
Expand Down
8 changes: 4 additions & 4 deletions lib/instructions/instruction_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static struct evmc_instruction_metrics istanbul_metrics[256] = {
/* = 0x2e */ {UNDEFINED, 0, 0},
/* = 0x2f */ {UNDEFINED, 0, 0},
/* ADDRESS = 0x30 */ {BASE, 0, 1},
/* BALANCE = 0x31 */ {400, 1, 1},
/* BALANCE = 0x31 */ {700, 1, 1},
/* ORIGIN = 0x32 */ {BASE, 0, 1},
/* CALLER = 0x33 */ {BASE, 0, 1},
/* CALLVALUE = 0x34 */ {BASE, 0, 1},
Expand All @@ -85,15 +85,15 @@ static struct evmc_instruction_metrics istanbul_metrics[256] = {
/* EXTCODECOPY = 0x3c */ {700, 4, 0},
/* RETURNDATASIZE = 0x3d */ {BASE, 0, 1},
/* RETURNDATACOPY = 0x3e */ {VERYLOW, 3, 0},
/* EXTCODEHASH = 0x3f */ {400, 1, 1},
/* EXTCODEHASH = 0x3f */ {700, 1, 1},
/* BLOCKHASH = 0x40 */ {20, 1, 1},
/* COINBASE = 0x41 */ {BASE, 0, 1},
/* TIMESTAMP = 0x42 */ {BASE, 0, 1},
/* NUMBER = 0x43 */ {BASE, 0, 1},
/* DIFFICULTY = 0x44 */ {BASE, 0, 1},
/* GASLIMIT = 0x45 */ {BASE, 0, 1},
/* CHAINID = 0x46 */ {BASE, 0, 1},
/* = 0x47 */ {UNDEFINED, 0, 0},
/* SELFBALANCE = 0x47 */ {LOW, 0, 1},
/* = 0x48 */ {UNDEFINED, 0, 0},
/* = 0x49 */ {UNDEFINED, 0, 0},
/* = 0x4a */ {UNDEFINED, 0, 0},
Expand All @@ -106,7 +106,7 @@ static struct evmc_instruction_metrics istanbul_metrics[256] = {
/* MLOAD = 0x51 */ {VERYLOW, 1, 1},
/* MSTORE = 0x52 */ {VERYLOW, 2, 0},
/* MSTORE8 = 0x53 */ {VERYLOW, 2, 0},
/* SLOAD = 0x54 */ {200, 1, 1},
/* SLOAD = 0x54 */ {800, 1, 1},
/* SSTORE = 0x55 */ {0, 2, 0},
/* JUMP = 0x56 */ {MID, 1, 0},
/* JUMPI = 0x57 */ {HIGH, 2, 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 @@ -77,7 +77,7 @@ static const char* istanbul_names[256] = {
/* 0x44 */ "DIFFICULTY",
/* 0x45 */ "GASLIMIT",
/* 0x46 */ "CHAINID",
/* 0x47 */ NULL,
/* 0x47 */ "SELFBALANCE",
/* 0x48 */ NULL,
/* 0x49 */ NULL,
/* 0x4a */ 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 @@ -253,7 +253,11 @@ TEST(instructions, istanbul_hard_fork)
{
switch (op)
{
case OP_BALANCE:
case OP_EXTCODEHASH:
case OP_CHAINID:
case OP_SELFBALANCE:
case OP_SLOAD:
continue;
default:
EXPECT_EQ(i[op], p[op]) << op;
Expand All @@ -268,6 +272,18 @@ TEST(instructions, istanbul_hard_fork)
EXPECT_EQ(p[OP_CHAINID].gas_cost, -1);
EXPECT_EQ(in[OP_CHAINID], std::string{"CHAINID"});
EXPECT_TRUE(pn[OP_CHAINID] == nullptr);

EXPECT_EQ(i[OP_SELFBALANCE].gas_cost, 5);
EXPECT_EQ(i[OP_SELFBALANCE].num_stack_arguments, 0);
EXPECT_EQ(i[OP_SELFBALANCE].num_stack_returned_items, 1);
EXPECT_EQ(p[OP_SELFBALANCE].gas_cost, -1);
EXPECT_EQ(in[OP_SELFBALANCE], std::string{"SELFBALANCE"});
EXPECT_TRUE(pn[OP_SELFBALANCE] == nullptr);

// Repricings
EXPECT_EQ(i[OP_BALANCE].gas_cost, 700);
EXPECT_EQ(i[OP_EXTCODEHASH].gas_cost, 700);
EXPECT_EQ(i[OP_SLOAD].gas_cost, 800);
axic marked this conversation as resolved.
Show resolved Hide resolved
}

TEST(instructions, berlin_hard_fork)
Expand Down