@@ -5,7 +5,7 @@ use commonware_cryptography::{sha256::Digest, Hasher, Sha256};
55use commonware_runtime:: { buffer:: paged:: CacheRef , deterministic, Runner } ;
66use commonware_storage:: {
77 journal:: contiguous:: fixed:: Config as FConfig ,
8- mmr :: { self , journaled:: Config as MmrConfig , Location } ,
8+ merkle :: { journaled:: Config as MerkleConfig , mmb , mmr , Graftable , Location } ,
99 qmdb:: current:: { ordered:: fixed:: Db as CurrentDb , FixedConfig as Config } ,
1010 translator:: TwoCap ,
1111} ;
@@ -20,7 +20,7 @@ type Key = FixedBytes<32>;
2020type Value = FixedBytes < 32 > ;
2121type RawKey = [ u8 ; 32 ] ;
2222type RawValue = [ u8 ; 32 ] ;
23- type Db = CurrentDb < mmr :: Family , deterministic:: Context , Key , Value , Sha256 , TwoCap , 32 > ;
23+ type Db < F > = CurrentDb < F , deterministic:: Context , Key , Value , Sha256 , TwoCap , 32 > ;
2424
2525#[ derive( Arbitrary , Debug , Clone ) ]
2626enum CurrentOperation {
@@ -78,12 +78,12 @@ impl<'a> Arbitrary<'a> for FuzzInput {
7878
7979const PAGE_SIZE : NonZeroU16 = NZU16 ! ( 91 ) ;
8080const PAGE_CACHE_SIZE : usize = 8 ;
81- const MMR_ITEMS_PER_BLOB : u64 = 11 ;
81+ const MERKLE_ITEMS_PER_BLOB : u64 = 11 ;
8282const LOG_ITEMS_PER_BLOB : u64 = 7 ;
8383const WRITE_BUFFER_SIZE : usize = 1024 ;
8484
85- async fn commit_pending (
86- db : & mut Db ,
85+ async fn commit_pending < F : Graftable > (
86+ db : & mut Db < F > ,
8787 pending_writes : & mut Vec < ( Key , Option < Value > ) > ,
8888 committed_state : & mut HashMap < RawKey , RawValue > ,
8989 pending_inserts : & mut HashMap < RawKey , RawValue > ,
@@ -104,9 +104,11 @@ async fn commit_pending(
104104 committed_state. extend ( pending_inserts. drain ( ) ) ;
105105}
106106
107- fn fuzz ( data : FuzzInput ) {
107+ fn fuzz_family < F : Graftable > ( data : & FuzzInput , suffix : & str ) {
108108 let runner = deterministic:: Runner :: default ( ) ;
109109
110+ let suffix = suffix. to_string ( ) ;
111+ let operations = data. operations . clone ( ) ;
110112 runner. start ( |context| async move {
111113 let mut hasher = Sha256 :: new ( ) ;
112114 let page_cache = CacheRef :: from_pooler (
@@ -115,25 +117,25 @@ fn fuzz(data: FuzzInput) {
115117 NZUsize ! ( PAGE_CACHE_SIZE ) ,
116118 ) ;
117119 let cfg = Config {
118- merkle_config : MmrConfig {
119- journal_partition : "fuzz-current-mmr- journal" . into ( ) ,
120- metadata_partition : "fuzz-current-mmr- metadata" . into ( ) ,
121- items_per_blob : NZU64 ! ( MMR_ITEMS_PER_BLOB ) ,
120+ merkle_config : MerkleConfig {
121+ journal_partition : format ! ( "fuzz-current-ord-{suffix}-merkle- journal" ) ,
122+ metadata_partition : format ! ( "fuzz-current-ord-{suffix}-merkle- metadata" ) ,
123+ items_per_blob : NZU64 ! ( MERKLE_ITEMS_PER_BLOB ) ,
122124 write_buffer : NZUsize ! ( WRITE_BUFFER_SIZE ) ,
123125 thread_pool : None ,
124126 page_cache : page_cache. clone ( ) ,
125127 } ,
126128 journal_config : FConfig {
127- partition : "fuzz-current-log-journal" . into ( ) ,
129+ partition : format ! ( "fuzz-current-ord-{suffix}- log-journal" ) ,
128130 items_per_blob : NZU64 ! ( LOG_ITEMS_PER_BLOB ) ,
129131 write_buffer : NZUsize ! ( WRITE_BUFFER_SIZE ) ,
130132 page_cache,
131133 } ,
132- grafted_metadata_partition : "fuzz-current-grafted-mmr -metadata" . into ( ) ,
134+ grafted_metadata_partition : format ! ( "fuzz-current-ord-{suffix}- grafted-merkle -metadata" ) ,
133135 translator : TwoCap ,
134136 } ;
135137
136- let mut db = Db :: init ( context. clone ( ) , cfg)
138+ let mut db: Db < F > = Db :: init ( context. clone ( ) , cfg)
137139 . await
138140 . expect ( "Failed to initialize Current database" ) ;
139141
@@ -144,9 +146,9 @@ fn fuzz(data: FuzzInput) {
144146 let mut pending_deletes: HashSet < RawKey > = HashSet :: new ( ) ;
145147 let mut all_keys = HashSet :: new ( ) ;
146148 let mut pending_writes: Vec < ( Key , Option < Value > ) > = Vec :: new ( ) ;
147- let mut committed_op_count = Location :: new ( 1 ) ;
149+ let mut committed_op_count = Location :: < F > :: new ( 1 ) ;
148150
149- for op in & data . operations {
151+ for op in & operations {
150152 match op {
151153 CurrentOperation :: Update { key, value } => {
152154 let k = Key :: new ( * key) ;
@@ -241,7 +243,7 @@ fn fuzz(data: FuzzInput) {
241243 let current_root = db. root ( ) ;
242244
243245 let current_op_count = db. bounds ( ) . await . end ;
244- let start_loc = Location :: new ( start_loc % * current_op_count) ;
246+ let start_loc = Location :: < F > :: new ( start_loc % * current_op_count) ;
245247
246248 let oldest_loc = db. sync_boundary ( ) ;
247249 if start_loc >= oldest_loc {
@@ -251,7 +253,7 @@ fn fuzz(data: FuzzInput) {
251253 . expect ( "Range proof should not fail" ) ;
252254
253255 assert ! (
254- Db :: verify_range_proof(
256+ Db :: < F > :: verify_range_proof(
255257 & mut hasher,
256258 & proof,
257259 start_loc,
@@ -276,7 +278,7 @@ fn fuzz(data: FuzzInput) {
276278 committed_op_count = db. bounds ( ) . await . end ;
277279
278280 let current_op_count = db. bounds ( ) . await . end ;
279- let start_loc = Location :: new ( start_loc % current_op_count. as_u64 ( ) ) ;
281+ let start_loc = Location :: < F > :: new ( start_loc % current_op_count. as_u64 ( ) ) ;
280282 let root = db. root ( ) ;
281283
282284 if let Ok ( ( range_proof, ops, chunks) ) = db
@@ -287,7 +289,7 @@ fn fuzz(data: FuzzInput) {
287289 if range_proof. proof . digests != bad_digests {
288290 let mut bad_proof = range_proof. clone ( ) ;
289291 bad_proof. proof . digests = bad_digests;
290- assert ! ( !Db :: verify_range_proof(
292+ assert ! ( !Db :: < F > :: verify_range_proof(
291293 & mut hasher,
292294 & bad_proof,
293295 start_loc,
@@ -299,7 +301,7 @@ fn fuzz(data: FuzzInput) {
299301
300302 // Try to verify the proof when providing bad input chunks.
301303 if & chunks != bad_chunks {
302- assert ! ( !Db :: verify_range_proof(
304+ assert ! ( !Db :: < F > :: verify_range_proof(
303305 & mut hasher,
304306 & range_proof,
305307 start_loc,
@@ -324,7 +326,7 @@ fn fuzz(data: FuzzInput) {
324326 match db. key_value_proof ( & mut hasher, k. clone ( ) ) . await {
325327 Ok ( proof) => {
326328 let value = db. get ( & k) . await . expect ( "get should not fail" ) . expect ( "key should exist" ) ;
327- let verification_result = Db :: verify_key_value_proof (
329+ let verification_result = Db :: < F > :: verify_key_value_proof (
328330 & mut hasher,
329331 k,
330332 value,
@@ -354,7 +356,7 @@ fn fuzz(data: FuzzInput) {
354356
355357 match db. exclusion_proof ( & mut hasher, & k) . await {
356358 Ok ( proof) => {
357- let verification_result = Db :: verify_exclusion_proof (
359+ let verification_result = Db :: < F > :: verify_exclusion_proof (
358360 & mut hasher,
359361 & k,
360362 & proof,
@@ -404,5 +406,6 @@ fn fuzz(data: FuzzInput) {
404406}
405407
406408fuzz_target ! ( |input: FuzzInput | {
407- fuzz( input) ;
409+ fuzz_family:: <mmr:: Family >( & input, "mmr" ) ;
410+ fuzz_family:: <mmb:: Family >( & input, "mmb" ) ;
408411} ) ;
0 commit comments