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

fuzzer: Add evmone-fuzzer for EVMC VMs #162

Merged
merged 1 commit into from
Sep 11, 2019
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
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ endif()

option(BUILD_SHARED_LIBS "Build evmone as a shared library" ON)
option(EVMONE_TESTING "Build tests and test tools" OFF)
option(EVMONE_FUZZING "Instrument libraries and build fuzzing tools" OFF)

include(cmake/cable/bootstrap.cmake)
include(CableBuildType)
Expand Down Expand Up @@ -44,6 +45,25 @@ elseif(MSVC)
add_compile_options(/wd5030) # Allow using unknown attributes.
endif()

if(EVMONE_FUZZING)
if(NOT ${CMAKE_CXX_COMPILER_ID} MATCHES Clang OR ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 8)
message(FATAL_ERROR "Clang 8+ compiler is required for fuzzing")
endif()

option(EVMONE_FUZZING_COVERAGE "Fuzzing coverage" OFF)

set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build evmone as a shared library" FORCE)
set(EVMONE_TESTING ON CACHE BOOL "Build tests and test tools" FORCE)

if(EVMONE_FUZZING_COVERAGE)
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
else()
set(fuzzing_flags -fsanitize=fuzzer-no-link,undefined,address)
add_compile_options(${fuzzing_flags})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${fuzzing_flags}")
endif()
endif()

set(include_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_subdirectory(lib)
Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ add_subdirectory(unittests)

set(targets evm-test evmone-bench evmone-bench-internal evmone-unittests testutils)

if(EVMONE_FUZZING)
add_subdirectory(fuzzer)
list(APPEND targets evmone-fuzzer)
endif()

set_target_properties(
${targets} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
Expand Down
67 changes: 67 additions & 0 deletions test/fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# evmone: Fast Ethereum Virtual Machine implementation
# Copyright 2019 The evmone Authors.
# Licensed under the Apache License, Version 2.0.
include(ExternalProject)

get_target_property(type evmone TYPE)
if(NOT type STREQUAL STATIC_LIBRARY)
message(FATAL_ERROR "The evmone must be built as static library")
endif()

if(EVMONE_FUZZING_COVERAGE)
set(CMAKE_EXE_LINKER_FLAGS "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer")
else()
string(REPLACE fuzzer-no-link fuzzer CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
endif()

add_executable(evmone-fuzzer fuzzer.cpp)
target_link_libraries(evmone-fuzzer PRIVATE evmone testutils)

if(NOT EVMONE_FUZZING_COVERAGE)
# TODO: Aleth reports undefined behaviors, disable it for fuzzing.
string(REPLACE undefined "" aleth_fuzzing_flags ${fuzzing_flags})

set(aleth_git_tag v1.7.0-alpha.1)
if(NOT aleth_git_tag STREQUAL "${aleth_current_git_tag}")
message(STATUS "Aleth git tag has changed: ${aleth_current_git_tag} -> ${aleth_git_tag}")
set(aleth_current_git_tag ${aleth_git_tag} CACHE INTERNAL "Current Aleth git tag" FORCE)
else()
message(STATUS "Aleth git tag: ${aleth_git_tag}; updates disabled")
set(aleth_disable_git_update UPDATE_COMMAND "")
endif()


ExternalProject_Add(
aleth-interpreter
PREFIX external
EXCLUDE_FROM_ALL TRUE

GIT_REPOSITORY https://github.com/ethereum/aleth
GIT_TAG ${aleth_git_tag}
GIT_SUBMODULES evmc cmake/cable
GIT_SHALLOW TRUE
"${aleth_disable_git_update}"

CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_FLAGS=${aleth_fuzzing_flags}
-DCMAKE_C_FLAGS=${aleth_fuzzing_flags}

BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target aleth-interpreter
INSTALL_COMMAND ""
)

set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/external/src/aleth-interpreter-build)

add_library(aleth::interpreter IMPORTED STATIC)
add_dependencies(aleth::interpreter aleth-interpreter)
set_target_properties(aleth::interpreter PROPERTIES
IMPORTED_CONFIGURATIONS Release
IMPORTED_LOCATION_RELEASE ${build_dir}/libaleth-interpreter/libaleth-interpreter.a
INTERFACE_LINK_LIBRARIES ${build_dir}/aleth/libaleth-buildinfo.a)

target_link_libraries(evmone-fuzzer PRIVATE aleth::interpreter)
target_compile_definitions(evmone-fuzzer PRIVATE ALETH)
endif()
Loading