Skip to content

Commit

Permalink
Use ethash::keccak in example_host
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Nov 6, 2019
1 parent 0c2a99f commit 66dd1cc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions examples/example_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "example_host.h"

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

#include <algorithm>
#include <map>
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 ethash::keccak256(code, code.size());
}
};

Expand Down

0 comments on commit 66dd1cc

Please sign in to comment.