-
Notifications
You must be signed in to change notification settings - Fork 293
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
Introduce eofparse and eofparsefuzz #568
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# evmone: Fast Ethereum Virtual Machine implementation | ||
# Copyright 2023 The evmone Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_executable(evmone-eofparse eofparse.cpp) | ||
target_link_libraries(evmone-eofparse PRIVATE evmone) | ||
target_include_directories(evmone-eofparse PRIVATE ${evmone_private_include_dir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <evmc/evmc.hpp> | ||
#include <evmone/eof.hpp> | ||
#include <iostream> | ||
#include <string> | ||
|
||
namespace | ||
{ | ||
inline constexpr bool isalnum(char ch) noexcept | ||
{ | ||
return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); | ||
} | ||
|
||
template <typename BaseIterator> | ||
struct skip_nonalnum_iterator : evmc::filter_iterator<BaseIterator, isalnum> | ||
{ | ||
using evmc::filter_iterator<BaseIterator, isalnum>::filter_iterator; | ||
}; | ||
|
||
template <typename BaseIterator> | ||
skip_nonalnum_iterator(BaseIterator, BaseIterator) -> skip_nonalnum_iterator<BaseIterator>; | ||
|
||
template <typename InputIterator> | ||
std::optional<evmc::bytes> from_hex_skip_nonalnum(InputIterator begin, InputIterator end) noexcept | ||
{ | ||
evmc::bytes bs; | ||
if (!from_hex(skip_nonalnum_iterator{begin, end}, skip_nonalnum_iterator{end, end}, | ||
std::back_inserter(bs))) | ||
return {}; | ||
return bs; | ||
} | ||
|
||
} // namespace | ||
|
||
int main() | ||
{ | ||
try | ||
{ | ||
for (std::string line; std::getline(std::cin, line);) | ||
{ | ||
if (line.empty() || line.starts_with('#')) | ||
continue; | ||
|
||
auto o = from_hex_skip_nonalnum(line.begin(), line.end()); | ||
if (!o) | ||
{ | ||
std::cout << "err: invalid hex\n"; | ||
continue; | ||
} | ||
|
||
const auto& eof = *o; | ||
const auto err = evmone::validate_eof(EVMC_CANCUN, eof); | ||
if (err != evmone::EOFValidationError::success) | ||
{ | ||
std::cout << "err: " << evmone::get_error_message(err) << "\n"; | ||
continue; | ||
} | ||
|
||
const auto header = evmone::read_valid_eof1_header(evmone::bytes_view{eof}.begin()); | ||
gumb0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::cout << "OK " << evmc::hex({&eof[header.code_begin()], header.code_size}) << "\n"; | ||
} | ||
return 0; | ||
} | ||
catch (const std::exception& ex) | ||
{ | ||
std::cerr << ex.what() << "\n"; | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# evmone-fuzzer: LibFuzzer based testing tool for EVMC-compatible EVM implementations. | ||
# Copyright 2023 The evmone Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
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(fuzzing_coverage) | ||
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=fuzzer") | ||
else() | ||
string(REPLACE fuzzer-no-link fuzzer CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}) | ||
endif() | ||
|
||
add_executable(evmone-eofparsefuzz eofparsefuzz.cpp) | ||
target_link_libraries(evmone-eofparsefuzz PRIVATE evmone) | ||
target_include_directories(evmone-eofparsefuzz PRIVATE ${evmone_private_include_dir}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// evmone-fuzzer: LibFuzzer based testing tool for EVMC-compatible EVM implementations. | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <evmone/eof.hpp> | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t data_size) noexcept | ||
{ | ||
const evmone::bytes_view eof{data, data_size}; | ||
if (evmone::validate_eof(EVMC_CANCUN, eof) == evmone::EOFValidationError::success) | ||
(void)evmone::read_valid_eof1_header(eof.begin()); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surprised that such thing is in public evmc API