Skip to content

Remove support for C++/Javascript version of evm2wasm #417

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

Merged
merged 5 commits into from
Nov 26, 2018
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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "evmc"]
path = evmc
url = https://github.com/ethereum/evmc
[submodule "evm2wasm"]
path = evm2wasm
url = https://github.com/ewasm/evm2wasm
[submodule "cable"]
path = cmake/cable
url = https://github.com/ethereum/cable
17 changes: 7 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ include(CableToolchains)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

option(EVMC_TESTING "Build EVMC tests and test tools" OFF)
Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't this a foreign key? ${EVMC_TESTING} instead of OFF?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. It's defined before EVMC defines it. I think this line can be dropped actually.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll just merge this now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I will remove the line.

if(EVMC_TESTING)
# If Hunter is needed it must be initialized before project(hera).
include(evmc/cmake/cable/HunterGate.cmake)
include(evmc/cmake/HunterConfig.cmake)
endif()

cable_configure_toolchain(DEFAULT cxx11-pic)

set(CMAKE_DEBUG_POSTFIX "")
set(HUNTER_CONFIGURATION_TYPES Release CACHE STRING "Build type of the 3rd party packages")

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/evm2wasm/cmake/HunterGate.cmake)
include(evm2wasm/cmake/HunterGate.cmake)
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.21.19.tar.gz"
SHA1 "5ead1e069b437930d0de8a21824b20fb52b37b50"
)
endif()

project(hera)
set(PROJECT_VERSION 0.2.0)
Expand Down Expand Up @@ -53,7 +51,6 @@ if (HERA_WAVM)
endif()

add_subdirectory(evmc)
add_subdirectory(evm2wasm)
add_subdirectory(src)


Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ These are to be used via EVMC `set_option`:
- `reject` will reject any EVM1 bytecode with an error (the default setting)
- `fallback` will allow EVM1 bytecode to be passed through to the client for execution
- `evm2wasm` will enable transformation of bytecode using the [EVM Transcompiler]
- `evm2wasm.js` will use a `evm2wasm.js` as an external commandline tool instead of the system contract
- `evm2wasm.js-trace` will use `evm2wasm.js` with tracing option turned on
- `evm2wasm.cpp` will use a `evm2wasm` as a compiled-in dependency instead of the system contract
- `evm2wasm.cpp-trace` will turn use `evm2wasm` with tracing option turned on

## Interfaces

Expand Down
24 changes: 12 additions & 12 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defaults:
# (ninja is using relative paths otherwise).
working_directory: ~/build
command: |
cmake ../project -G "$GENERATOR" -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_OPTIONS -DEVM2WASM_TOOLS=OFF
cmake ../project -G "$GENERATOR" -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_OPTIONS

codespell: &codespell
run:
Expand Down Expand Up @@ -58,7 +58,7 @@ defaults:
save-deps-cache: &save-deps-cache
cache-save:
name: "Save dependencies cache"
key: &deps-cache-key deps-4-{{arch}}-{{checksum "toolchain"}}-{{checksum "cmake/ProjectBinaryen.cmake"}}
key: &deps-cache-key deps-5-{{arch}}-{{checksum "toolchain"}}-{{checksum "cmake/ProjectBinaryen.cmake"}}
paths:
- ~/build/deps

Expand Down Expand Up @@ -176,14 +176,14 @@ defaults:
command: |
~/build/evmc/test/evmc-vmtester ~/build/src/libhera.so

evm2wasm-test: &evm2wasm-test
run:
name: "Run evm2wasm state tests"
command: |
if [[ $PRELOAD_ASAN ]]; then export LD_PRELOAD=/usr/lib/clang/6.0/lib/linux/libclang_rt.asan-x86_64.so; fi
testeth --version
testeth -t GeneralStateTests/stExample -- --testpath tests --vm ~/build/src/libhera.so --singlenet Byzantium --singletest "add11" --evmc evm1mode=evm2wasm.cpp
testeth -t GeneralStateTests/stStackTests -- --testpath tests --vm ~/build/src/libhera.so --singlenet Byzantium --evmc evm1mode=evm2wasm.cpp
# evm2wasm-test: &evm2wasm-test
# run:
# name: "Run evm2wasm state tests"
# command: |
# if [[ $PRELOAD_ASAN ]]; then export LD_PRELOAD=/usr/lib/clang/6.0/lib/linux/libclang_rt.asan-x86_64.so; fi
# testeth --version
# testeth -t GeneralStateTests/stExample -- --testpath tests --vm ~/build/src/libhera.so --singlenet Byzantium --singletest "add11" --evmc evm1mode=evm2wasm.cpp
# testeth -t GeneralStateTests/stStackTests -- --testpath tests --vm ~/build/src/libhera.so --singlenet Byzantium --evmc evm1mode=evm2wasm.cpp

upload-coverage-data: &upload-coverage-data
run:
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
- *test-wabt
- *test-wavm
- *evmc-test
- *evm2wasm-test
# - *evm2wasm-test

linux-clang-shared-asan:
environment:
Expand Down Expand Up @@ -250,7 +250,7 @@ jobs:
- *test-wabt
- *test-wavm
- *evmc-test
- *evm2wasm-test
# - *evm2wasm-test

linux-gcc-shared-coverage:
environment:
Expand Down
1 change: 0 additions & 1 deletion evm2wasm
Submodule evm2wasm deleted from 926dab
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ endif()
target_include_directories(hera
PUBLIC $<BUILD_INTERFACE:${hera_include_dir}>$<INSTALL_INTERFACE:include>
PRIVATE ${evmc_include_dir})
target_link_libraries(hera PRIVATE hera-buildinfo evmc::evmc evmc::instructions libevm2wasm binaryen::binaryen Threads::Threads)
target_link_libraries(hera PRIVATE hera-buildinfo evmc::evmc evmc::instructions binaryen::binaryen Threads::Threads)
if(NOT WIN32)
if(CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(hera PROPERTIES LINK_FLAGS "-Wl,--no-undefined")
Expand Down
91 changes: 1 addition & 90 deletions src/hera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
#include <iostream>
#include <fstream>
#include <iomanip>
#include <map>

#include <evmc/evmc.h>

#include <evm2wasm.h>

#include "binaryen.h"
#include "debugging.h"
#include "eei.h"
Expand Down Expand Up @@ -60,10 +59,6 @@ enum class hera_evm1mode {
reject,
fallback,
evm2wasm_contract,
evm2wasm_cpp,
evm2wasm_cpp_tracing,
evm2wasm_js,
evm2wasm_js_tracing
};

using WasmEngineCreateFn = unique_ptr<WasmEngine>(*)();
Expand All @@ -82,10 +77,6 @@ const map<string, hera_evm1mode> evm1mode_options {
{ "reject", hera_evm1mode::reject },
{ "fallback", hera_evm1mode::fallback },
{ "evm2wasm", hera_evm1mode::evm2wasm_contract },
{ "evm2wasm.cpp", hera_evm1mode::evm2wasm_cpp },
{ "evm2wasm.cpp-trace", hera_evm1mode::evm2wasm_cpp_tracing },
{ "evm2wasm.js", hera_evm1mode::evm2wasm_js },
{ "evm2wasm.js-trace", hera_evm1mode::evm2wasm_js_tracing },
};

struct hera_instance : evmc_instance {
Expand Down Expand Up @@ -165,72 +156,6 @@ vector<uint8_t> sentinel(evmc_context* context, vector<uint8_t> const& input)
return ret;
}

// NOTE: assumes that pattern doesn't contain any formatting characters (e.g. %)
string mktemp_string(string pattern) {
const unsigned long len = pattern.size();
char tmp[len + 1];
strcpy(tmp, pattern.data());
if (!mktemp(tmp) || (tmp[0] == 0))
return string();
return string(tmp, strlen(tmp));
}

// Calls evm2wasm (as a Javascript CLI) with input data @input.
// @returns the compiled output or empty output otherwise.
vector<uint8_t> evm2wasm_js(vector<uint8_t> const& input, bool evmTrace) {
HERA_DEBUG << "Calling evm2wasm.js (input " << input.size() << " bytes)...\n";

string fileEVM = mktemp_string("/tmp/hera.evm2wasm.evm.XXXXXX");
string fileWASM = mktemp_string("/tmp/hera.evm2wasm.wasm.XXXXXX");

if (fileEVM.size() == 0 || fileWASM.size() == 0)
return vector<uint8_t>();

ofstream os;
os.open(fileEVM);
// print as a hex string
os << hex;
for (uint8_t byte: input)
os << setfill('0') << setw(2) << static_cast<int>(byte);
os.close();

string cmd = string("evm2wasm.js ") + "-e " + fileEVM + " -o " + fileWASM + " --charge-per-op";
if (evmTrace)
cmd += " --trace";

HERA_DEBUG << "(Calling evm2wasm.js with command: " << cmd << ")\n";

int ret = system(cmd.data());
unlink(fileEVM.data());

if (ret != 0) {
HERA_DEBUG << "evm2wasm.js failed\n";

unlink(fileWASM.data());
return vector<uint8_t>();
}

string str = loadFileContents(fileWASM);

unlink(fileWASM.data());

HERA_DEBUG << "evm2wasm.js done (output " << str.length() << " bytes)\n";

return vector<uint8_t>(str.begin(), str.end());
}

// Calls evm2wasm (through the built-in C++ interface) with input data @input.
// @returns the compiled output or empty output otherwise.
vector<uint8_t> evm2wasm_cpp(vector<uint8_t> const& input, bool evmTrace) {
HERA_DEBUG << "Calling evm2wasm.cpp (input " << input.size() << " bytes)...\n";

string str = evm2wasm::evm2wasm(input, evmTrace);

HERA_DEBUG << "evm2wasm.cpp done (output " << str.length() << " bytes)\n";

return vector<uint8_t>(str.begin(), str.end());
}

// Calls the evm2wasm contract with input data @input.
// @returns the compiled output or empty output otherwise.
vector<uint8_t> evm2wasm(evmc_context* context, vector<uint8_t> const& input) {
Expand Down Expand Up @@ -303,20 +228,6 @@ evmc_result hera_execute(
// TODO: enable this once evm2wasm does metering of interfaces
// meterInterfaceGas = false;
break;
case hera_evm1mode::evm2wasm_cpp:
case hera_evm1mode::evm2wasm_cpp_tracing:
run_code = evm2wasm_cpp(run_code, hera->evm1mode == hera_evm1mode::evm2wasm_cpp_tracing);
ensureCondition(run_code.size() > 8, ContractValidationFailure, "Transcompiling via evm2wasm.cpp failed");
// TODO: enable this once evm2wasm does metering of interfaces
// meterInterfaceGas = false;
break;
case hera_evm1mode::evm2wasm_js:
case hera_evm1mode::evm2wasm_js_tracing:
run_code = evm2wasm_js(run_code, hera->evm1mode == hera_evm1mode::evm2wasm_js_tracing);
ensureCondition(run_code.size() > 8, ContractValidationFailure, "Transcompiling via evm2wasm.js failed");
// TODO: enable this once evm2wasm does metering of interfaces
// meterInterfaceGas = false;
break;
case hera_evm1mode::fallback:
HERA_DEBUG << "Non-WebAssembly input, but fallback mode enabled, asking client to deal with it.\n";
ret.status_code = EVMC_REJECTED;
Expand Down