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

Use ethash::keccak in example_host #448

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ if(NOT CMAKE_CXX_STANDARD)
endif()
set(CMAKE_DEBUG_POSTFIX "")

hunter_add_package(ethash)
find_package(ethash CONFIG REQUIRED)

add_subdirectory(example_vm)
add_subdirectory(example_precompiles_vm)

add_library(evmc-example-host STATIC example_host.cpp)
target_link_libraries(evmc-example-host PRIVATE evmc)
target_link_libraries(evmc-example-host PRIVATE evmc ethash::keccak)

add_executable(evmc-example-static example.c)
target_link_libraries(evmc-example-static PRIVATE evmc-example-host evmc::example-vm-static evmc)
Expand Down
10 changes: 2 additions & 8 deletions examples/example_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "example_host.h"

#include <ethash/keccak.hpp>
#include <evmc/evmc.hpp>

#include <algorithm>
Expand All @@ -26,14 +27,7 @@ struct account

virtual evmc::bytes32 code_hash()
{
// Extremely dumb "hash" function.
evmc::bytes32 ret{};
for (std::vector<uint8_t>::size_type i = 0; i != code.size(); i++)
{
auto v = code[i];
ret.bytes[v % sizeof(ret.bytes)] ^= v;
}
return ret;
return evmc_bytes32{*ethash::keccak256(code.data(), code.size()).bytes};
}
};

Expand Down