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

Upgrade EVMC to version 7.5.0 #294

Merged
merged 1 commit into from
Mar 24, 2021
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
2 changes: 1 addition & 1 deletion evmc
Submodule evmc updated 72 files
+1 −1 .bumpversion.cfg
+15 −10 .clang-format
+49 −0 CHANGELOG.md
+12 −1 CMakeLists.txt
+1 −1 Doxyfile
+6 −3 README.md
+2 −0 bindings/go/evmc/evmc.go
+8 −8 bindings/go/evmc/evmc_test.go
+20 −12 bindings/go/evmc/host_test.go
+1 −0 bindings/java/CMakeLists.txt
+27 −2 bindings/java/Makefile
+9 −9 bindings/java/build.gradle
+12 −19 bindings/java/c/evmc-vm.c
+297 −393 bindings/java/c/host.c
+12 −5 bindings/java/c/host.h
+15 −0 bindings/java/java/src/main/java/org/ethereum/evmc/EvmcLoaderException.java
+84 −49 bindings/java/java/src/main/java/org/ethereum/evmc/EvmcVm.java
+28 −95 bindings/java/java/src/main/java/org/ethereum/evmc/Host.java
+30 −16 bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java
+5 −5 bindings/java/java/src/test/java/org/ethereum/evmc/TestHostContext.java
+1 −1 bindings/rust/evmc-declare-tests/Cargo.toml
+2 −2 bindings/rust/evmc-declare/Cargo.toml
+1 −1 bindings/rust/evmc-declare/src/lib.rs
+2 −2 bindings/rust/evmc-sys/Cargo.toml
+4 −4 bindings/rust/evmc-sys/build.rs
+1 −15 bindings/rust/evmc-sys/src/lib.rs
+2 −2 bindings/rust/evmc-vm/Cargo.toml
+29 −29 bindings/rust/evmc-vm/src/lib.rs
+19 −16 circle.yml
+8 −0 cmake/Hunter/config.cmake
+1 −1 docs/VM_Guide.md
+1 −1 examples/example-rust-vm/Cargo.toml
+1 −1 examples/example-rust-vm/src/lib.rs
+5 −2 examples/example_host.cpp
+5 −3 examples/example_vm/CMakeLists.txt
+0 −234 examples/example_vm/example_vm.c
+395 −0 examples/example_vm/example_vm.cpp
+6 −3 include/evmc/evmc.h
+56 −42 include/evmc/evmc.hpp
+66 −0 include/evmc/hex.hpp
+2 −2 include/evmc/instructions.h
+3 −3 include/evmc/loader.h
+1 −1 include/evmc/utils.h
+1 −0 lib/CMakeLists.txt
+18 −0 lib/hex/CMakeLists.txt
+122 −0 lib/hex/hex.cpp
+2 −2 lib/loader/loader.c
+2 −1 test/CMakeLists.txt
+8 −0 test/examples/CMakeLists.txt
+1 −1 test/gomod/README
+78 −10 test/tools/CMakeLists.txt
+1 −0 test/tools/code.hex
+1 −0 test/tools/input.hex
+1 −0 test/tools/invalid_code.evm
+6 −0 test/unittests/CMakeLists.txt
+26 −6 test/unittests/cpp_test.cpp
+206 −0 test/unittests/example_vm_test.cpp
+119 −0 test/unittests/hex_test.cpp
+2 −1 test/unittests/instructions_test.cpp
+3 −0 test/unittests/loader_mock.h
+1 −1 test/unittests/loader_test.cpp
+119 −0 test/unittests/tool_commands_test.cpp
+3 −1 tools/CMakeLists.txt
+9 −0 tools/commands/CMakeLists.txt
+21 −0 tools/commands/commands.hpp
+88 −0 tools/commands/run.cpp
+3 −3 tools/evmc/CMakeLists.txt
+76 −34 tools/evmc/main.cpp
+0 −39 tools/evmc/utils.hpp
+9 −0 tools/utils/CMakeLists.txt
+6 −41 tools/utils/utils.cpp
+20 −0 tools/utils/utils.hpp
34 changes: 0 additions & 34 deletions test/unittests/utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,6 @@
#include <gtest/gtest.h>
#include <test/utils/utils.hpp>

TEST(utils, hex)
{
auto data = bytes{0x0, 0x1, 0xa, 0xf, 0x1f, 0xa0, 0xff, 0xf0};
EXPECT_EQ(hex(data), "00010a0f1fa0fff0");
}

TEST(utils, from_hex_empty)
{
EXPECT_TRUE(from_hex({}).empty());
}

TEST(utils, from_hex_odd_input_length)
{
EXPECT_THROW(from_hex("0"), std::length_error);
}

TEST(utils, from_hex_capital_letters)
{
EXPECT_EQ(from_hex("ABCDEF"), (bytes{0xab, 0xcd, 0xef}));
}

TEST(utils, from_hex_invalid_encoding)
{
EXPECT_THROW(from_hex({"\0\0", 2}), std::out_of_range);
}

TEST(utils, hex_byte)
{
auto b = uint8_t{};
EXPECT_EQ(hex(b), "00");
b = 0xaa;
EXPECT_EQ(hex(b), "aa");
}

TEST(utils, from_hexx)
{
EXPECT_EQ(hex(from_hexx("")), "");
Expand Down
2 changes: 1 addition & 1 deletion test/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_library(testutils STATIC
utils.hpp
)

target_link_libraries(testutils PRIVATE evmc::instructions)
target_link_libraries(testutils PRIVATE evmc::instructions evmc::hex)
target_include_directories(testutils PUBLIC ${PROJECT_SOURCE_DIR})

add_library(testutils-dump STATIC dump.cpp dump.hpp)
Expand Down
41 changes: 1 addition & 40 deletions test/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,8 @@
// Copyright 2018-2019 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include <test/utils/utils.hpp>
#include "utils.hpp"
#include <regex>
#include <stdexcept>

bytes from_hex(std::string_view hex)
{
if (hex.length() % 2 == 1)
throw std::length_error{"the length of the input is odd"};

bytes bs;
bs.reserve(hex.length() / 2);
int b = 0;
for (size_t i = 0; i < hex.size(); ++i)
{
const auto h = hex[i];
int v;
if (h >= '0' && h <= '9')
v = h - '0';
else if (h >= 'a' && h <= 'f')
v = h - 'a' + 10;
else if (h >= 'A' && h <= 'F')
v = h - 'A' + 10;
else
throw std::out_of_range{"not a hex digit"};

if (i % 2 == 0)
b = v << 4;
else
bs.push_back(static_cast<uint8_t>(b | v));
}
return bs;
}

std::string hex(bytes_view bs)
{
std::string str;
str.reserve(bs.size() * 2);
for (auto b : bs)
str += hex(b);
return str;
}

bytes from_hexx(const std::string& hexx)
{
Expand Down
25 changes: 10 additions & 15 deletions test/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,23 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <cstdint>
#include <string>
#include <evmc/hex.hpp>

using bytes = std::basic_string<uint8_t>;
using evmc::bytes;
using evmc::hex;
using bytes_view = std::basic_string_view<uint8_t>;

/// Encode a byte to a hex string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the others kept the docs, except this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

inline std::string hex(uint8_t b) noexcept
/// Decodes hex encoded string to bytes.
inline bytes from_hex(std::string_view hex)
{
static constexpr auto hex_chars = "0123456789abcdef";
return {hex_chars[b >> 4], hex_chars[b & 0xf]};
return evmc::from_hex(std::string{hex});
}

/// Decodes hex encoded string to bytes.
///
/// Exceptions:
/// - std::length_error when the input has invalid length (must be even).
/// - std::out_of_range when invalid hex digit encountered.
bytes from_hex(std::string_view hex);

/// Encodes bytes as hex string.
std::string hex(bytes_view bs);
inline std::string hex(bytes_view bs)
{
return evmc::hex(bs.data(), bs.size());
}

/// Decodes the hexx encoded string.
///
Expand Down