Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.
Open
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
Expand Up @@ -5,9 +5,6 @@
[submodule "test/tests"]
path = test/jsontests
url = https://github.com/ethereum/tests.git
[submodule "hera"]
path = hera
url = https://github.com/ewasm/hera
[submodule "cpp-ethereum"]
path = cpp-ethereum
url = https://github.com/ethereum/cpp-ethereum.git
1 change: 0 additions & 1 deletion CMakeLists.txt

This file was deleted.

173 changes: 173 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#------------------------------------------------------------------------------
# Top-level CMake file for cpp-ethereum.
#
# The documentation for cpp-ethereum is hosted at http://cpp-ethereum.org
#
# ------------------------------------------------------------------------------
# This file is part of cpp-ethereum.
#
# cpp-ethereum is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cpp-ethereum is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>
#
# (c) 2014-2016 cpp-ethereum contributors.
#------------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.5.1)

if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
# The default toolchain file configures compilers and build environment.
# This configuration is also used by hunter to build dependencies.
# CMake will cache this value, not need to explictly specify CACHE param.
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain.cmake)
endif()

set(ETH_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake" CACHE PATH "The path to the cmake directory")
list(APPEND CMAKE_MODULE_PATH ${ETH_CMAKE_DIR})

set(CPP_ETHEREUM_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Path to the root directory for cpp-ethereum")

# set cmake_policies
include(EthPolicy)
eth_policy()

if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo" CACHE STRING "" FORCE)
endif()

# Map current configuration to configurations of imported targets.
set(CMAKE_MAP_IMPORTED_CONFIG_DEBUG Release)
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)

set(HUNTER_CONFIGURATION_TYPES Release)
set(HUNTER_JOBS_NUMBER 4)
set(HUNTER_CACHE_SERVERS "https://github.com/ethereum/hunter-cache")
include(HunterGate)
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.19.232.tar.gz"
SHA1 "a412c45fe4c5a72fed386f62dd8d753bd4fd3d11"
LOCAL
)

if(HUNTER_ENABLED)
# Find Python executable,
# prefer version 3 that has requests module included.
set(Python_ADDITIONAL_VERSIONS 3)
find_package(PythonInterp)
if(PYTHONINTERP_FOUND)
hunter_gate_self(
"${HUNTER_CACHED_ROOT}"
"${HUNTER_VERSION}"
"${HUNTER_SHA1}"
hunter_dir
)
set(hunter_upload_script "${hunter_dir}/maintenance/upload-cache-to-github.py")
set(hunter_cache_dir "${HUNTER_GATE_ROOT}/_Base/Cache")
set(hunter_tmp_dir "${HUNTER_GATE_ROOT}/tmp")
add_custom_target(
hunter_upload_cache
${PYTHON_EXECUTABLE} ${hunter_upload_script}
--username hunter-cache-bot
--repo-owner ethereum
--repo hunter-cache
--cache-dir ${hunter_cache_dir}
--temp-dir ${hunter_tmp_dir}
)
endif()
endif()

# project name and version should be set after cmake_policy CMP0048
project(cpp-ethereum VERSION "1.3.0")

if (NOT EXISTS ${CMAKE_SOURCE_DIR}/evmjit/.git)
message(FATAL_ERROR "Git submodules not initialized, execute:\n git submodule update --init")
endif()

set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY On)

include(EthCcache)
include(EthOptions)
include(EthCompilerSettings)
include(EthExecutableHelper)
include(EthDependencies)
include(EthUtils)

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
hunter_add_package(Boost COMPONENTS program_options filesystem system thread context fiber)
find_package(Boost CONFIG REQUIRED program_options filesystem system thread context fiber)

hunter_add_package(jsoncpp)
find_package(jsoncpp CONFIG REQUIRED)

hunter_add_package(Snappy)
find_package(Snappy CONFIG REQUIRED)

hunter_add_package(cryptopp)
find_package(cryptopp CONFIG REQUIRED)

hunter_add_package(libjson-rpc-cpp)
find_package(libjson-rpc-cpp CONFIG REQUIRED)

include(ProjectSecp256k1)
include(ProjectLibFF)

find_package(Threads)

if(MINIUPNPC)
find_package(Miniupnpc 1.8.2013 REQUIRED)
endif()

set(UTILS_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/utils")

configure_project()

if (HERA)
add_subdirectory(hera)
endif()

#Global include path for all libs.
include_directories("${CMAKE_SOURCE_DIR}")

add_subdirectory(libdevcore)
add_subdirectory(libdevcrypto)
add_subdirectory(libp2p)

add_subdirectory(libethash)

add_subdirectory(libethcore)
add_subdirectory(libevm)
add_subdirectory(libethereum)
add_subdirectory(libethashseal)

add_subdirectory(libwebthree)
add_subdirectory(libweb3jsonrpc)

if (EVMJIT)
add_subdirectory(evmjit)
endif()

add_subdirectory(eth)

if (TOOLS)
add_subdirectory(ethkey)
add_subdirectory(ethvm)
add_subdirectory(rlp)
endif()

if (TESTS)
enable_testing()
add_subdirectory(test)
endif()

# TODO: Split out json_spirit, libscrypt and sec256k1.
add_subdirectory(utils)
1 change: 0 additions & 1 deletion hera
Submodule hera deleted from 2645bd
1 change: 0 additions & 1 deletion libevm

This file was deleted.

35 changes: 35 additions & 0 deletions libevm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

set(sources
ExtVMFace.cpp ExtVMFace.h
Instruction.cpp Instruction.h
VMFace.h
VMConfig.h
VM.cpp VM.h
VMCalls.cpp
VMOpt.cpp
VMSIMD.cpp
VMValidate.cpp
VMFactory.cpp VMFactory.h
)

if(EVMJIT OR HERA)
list(APPEND sources
EVMC.cpp EVMC.h
)
endif()

add_library(evm ${sources})

target_link_libraries(evm PUBLIC ethcore devcore PRIVATE jsoncpp_lib_static Boost::program_options)
target_include_directories(evm PUBLIC ${CMAKE_SOURCE_DIR}/evmjit/include)
target_include_directories(evm PUBLIC ${CMAKE_SOURCE_DIR}/hera/src)

if(EVMJIT)
target_link_libraries(evm PRIVATE evmjit)
target_compile_definitions(evm PRIVATE ETH_EVMJIT)
endif()

if(HERA)
target_link_libraries(evm PRIVATE hera)
target_compile_definitions(evm PRIVATE ETH_HERA)
endif()
78 changes: 78 additions & 0 deletions libevm/EVMC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2018 cpp-ethereum Authors.
// Licensed under the GNU General Public License v3. See the LICENSE file.

#include "EVMC.h"

#include <libdevcore/Log.h>
#include <libevm/VM.h>
#include <libevm/VMFactory.h>

namespace dev
{
namespace eth
{
EVM::EVM(evm_instance* _instance) noexcept : m_instance(_instance)
{
assert(m_instance != nullptr);
assert(m_instance->abi_version == EVM_ABI_VERSION);

// Set the options.
for (auto& pair : evmcOptions())
m_instance->set_option(m_instance, pair.first.c_str(), pair.second.c_str());
}

owning_bytes_ref EVMC::exec(u256& io_gas, ExtVMFace& _ext, const OnOpFunc& _onOp)
{
assert(_ext.envInfo().number() >= 0);
assert(_ext.envInfo().timestamp() >= 0);

constexpr int64_t int64max = std::numeric_limits<int64_t>::max();

// TODO: The following checks should be removed by changing the types
// used for gas, block number and timestamp.
(void)int64max;
assert(io_gas <= int64max);
assert(_ext.envInfo().gasLimit() <= int64max);
assert(_ext.depth <= std::numeric_limits<int32_t>::max());

auto gas = static_cast<int64_t>(io_gas);
EVM::Result r = execute(_ext, gas);

if (r.status() == EVM_REJECTED)
{
cwarn << "Execution rejected by EVM-C, executing with interpreter";
return VMFactory::create(VMKind::Interpreter)->exec(io_gas, _ext, _onOp);
}

// TODO: Add EVM-C result codes mapping with exception types.
if (r.status() == EVM_FAILURE)
BOOST_THROW_EXCEPTION(OutOfGas());

io_gas = r.gasLeft();

// FIXME: Copy the output for now, but copyless version possible.
owning_bytes_ref output{r.output().toVector(), 0, r.output().size()};

if (r.status() == EVM_REVERT)
throw RevertInstruction(std::move(output));

return output;
}

evm_revision toRevision(EVMSchedule const& _schedule)
{
if (_schedule.haveCreate2)
return EVM_CONSTANTINOPLE;
if (_schedule.haveRevert)
return EVM_BYZANTIUM;
if (_schedule.eip158Mode)
return EVM_SPURIOUS_DRAGON;
if (_schedule.eip150Mode)
return EVM_TANGERINE_WHISTLE;
if (_schedule.haveDelegateCall)
return EVM_HOMESTEAD;
return EVM_FRONTIER;
}

}
}
Loading