(
program_id: &Pubkey,
accounts: &[AccountInfo],
current_instruction_index: usize,
)
| 24 | // Processor for deposit and withdraw logic. |
| 25 | #[allow(clippy::comparison_chain)] |
| 26 | pub fn process_instruction( |
| 27 | program_id: &Pubkey, |
| 28 | accounts: &[AccountInfo], |
| 29 | current_instruction_index: usize, |
| 30 | ) -> Result<(), ProgramError> { |
| 31 | let account = &mut accounts.iter(); |
| 32 | let signer_account = next_account_info(account)?; |
| 33 | let tmp_storage_pda = next_account_info(account)?; |
| 34 | let mut tmp_storage_pda_data = ChecksAndTransferState::unpack(&tmp_storage_pda.data.borrow())?; |
| 35 | |
| 36 | // Checks whether passed-in root exists in Merkle tree history array. |
| 37 | // We do this check as soon as possible to avoid proof transaction invalidation for missing |
| 38 | // root. Currently 500 roots are stored at once. After 500 transactions roots are overwritten. |
| 39 | if current_instruction_index == 1 { |
| 40 | let merkle_tree_pda = next_account_info(account)?; |
| 41 | tmp_storage_pda_data.found_root = check_root_hash_exists( |
| 42 | merkle_tree_pda, |
| 43 | &tmp_storage_pda_data.root_hash, |
| 44 | program_id, |
| 45 | tmp_storage_pda_data.merkle_tree_index, |
| 46 | )?; |
| 47 | tmp_storage_pda_data.changed_constants[1] = true; |
| 48 | tmp_storage_pda_data.current_instruction_index += 1; |
| 49 | ChecksAndTransferState::pack_into_slice( |
| 50 | &tmp_storage_pda_data, |
| 51 | &mut tmp_storage_pda.data.borrow_mut(), |
| 52 | ); |
| 53 | } |
| 54 | // Checks and inserts nullifier pdas, two Merkle tree leaves (output utxo hashes), |
| 55 | // executes transaction, deposit or withdrawal, and closes the tmp account. |
| 56 | else if current_instruction_index == 1501 { |
| 57 | let two_leaves_pda = next_account_info(account)?; |
| 58 | let nullifier0_pda = next_account_info(account)?; |
| 59 | let nullifier1_pda = next_account_info(account)?; |
| 60 | let merkle_tree_pda = next_account_info(account)?; |
| 61 | let merkle_tree_pda_token = next_account_info(account)?; |
| 62 | let system_program_account = next_account_info(account)?; |
| 63 | let token_program_account = next_account_info(account)?; |
| 64 | let rent_sysvar_info = next_account_info(account)?; |
| 65 | let rent = &Rent::from_account_info(rent_sysvar_info)?; |
| 66 | |
| 67 | let authority = next_account_info(account)?; |
| 68 | let authority_seed = program_id.to_bytes(); |
| 69 | let (expected_authority_pubkey, authority_bump_seed) = |
| 70 | Pubkey::find_program_address(&[&authority_seed], program_id); |
| 71 | |
| 72 | if expected_authority_pubkey != *authority.key { |
| 73 | msg!("Invalid passed-in authority."); |
| 74 | return Err(ProgramError::InvalidArgument); |
| 75 | } |
| 76 | |
| 77 | if tmp_storage_pda_data.found_root != 1u8 { |
| 78 | msg!("Root was not found. {}", tmp_storage_pda_data.found_root); |
| 79 | return Err(ProgramError::InvalidArgument); |
| 80 | } |
| 81 | |
| 82 | if *merkle_tree_pda.key |
| 83 | != solana_program::pubkey::Pubkey::new( |
nothing calls this directly
no test coverage detected