Skip to content

Commit

Permalink
Upgrade EVMC to 6.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 19, 2019
1 parent ba43060 commit d8f9883
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 47 deletions.
2 changes: 1 addition & 1 deletion evmc
Submodule evmc updated 60 files
+1 −1 .bumpversion.cfg
+26 −5 .clang-format
+299 −139 CHANGELOG.md
+32 −25 CMakeLists.txt
+1 −1 Doxyfile
+1 −1 README.md
+6 −2 appveyor.yml
+20 −0 bindings/go/evmc/evmc.go
+15 −1 bindings/go/evmc/evmc_test.go
+0 −7 bindings/go/evmc/host.c
+5 −12 bindings/go/evmc/host.go
+25 −2 bindings/go/evmc/host_test.go
+1 −1 bindings/rust/evmc-declare-tests/Cargo.toml
+8 −1 bindings/rust/evmc-declare-tests/src/lib.rs
+1 −1 bindings/rust/evmc-declare/Cargo.toml
+37 −15 bindings/rust/evmc-declare/src/lib.rs
+2 −2 bindings/rust/evmc-sys/Cargo.toml
+1 −1 bindings/rust/evmc-vm/Cargo.toml
+126 −7 bindings/rust/evmc-vm/src/container.rs
+390 −148 bindings/rust/evmc-vm/src/lib.rs
+37 −0 bindings/rust/evmc-vm/src/types.rs
+17 −2 circle.yml
+3 −1 cmake/Config.cmake.in
+18 −0 cmake/EVMC.cmake
+1 −0 cmake/cable/CableBuildInfo.cmake
+1 −1 cmake/cable/CableCompilerSettings.cmake
+28 −0 cmake/cable/CablePackage.cmake
+4 −4 cmake/cable/bootstrap.cmake
+5 −2 cmake/cable/buildinfo/buildinfo.cmake
+14 −0 cmake/cable/buildinfo/version.h.in
+4 −4 cmake/cable/toolchains/cxx11-32bit.cmake
+10 −0 cmake/cable/toolchains/cxx14-32bit.cmake
+10 −0 cmake/cable/toolchains/cxx17-32bit.cmake
+5 −18 examples/CMakeLists.txt
+33 −6 examples/example-rust-vm/src/lib.rs
+42 −8 examples/example.c
+31 −35 examples/example_host.cpp
+1 −1 examples/example_host.h
+9 −1 examples/example_precompiles_vm/CMakeLists.txt
+20 −0 examples/example_vm/CMakeLists.txt
+42 −15 examples/example_vm/example_vm.c
+0 −0 examples/example_vm/example_vm.h
+7 −0 examples/use_evmc_in_cmake/CMakeLists.txt
+26 −9 include/evmc/evmc.h
+328 −32 include/evmc/evmc.hpp
+55 −0 include/evmc/helpers.h
+9 −15 include/evmc/helpers.hpp
+3 −1 lib/instructions/CMakeLists.txt
+260 −0 lib/instructions/instruction_metrics.c
+260 −0 lib/instructions/instruction_names.c
+3 −1 lib/loader/CMakeLists.txt
+1 −0 test/unittests/CMakeLists.txt
+250 −9 test/unittests/test_cpp.cpp
+50 −0 test/unittests/test_deprecated.cpp
+0 −45 test/unittests/test_helpers.cpp
+139 −15 test/unittests/test_instructions.cpp
+7 −3 test/vmtester/CMakeLists.txt
+9 −6 test/vmtester/tests.cpp
+10 −19 test/vmtester/vmtester.cpp
+11 −11 test/vmtester/vmtester.hpp
14 changes: 3 additions & 11 deletions lib/evmone/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<evmc_bytes32, 4>{};
auto topics = std::array<evmc::bytes32, 4>{};
for (size_t i = 0; i < num_topics; ++i)
intx::be::store(topics[i].bytes, state.stack.pop());

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/evm_calls_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/evm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
65 changes: 32 additions & 33 deletions test/utils/host_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once

#include <evmc/evmc.hpp>
#include <evmc/helpers.hpp>
#include <string>
#include <unordered_map>
#include <vector>
Expand All @@ -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<evmc_bytes32, storage_value> storage;
evmc::bytes32 codehash;
evmc::uint256be balance;
std::unordered_map<evmc::bytes32, storage_value> 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<uint8_t>(x >> (8 * i));
}
Expand All @@ -48,11 +47,11 @@ class MockedHost : public evmc::Host
public:
struct log_record
{
evmc_address address;
evmc::address address;
bytes data;
std::vector<evmc_bytes32> topics;
std::vector<evmc::bytes32> 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(
Expand All @@ -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<evmc_address, MockedAccount> accounts;
std::unordered_map<evmc::address, MockedAccount> accounts;

evmc_tx_context tx_context = {};

evmc_bytes32 blockhash = {};
evmc::bytes32 blockhash = {};

evmc_result call_result = {};

std::vector<int64_t> recorded_blockhashes;

static constexpr auto max_recorded_account_accesses = 200;
std::vector<evmc_address> recorded_account_accesses;
std::vector<evmc::address> recorded_account_accesses;

static constexpr auto max_recorded_calls = 100;
std::vector<evmc_message> recorded_calls;
Expand All @@ -93,7 +92,7 @@ class MockedHost : public evmc::Host
protected:
std::vector<bytes> 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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});
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d8f9883

Please sign in to comment.