@@ -24,7 +24,7 @@ use std::iter::IntoIterator;
2424
2525use crate :: backends:: counter;
2626use crate :: backends:: plonky2:: basetypes:: {
27- hash_fields, Hash , Value , D , EMPTY , F , HASH_SIZE , NULL , VALUE_SIZE ,
27+ hash_fields, Hash , Value , D , EMPTY_HASH , EMPTY_VALUE , F , HASH_SIZE , VALUE_SIZE ,
2828} ;
2929use crate :: backends:: plonky2:: primitives:: merkletree:: MerkleProof ;
3030
@@ -34,7 +34,6 @@ pub struct MerkleProofCircuit<const MAX_DEPTH: usize> {
3434 value : Vec < Target > ,
3535 existence : BoolTarget ,
3636 siblings : Vec < HashOutTarget > ,
37- // siblings_selectors: Vec<BoolTarget>,
3837 case_ii_selector : BoolTarget , // for case ii)
3938 other_key : Vec < Target > ,
4039 other_value : Vec < Target > ,
@@ -49,7 +48,7 @@ impl<const MAX_DEPTH: usize> MerkleProofCircuit<MAX_DEPTH> {
4948 let value = builder. add_virtual_targets ( VALUE_SIZE ) ;
5049 // from proof struct:
5150 let existence = builder. add_virtual_bool_target_safe ( ) ;
52- // siblings are padded
51+ // siblings are padded till MAX_DEPTH length
5352 let siblings = builder. add_virtual_hashes ( MAX_DEPTH ) ;
5453
5554 let case_ii_selector = builder. add_virtual_bool_target_safe ( ) ;
@@ -102,7 +101,7 @@ impl<const MAX_DEPTH: usize> MerkleProofCircuit<MAX_DEPTH> {
102101
103102 // if we're in the case i), use leaf_hash=EMPTY_HASH, else use the
104103 // previously computed hash h.
105- let empty_hash = builder. constant_hash ( HashOut :: from ( NULL . 0 ) ) ;
104+ let empty_hash = builder. constant_hash ( HashOut :: from ( EMPTY_HASH . 0 ) ) ;
106105 let leaf_hash = HashOutTarget :: from_vec (
107106 ( 0 ..4 )
108107 . map ( |j| builder. select ( case_i_selector, empty_hash. elements [ j] , h. elements [ j] ) )
@@ -115,10 +114,7 @@ impl<const MAX_DEPTH: usize> MerkleProofCircuit<MAX_DEPTH> {
115114 // compute the root for the given siblings and the computed leaf_hash
116115 // (this is for the three cases (existence, non-existence case i, and
117116 // non-existence case ii)
118- let computed_root = Self :: compute_root_from_leaf (
119- builder, & path, & leaf_hash, & siblings,
120- // &siblings_selectors,
121- ) ?;
117+ let computed_root = Self :: compute_root_from_leaf ( builder, & path, & leaf_hash, & siblings) ?;
122118 // ensure that the computed root matches the given root (which is a
123119 // public input)
124120 builder. connect_hashes ( computed_root, root) ;
@@ -152,7 +148,7 @@ impl<const MAX_DEPTH: usize> MerkleProofCircuit<MAX_DEPTH> {
152148
153149 // pad siblings with zeros to length MAX_DEPTH
154150 let mut siblings = proof. siblings . clone ( ) ;
155- siblings. resize ( MAX_DEPTH , NULL ) ;
151+ siblings. resize ( MAX_DEPTH , EMPTY_HASH ) ;
156152 assert_eq ! ( self . siblings. len( ) , siblings. len( ) ) ;
157153
158154 for ( i, sibling) in siblings. iter ( ) . enumerate ( ) {
@@ -167,8 +163,8 @@ impl<const MAX_DEPTH: usize> MerkleProofCircuit<MAX_DEPTH> {
167163 } else {
168164 // existence & non-existence case i) expected leaf does not exist
169165 pw. set_bool_target ( self . case_ii_selector , false ) ?;
170- pw. set_target_arr ( & self . other_key , & EMPTY . 0 . to_vec ( ) ) ?;
171- pw. set_target_arr ( & self . other_value , & EMPTY . 0 . to_vec ( ) ) ?;
166+ pw. set_target_arr ( & self . other_key , & EMPTY_VALUE . 0 . to_vec ( ) ) ?;
167+ pw. set_target_arr ( & self . other_value , & EMPTY_VALUE . 0 . to_vec ( ) ) ?;
172168 }
173169
174170 Ok ( ( ) )
@@ -408,7 +404,7 @@ pub mod tests {
408404 ( key, value, proof)
409405 } else {
410406 let key = Value :: from ( hash_value ( & Value :: from ( 200 ) ) ) ;
411- ( key, EMPTY , tree. prove_nonexistence ( & key) ?)
407+ ( key, EMPTY_VALUE , tree. prove_nonexistence ( & key) ?)
412408 } ;
413409 assert_eq ! ( proof. existence, existence) ;
414410
@@ -473,7 +469,7 @@ pub mod tests {
473469 tree. prove ( & key) ?
474470 } else {
475471 let proof = tree. prove_nonexistence ( & key) ?;
476- ( EMPTY , proof)
472+ ( EMPTY_VALUE , proof)
477473 } ;
478474
479475 assert_eq ! ( proof. existence, contains) ;
0 commit comments