diff --git a/circuit-lib/light-prover-client/src/batch_append_with_proofs.rs b/circuit-lib/light-prover-client/src/batch_append_with_proofs.rs index 8c10d81ca..bf9aac93e 100644 --- a/circuit-lib/light-prover-client/src/batch_append_with_proofs.rs +++ b/circuit-lib/light-prover-client/src/batch_append_with_proofs.rs @@ -42,7 +42,6 @@ pub fn get_batch_append_with_proofs_inputs( merkle_proofs: Vec>, batch_size: u32, ) -> BatchAppendWithProofsCircuitInputs { - println!("=== get_batch_append_with_proofs_inputs ==="); let mut new_root = [0u8; 32]; let mut changelog: Vec> = Vec::new(); let mut circuit_merkle_proofs = Vec::with_capacity(batch_size as usize); @@ -92,12 +91,6 @@ pub fn get_batch_append_with_proofs_inputs( // Calculate the public input hash chain with old root, new root, and leaves hash chain let public_input_hash = calculate_hash_chain(&[current_root, new_root, leaves_hashchain, start_index_bytes]); - println!("public_input_hash: {:?}", public_input_hash); - println!("current root {:?}", current_root); - println!("new root {:?}", new_root); - println!("leaves hashchain {:?}", leaves_hashchain); - println!("start index {:?}", start_index_bytes); - println!("leaves circuit {:?}", leaves); BatchAppendWithProofsCircuitInputs { public_input_hash: BigInt::from_bytes_be(Sign::Plus, &public_input_hash), old_root: BigInt::from_bytes_be(Sign::Plus, ¤t_root), diff --git a/client/src/rpc/rpc_connection.rs b/client/src/rpc/rpc_connection.rs index b00c70ee9..0b3d1eaff 100644 --- a/client/src/rpc/rpc_connection.rs +++ b/client/src/rpc/rpc_connection.rs @@ -11,7 +11,6 @@ use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, Signature}; use solana_sdk::transaction::Transaction; -use solana_transaction_status::EncodedConfirmedTransactionWithStatusMeta; use std::fmt::Debug; #[async_trait] diff --git a/client/src/rpc/solana_rpc.rs b/client/src/rpc/solana_rpc.rs index 11eeb3be3..ee8220759 100644 --- a/client/src/rpc/solana_rpc.rs +++ b/client/src/rpc/solana_rpc.rs @@ -19,7 +19,7 @@ use solana_sdk::signature::{Keypair, Signature}; use solana_sdk::transaction::Transaction; use solana_transaction_status::option_serializer::OptionSerializer; use solana_transaction_status::{ - EncodedConfirmedTransactionWithStatusMeta, UiInstruction, UiTransactionEncoding, + UiInstruction, UiTransactionEncoding, }; use std::fmt::{Debug, Display, Formatter}; use std::time::Duration; diff --git a/forester/src/batched_ops.rs b/forester/src/batched_ops.rs index 42db17b45..f605d4520 100644 --- a/forester/src/batched_ops.rs +++ b/forester/src/batched_ops.rs @@ -12,7 +12,6 @@ use light_client::rpc::RpcConnection; use light_client::rpc_pool::SolanaRpcPool; use light_hasher::{Hasher, Poseidon}; use light_prover_client::batch_append_with_proofs::get_batch_append_with_proofs_inputs; -use light_prover_client::batch_append_with_subtrees::calculate_hash_chain; use light_prover_client::batch_update::get_batch_update_inputs; use light_prover_client::gnark::batch_append_with_proofs_json_formatter::BatchAppendWithProofsInputsJson; use light_prover_client::gnark::batch_update_json_formatter::update_inputs_string; @@ -31,7 +30,7 @@ use solana_sdk::signature::Keypair; use solana_sdk::signer::Signer; use std::sync::Arc; use tokio::sync::Mutex; -use tracing::{error, info}; +use tracing::error; pub struct BatchedOperations> { pub rpc_pool: Arc>, @@ -72,39 +71,25 @@ impl> BatchedOperations { } pub async fn perform_batch_append(&self) -> Result { - info!("=== perform_batch_append begin ==="); let mut rpc = self.rpc_pool.get_connection().await?; let (num_inserted_zkps, batch_size) = { let mut output_queue_account = rpc.get_account(self.output_queue).await.unwrap().unwrap(); - let mut output_queue = ZeroCopyBatchedQueueAccount::from_bytes_mut( + let output_queue = ZeroCopyBatchedQueueAccount::from_bytes_mut( output_queue_account.data.as_mut_slice(), ) .unwrap(); let queue_account = output_queue.get_account(); let batch_index = queue_account.queue.next_full_batch_index; - - println!("queue: {:?}", queue_account.queue); - let num_inserted_zkps = output_queue.batches[batch_index as usize].get_num_inserted_zkps(); let zkp_batch_size = queue_account.queue.zkp_batch_size; - let batches = &mut output_queue.batches; - let full_batch = batches.get_mut(batch_index as usize).unwrap(); - println!("full batch: {:?}", full_batch); - (num_inserted_zkps, zkp_batch_size) }; - println!( - "num_inserted_zkps: {}, batch_size: {}", - num_inserted_zkps, batch_size - ); - let instruction_data = self.create_append_batch_ix_data().await; - let instruction = create_batch_append_instruction( self.authority.pubkey(), self.derivation, @@ -114,7 +99,7 @@ impl> BatchedOperations { instruction_data?.try_to_vec()?, ); - let result = rpc + rpc .create_and_send_transaction_with_event::( &[instruction], &self.authority.pubkey(), @@ -122,7 +107,6 @@ impl> BatchedOperations { None, ) .await?; - println!("batch append result: {:?}", result); self.indexer .lock() @@ -134,13 +118,10 @@ impl> BatchedOperations { num_inserted_zkps, ) .await; - - info!("=== perform_batch_append end ==="); Ok(batch_size as usize) } pub async fn perform_batch_nullify(&self) -> Result { - info!("=== perform_batch_nullify begin ==="); let mut rpc = self.rpc_pool.get_connection().await?; let instruction_data = self.get_batched_nullify_ix_data().await?; @@ -153,7 +134,7 @@ impl> BatchedOperations { instruction_data.try_to_vec()?, ); - let result = rpc + rpc .create_and_send_transaction_with_event::( &[instruction], &self.authority.pubkey(), @@ -162,8 +143,6 @@ impl> BatchedOperations { ) .await?; - println!("batch nullify result: {:?}", result); - let (batch_index, batch_size) = { let mut account = rpc.get_account(self.merkle_tree).await.unwrap().unwrap(); let merkle_tree = @@ -184,13 +163,10 @@ impl> BatchedOperations { batch_index as usize, ) .await; - - info!("=== perform_batch_nullify end ==="); Ok(batch_size as usize) } async fn create_append_batch_ix_data(&self) -> Result { - info!("=== create_append_batch_ix_data begin ==="); let mut rpc = self.rpc_pool.get_connection().await.unwrap(); let (merkle_tree_next_index, current_root) = { @@ -205,9 +181,6 @@ impl> BatchedOperations { ) }; - info!("Merkle tree next index: {}", merkle_tree_next_index); - info!("Current root: {:?}", current_root); - let (zkp_batch_size, _full_batch_index, num_inserted_zkps, leaves_hashchain) = { let mut output_queue_account = rpc.get_account(self.output_queue).await.unwrap().unwrap(); @@ -233,9 +206,6 @@ impl> BatchedOperations { leaves_hashchain, ) }; - info!("ZKP batch size: {}", zkp_batch_size); - info!("Number of inserted zkps: {}", num_inserted_zkps); - let start = num_inserted_zkps as usize * zkp_batch_size as usize; let end = start + zkp_batch_size as usize; @@ -247,14 +217,6 @@ impl> BatchedOperations { .await .unwrap(); - let local_leaves_hashchain = calculate_hash_chain(&leaves); - info!("start index: {}", start); - info!("end index: {}", end); - info!("num inserted zkps: {}", num_inserted_zkps); - info!("zkp batch size: {}", zkp_batch_size); - assert_eq!(local_leaves_hashchain, leaves_hashchain); - // info!("In hash chain Batch update leaves: {:?}", leaves); - let (old_leaves, merkle_proofs) = { let mut old_leaves = vec![]; let mut merkle_proofs = vec![]; @@ -273,18 +235,6 @@ impl> BatchedOperations { (old_leaves, merkle_proofs) }; - let leaf_strings = leaves - .iter() - .map(|l| Pubkey::from(*l).to_string()) - .collect::>(); - println!("leaves: {:?}", leaf_strings); - - let old_leaf_strings = old_leaves - .iter() - .map(|l| Pubkey::from(*l).to_string()) - .collect::>(); - println!("old_leaves: {:?}", old_leaf_strings); - let (proof, new_root) = { let circuit_inputs = get_batch_append_with_proofs_inputs::<26>( current_root, @@ -333,8 +283,6 @@ impl> BatchedOperations { } }; - info!("=== create_append_batch_ix_data end ==="); - Ok(InstructionDataBatchAppendInputs { public_inputs: AppendBatchProofInputsIx { new_root }, compressed_proof: proof, @@ -342,7 +290,6 @@ impl> BatchedOperations { } async fn get_batched_nullify_ix_data(&self) -> Result { - info!("=== get_batched_nullify_ix_data begin ==="); let mut rpc = self.rpc_pool.get_connection().await.unwrap(); let (zkp_batch_size, old_root, old_root_index, leaves_hashchain) = { @@ -355,24 +302,9 @@ impl> BatchedOperations { let zkp_size = account.queue.zkp_batch_size; let batch = &merkle_tree.batches[batch_idx]; let zkp_idx = batch.get_num_inserted_zkps(); - - let hashchains = merkle_tree - .hashchain_store - .clone() - .iter() - .map(|x| { - let x = x.clone(); - x.as_slice().to_vec() - }) - .collect::>(); - for (i, x) in hashchains.iter().enumerate() { - println!("hashchain {}: {:?}", i, x); - } - 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) }; @@ -408,19 +340,6 @@ impl> BatchedOperations { nullifiers.push(nullifier); } - let leaf_strings = leaves - .iter() - .map(|l| Pubkey::from(*l).to_string()) - .collect::>(); - - let old_leaf_strings = old_leaves - .iter() - .map(|l| Pubkey::from(*l).to_string()) - .collect::>(); - - let local_nullifier_hashchain = calculate_hash_chain(&nullifiers); - assert_eq!(leaves_hashchain, local_nullifier_hashchain); - let inputs = get_batch_update_inputs::<26>( old_root, tx_hashes, @@ -463,8 +382,6 @@ impl> BatchedOperations { )); }; - info!("=== get_batched_nullify_ix_data end ==="); - Ok(InstructionDataBatchNullifyInputs { public_inputs: BatchProofInputsIx { new_root, diff --git a/programs/registry/src/utils.rs b/programs/registry/src/utils.rs index c185cabeb..fd49b2fc5 100644 --- a/programs/registry/src/utils.rs +++ b/programs/registry/src/utils.rs @@ -11,19 +11,11 @@ pub fn get_cpi_authority_pda() -> (Pubkey, u8) { } pub fn get_forester_epoch_pda_from_authority(authority: &Pubkey, epoch: u64) -> (Pubkey, u8) { - println!( - "get_forester_epoch_pda_from_authority: authority: {}, epoch: {}", - authority, epoch - ); let forester_pda = get_forester_pda(authority); get_forester_epoch_pda(&forester_pda.0, epoch) } pub fn get_forester_epoch_pda_from_derivation(derivation: &Pubkey, epoch: u64) -> (Pubkey, u8) { - println!( - "get_forester_epoch_pda_from_derivation: derivation: {}, epoch: {}", - derivation, epoch - ); let forester_pda = get_forester_pda(derivation); get_forester_epoch_pda(&forester_pda.0, epoch) } diff --git a/test-utils/src/indexer/test_indexer.rs b/test-utils/src/indexer/test_indexer.rs index 4c9ad8a4e..7c32cf8a0 100644 --- a/test-utils/src/indexer/test_indexer.rs +++ b/test-utils/src/indexer/test_indexer.rs @@ -327,106 +327,6 @@ impl Indexer for TestIndexer { &self.group_pda } - async fn create_proof_for_compressed_accounts2( - &mut self, - compressed_accounts: Option>, - state_merkle_tree_pubkeys: Option>, - new_addresses: Option<&[[u8; 32]]>, - address_merkle_tree_pubkeys: Option>, - rpc: &mut R, - ) -> BatchedTreeProofRpcResult { - let mut indices_to_remove = Vec::new(); - - // for all accounts in batched trees, check whether values are in tree or queue - let (compressed_accounts, state_merkle_tree_pubkeys) = - if let Some((compressed_accounts, state_merkle_tree_pubkeys)) = - compressed_accounts.zip(state_merkle_tree_pubkeys) - { - for (i, (compressed_account, state_merkle_tree_pubkey)) in compressed_accounts - .iter() - .zip(state_merkle_tree_pubkeys.iter()) - .enumerate() - { - let accounts = self.state_merkle_trees.iter().find(|x| { - x.accounts.merkle_tree == *state_merkle_tree_pubkey && x.version == 2 - }); - if let Some(accounts) = accounts { - let output_queue_pubkey = accounts.accounts.nullifier_queue; - let mut queue = - AccountZeroCopy::::new(rpc, output_queue_pubkey) - .await; - let queue_zero_copy = ZeroCopyBatchedQueueAccount::from_bytes_mut( - queue.account.data.as_mut_slice(), - ) - .unwrap(); - for (j, value_array) in queue_zero_copy.value_vecs.iter().enumerate() { - let index = value_array.iter().position(|x| *x == *compressed_account); - if let Some(index) = index { - indices_to_remove.push(i); - } - } - } - } - let compress_accounts = compressed_accounts - .iter() - .enumerate() - .filter(|(i, _)| !indices_to_remove.contains(i)) - .map(|(_, x)| *x) - .collect::>(); - let state_merkle_tree_pubkeys = state_merkle_tree_pubkeys - .iter() - .enumerate() - .filter(|(i, _)| !indices_to_remove.contains(i)) - .map(|(_, x)| *x) - .collect::>(); - if compress_accounts.is_empty() { - (None, None) - } else { - (Some(compress_accounts), Some(state_merkle_tree_pubkeys)) - } - } else { - (None, None) - }; - let rpc_result = if (compressed_accounts.is_some() - && !compressed_accounts.as_ref().unwrap().is_empty()) - || address_merkle_tree_pubkeys.is_some() - { - Some( - self.create_proof_for_compressed_accounts( - compressed_accounts, - state_merkle_tree_pubkeys, - new_addresses, - address_merkle_tree_pubkeys, - rpc, - ) - .await, - ) - } else { - None - }; - let address_root_indices = if let Some(rpc_result) = rpc_result.as_ref() { - rpc_result.address_root_indices.clone() - } else { - Vec::new() - }; - let root_indices = { - let mut root_indices = if let Some(rpc_result) = rpc_result.as_ref() { - rpc_result.root_indices.clone() - } else { - Vec::new() - }; - for index in indices_to_remove { - root_indices.insert(index, None); - } - root_indices - }; - BatchedTreeProofRpcResult { - proof: rpc_result.map(|x| x.proof), - root_indices, - address_root_indices, - } - } - async fn create_proof_for_compressed_accounts( &mut self, mut compressed_accounts: Option>, @@ -507,7 +407,6 @@ impl Indexer for TestIndexer { .send() .await .expect("Failed to execute request."); - println!("response_result {:?}", response_result); if response_result.status().is_success() { let body = response_result.text().await.unwrap(); let proof_json = deserialize_gnark_proof_json(&body).unwrap(); @@ -535,6 +434,106 @@ impl Indexer for TestIndexer { panic!("Failed to get proof from server"); } + async fn create_proof_for_compressed_accounts2( + &mut self, + compressed_accounts: Option>, + state_merkle_tree_pubkeys: Option>, + new_addresses: Option<&[[u8; 32]]>, + address_merkle_tree_pubkeys: Option>, + rpc: &mut R, + ) -> BatchedTreeProofRpcResult { + let mut indices_to_remove = Vec::new(); + + // for all accounts in batched trees, check whether values are in tree or queue + let (compressed_accounts, state_merkle_tree_pubkeys) = + if let Some((compressed_accounts, state_merkle_tree_pubkeys)) = + compressed_accounts.zip(state_merkle_tree_pubkeys) + { + for (i, (compressed_account, state_merkle_tree_pubkey)) in compressed_accounts + .iter() + .zip(state_merkle_tree_pubkeys.iter()) + .enumerate() + { + let accounts = self.state_merkle_trees.iter().find(|x| { + x.accounts.merkle_tree == *state_merkle_tree_pubkey && x.version == 2 + }); + if let Some(accounts) = accounts { + let output_queue_pubkey = accounts.accounts.nullifier_queue; + let mut queue = + AccountZeroCopy::::new(rpc, output_queue_pubkey) + .await; + let queue_zero_copy = ZeroCopyBatchedQueueAccount::from_bytes_mut( + queue.account.data.as_mut_slice(), + ) + .unwrap(); + for value_array in queue_zero_copy.value_vecs.iter() { + let index = value_array.iter().position(|x| *x == *compressed_account); + if index.is_some() { + indices_to_remove.push(i); + } + } + } + } + let compress_accounts = compressed_accounts + .iter() + .enumerate() + .filter(|(i, _)| !indices_to_remove.contains(i)) + .map(|(_, x)| *x) + .collect::>(); + let state_merkle_tree_pubkeys = state_merkle_tree_pubkeys + .iter() + .enumerate() + .filter(|(i, _)| !indices_to_remove.contains(i)) + .map(|(_, x)| *x) + .collect::>(); + if compress_accounts.is_empty() { + (None, None) + } else { + (Some(compress_accounts), Some(state_merkle_tree_pubkeys)) + } + } else { + (None, None) + }; + let rpc_result = if (compressed_accounts.is_some() + && !compressed_accounts.as_ref().unwrap().is_empty()) + || address_merkle_tree_pubkeys.is_some() + { + Some( + self.create_proof_for_compressed_accounts( + compressed_accounts, + state_merkle_tree_pubkeys, + new_addresses, + address_merkle_tree_pubkeys, + rpc, + ) + .await, + ) + } else { + None + }; + let address_root_indices = if let Some(rpc_result) = rpc_result.as_ref() { + rpc_result.address_root_indices.clone() + } else { + Vec::new() + }; + let root_indices = { + let mut root_indices = if let Some(rpc_result) = rpc_result.as_ref() { + rpc_result.root_indices.clone() + } else { + Vec::new() + }; + for index in indices_to_remove { + root_indices.insert(index, None); + } + root_indices + }; + BatchedTreeProofRpcResult { + proof: rpc_result.map(|x| x.proof), + root_indices, + address_root_indices, + } + } + fn add_address_merkle_tree_accounts( &mut self, merkle_tree_keypair: &Keypair, @@ -582,17 +581,6 @@ impl Indexer for TestIndexer { self.get_state_merkle_trees_mut().push(state_bundle); } - fn get_proofs_by_indices( - &mut self, - merkle_tree_pubkey: Pubkey, - indices: &[u64], - ) -> Vec { - indices - .iter() - .map(|&index| self.get_proof_by_index(merkle_tree_pubkey, index)) - .collect() - } - fn get_proof_by_index(&mut self, merkle_tree_pubkey: Pubkey, index: u64) -> ProofOfLeaf { let mut bundle = self .state_merkle_trees @@ -621,6 +609,17 @@ impl Indexer for TestIndexer { ProofOfLeaf { leaf, proof } } + fn get_proofs_by_indices( + &mut self, + merkle_tree_pubkey: Pubkey, + indices: &[u64], + ) -> Vec { + indices + .iter() + .map(|&index| self.get_proof_by_index(merkle_tree_pubkey, index)) + .collect() + } + /// leaf index, leaf, tx hash fn get_leaf_indices_tx_hashes( &mut self, @@ -633,11 +632,7 @@ impl Indexer for TestIndexer { .find(|x| x.accounts.merkle_tree == merkle_tree_pubkey) .unwrap(); - let leaf_indices_tx_hashes = - state_merkle_tree_bundle.input_leaf_indices[..zkp_batch_size].to_vec(); - println!("leaf_indices_tx_hashes: {:?}", leaf_indices_tx_hashes); - - leaf_indices_tx_hashes + state_merkle_tree_bundle.input_leaf_indices[..zkp_batch_size].to_vec() } async fn update_test_indexer_after_append( @@ -647,7 +642,6 @@ impl Indexer for TestIndexer { output_queue_pubkey: Pubkey, num_inserted_zkps: u64, ) { - println!("=== update_test_indexer_after_append begin ==="); let mut state_merkle_tree_bundle = self .state_merkle_trees .iter_mut() @@ -683,14 +677,11 @@ impl Indexer for TestIndexer { let leaves = state_merkle_tree_bundle.output_queue_elements.to_vec(); - println!("zkp_batch_size: {}", zkp_batch_size); - println!("num_inserted_zkps: {}", num_inserted_zkps); - let start = (num_inserted_zkps as usize) * zkp_batch_size as usize; let end = start + zkp_batch_size as usize; let batch_update_leaves = leaves[start..end].to_vec(); - for (i, leaf) in batch_update_leaves.iter().enumerate() { + for (i, _) in batch_update_leaves.iter().enumerate() { // if leaves[i] == [0u8; 32] { let index = merkle_tree_next_index + i - zkp_batch_size as usize; // This is dangerous it should call self.get_leaf_by_index() but it @@ -700,19 +691,11 @@ impl Indexer for TestIndexer { .merkle_tree .get_leaf(index) .unwrap(); - println!("index: {:?}", index); - println!("old leaf: {:?}", leaf); if leaf == [0u8; 32] { state_merkle_tree_bundle .merkle_tree .update(&batch_update_leaves[i], index) .unwrap(); - - let updated_leaf = state_merkle_tree_bundle - .merkle_tree - .get_leaf(index) - .unwrap(); - println!("updated leaf: {:?}", updated_leaf); } } assert_eq!( @@ -720,19 +703,12 @@ impl Indexer for TestIndexer { state_merkle_tree_bundle.merkle_tree.root(), "update indexer after append root invalid" ); - println!( - "max_num_zkp_updates: {}, num_inserted_zkps: {}", - max_num_zkp_updates, num_inserted_zkps - ); // check can we get rid of this and use the data from the merkle tree if num_inserted_zkps == max_num_zkp_updates { - println!("removing elements from output queue"); for _ in 0..zkp_batch_size { state_merkle_tree_bundle.output_queue_elements.remove(0); } } - - println!("=== update_test_indexer_after_append end ==="); } async fn update_test_indexer_after_nullification( @@ -754,7 +730,6 @@ impl Indexer for TestIndexer { .unwrap(); let batch = &merkle_tree.batches[batch_index]; - println!("batch: {:?}", batch); if batch.get_state() == BatchState::Inserted || batch.get_state() == BatchState::ReadyToUpdateTree { @@ -1202,8 +1177,6 @@ impl TestIndexer { &event.output_compressed_account_hashes, slot, ); - println!("tx_hash {:?}", tx_hash); - println!("slot {:?}", slot); let hash = event.input_compressed_account_hashes[i]; let index = self.compressed_accounts.iter().position(|x| { x.compressed_account @@ -1285,7 +1258,6 @@ impl TestIndexer { }) .unwrap() }; - println!("found merkle tree {:?}", merkle_tree.accounts.merkle_tree); let nullifier_queue_pubkey = merkle_tree.accounts.nullifier_queue; let merkle_tree_pubkey = merkle_tree.accounts.merkle_tree; // if data is some, try to deserialize token data, if it fails, add to compressed_accounts @@ -1356,8 +1328,6 @@ impl TestIndexer { .unwrap() }; let is_batched = seq.seq == u64::MAX; - - println!("Output is batched {:?}", is_batched); if !is_batched { let merkle_tree = &mut self .state_merkle_trees