Skip to content

Commit

Permalink
Use cargo fuzz to add a single file compilation fuzzer.
Browse files Browse the repository at this point in the history
  • Loading branch information
bshastry committed Nov 30, 2023
1 parent 79d1b68 commit 7066a1a
Show file tree
Hide file tree
Showing 8 changed files with 3,281 additions and 425 deletions.
1,242 changes: 826 additions & 416 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[package]
name = "fe-compiler"
version = "0.26.0"

[workspace]
members = ["crates/*"]
resolver = "2"
Expand All @@ -8,3 +12,7 @@ opt-level = 3
[profile.dev]
# Speeds up the build. May need to diable for debugging.
debug = 0

[[bin]]
path = "."
name = "crates/fe/src/main.rs"
5 changes: 4 additions & 1 deletion crates/test-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ indexmap = "1.6.2"

# used by revm; we need to force the js feature for wasm support
getrandom = { version = "0.2.8", features = ["js"] }
revm = "3.0"
revm = "3.5.0"
alloy-primitives = { version = "0.4", default-features = false, features = [
"rlp",
] }
19 changes: 11 additions & 8 deletions crates/test-runner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use bytes::Bytes;
use alloy_primitives::{Address, Bytes};
use colored::Colorize;
use ethabi::{Event, Hash, RawLog};
use indexmap::IndexMap;
use revm::primitives::{AccountInfo, Bytecode, Env, ExecutionResult, TransactTo, B160, U256};
use std::fmt::Display;
use revm::primitives::{AccountInfo, Bytecode, Env, ExecutionResult, TransactTo, U256};

use std::{fmt::Display, str::FromStr};

pub use ethabi;

Expand Down Expand Up @@ -112,11 +113,13 @@ pub fn execute(name: &str, events: &[Event], bytecode: &str, sink: &mut TestSink
.iter()
.map(|event| (event.signature(), event))
.collect();
let bytecode = Bytecode::new_raw(Bytes::copy_from_slice(&hex::decode(bytecode).unwrap()));
let bytecode = Bytecode::new_raw(alloy_primitives::Bytes(
Bytes::copy_from_slice(&hex::decode(bytecode).unwrap()).into(),
));

let mut database = revm::InMemoryDB::default();
let test_address = B160::from(42);
let test_info = AccountInfo::new(U256::ZERO, 0, bytecode);
let test_address = Address::from_str("42").unwrap();
let test_info = AccountInfo::new(U256::ZERO, 0, bytecode.hash_slow(), bytecode);
database.insert_account_info(test_address, test_info);

let mut env = Env::default();
Expand All @@ -134,12 +137,12 @@ pub fn execute(name: &str, events: &[Event], bytecode: &str, sink: &mut TestSink
if let Some(Some(event)) = log
.topics
.get(0)
.map(|sig| events.get(&Hash::from_slice(sig.as_bytes())))
.map(|sig| events.get(&Hash::from_slice(sig.as_ref())))
{
let topics = log
.topics
.iter()
.map(|topic| Hash::from_slice(topic.as_bytes()))
.map(|topic| Hash::from_slice(topic.as_ref()))
.collect();
let data = log.data.clone().to_vec();
let raw_log = RawLog { topics, data };
Expand Down
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
Loading

0 comments on commit 7066a1a

Please sign in to comment.