diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e22f3a51..351477801 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,9 @@ if(EVMC_TESTING OR EVMC_TEST_TOOLS) endif() if(EVMC_TESTING OR EVMC_EXAMPLES) + hunter_add_package(ethash) + find_package(ethash CONFIG REQUIRED) + add_subdirectory(examples) endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 66f4212f7..1697d03ec 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,7 +14,7 @@ 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) diff --git a/examples/example_host.cpp b/examples/example_host.cpp index 64545a009..9ece208b9 100644 --- a/examples/example_host.cpp +++ b/examples/example_host.cpp @@ -9,6 +9,7 @@ #include "example_host.h" #include +#include #include #include @@ -26,14 +27,7 @@ struct account virtual evmc::bytes32 code_hash() { - // Extremely dumb "hash" function. - evmc::bytes32 ret{}; - for (std::vector::size_type i = 0; i != code.size(); i++) - { - auto v = code[i]; - ret.bytes[v % sizeof(ret.bytes)] ^= v; - } - return ret; + return ethash::keccak256(code, code.size()); } };