Skip to content

Commit bf6a397

Browse files
authored
Merge pull request #415 from filecoin-project/fuzz/amt-index-limit
Improve AMT equivalance fuzzer
2 parents 52cb0d5 + d3feeec commit bf6a397

File tree

7 files changed

+14
-74
lines changed

7 files changed

+14
-74
lines changed

ipld/amt/fuzz/Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "ipld_amt-fuzz"
2+
name = "ipld_amt_fuzz"
33
version = "0.0.0"
44
authors = ["ChainSafe Systems <[email protected]>", "Protocol Labs", "Filecoin Core Devs"]
55
publish = false
@@ -23,11 +23,6 @@ fvm_shared = { path = "../../../shared" }
2323
[workspace]
2424
members = ["."]
2525

26-
[[bin]]
27-
name = "simple"
28-
path = "fuzz_targets/simple.rs"
29-
test = false
30-
doc = false
3126

3227
[[bin]]
3328
name = "equivalence"

ipld/amt/fuzz/corpus/equivalence

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../testing/fuzz-corpora/corpus/amt_equivalence/
1+
../../../../testing/fuzz-corpora/corpus/amt_equivalence

ipld/amt/fuzz/corpus/simple

Lines changed: 0 additions & 1 deletion
This file was deleted.

ipld/amt/fuzz/fuzz_targets/equivalence.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33

44
#![no_main]
55
use arbitrary::Arbitrary;
6-
use fvm_ipld_amt::{Amt, MAX_INDEX};
6+
use fvm_ipld_amt::Amt;
77
use libfuzzer_sys::fuzz_target;
88
use cid::Cid;
99
use itertools::Itertools;
1010

1111

1212
#[derive(Debug, Arbitrary)]
1313
struct Operation {
14-
idx: u64,
14+
idx: u16,
1515
method: Method,
16+
flush: u8, // flush in 5% of cases on expectation so > (255 - 13)
1617
}
1718

1819
#[derive(Debug, Arbitrary)]
@@ -21,15 +22,17 @@ enum Method {
2122
Remove,
2223
Get,
2324
}
24-
2525
fn execute(ops: Vec<Operation>) -> (Cid, ahash::AHashMap<u64, u64>) {
2626
let db = fvm_shared::blockstore::MemoryBlockstore::default();
2727
let mut amt = Amt::new(&db);
2828
let mut elements = ahash::AHashMap::new();
2929

30-
for (i, Operation { idx, method }) in ops.into_iter().enumerate() {
31-
if idx > MAX_INDEX {
32-
continue;
30+
for (i, Operation { idx, method, flush}) in ops.into_iter().enumerate() {
31+
let idx = idx as u64;
32+
if flush > 255 - 13 {
33+
// Periodic flushing and reloading of Amt to fuzz blockstore usage also
34+
let cid = amt.flush().unwrap();
35+
amt = Amt::load(&cid, &db).unwrap();
3336
}
3437

3538
match method {
@@ -60,7 +63,7 @@ fuzz_target!(|ops: Vec<Operation>| {
6063
let (res_cid, m) = execute(ops);
6164

6265
let simplified_ops = m.iter().sorted_by_key(|(_, v)| *v).map(|(k ,v)| {
63-
Operation{idx: *k, method: Method::Insert(*v)}
66+
Operation{idx: *k as u16, method: Method::Insert(*v), flush: 0}
6467
}).collect();
6568

6669
let (simplified_cid, _) = execute(simplified_ops);

ipld/amt/fuzz/fuzz_targets/simple.rs

Lines changed: 0 additions & 57 deletions
This file was deleted.

ipld/hamt/fuzz/corpus/simple

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../testing/fuzz-corpora/corpus/hamt_simple
1+
../../../../testing/fuzz-corpora/corpus/hamt_simple

testing/fuzz-corpora

Submodule fuzz-corpora updated 2988 files

0 commit comments

Comments
 (0)