Skip to content

Commit 9e40e1d

Browse files
authored
SRLabs: Introduce Fuzzing Harness (#365)
We use [ziggy](https://github.com/srlabs/ziggy/) to orchestrate fuzzing. Ziggy uses both AFL++ and Honggfuzz under the hood. This harness performs "structure aware" fuzzing where the messages are serialized using bincode/serde, similar to [arbitrary](https://github.com/rust-fuzz/arbitrary) Note that I had to update ``cid`` to get the ``serde`` feature support. Hope this is okay.
1 parent 403ec00 commit 9e40e1d

File tree

19 files changed

+3231
-35
lines changed

19 files changed

+3231
-35
lines changed

Cargo.lock

+63-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ license = "MIT"
55
version = "0.9.3"
66
edition = "2021"
77

8+
# cargo-machete does not detect serde_millis usage, so we ignore the warning
9+
[package.metadata.cargo-machete]
10+
ignored = ["serde_millis"]
11+
812
[build-dependencies]
913
prost-build = "0.13"
1014

1115
[dependencies]
1216
async-trait = "0.1.81"
1317
bs58 = "0.5.1"
1418
bytes = "1.6.1"
15-
cid = "0.10.1"
19+
cid = "0.11.1"
1620
ed25519-dalek = { version = "2.1.1", features = ["rand_core"] }
1721
futures = "0.3.27"
1822
futures-timer = "3.0.3"
@@ -21,14 +25,14 @@ indexmap = { version = "2.7.1", features = ["std"] }
2125
libc = "0.2.158"
2226
mockall = "0.13.1"
2327
multiaddr = "0.17.0"
24-
multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2"] }
28+
multihash = { version = "0.17.0", default-features = false, features = ["std", "multihash-impl", "identity", "sha2", "blake2b"] }
2529
network-interface = "1.1.1"
2630
parking_lot = "0.12.3"
2731
pin-project = "1.1.0"
2832
prost = "0.12.6"
2933
rand = { version = "0.8.0", features = ["getrandom"] }
3034
rcgen = "0.10.0"
31-
serde = "1.0.158"
35+
serde = { version = "1.0.158" }
3236
sha2 = "0.10.8"
3337
simple-dns = "0.9.3"
3438
smallvec = "1.13.2"
@@ -56,6 +60,7 @@ quinn = { version = "0.9.3", default-features = false, features = ["tls-rustls",
5660
rustls = { version = "0.20.7", default-features = false, features = ["dangerous_configuration"], optional = true }
5761
ring = { version = "0.16.20", optional = true }
5862
webpki = { version = "0.22.4", optional = true }
63+
serde_millis = {version = "0.1", optional = true}
5964

6065
[dev-dependencies]
6166
libp2p = { version = "0.51.4", features = [
@@ -78,6 +83,8 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
7883
futures_ringbuf = "0.4.0"
7984

8085
[features]
86+
fuzz = ["serde/derive", "serde/rc", "bytes/serde", "dep:serde_millis", "cid/serde", "multihash/serde"]
87+
custom_sc_network = []
8188
quic = ["dep:webpki", "dep:quinn", "dep:rustls", "dep:ring"]
8289
webrtc = ["dep:str0m"]
8390
websocket = ["dep:tokio-tungstenite"]

build.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
fn main() {
2-
prost_build::compile_protos(
3-
&[
4-
"src/schema/keys.proto",
5-
"src/schema/noise.proto",
6-
"src/schema/webrtc.proto",
7-
"src/protocol/libp2p/schema/identify.proto",
8-
"src/protocol/libp2p/schema/kademlia.proto",
9-
"src/protocol/libp2p/schema/bitswap.proto",
10-
],
11-
&["src"],
12-
)
13-
.unwrap();
2+
let mut config = prost_build::Config::new();
3+
// Configure Prost to add #[derive(Serialize, Deserialize)] to all generated structs
4+
config.type_attribute(
5+
".",
6+
"#[cfg_attr(feature = \"fuzz\", derive(serde::Serialize, serde::Deserialize))]",
7+
);
8+
config
9+
.compile_protos(
10+
&[
11+
"src/schema/keys.proto",
12+
"src/schema/noise.proto",
13+
"src/schema/webrtc.proto",
14+
"src/protocol/libp2p/schema/identify.proto",
15+
"src/protocol/libp2p/schema/kademlia.proto",
16+
"src/protocol/libp2p/schema/bitswap.proto",
17+
],
18+
&["src"],
19+
)
20+
.unwrap();
1421
}

0 commit comments

Comments
 (0)