@@ -356,22 +356,22 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
356
356
/// Update the tree from the output queue account.
357
357
/// 1. Create public inputs hash.
358
358
/// 2. Verify update proof and update tree account.
359
- /// 2.1. Verify proof.
360
- /// 2.2. Increment sequence number.
361
- /// 2.3. Increment next index.
362
- /// 2.4. Append new root to root history.
359
+ /// 2.1. Verify proof.
360
+ /// 2.2. Increment sequence number.
361
+ /// 2.3. Increment next index.
362
+ /// 2.4. Append new root to root history.
363
363
/// 3. Mark zkp batch as inserted in the merkle tree.
364
- /// 3.1. Checks that the batch is ready.
365
- /// 3.2. Increment the number of inserted zkps.
366
- /// 3.3. If all zkps are inserted, set batch state to inserted.
364
+ /// 3.1. Checks that the batch is ready.
365
+ /// 3.2. Increment the number of inserted zkps.
366
+ /// 3.3. If all zkps are inserted, set batch state to inserted.
367
367
/// 4. Increment next full batch index if inserted.
368
368
/// 5. Zero out previous batch bloom filter of input queue
369
- /// if current batch is 50% inserted.
369
+ /// if current batch is 50% inserted.
370
370
/// 6. Return the batch append event.
371
371
///
372
372
/// Note: when proving inclusion by index in
373
- /// value array we need to insert the value into a bloom_filter once it is
374
- /// inserted into the tree. Check this with get_num_inserted_zkps
373
+ /// value array we need to insert the value into a bloom_filter once it is
374
+ /// inserted into the tree. Check this with get_num_inserted_zkps
375
375
pub fn update_tree_from_output_queue_account (
376
376
& mut self ,
377
377
queue_account : & mut BatchedQueueAccount ,
@@ -475,14 +475,14 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
475
475
/// Update the tree from the input/address queue account.
476
476
/// 1. Create public inputs hash.
477
477
/// 2. Verify update proof and update tree account.
478
- /// 2.1. Verify proof.
479
- /// 2.2. Increment sequence number.
480
- /// 2.3. If address tree increment next index.
481
- /// 2.4. Append new root to root history.
478
+ /// 2.1. Verify proof.
479
+ /// 2.2. Increment sequence number.
480
+ /// 2.3. If address tree increment next index.
481
+ /// 2.4. Append new root to root history.
482
482
/// 3. Mark batch as inserted in the merkle tree.
483
- /// 3.1. Checks that the batch is ready.
484
- /// 3.2. Increment the number of inserted zkps.
485
- /// 3.3. If all zkps are inserted, set the state to inserted.
483
+ /// 3.1. Checks that the batch is ready.
484
+ /// 3.2. Increment the number of inserted zkps.
485
+ /// 3.3. If all zkps are inserted, set the state to inserted.
486
486
/// 4. Zero out previous batch bloom filter if current batch is 50% inserted.
487
487
/// 5. Increment next full batch index if inserted.
488
488
/// 6. Return the batch nullify event.
@@ -618,13 +618,13 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
618
618
/// 1. Check that the tree is a state tree.
619
619
/// 2. Create nullifier Hash(value,leaf_index, tx_hash).
620
620
/// 3. Insert nullifier into current batch.
621
- /// 3.1. Insert compressed_account_hash into bloom filter.
622
- /// (bloom filter enables non-inclusion proofs in later txs)
623
- /// 3.2. Add nullifier to leaves hash chain.
624
- /// (Nullification means, the compressed_account_hash in the tree,
625
- /// is overwritten with a nullifier hash)
626
- /// 3.3. Check that compressed_account_hash
627
- /// does not exist in any other bloom filter.
621
+ /// 3.1. Insert compressed_account_hash into bloom filter.
622
+ /// (bloom filter enables non-inclusion proofs in later txs)
623
+ /// 3.2. Add nullifier to leaves hash chain.
624
+ /// (Nullification means, the compressed_account_hash in the tree,
625
+ /// is overwritten with a nullifier hash)
626
+ /// 3.3. Check that compressed_account_hash
627
+ /// does not exist in any other bloom filter.
628
628
pub fn insert_nullifier_into_queue (
629
629
& mut self ,
630
630
compressed_account_hash : & [ u8 ; 32 ] ,
@@ -707,8 +707,8 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
707
707
/// Steps:
708
708
/// 1. Check whether overlapping roots exist.
709
709
/// 2. If yes:
710
- /// 2.1. Get, first safe root index.
711
- /// 2.2. Zero out roots from the oldest root to first safe root.
710
+ /// 2.1. Get, first safe root index.
711
+ /// 2.2. Zero out roots from the oldest root to first safe root.
712
712
///
713
713
/// Note on security for root buffer:
714
714
/// Account {
@@ -722,20 +722,20 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
722
722
/// Timeslot 1:
723
723
/// - insert into B1 until full
724
724
/// - update tree with B0 in 4 partial updates, don't clear B0 yet
725
- /// -> R0 -> B0.1
726
- /// -> R1 -> B0.2
727
- /// -> R2 -> B0.3
728
- /// -> R3 -> B0.4 - final B0 root
729
- /// B0.sequence_number = 13 (3 + account.root.length)
730
- /// B0.root_index = 3
725
+ /// -> R0 -> B0.1
726
+ /// -> R1 -> B0.2
727
+ /// -> R2 -> B0.3
728
+ /// -> R3 -> B0.4 - final B0 root
729
+ /// B0.sequence_number = 13 (3 + account.root.length)
730
+ /// B0.root_index = 3
731
731
/// - execute some B1 root updates
732
- /// -> R4 -> B1.1
733
- /// -> R5 -> B1.2
734
- /// -> R6 -> B1.3
735
- /// -> R7 -> B1.4 - final B1 (update batch 0) root
736
- /// B0.sequence_number = 17 (7 + account.root.length)
737
- /// B0.root_index = 7
738
- /// current_sequence_number = 8
732
+ /// -> R4 -> B1.1
733
+ /// -> R5 -> B1.2
734
+ /// -> R6 -> B1.3
735
+ /// -> R7 -> B1.4 - final B1 (update batch 0) root
736
+ /// B0.sequence_number = 17 (7 + account.root.length)
737
+ /// B0.root_index = 7
738
+ /// current_sequence_number = 8
739
739
///
740
740
/// Timeslot 2:
741
741
/// - clear B0
@@ -779,12 +779,12 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
779
779
///
780
780
/// Idea:
781
781
/// 1. Zeroing out the bloom filter of the previous batch is expensive
782
- /// -> the forester should do it.
782
+ /// -> the forester should do it.
783
783
/// 2. We don't want to zero out the bloom filter when inserting
784
- /// the last zkp of a batch for this might result in failing user tx.
784
+ /// the last zkp of a batch for this might result in failing user tx.
785
785
/// 3. Wait until next batch is 50% full as grace period for clients
786
- /// to switch from proof by index to proof by zkp
787
- /// for values inserted in the previous batch.
786
+ /// to switch from proof by index to proof by zkp
787
+ /// for values inserted in the previous batch.
788
788
///
789
789
/// Steps:
790
790
/// 1. Previous batch must be inserted and bloom filter must not be zeroed out.
@@ -794,9 +794,9 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
794
794
/// 3.2. zero out bloom filter
795
795
/// 3.3. zero out roots if needed
796
796
///
797
- /// Initial state: 0 pending -> 1 previous pending even though it was never used
798
- /// 0 inserted -> 1 pending 0 -> 1 pending 50% - zero out 0 -> 1 inserted
799
- /// 0 pending -> 1 inserted
797
+ /// Initial state: 0 pending -> 1 previous pending even though it was never used
798
+ /// 0 inserted -> 1 pending 0 -> 1 pending 50% - zero out 0 -> 1 inserted
799
+ /// 0 pending -> 1 inserted
800
800
fn zero_out_previous_batch_bloom_filter ( & mut self ) -> Result < ( ) , BatchedMerkleTreeError > {
801
801
let current_batch = self . queue_batches . pending_batch_index as usize ;
802
802
let batch_size = self . queue_batches . batch_size ;
@@ -1101,15 +1101,15 @@ mod test {
1101
1101
/// 1. No batch is ready -> nothing should happen.
1102
1102
/// 2. Batch 0 is inserted but Batch 1 is empty -> nothing should happen.
1103
1103
/// 3. Batch 0 is inserted but Batch 1 is 25% full (not the required half)
1104
- /// -> nothing should happen.
1104
+ /// -> nothing should happen.
1105
1105
/// 4. Batch 0 is inserted and Batch 1 is full
1106
- /// -> should zero out all existing roots except the last one.
1106
+ /// -> should zero out all existing roots except the last one.
1107
1107
/// 5. Batch 1 is inserted and Batch 0 is empty
1108
- /// -> nothing should happen.
1108
+ /// -> nothing should happen.
1109
1109
/// 6. Batch 1 is inserted and Batch 0 is 25% full (not the required half)
1110
- /// -> nothing should happen.
1110
+ /// -> nothing should happen.
1111
1111
/// 7. Batch 1 is inserted and Batch 0 is half full and no overlapping roots exist
1112
- /// -> bloom filter is zeroed, roots are untouched.
1112
+ /// -> bloom filter is zeroed, roots are untouched.
1113
1113
/// 8. Batch 1 is already zeroed -> nothing should happen
1114
1114
/// 9. Batch 1 is inserted and Batch 0 is full and overlapping roots exist
1115
1115
#[ test]
0 commit comments