Skip to content

Commit

Permalink
Upgrade EVMC to 10.0.0-alpha.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 17, 2021
1 parent 0a80512 commit 1dbe29d
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 105 deletions.
18 changes: 9 additions & 9 deletions lib/evmone/instructions.hpp
Expand Up @@ -278,7 +278,7 @@ inline evmc_status_code keccak256(ExecutionState& state) noexcept

inline void address(ExecutionState& state) noexcept
{
state.stack.push(intx::be::load<uint256>(state.msg->destination));
state.stack.push(intx::be::load<uint256>(state.msg->recipient));
}

inline evmc_status_code balance(ExecutionState& state) noexcept
Expand Down Expand Up @@ -559,7 +559,7 @@ inline void chainid(ExecutionState& state) noexcept
inline void selfbalance(ExecutionState& state) noexcept
{
// TODO: introduce selfbalance in EVMC?
state.stack.push(intx::be::load<uint256>(state.host.get_balance(state.msg->destination)));
state.stack.push(intx::be::load<uint256>(state.host.get_balance(state.msg->recipient)));
}


Expand Down Expand Up @@ -609,7 +609,7 @@ inline evmc_status_code sload(ExecutionState& state) noexcept
const auto key = intx::be::store<evmc::bytes32>(x);

if (state.rev >= EVMC_BERLIN &&
state.host.access_storage(state.msg->destination, key) == EVMC_ACCESS_COLD)
state.host.access_storage(state.msg->recipient, key) == EVMC_ACCESS_COLD)
{
// The warm storage access cost is already applied (from the cost table).
// Here we need to apply additional cold storage access cost.
Expand All @@ -619,7 +619,7 @@ inline evmc_status_code sload(ExecutionState& state) noexcept
return EVMC_OUT_OF_GAS;
}

x = intx::be::load<uint256>(state.host.get_storage(state.msg->destination, key));
x = intx::be::load<uint256>(state.host.get_storage(state.msg->recipient, key));

return EVMC_SUCCESS;
}
Expand All @@ -637,10 +637,10 @@ inline evmc_status_code sstore(ExecutionState& state) noexcept

int cost = 0;
if (state.rev >= EVMC_BERLIN &&
state.host.access_storage(state.msg->destination, key) == EVMC_ACCESS_COLD)
state.host.access_storage(state.msg->recipient, key) == EVMC_ACCESS_COLD)
cost = instr::cold_sload_cost;

const auto status = state.host.set_storage(state.msg->destination, key, value);
const auto status = state.host.set_storage(state.msg->recipient, key, value);

switch (status)
{
Expand Down Expand Up @@ -776,7 +776,7 @@ inline evmc_status_code log(ExecutionState& state) noexcept
topic = intx::be::store<evmc::bytes32>(state.stack.pop());

const auto data = s != 0 ? &state.memory[o] : nullptr;
state.host.emit_log(state.msg->destination, data, s, topics.data(), NumTopics);
state.host.emit_log(state.msg->recipient, data, s, topics.data(), NumTopics);
return EVMC_SUCCESS;
}

Expand Down Expand Up @@ -822,7 +822,7 @@ inline StopToken selfdestruct(ExecutionState& state) noexcept

if (state.rev >= EVMC_TANGERINE_WHISTLE)
{
if (state.rev == EVMC_TANGERINE_WHISTLE || state.host.get_balance(state.msg->destination))
if (state.rev == EVMC_TANGERINE_WHISTLE || state.host.get_balance(state.msg->recipient))
{
// After TANGERINE_WHISTLE apply additional cost of
// sending value to a non-existing account.
Expand All @@ -834,7 +834,7 @@ inline StopToken selfdestruct(ExecutionState& state) noexcept
}
}

state.host.selfdestruct(state.msg->destination, beneficiary);
state.host.selfdestruct(state.msg->recipient, beneficiary);
return {EVMC_SUCCESS};
}

Expand Down
11 changes: 5 additions & 6 deletions lib/evmone/instructions_calls.cpp
Expand Up @@ -36,8 +36,8 @@ evmc_status_code call(ExecutionState& state) noexcept
msg.kind = Kind;
msg.flags = Static ? uint32_t{EVMC_STATIC} : state.msg->flags;
msg.depth = state.msg->depth + 1;
msg.destination = dst;
msg.sender = (Kind == EVMC_DELEGATECALL) ? state.msg->sender : state.msg->destination;
msg.recipient = dst;
msg.sender = (Kind == EVMC_DELEGATECALL) ? state.msg->sender : state.msg->recipient;
msg.value =
(Kind == EVMC_DELEGATECALL) ? state.msg->value : intx::be::store<evmc::uint256be>(value);

Expand Down Expand Up @@ -81,8 +81,7 @@ evmc_status_code call(ExecutionState& state) noexcept
if (state.msg->depth >= 1024)
return EVMC_SUCCESS;

if (has_value &&
intx::be::load<uint256>(state.host.get_balance(state.msg->destination)) < value)
if (has_value && intx::be::load<uint256>(state.host.get_balance(state.msg->recipient)) < value)
return EVMC_SUCCESS;

const auto result = state.host.call(msg);
Expand Down Expand Up @@ -132,7 +131,7 @@ evmc_status_code create(ExecutionState& state) noexcept
return EVMC_SUCCESS;

if (endowment != 0 &&
intx::be::load<uint256>(state.host.get_balance(state.msg->destination)) < endowment)
intx::be::load<uint256>(state.host.get_balance(state.msg->recipient)) < endowment)
return EVMC_SUCCESS;

auto msg = evmc_message{};
Expand All @@ -146,7 +145,7 @@ evmc_status_code create(ExecutionState& state) noexcept
msg.input_data = &state.memory[size_t(init_code_offset)];
msg.input_size = size_t(init_code_size);
}
msg.sender = state.msg->destination;
msg.sender = state.msg->recipient;
msg.depth = state.msg->depth + 1;
msg.create2_salt = intx::be::store<evmc::bytes32>(salt);
msg.value = intx::be::store<evmc::uint256be>(endowment);
Expand Down
42 changes: 21 additions & 21 deletions test/unittests/evm_calls_test.cpp
Expand Up @@ -235,8 +235,8 @@ TEST_P(evm, call_with_value)
constexpr auto call_sender = 0x5e4d00000000000000000000000000000000d4e5_address;
constexpr auto call_dst = 0x00000000000000000000000000000000000000aa_address;

msg.destination = call_sender;
host.accounts[msg.destination].set_balance(1);
msg.recipient = call_sender;
host.accounts[msg.recipient].set_balance(1);
host.accounts[call_dst] = {};
host.call_result.gas_left = 1;

Expand All @@ -248,7 +248,7 @@ TEST_P(evm, call_with_value)
EXPECT_EQ(call_msg.kind, EVMC_CALL);
EXPECT_EQ(call_msg.depth, 1);
EXPECT_EQ(call_msg.gas, 32083);
EXPECT_EQ(call_msg.destination, call_dst);
EXPECT_EQ(call_msg.recipient, call_dst);
EXPECT_EQ(call_msg.sender, call_sender);
}

Expand Down Expand Up @@ -350,7 +350,7 @@ TEST_P(evm, call_value_zero_to_nonexistent_account)
EXPECT_EQ(call_msg.depth, 1);
EXPECT_EQ(call_msg.gas, 6000);
EXPECT_EQ(call_msg.input_size, 64);
EXPECT_EQ(call_msg.destination, 0x00000000000000000000000000000000000000aa_address);
EXPECT_EQ(call_msg.recipient, 0x00000000000000000000000000000000000000aa_address);
EXPECT_EQ(call_msg.value.bytes[31], 0);
}

Expand All @@ -360,16 +360,16 @@ TEST_P(evm, call_new_account_creation_cost)
constexpr auto msg_dst = 0x0000000000000000000000000000000000000003_address;
const auto code = 4 * push(0) + calldataload(0) + push({call_dst.bytes, sizeof(call_dst)}) +
push(0) + OP_CALL + ret_top();
msg.destination = msg_dst;
msg.recipient = msg_dst;


rev = EVMC_TANGERINE_WHISTLE;
host.accounts[msg.destination].set_balance(0);
host.accounts[msg.recipient].set_balance(0);
execute(code, "00");
EXPECT_GAS_USED(EVMC_SUCCESS, 25000 + 739);
EXPECT_OUTPUT_INT(1);
ASSERT_EQ(host.recorded_calls.size(), 1);
EXPECT_EQ(host.recorded_calls.back().destination, call_dst);
EXPECT_EQ(host.recorded_calls.back().recipient, call_dst);
EXPECT_EQ(host.recorded_calls.back().gas, 0);
ASSERT_EQ(host.recorded_account_accesses.size(), 2);
EXPECT_EQ(host.recorded_account_accesses[0], call_dst); // Account exist?
Expand All @@ -378,30 +378,30 @@ TEST_P(evm, call_new_account_creation_cost)
host.recorded_calls.clear();

rev = EVMC_TANGERINE_WHISTLE;
host.accounts[msg.destination].set_balance(1);
host.accounts[msg.recipient].set_balance(1);
execute(code, "0000000000000000000000000000000000000000000000000000000000000001");
EXPECT_GAS_USED(EVMC_SUCCESS, 25000 + 9000 + 739);
EXPECT_OUTPUT_INT(1);
ASSERT_EQ(host.recorded_calls.size(), 1);
EXPECT_EQ(host.recorded_calls.back().destination, call_dst);
EXPECT_EQ(host.recorded_calls.back().recipient, call_dst);
EXPECT_EQ(host.recorded_calls.back().gas, 2300);
EXPECT_EQ(host.recorded_calls.back().sender, msg_dst);
EXPECT_EQ(host.recorded_calls.back().value.bytes[31], 1);
EXPECT_EQ(host.recorded_calls.back().input_size, 0);
ASSERT_EQ(host.recorded_account_accesses.size(), 3);
EXPECT_EQ(host.recorded_account_accesses[0], call_dst); // Account exist?
EXPECT_EQ(host.recorded_account_accesses[1], msg.destination); // Balance.
EXPECT_EQ(host.recorded_account_accesses[2], call_dst); // Call.
EXPECT_EQ(host.recorded_account_accesses[0], call_dst); // Account exist?
EXPECT_EQ(host.recorded_account_accesses[1], msg.recipient); // Balance.
EXPECT_EQ(host.recorded_account_accesses[2], call_dst); // Call.
host.recorded_account_accesses.clear();
host.recorded_calls.clear();

rev = EVMC_SPURIOUS_DRAGON;
host.accounts[msg.destination].set_balance(0);
host.accounts[msg.recipient].set_balance(0);
execute(code, "00");
EXPECT_GAS_USED(EVMC_SUCCESS, 739);
EXPECT_OUTPUT_INT(1);
ASSERT_EQ(host.recorded_calls.size(), 1);
EXPECT_EQ(host.recorded_calls.back().destination, call_dst);
EXPECT_EQ(host.recorded_calls.back().recipient, call_dst);
EXPECT_EQ(host.recorded_calls.back().gas, 0);
EXPECT_EQ(host.recorded_calls.back().sender, msg_dst);
EXPECT_EQ(host.recorded_calls.back().value.bytes[31], 0);
Expand All @@ -412,20 +412,20 @@ TEST_P(evm, call_new_account_creation_cost)
host.recorded_calls.clear();

rev = EVMC_SPURIOUS_DRAGON;
host.accounts[msg.destination].set_balance(1);
host.accounts[msg.recipient].set_balance(1);
execute(code, "0000000000000000000000000000000000000000000000000000000000000001");
EXPECT_GAS_USED(EVMC_SUCCESS, 25000 + 9000 + 739);
EXPECT_OUTPUT_INT(1);
ASSERT_EQ(host.recorded_calls.size(), 1);
EXPECT_EQ(host.recorded_calls.back().destination, call_dst);
EXPECT_EQ(host.recorded_calls.back().recipient, call_dst);
EXPECT_EQ(host.recorded_calls.back().gas, 2300);
EXPECT_EQ(host.recorded_calls.back().sender, msg_dst);
EXPECT_EQ(host.recorded_calls.back().value.bytes[31], 1);
EXPECT_EQ(host.recorded_calls.back().input_size, 0);
ASSERT_EQ(host.recorded_account_accesses.size(), 3);
EXPECT_EQ(host.recorded_account_accesses[0], call_dst); // Account exist?
EXPECT_EQ(host.recorded_account_accesses[1], msg.destination); // Balance.
EXPECT_EQ(host.recorded_account_accesses[2], call_dst); // Call.
EXPECT_EQ(host.recorded_account_accesses[0], call_dst); // Account exist?
EXPECT_EQ(host.recorded_account_accesses[1], msg.recipient); // Balance.
EXPECT_EQ(host.recorded_account_accesses[2], call_dst); // Call.
host.recorded_account_accesses.clear();
host.recorded_calls.clear();
}
Expand All @@ -435,8 +435,8 @@ TEST_P(evm, callcode_new_account_create)
constexpr auto code = "60008080806001600061c350f250";
constexpr auto call_sender = 0x5e4d00000000000000000000000000000000d4e5_address;

msg.destination = call_sender;
host.accounts[msg.destination].set_balance(1);
msg.recipient = call_sender;
host.accounts[msg.recipient].set_balance(1);
host.call_result.gas_left = 1;
execute(100000, code);
EXPECT_EQ(gas_used, 59722);
Expand Down
52 changes: 26 additions & 26 deletions test/unittests/evm_eip2929_test.cpp
Expand Up @@ -15,7 +15,7 @@ TEST_P(evm, eip2929_case1)
// https://gist.github.com/holiman/174548cad102096858583c6fbbb0649a#case-1
rev = EVMC_BERLIN;
msg.sender = 0x0000000000000000000000000000000000000000_address;
msg.destination = 0x000000000000000000000000636F6E7472616374_address;
msg.recipient = 0x000000000000000000000000636F6E7472616374_address;
const auto code =
"0x60013f5060023b506003315060f13f5060f23b5060f3315060f23f5060f33b5060f1315032315030315000";

Expand All @@ -26,7 +26,7 @@ TEST_P(evm, eip2929_case1)
const auto& r = host.recorded_account_accesses;
ASSERT_EQ(r.size(), 24);
EXPECT_EQ(r[0], msg.sender);
EXPECT_EQ(r[1], msg.destination);
EXPECT_EQ(r[1], msg.recipient);
EXPECT_EQ(r[2], 0x0000000000000000000000000000000000000001_address);
EXPECT_EQ(r[3], 0x0000000000000000000000000000000000000001_address);
EXPECT_EQ(r[4], 0x0000000000000000000000000000000000000002_address);
Expand All @@ -47,16 +47,16 @@ TEST_P(evm, eip2929_case1)
EXPECT_EQ(r[19], 0x00000000000000000000000000000000000000f1_address);
EXPECT_EQ(r[20], 0x0000000000000000000000000000000000000000_address);
EXPECT_EQ(r[21], 0x0000000000000000000000000000000000000000_address);
EXPECT_EQ(r[22], msg.destination);
EXPECT_EQ(r[23], msg.destination);
EXPECT_EQ(r[22], msg.recipient);
EXPECT_EQ(r[23], msg.recipient);
}

TEST_P(evm, eip2929_case2)
{
// https://gist.github.com/holiman/174548cad102096858583c6fbbb0649a#case-2
rev = EVMC_BERLIN;
msg.sender = 0x0000000000000000000000000000000000000000_address;
msg.destination = 0x000000000000000000000000636F6E7472616374_address;
msg.recipient = 0x000000000000000000000000636F6E7472616374_address;
const auto code = "0x60006000600060ff3c60006000600060ff3c600060006000303c00";

execute(code);
Expand All @@ -66,18 +66,18 @@ TEST_P(evm, eip2929_case2)
const auto& r = host.recorded_account_accesses;
ASSERT_EQ(r.size(), 5);
EXPECT_EQ(r[0], msg.sender);
EXPECT_EQ(r[1], msg.destination);
EXPECT_EQ(r[1], msg.recipient);
EXPECT_EQ(r[2], 0x00000000000000000000000000000000000000ff_address);
EXPECT_EQ(r[3], 0x00000000000000000000000000000000000000ff_address);
EXPECT_EQ(r[4], msg.destination);
EXPECT_EQ(r[4], msg.recipient);
}

TEST_P(evm, eip2929_case3)
{
// https://gist.github.com/holiman/174548cad102096858583c6fbbb0649a#case-3
rev = EVMC_BERLIN;
msg.sender = 0x0000000000000000000000000000000000000000_address;
msg.destination = 0x000000000000000000000000636F6E7472616374_address;
msg.recipient = 0x000000000000000000000000636F6E7472616374_address;
const auto code = "0x60015450601160015560116002556011600255600254600154";

execute(code);
Expand All @@ -90,7 +90,7 @@ TEST_P(evm, eip2929_case4)
// https://gist.github.com/holiman/174548cad102096858583c6fbbb0649a#case-4
rev = EVMC_BERLIN;
msg.sender = 0x0000000000000000000000000000000000000000_address;
msg.destination = 0x000000000000000000000000636F6E7472616374_address;
msg.recipient = 0x000000000000000000000000636F6E7472616374_address;
const auto code = "0x60008080808060046000f15060008080808060ff6000f15060008080808060ff6000fa50";

execute(code);
Expand Down Expand Up @@ -156,13 +156,13 @@ TEST_P(evm, eip2929_sload_cold)
const auto code = push(1) + OP_SLOAD;

const evmc::bytes32 key{1};
host.accounts[msg.destination].storage[key] = evmc::bytes32{2};
ASSERT_EQ(host.accounts[msg.destination].storage[key].access_status, EVMC_ACCESS_COLD);
host.accounts[msg.recipient].storage[key] = evmc::bytes32{2};
ASSERT_EQ(host.accounts[msg.recipient].storage[key].access_status, EVMC_ACCESS_COLD);
execute(2103, code);
EXPECT_GAS_USED(EVMC_SUCCESS, 2103);
EXPECT_EQ(host.accounts[msg.destination].storage[key].access_status, EVMC_ACCESS_WARM);
EXPECT_EQ(host.accounts[msg.recipient].storage[key].access_status, EVMC_ACCESS_WARM);

host.accounts[msg.destination].storage[key].access_status = EVMC_ACCESS_COLD;
host.accounts[msg.recipient].storage[key].access_status = EVMC_ACCESS_COLD;
execute(2102, code);
EXPECT_GAS_USED(EVMC_OUT_OF_GAS, 2102);
}
Expand All @@ -176,8 +176,8 @@ TEST_P(evm, eip2929_sload_two_slots)

execute(30000, code);
EXPECT_GAS_USED(EVMC_SUCCESS, 4210);
EXPECT_EQ(host.accounts[msg.destination].storage[key0].access_status, EVMC_ACCESS_WARM);
EXPECT_EQ(host.accounts[msg.destination].storage[key1].access_status, EVMC_ACCESS_WARM);
EXPECT_EQ(host.accounts[msg.recipient].storage[key0].access_status, EVMC_ACCESS_WARM);
EXPECT_EQ(host.accounts[msg.recipient].storage[key1].access_status, EVMC_ACCESS_WARM);
}

TEST_P(evm, eip2929_sload_warm)
Expand All @@ -186,11 +186,11 @@ TEST_P(evm, eip2929_sload_warm)
const auto code = push(1) + OP_SLOAD;

const evmc::bytes32 key{1};
host.accounts[msg.destination].storage[key] = {evmc::bytes32{2}, EVMC_ACCESS_WARM};
ASSERT_EQ(host.accounts[msg.destination].storage[key].access_status, EVMC_ACCESS_WARM);
host.accounts[msg.recipient].storage[key] = {evmc::bytes32{2}, EVMC_ACCESS_WARM};
ASSERT_EQ(host.accounts[msg.recipient].storage[key].access_status, EVMC_ACCESS_WARM);
execute(103, code);
EXPECT_GAS_USED(EVMC_SUCCESS, 103);
EXPECT_EQ(host.accounts[msg.destination].storage[key].access_status, EVMC_ACCESS_WARM);
EXPECT_EQ(host.accounts[msg.recipient].storage[key].access_status, EVMC_ACCESS_WARM);

execute(102, code);
EXPECT_GAS_USED(EVMC_OUT_OF_GAS, 102);
Expand All @@ -202,18 +202,18 @@ TEST_P(evm, eip2929_sstore_modify_cold)
const auto code = sstore(1, 3);

const evmc::bytes32 key{1};
host.accounts[msg.destination].storage[key] = evmc::bytes32{2};
host.accounts[msg.recipient].storage[key] = evmc::bytes32{2};
execute(5006, code);
EXPECT_GAS_USED(EVMC_SUCCESS, 5006);
EXPECT_EQ(host.accounts[msg.destination].storage[key].value, evmc::bytes32{3});
EXPECT_EQ(host.accounts[msg.destination].storage[key].access_status, EVMC_ACCESS_WARM);
EXPECT_EQ(host.accounts[msg.recipient].storage[key].value, evmc::bytes32{3});
EXPECT_EQ(host.accounts[msg.recipient].storage[key].access_status, EVMC_ACCESS_WARM);

host.accounts[msg.destination].storage[key] = evmc::bytes32{2};
host.accounts[msg.recipient].storage[key] = evmc::bytes32{2};
execute(5005, code);
EXPECT_GAS_USED(EVMC_OUT_OF_GAS, 5005);
// The storage will be modified anyway, because the cost is checked after.
EXPECT_EQ(host.accounts[msg.destination].storage[key].value, evmc::bytes32{3});
EXPECT_EQ(host.accounts[msg.destination].storage[key].access_status, EVMC_ACCESS_WARM);
EXPECT_EQ(host.accounts[msg.recipient].storage[key].value, evmc::bytes32{3});
EXPECT_EQ(host.accounts[msg.recipient].storage[key].access_status, EVMC_ACCESS_WARM);
}

TEST_P(evm, eip2929_selfdestruct_cold_beneficiary)
Expand Down Expand Up @@ -254,7 +254,7 @@ TEST_P(evm, eip2929_delegatecall_cold)
EXPECT_GAS_USED(EVMC_SUCCESS, 2618);
ASSERT_EQ(r.size(), 4);
EXPECT_EQ(r[0], msg.sender);
EXPECT_EQ(r[1], msg.destination);
EXPECT_EQ(r[1], msg.recipient);
EXPECT_EQ(r[2], 0x00000000000000000000000000000000000000de_address);
EXPECT_EQ(r[3], 0x00000000000000000000000000000000000000de_address);

Expand All @@ -263,6 +263,6 @@ TEST_P(evm, eip2929_delegatecall_cold)
EXPECT_GAS_USED(EVMC_OUT_OF_GAS, 2617);
ASSERT_EQ(r.size(), 3);
EXPECT_EQ(r[0], msg.sender);
EXPECT_EQ(r[1], msg.destination);
EXPECT_EQ(r[1], msg.recipient);
EXPECT_EQ(r[2], 0x00000000000000000000000000000000000000de_address);
}

0 comments on commit 1dbe29d

Please sign in to comment.