diff --git a/evmc b/evmc index f6d3f97e13..e9d4648200 160000 --- a/evmc +++ b/evmc @@ -1 +1 @@ -Subproject commit f6d3f97e131785adb0207d35c59e5a529f385355 +Subproject commit e9d4648200d73c1ce63b74a33a50758db1fd48db diff --git a/lib/evmone/instructions.cpp b/lib/evmone/instructions.cpp index f8581df0bc..2e4c195cbf 100644 --- a/lib/evmone/instructions.cpp +++ b/lib/evmone/instructions.cpp @@ -714,7 +714,7 @@ void op_log(execution_state& state, size_t num_topics) noexcept if ((state.gas_left -= cost) < 0) return state.exit(EVMC_OUT_OF_GAS); - auto topics = std::array{}; + auto topics = std::array{}; for (size_t i = 0; i < num_topics; ++i) intx::be::store(topics[i].bytes, state.stack.pop()); @@ -1158,20 +1158,12 @@ void op_selfdestruct(execution_state& state, instr_argument) noexcept uint8_t data[32]; intx::be::store(data, state.stack[0]); - evmc_address addr; + evmc::address addr; std::memcpy(addr.bytes, &data[12], sizeof(addr)); if (state.rev >= EVMC_TANGERINE_WHISTLE) { - auto check_existance = true; - - if (state.rev >= EVMC_SPURIOUS_DRAGON) - { - auto balance = state.host.get_balance(state.msg->destination); - check_existance = !is_zero(balance); - } - - if (check_existance) + if (state.rev == EVMC_TANGERINE_WHISTLE || state.host.get_balance(state.msg->destination)) { // After TANGERINE_WHISTLE apply additional cost of // sending value to a non-existing account. diff --git a/test/unittests/evm_calls_test.cpp b/test/unittests/evm_calls_test.cpp index 79cd5d48de..4deff3d861 100644 --- a/test/unittests/evm_calls_test.cpp +++ b/test/unittests/evm_calls_test.cpp @@ -181,7 +181,7 @@ TEST_F(evm, call_with_value) auto code = "60ff600060ff6000600160aa618000f150"; accounts[{}].set_balance(1); - auto call_dst = evmc_address{}; + auto call_dst = evmc::address{}; call_dst.bytes[19] = 0xaa; accounts[call_dst] = {}; call_result.gas_left = 1; diff --git a/test/unittests/evm_test.cpp b/test/unittests/evm_test.cpp index 35810b6051..67af477deb 100644 --- a/test/unittests/evm_test.cpp +++ b/test/unittests/evm_test.cpp @@ -562,7 +562,7 @@ TEST_F(evm, sstore_cost) { auto& storage = accounts[msg.destination].storage; - auto v1 = evmc_bytes32{}; + auto v1 = evmc::bytes32{}; v1.bytes[31] = 1; auto revs = {EVMC_BYZANTIUM, EVMC_CONSTANTINOPLE, EVMC_PETERSBURG}; diff --git a/test/utils/host_mock.hpp b/test/utils/host_mock.hpp index ae661646d9..b70e70683a 100644 --- a/test/utils/host_mock.hpp +++ b/test/utils/host_mock.hpp @@ -4,7 +4,6 @@ #pragma once #include -#include #include #include #include @@ -15,29 +14,29 @@ struct MockedAccount { struct storage_value { - evmc_bytes32 value{}; + evmc::bytes32 value; /// True means this value has been modified already by the current transaction. bool dirty{false}; storage_value() noexcept = default; - storage_value(const evmc_bytes32& _value, bool _dirty = false) noexcept // NOLINT + storage_value(const evmc::bytes32& _value, bool _dirty = false) noexcept // NOLINT : value{_value}, dirty{_dirty} {} }; bytes code; - evmc_bytes32 codehash; - evmc_uint256be balance; - std::unordered_map storage; + evmc::bytes32 codehash; + evmc::uint256be balance; + std::unordered_map storage; /// Helper method for setting balance by numeric type. /// Might not be needed when intx API is improved, /// track https://github.com/chfast/intx/issues/105. void set_balance(uint64_t x) noexcept { - balance = evmc_uint256be{}; + balance = evmc::uint256be{}; for (std::size_t i = 0; i < sizeof(x); ++i) balance.bytes[sizeof(balance) - 1 - i] = static_cast(x >> (8 * i)); } @@ -48,11 +47,11 @@ class MockedHost : public evmc::Host public: struct log_record { - evmc_address address; + evmc::address address; bytes data; - std::vector topics; + std::vector topics; - bool operator==(const log_record& other) noexcept + bool operator==(const log_record& other) const noexcept { return address == other.address && data == other.data && std::equal( @@ -62,27 +61,27 @@ class MockedHost : public evmc::Host struct selfdestuct_record { - evmc_address address; - evmc_address beneficiary; + evmc::address address; + evmc::address beneficiary; - bool operator==(const selfdestuct_record& other) noexcept + bool operator==(const selfdestuct_record& other) const noexcept { return address == other.address && beneficiary == other.beneficiary; } }; - std::unordered_map accounts; + std::unordered_map accounts; evmc_tx_context tx_context = {}; - evmc_bytes32 blockhash = {}; + evmc::bytes32 blockhash = {}; evmc_result call_result = {}; std::vector recorded_blockhashes; static constexpr auto max_recorded_account_accesses = 200; - std::vector recorded_account_accesses; + std::vector recorded_account_accesses; static constexpr auto max_recorded_calls = 100; std::vector recorded_calls; @@ -93,7 +92,7 @@ class MockedHost : public evmc::Host protected: std::vector m_recorded_calls_inputs; - void record_account_access(const evmc_address& addr) + void record_account_access(const evmc::address& addr) { if (recorded_account_accesses.empty()) recorded_account_accesses.reserve(max_recorded_account_accesses); @@ -102,13 +101,13 @@ class MockedHost : public evmc::Host recorded_account_accesses.emplace_back(addr); } - bool account_exists(const evmc_address& addr) noexcept override + bool account_exists(const evmc::address& addr) noexcept override { record_account_access(addr); return accounts.count(addr); } - evmc_bytes32 get_storage(const evmc_address& addr, const evmc_bytes32& key) noexcept override + evmc::bytes32 get_storage(const evmc::address& addr, const evmc::bytes32& key) noexcept override { record_account_access(addr); const auto ait = accounts.find(addr); @@ -120,8 +119,8 @@ class MockedHost : public evmc::Host return {}; } - evmc_storage_status set_storage(const evmc_address& addr, const evmc_bytes32& key, - const evmc_bytes32& value) noexcept override + evmc_storage_status set_storage(const evmc::address& addr, const evmc::bytes32& key, + const evmc::bytes32& value) noexcept override { record_account_access(addr); const auto it = accounts.find(addr); @@ -141,12 +140,12 @@ class MockedHost : public evmc::Host if (!old.dirty) { old.dirty = true; - if (is_zero(old.value)) + if (!old.value) status = EVMC_STORAGE_ADDED; - else if (is_zero(value)) - status = EVMC_STORAGE_DELETED; - else + else if (value) status = EVMC_STORAGE_MODIFIED; + else + status = EVMC_STORAGE_DELETED; } else status = EVMC_STORAGE_MODIFIED_AGAIN; @@ -156,7 +155,7 @@ class MockedHost : public evmc::Host return status; } - evmc_uint256be get_balance(const evmc_address& addr) noexcept override + evmc::uint256be get_balance(const evmc::address& addr) noexcept override { record_account_access(addr); const auto it = accounts.find(addr); @@ -166,7 +165,7 @@ class MockedHost : public evmc::Host return it->second.balance; } - size_t get_code_size(const evmc_address& addr) noexcept override + size_t get_code_size(const evmc::address& addr) noexcept override { record_account_access(addr); const auto it = accounts.find(addr); @@ -175,7 +174,7 @@ class MockedHost : public evmc::Host return it->second.code.size(); } - evmc_bytes32 get_code_hash(const evmc_address& addr) noexcept override + evmc::bytes32 get_code_hash(const evmc::address& addr) noexcept override { record_account_access(addr); const auto it = accounts.find(addr); @@ -184,7 +183,7 @@ class MockedHost : public evmc::Host return it->second.codehash; } - size_t copy_code(const evmc_address& addr, size_t code_offset, uint8_t* buffer_data, + size_t copy_code(const evmc::address& addr, size_t code_offset, uint8_t* buffer_data, size_t buffer_size) noexcept override { record_account_access(addr); @@ -204,7 +203,7 @@ class MockedHost : public evmc::Host return n; } - void selfdestruct(const evmc_address& addr, const evmc_address& beneficiary) noexcept override + void selfdestruct(const evmc::address& addr, const evmc::address& beneficiary) noexcept override { record_account_access(addr); recorded_selfdestructs.push_back({addr, beneficiary}); @@ -235,14 +234,14 @@ class MockedHost : public evmc::Host evmc_tx_context get_tx_context() noexcept override { return tx_context; } - evmc_bytes32 get_block_hash(int64_t block_number) noexcept override + evmc::bytes32 get_block_hash(int64_t block_number) noexcept override { recorded_blockhashes.emplace_back(block_number); return blockhash; } - void emit_log(const evmc_address& addr, const uint8_t* data, size_t data_size, - const evmc_bytes32 topics[], size_t topics_count) noexcept override + void emit_log(const evmc::address& addr, const uint8_t* data, size_t data_size, + const evmc::bytes32 topics[], size_t topics_count) noexcept override { recorded_logs.push_back({addr, {data, data_size}, {}}); auto& record_topics = recorded_logs.back().topics;