Skip to content

Commit b13c7ba

Browse files
no default bagging for Standard hasher
1 parent 14d789e commit b13c7ba

42 files changed

Lines changed: 302 additions & 287 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

storage/fuzz/fuzz_targets/merkle_family_operations.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use arbitrary::Arbitrary;
44
use commonware_cryptography::{sha256::Digest, Sha256};
55
use commonware_runtime::{deterministic, Runner};
66
use commonware_storage::merkle::{
7-
hasher::Standard, mem::Mem, mmb, mmr, Error, Family as MerkleFamily, Location, Position,
7+
hasher::Standard, mem::Mem, mmb, mmr, Bagging::ForwardFold, Error, Family as MerkleFamily,
8+
Location, Position,
89
};
910
use core::any::type_name;
1011
use libfuzzer_sys::fuzz_target;
@@ -128,7 +129,7 @@ fn fuzz_family<F: MerkleFamily>(operations: &[MerkleOperation]) {
128129
let runner = deterministic::Runner::default();
129130

130131
runner.start(|_context| async move {
131-
let hasher = Standard::<Sha256>::new();
132+
let hasher = Standard::<Sha256>::new(ForwardFold);
132133
let mut merkle = Mem::<F, Digest>::new();
133134
let mut reference = ReferenceMerkle::<F>::new();
134135

storage/fuzz/fuzz_targets/merkle_full.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use commonware_cryptography::Sha256;
55
use commonware_parallel::Sequential;
66
use commonware_runtime::{buffer::paged::CacheRef, deterministic, BufferPooler, Metrics, Runner};
77
use commonware_storage::merkle::{
8-
full::Config, hasher::Standard, mem::Mem, mmb, mmr, Error, Family as MerkleFamily, Location,
9-
LocationRangeExt as _, Position,
8+
full::Config, hasher::Standard, mem::Mem, mmb, mmr, Bagging::ForwardFold, Error,
9+
Family as MerkleFamily, Location, LocationRangeExt as _, Position,
1010
};
1111
use commonware_utils::{non_empty_range, NZUsize, NZU16, NZU64};
1212
use libfuzzer_sys::fuzz_target;
@@ -92,7 +92,7 @@ fn historical_root<F: MerkleFamily>(
9292
leaves: &[Vec<u8>],
9393
requested_leaves: Location<F>,
9494
) -> <Sha256 as commonware_cryptography::Hasher>::Digest {
95-
let hasher = Standard::<Sha256>::new();
95+
let hasher = Standard::<Sha256>::new(ForwardFold);
9696
let mut mem = Mem::<F, _>::new();
9797
let batch = {
9898
let mut batch = mem.new_batch();
@@ -115,7 +115,7 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
115115
let operations = input.operations.clone();
116116
async move {
117117
let mut leaves = Vec::new();
118-
let hasher = Standard::<Sha256>::new();
118+
let hasher = Standard::<Sha256>::new(ForwardFold);
119119
let mut merkle =
120120
Merkle::<F, _, _>::init(context.clone(), &hasher, test_config(suffix, &context))
121121
.await
@@ -258,7 +258,7 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
258258
.await;
259259
match result {
260260
Ok(historical_proof) => {
261-
let verify_hasher = Standard::<Sha256>::new();
261+
let verify_hasher = Standard::<Sha256>::new(ForwardFold);
262262
assert!(historical_proof.verify_range_inclusion(
263263
&verify_hasher,
264264
&leaves[range.to_usize_range()],

storage/fuzz/fuzz_targets/merkle_full_crash_recovery.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use commonware_runtime::{
1010
buffer::paged::CacheRef, deterministic, BufferPooler, Metrics as _, Runner,
1111
};
1212
use commonware_storage::merkle::{
13-
full::Config, hasher::Standard as StandardHasher, mmb, mmr, Family as MerkleFamily, Location,
13+
full::Config, hasher::Standard as StandardHasher, mmb, mmr, Bagging::ForwardFold,
14+
Family as MerkleFamily, Location,
1415
};
1516
use commonware_utils::NZU64;
1617
use libfuzzer_sys::fuzz_target;
@@ -235,7 +236,7 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
235236
let partition_suffix = partition_suffix.clone();
236237
let operations = operations.clone();
237238
async move {
238-
let hasher = StandardHasher::<Sha256>::new();
239+
let hasher = StandardHasher::<Sha256>::new(ForwardFold);
239240
let mut merkle = Merkle::<F>::init(
240241
ctx.with_label("merkle"),
241242
&hasher,
@@ -267,7 +268,7 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
267268
runner.start(|ctx| async move {
268269
*ctx.storage_fault_config().write() = deterministic::FaultConfig::default();
269270

270-
let hasher = StandardHasher::<Sha256>::new();
271+
let hasher = StandardHasher::<Sha256>::new(ForwardFold);
271272
let mut merkle = Merkle::<F>::init(
272273
ctx.with_label("recovered"),
273274
&hasher,

storage/fuzz/fuzz_targets/mmr_bitmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use arbitrary::Arbitrary;
44
use commonware_cryptography::{sha256, Digest, Sha256};
55
use commonware_parallel::Sequential;
66
use commonware_runtime::{deterministic, Clock, Metrics, Runner, Storage};
7-
use commonware_storage::{MerkleizedBitMap, UnmerkleizedBitMap};
7+
use commonware_storage::{merkle::Bagging::ForwardFold, MerkleizedBitMap, UnmerkleizedBitMap};
88
use commonware_utils::bitmap::BitMap;
99
use libfuzzer_sys::fuzz_target;
1010

@@ -59,7 +59,7 @@ fn fuzz(input: FuzzInput) {
5959
const PARTITION: &str = "fuzz-mmr-bitmap-test-partition";
6060

6161
runner.start(|context| async move {
62-
let hasher = commonware_storage::mmr::StandardHasher::<Sha256>::new();
62+
let hasher = commonware_storage::mmr::StandardHasher::<Sha256>::new(ForwardFold);
6363
let init_bitmap = MerkleizedBitMap::<_, _, CHUNK_SIZE>::init(
6464
context.with_label("bitmap"),
6565
PARTITION,

storage/fuzz/fuzz_targets/proof_store.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use arbitrary::{Arbitrary, Unstructured};
44
use commonware_codec::Encode as _;
55
use commonware_cryptography::{sha256::Digest, Sha256};
66
use commonware_storage::merkle::{
7-
self, mmb, mmr, verification::ProofStore, Family as MerkleFamily, Location, Position, Proof,
7+
self, mmb, mmr, verification::ProofStore, Bagging::BackwardFold, Family as MerkleFamily,
8+
Location, Position, Proof,
89
};
910
use libfuzzer_sys::fuzz_target;
1011
use std::ops::Range;
@@ -57,7 +58,7 @@ impl<'a, F: MerkleFamily> Arbitrary<'a> for FuzzInput<F> {
5758
}
5859

5960
fn fuzz_family<F: MerkleFamily>(input: &FuzzInput<F>) {
60-
let hasher = merkle::hasher::Standard::<Sha256>::with_bagging(merkle::Bagging::BackwardFold);
61+
let hasher = merkle::hasher::Standard::<Sha256>::new(BackwardFold);
6162
let proof = Proof::<F, Digest> {
6263
leaves: input.proof_leaves,
6364
inactive_peaks: input.inactive_peaks,

storage/fuzz/fuzz_targets/proofs_malleability.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use commonware_cryptography::{sha256::Digest, Hasher as _, Sha256};
66
use commonware_storage::{
77
bmt::Builder as BmtBuilder,
88
merkle::{
9-
hasher::Standard, mem::Mem, mmb, mmr, verification, Bagging, Family as MerkleFamily,
10-
Location,
9+
hasher::Standard, mem::Mem, mmb, mmr, verification, Bagging, Bagging::ForwardFold,
10+
Family as MerkleFamily, Location,
1111
},
1212
};
1313
use futures::executor::block_on;
@@ -143,7 +143,7 @@ fn supported_root_specs<F: MerkleFamily>(merkle: &Mem<F, Digest>) -> Vec<(Baggin
143143
}
144144

145145
fn fuzz_element_proof<F: MerkleFamily>(input: &FuzzInput, digests: &[Digest]) {
146-
let build_hasher = Standard::<Sha256>::new();
146+
let build_hasher = Standard::<Sha256>::new(ForwardFold);
147147
let mut merkle = Mem::<F, Digest>::new();
148148
let batch = {
149149
let mut batch = merkle.new_batch();
@@ -155,7 +155,7 @@ fn fuzz_element_proof<F: MerkleFamily>(input: &FuzzInput, digests: &[Digest]) {
155155
merkle.apply_batch(&batch).unwrap();
156156

157157
for (bagging, inactive_peaks) in supported_root_specs(&merkle) {
158-
let hasher = Standard::<Sha256>::with_bagging(bagging);
158+
let hasher = Standard::<Sha256>::new(bagging);
159159
let root = merkle.root(&hasher, inactive_peaks).unwrap();
160160
for (leaf, element) in digests.iter().enumerate() {
161161
let loc = Location::<F>::new(leaf as u64);
@@ -179,7 +179,7 @@ fn fuzz_element_proof<F: MerkleFamily>(input: &FuzzInput, digests: &[Digest]) {
179179
}
180180

181181
fn fuzz_range_proof<F: MerkleFamily>(input: &FuzzInput, digests: &[Digest]) {
182-
let hasher = Standard::<Sha256>::new();
182+
let hasher = Standard::<Sha256>::new(ForwardFold);
183183
let mut merkle = Mem::<F, Digest>::new();
184184
let batch = {
185185
let mut batch = merkle.new_batch();
@@ -229,7 +229,7 @@ fn fuzz_range_proof<F: MerkleFamily>(input: &FuzzInput, digests: &[Digest]) {
229229
}
230230

231231
for (bagging, inactive_peaks) in supported_root_specs(&merkle) {
232-
let hasher = Standard::<Sha256>::with_bagging(bagging);
232+
let hasher = Standard::<Sha256>::new(bagging);
233233
let root = merkle.root(&hasher, inactive_peaks).unwrap();
234234
let Ok(original_proof) = block_on(verification::historical_range_proof(
235235
&hasher,

storage/fuzz/fuzz_targets/qmdb_any_variable_sync.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use commonware_parallel::Sequential;
66
use commonware_runtime::{buffer::paged::CacheRef, deterministic, BufferPooler, Metrics, Runner};
77
use commonware_storage::{
88
journal::contiguous::variable::Config as VConfig,
9-
merkle::{self, full::Config as MerkleConfig, mmb, mmr, Family as MerkleFamily, Location},
9+
merkle::{
10+
self, full::Config as MerkleConfig, mmb, mmr, Bagging::BackwardFold,
11+
Family as MerkleFamily, Location,
12+
},
1013
qmdb::{
1114
any::{unordered::variable::Db, VariableConfig as Config},
1215
verify_proof,
@@ -164,8 +167,7 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, test_name: &str) {
164167

165168
let test_name = test_name.to_string();
166169
runner.start(|context| async move {
167-
let hasher =
168-
merkle::hasher::Standard::<Sha256>::with_bagging(merkle::Bagging::BackwardFold);
170+
let hasher = merkle::hasher::Standard::<Sha256>::new(BackwardFold);
169171
let cfg = test_config(&test_name, &context);
170172
let mut db = Db::<F, _, Key, Vec<u8>, Sha256, TwoCap>::init(context.clone(), cfg)
171173
.await

storage/fuzz/fuzz_targets/qmdb_immutable.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use commonware_parallel::Sequential;
77
use commonware_runtime::{buffer::paged::CacheRef, deterministic, BufferPooler, Runner};
88
use commonware_storage::{
99
journal::contiguous::variable::Config as VConfig,
10-
merkle::{self, mmb, mmr, Family as MerkleFamily, Location},
10+
merkle::{self, mmb, mmr, Bagging::BackwardFold, Family as MerkleFamily, Location},
1111
mmr::full::Config as MerkleConfig,
1212
qmdb::{
1313
immutable::{variable::Db as Immutable, Config},
@@ -151,8 +151,7 @@ fn fuzz_family<F: MerkleFamily>(input: &FuzzInput, suffix: &str) {
151151
.await
152152
.unwrap();
153153

154-
let hasher =
155-
merkle::hasher::Standard::<Sha256>::with_bagging(merkle::Bagging::BackwardFold);
154+
let hasher = merkle::hasher::Standard::<Sha256>::new(BackwardFold);
156155
let mut keys_set: Vec<(Digest, Location<F>)> = Vec::new();
157156
let mut set_locations: Vec<(Digest, Location<F>)> = Vec::new();
158157
let mut last_commit_loc: Option<Location<F>> = None;

storage/fuzz/fuzz_targets/qmdb_keyless.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use commonware_parallel::Sequential;
66
use commonware_runtime::{buffer::paged::CacheRef, deterministic, BufferPooler, Metrics, Runner};
77
use commonware_storage::{
88
journal::contiguous::variable::Config as VConfig,
9-
merkle::{self, full::Config as MerkleConfig, mmb, mmr, Family, Location},
9+
merkle::{
10+
self, full::Config as MerkleConfig, mmb, mmr, Bagging::BackwardFold, Family, Location,
11+
},
1012
qmdb::{
1113
keyless::variable::{Config, Db as Keyless},
1214
verify_proof, Error,
@@ -216,7 +218,7 @@ fn fuzz_family<F: Family>(input: &FuzzInput, suffix: &str) {
216218
let runner = deterministic::Runner::default();
217219

218220
runner.start(|context| async move {
219-
let hasher = merkle::hasher::Standard::<Sha256>::with_bagging(merkle::Bagging::BackwardFold);
221+
let hasher = merkle::hasher::Standard::<Sha256>::new(BackwardFold);
220222
let cfg = test_config(suffix, &context);
221223
let mut db: Db<F> = Db::init(context.clone(), cfg)
222224
.await

storage/fuzz/fuzz_targets/qmdb_ordered_operations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use commonware_runtime::{buffer::paged::CacheRef, deterministic, Runner};
77
use commonware_storage::{
88
index::ordered::Index,
99
journal::contiguous::fixed::{Config as FConfig, Journal},
10-
merkle::{self, mmb, mmr, Family as MerkleFamily, Location, Proof},
10+
merkle::{self, mmb, mmr, Bagging::BackwardFold, Family as MerkleFamily, Location, Proof},
1111
mmr::full::Config as MerkleConfig,
1212
qmdb::{
1313
any::{
@@ -103,7 +103,7 @@ async fn commit_pending<F: MerkleFamily>(
103103
}
104104

105105
fn fuzz_family<F: MerkleFamily>(data: &FuzzInput, suffix: &str) {
106-
let hasher = merkle::hasher::Standard::<Sha256>::with_bagging(merkle::Bagging::BackwardFold);
106+
let hasher = merkle::hasher::Standard::<Sha256>::new(BackwardFold);
107107
let runner = deterministic::Runner::default();
108108

109109
runner.start(|context| {

0 commit comments

Comments
 (0)