Skip to content

Commit

Permalink
chore: cleanup & fix zero out bloom filter (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
ananas-block authored Jan 17, 2025
1 parent ad940c1 commit 79321b3
Show file tree
Hide file tree
Showing 20 changed files with 973 additions and 677 deletions.
27 changes: 9 additions & 18 deletions forester-utils/src/instructions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use light_batched_merkle_tree::{
constants::{DEFAULT_BATCH_ADDRESS_TREE_HEIGHT, DEFAULT_BATCH_STATE_TREE_HEIGHT},
merkle_tree::{
AppendBatchProofInputsIx, BatchProofInputsIx, BatchedMerkleTreeAccount,
InstructionDataBatchAppendInputs, InstructionDataBatchNullifyInputs,
BatchedMerkleTreeAccount, InstructionDataBatchAppendInputs,
InstructionDataBatchNullifyInputs,
},
queue::BatchedQueueAccount,
};
Expand Down Expand Up @@ -58,12 +58,11 @@ where
})?
.unwrap();

let (old_root_index, leaves_hashchain, start_index, current_root, batch_size, full_batch_index) = {
let (leaves_hashchain, start_index, current_root, batch_size, full_batch_index) = {
let merkle_tree =
BatchedMerkleTreeAccount::address_from_bytes(merkle_tree_account.data.as_mut_slice())
.unwrap();

let old_root_index = merkle_tree.root_history.last_index();
let full_batch_index = merkle_tree.queue_metadata.next_full_batch_index;
let batch = &merkle_tree.batches[full_batch_index as usize];
let zkp_batch_index = batch.get_num_inserted_zkps();
Expand All @@ -74,7 +73,6 @@ where
let batch_size = batch.zkp_batch_size as usize;

(
old_root_index,
leaves_hashchain,
start_index,
current_root,
Expand Down Expand Up @@ -175,7 +173,7 @@ where
})?;

let client = Client::new();
let circuit_inputs_new_root = bigint_to_be_bytes_array::<32>(&inputs.new_root).unwrap();
let new_root = bigint_to_be_bytes_array::<32>(&inputs.new_root).unwrap();
let inputs = to_json(&inputs);

let response_result = client
Expand All @@ -192,10 +190,7 @@ where
let (proof_a, proof_b, proof_c) = proof_from_json_struct(proof_json);
let (proof_a, proof_b, proof_c) = compress_proof(&proof_a, &proof_b, &proof_c);
let instruction_data = InstructionDataBatchNullifyInputs {
public_inputs: BatchProofInputsIx {
new_root: circuit_inputs_new_root,
old_root_index: old_root_index as u16,
},
new_root,
compressed_proof: CompressedProof {
a: proof_a,
b: proof_b,
Expand Down Expand Up @@ -330,7 +325,7 @@ pub async fn create_append_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
};

Ok(InstructionDataBatchAppendInputs {
public_inputs: AppendBatchProofInputsIx { new_root },
new_root,
compressed_proof: proof,
})
}
Expand All @@ -340,7 +335,7 @@ pub async fn create_nullify_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
indexer: &mut I,
merkle_tree_pubkey: Pubkey,
) -> Result<InstructionDataBatchNullifyInputs, ForesterUtilsError> {
let (zkp_batch_size, old_root, old_root_index, leaves_hashchain) = {
let (zkp_batch_size, old_root, leaves_hashchain) = {
let mut account = rpc.get_account(merkle_tree_pubkey).await.unwrap().unwrap();
let merkle_tree =
BatchedMerkleTreeAccount::state_from_bytes(account.data.as_mut_slice()).unwrap();
Expand All @@ -349,9 +344,8 @@ pub async fn create_nullify_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
let batch = &merkle_tree.batches[batch_idx];
let zkp_idx = batch.get_num_inserted_zkps();
let hashchain = merkle_tree.hashchain_store[batch_idx][zkp_idx as usize];
let root_idx = merkle_tree.root_history.last_index();
let root = *merkle_tree.root_history.last().unwrap();
(zkp_size, root, root_idx, hashchain)
(zkp_size, root, hashchain)
};

let leaf_indices_tx_hashes =
Expand Down Expand Up @@ -434,10 +428,7 @@ pub async fn create_nullify_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
};

Ok(InstructionDataBatchNullifyInputs {
public_inputs: BatchProofInputsIx {
new_root,
old_root_index: old_root_index as u16,
},
new_root,
compressed_proof: proof,
})
}
7 changes: 5 additions & 2 deletions forester/tests/batched_address_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,14 @@ async fn test_address_batched() {

let expected_sequence_number =
initial_sequence_number + (num_zkp_batches * UPDATES_PER_BATCH);
let expected_root_history_len = (expected_sequence_number + 1) as usize;
let expected_root_history_len = expected_sequence_number as usize;

assert_eq!(final_metadata.sequence_number, expected_sequence_number);

assert_eq!(merkle_tree.root_history.len(), expected_root_history_len);
assert_eq!(
merkle_tree.root_history.last_index(),
expected_root_history_len
);

assert_ne!(
pre_root,
Expand Down
6 changes: 4 additions & 2 deletions forester/tests/batched_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,13 @@ async fn test_state_batched() {

let expected_sequence_number =
initial_sequence_number + (num_zkp_batches * UPDATES_PER_BATCH);
let expected_root_history_len = (expected_sequence_number + 1) as usize;

assert_eq!(final_metadata.sequence_number, expected_sequence_number);

assert_eq!(merkle_tree.root_history.len(), expected_root_history_len);
assert_eq!(
merkle_tree.root_history.last_index(),
expected_sequence_number as usize
);

assert_ne!(
pre_root,
Expand Down
Loading

0 comments on commit 79321b3

Please sign in to comment.