Skip to content

Commit cbf3066

Browse files
chfastaxic
authored andcommitted
Add eofparsefuzz testing tool
1 parent 766b7e0 commit cbf3066

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

test/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ add_subdirectory(unittests)
2626
set(targets evmone-bench evmone-bench-internal evmone-eofparse evmone-state evmone-statetest evmone-t8n evmone-unittests testutils)
2727

2828
if(EVMONE_FUZZING)
29+
add_subdirectory(eofparsefuzz)
2930
add_subdirectory(fuzzer)
30-
list(APPEND targets evmone-fuzzer)
31+
list(APPEND targets evmone-eofparsefuzz evmone-fuzzer)
3132
endif()
3233

3334
set_target_properties(

test/eofparsefuzz/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# evmone-fuzzer: LibFuzzer based testing tool for EVMC-compatible EVM implementations.
2+
# Copyright 2023 The evmone Authors.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
get_target_property(type evmone TYPE)
6+
if(NOT type STREQUAL STATIC_LIBRARY)
7+
message(FATAL_ERROR "The evmone must be built as static library")
8+
endif()
9+
10+
if(fuzzing_coverage)
11+
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=fuzzer")
12+
else()
13+
string(REPLACE fuzzer-no-link fuzzer CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
14+
endif()
15+
16+
add_executable(evmone-eofparsefuzz eofparsefuzz.cpp)
17+
target_link_libraries(evmone-eofparsefuzz PRIVATE evmone)
18+
target_include_directories(evmone-eofparsefuzz PRIVATE ${evmone_private_include_dir})

test/eofparsefuzz/eofparsefuzz.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// evmone-fuzzer: LibFuzzer based testing tool for EVMC-compatible EVM implementations.
2+
// Copyright 2019 The evmone Authors.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include <evmone/eof.hpp>
6+
7+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t data_size) noexcept
8+
{
9+
const evmone::bytes_view eof{data, data_size};
10+
if (evmone::validate_eof(EVMC_CANCUN, eof) == evmone::EOFValidationError::success)
11+
(void)evmone::read_valid_eof1_header(eof.begin());
12+
return 0;
13+
}

0 commit comments

Comments
 (0)