Skip to content

Commit 7066a1a

Browse files
committed
Use cargo fuzz to add a single file compilation fuzzer.
1 parent 79d1b68 commit 7066a1a

File tree

8 files changed

+3281
-425
lines changed

8 files changed

+3281
-425
lines changed

Cargo.lock

Lines changed: 826 additions & 416 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[package]
2+
name = "fe-compiler"
3+
version = "0.26.0"
4+
15
[workspace]
26
members = ["crates/*"]
37
resolver = "2"
@@ -8,3 +12,7 @@ opt-level = 3
812
[profile.dev]
913
# Speeds up the build. May need to diable for debugging.
1014
debug = 0
15+
16+
[[bin]]
17+
path = "."
18+
name = "crates/fe/src/main.rs"

crates/test-runner/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ indexmap = "1.6.2"
1515

1616
# used by revm; we need to force the js feature for wasm support
1717
getrandom = { version = "0.2.8", features = ["js"] }
18-
revm = "3.0"
18+
revm = "3.5.0"
19+
alloy-primitives = { version = "0.4", default-features = false, features = [
20+
"rlp",
21+
] }

crates/test-runner/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use bytes::Bytes;
1+
use alloy_primitives::{Address, Bytes};
22
use colored::Colorize;
33
use ethabi::{Event, Hash, RawLog};
44
use indexmap::IndexMap;
5-
use revm::primitives::{AccountInfo, Bytecode, Env, ExecutionResult, TransactTo, B160, U256};
6-
use std::fmt::Display;
5+
use revm::primitives::{AccountInfo, Bytecode, Env, ExecutionResult, TransactTo, U256};
6+
7+
use std::{fmt::Display, str::FromStr};
78

89
pub use ethabi;
910

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

117120
let mut database = revm::InMemoryDB::default();
118-
let test_address = B160::from(42);
119-
let test_info = AccountInfo::new(U256::ZERO, 0, bytecode);
121+
let test_address = Address::from_str("42").unwrap();
122+
let test_info = AccountInfo::new(U256::ZERO, 0, bytecode.hash_slow(), bytecode);
120123
database.insert_account_info(test_address, test_info);
121124

122125
let mut env = Env::default();
@@ -134,12 +137,12 @@ pub fn execute(name: &str, events: &[Event], bytecode: &str, sink: &mut TestSink
134137
if let Some(Some(event)) = log
135138
.topics
136139
.get(0)
137-
.map(|sig| events.get(&Hash::from_slice(sig.as_bytes())))
140+
.map(|sig| events.get(&Hash::from_slice(sig.as_ref())))
138141
{
139142
let topics = log
140143
.topics
141144
.iter()
142-
.map(|topic| Hash::from_slice(topic.as_bytes()))
145+
.map(|topic| Hash::from_slice(topic.as_ref()))
143146
.collect();
144147
let data = log.data.clone().to_vec();
145148
let raw_log = RawLog { topics, data };

fuzz/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
corpus
3+
artifacts
4+
coverage

0 commit comments

Comments
 (0)