diff --git a/programs/system/src/invoke/instruction.rs b/programs/system/src/invoke/instruction.rs index 826c92c4c..eed73b192 100644 --- a/programs/system/src/invoke/instruction.rs +++ b/programs/system/src/invoke/instruction.rs @@ -129,7 +129,7 @@ pub struct NewAddressParams { } #[derive(Debug, PartialEq, Default, Clone, Copy, AnchorSerialize, AnchorDeserialize)] -pub struct ReadOnlyAddressParamsPacked { +pub struct PackedReadOnlyAddress { pub address: [u8; 32], pub address_merkle_tree_account_index: u8, pub address_merkle_tree_root_index: u16, diff --git a/programs/system/src/invoke/processor.rs b/programs/system/src/invoke/processor.rs index ed7c5cb1d..54ccbc19c 100644 --- a/programs/system/src/invoke/processor.rs +++ b/programs/system/src/invoke/processor.rs @@ -22,7 +22,7 @@ use crate::{ InstructionDataInvoke, }; -use super::ReadOnlyAddressParamsPacked; +use super::PackedReadOnlyAddress; // TODO: remove once upgraded to anchor 0.30.0 (right now it's required for idl generation) #[derive(Debug, Clone, PartialEq, Eq, AnchorSerialize, AnchorDeserialize)] @@ -60,7 +60,7 @@ pub fn process< invoking_program: Option, ctx: Context<'a, 'b, 'c, 'info, A>, cpi_context_inputs: usize, - read_only_addresses: Option>, + read_only_addresses: Option>, ) -> Result<()> { if inputs.relay_fee.is_some() { unimplemented!("Relay fee is not implemented yet."); diff --git a/programs/system/src/invoke/verify_signer.rs b/programs/system/src/invoke/verify_signer.rs index ab9b405e7..28c6eef41 100644 --- a/programs/system/src/invoke/verify_signer.rs +++ b/programs/system/src/invoke/verify_signer.rs @@ -20,7 +20,7 @@ pub fn input_compressed_accounts_signer_check( && compressed_account_with_context .compressed_account .data - .is_none() && !compressed_account_with_context.read_only + .is_none() { Ok(()) } else { diff --git a/programs/system/src/invoke/verify_state_proof.rs b/programs/system/src/invoke/verify_state_proof.rs index e86da8dbb..aade5baae 100644 --- a/programs/system/src/invoke/verify_state_proof.rs +++ b/programs/system/src/invoke/verify_state_proof.rs @@ -21,7 +21,7 @@ use light_verifier::{ }; use std::mem; -use super::ReadOnlyAddressParamsPacked; +use super::PackedReadOnlyAddress; // TODO: add support for batched Merkle trees #[inline(never)] @@ -98,7 +98,7 @@ pub fn fetch_roots_address_merkle_tree< A: InvokeAccounts<'info> + Bumps, >( new_address_params: &'a [NewAddressParamsPacked], - read_only_addresses: &'a [ReadOnlyAddressParamsPacked], + read_only_addresses: &'a [PackedReadOnlyAddress], ctx: &'a Context<'a, 'b, 'c, 'info, A>, roots: &'a mut Vec<[u8; 32]>, ) -> Result<()> { @@ -125,7 +125,7 @@ pub fn fetch_roots_address_merkle_tree< #[inline(always)] pub fn verify_read_only_address_queue_non_inclusion<'a>( remaining_accounts: &'a [AccountInfo<'_>], - read_only_addresses: &'a [ReadOnlyAddressParamsPacked], + read_only_addresses: &'a [PackedReadOnlyAddress], ) -> Result<()> { for read_only_address in read_only_addresses.iter() { let merkle_tree_account_info = diff --git a/programs/system/src/invoke_cpi/instruction.rs b/programs/system/src/invoke_cpi/instruction.rs index 8b84a307f..951ad4f80 100644 --- a/programs/system/src/invoke_cpi/instruction.rs +++ b/programs/system/src/invoke_cpi/instruction.rs @@ -9,10 +9,13 @@ use crate::{ invoke::{processor::CompressedProof, sol_compression::SOL_POOL_PDA_SEED}, sdk::{ accounts::{InvokeAccounts, SignerAccounts}, - compressed_account::PackedCompressedAccountWithMerkleContext, + compressed_account::{ + MerkleContext, PackedCompressedAccountWithMerkleContext, + PackedReadOnlyCompressedAccount, + }, CompressedCpiContext, }, - NewAddressParamsPacked, OutputCompressedAccountWithPackedContext, ReadOnlyAddressParamsPacked, + NewAddressParamsPacked, OutputCompressedAccountWithPackedContext, PackedReadOnlyAddress, }; #[derive(Accounts)] @@ -116,7 +119,8 @@ impl InstructionDataInvokeCpi { #[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize)] pub struct InstructionDataInvokeCpiWithReadOnlyAddress { pub invoke_cpi: InstructionDataInvokeCpi, - pub read_only_addresses: Option>, + pub read_only_addresses: Option>, + pub read_only_accounts: Option>, } #[cfg(test)] diff --git a/programs/system/src/invoke_cpi/processor.rs b/programs/system/src/invoke_cpi/processor.rs index 9c633db85..f30f0b577 100644 --- a/programs/system/src/invoke_cpi/processor.rs +++ b/programs/system/src/invoke_cpi/processor.rs @@ -5,7 +5,7 @@ use super::verify_signer::cpi_signer_checks; use crate::{ invoke::processor::process, invoke_cpi::instruction::InvokeCpiInstruction, sdk::accounts::SignerAccounts, InstructionDataInvoke, InstructionDataInvokeCpi, - ReadOnlyAddressParamsPacked, + PackedReadOnlyAddress, }; /// Processes an `InvokeCpi` instruction. @@ -16,7 +16,7 @@ use crate::{ pub fn process_invoke_cpi<'a, 'b, 'c: 'info + 'b, 'info>( mut ctx: Context<'a, 'b, 'c, 'info, InvokeCpiInstruction<'info>>, inputs: InstructionDataInvokeCpi, - read_only_addresses: Option>, + read_only_addresses: Option>, ) -> Result<()> { bench_sbf_start!("cpda_cpi_signer_checks"); cpi_signer_checks( diff --git a/programs/system/src/sdk/address.rs b/programs/system/src/sdk/address.rs index d7f8e9114..c3a8bbba6 100644 --- a/programs/system/src/sdk/address.rs +++ b/programs/system/src/sdk/address.rs @@ -4,8 +4,8 @@ use anchor_lang::{err, solana_program::pubkey::Pubkey, Result}; use light_utils::{hash_to_bn254_field_size_be, hashv_to_bn254_field_size_be}; use crate::{ - errors::SystemProgramError, NewAddressParams, NewAddressParamsPacked, ReadOnlyAddressParams, - ReadOnlyAddressParamsPacked, + errors::SystemProgramError, NewAddressParams, NewAddressParamsPacked, PackedReadOnlyAddress, + ReadOnlyAddressParams, }; pub fn derive_address_legacy(merkle_tree_pubkey: &Pubkey, seed: &[u8; 32]) -> Result<[u8; 32]> { let hash = match hash_to_bn254_field_size_be( @@ -98,15 +98,15 @@ pub fn pack_new_address_params( pub fn pack_read_only_address_params( new_address_params: &[ReadOnlyAddressParams], remaining_accounts: &mut HashMap, -) -> Vec { +) -> Vec { let mut new_address_params_packed = new_address_params .iter() - .map(|x| ReadOnlyAddressParamsPacked { + .map(|x| PackedReadOnlyAddress { address: x.address, address_merkle_tree_root_index: x.address_merkle_tree_root_index, address_merkle_tree_account_index: 0, // will be assigned later }) - .collect::>(); + .collect::>(); let mut next_index: usize = remaining_accounts.len(); for (i, params) in new_address_params.iter().enumerate() { match remaining_accounts.get(¶ms.address_merkle_tree_pubkey) { diff --git a/programs/system/src/sdk/compressed_account.rs b/programs/system/src/sdk/compressed_account.rs index d152e1c07..c543f0ba4 100644 --- a/programs/system/src/sdk/compressed_account.rs +++ b/programs/system/src/sdk/compressed_account.rs @@ -28,6 +28,18 @@ impl CompressedAccountWithMerkleContext { } } +#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize)] +pub struct ReadOnlyCompressedAccount { + pub account_hash: [u8; 32], + pub account: MerkleContext, +} + +#[derive(Debug, PartialEq, Default, Clone, AnchorSerialize, AnchorDeserialize)] +pub struct PackedReadOnlyCompressedAccount { + pub account_hash: [u8; 32], + pub account: PackedCompressedAccountWithMerkleContext, +} + #[derive(Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Default)] pub struct MerkleContext { pub merkle_tree_pubkey: Pubkey, diff --git a/test-programs/system-cpi-test/src/create_pda.rs b/test-programs/system-cpi-test/src/create_pda.rs index 4cbc32be5..316b06047 100644 --- a/test-programs/system-cpi-test/src/create_pda.rs +++ b/test-programs/system-cpi-test/src/create_pda.rs @@ -284,6 +284,7 @@ fn cpi_compressed_pda_transfer_as_program<'info>( let inputs_struct = InstructionDataInvokeCpiWithReadOnlyAddress { invoke_cpi: inputs_struct, read_only_addresses: read_only_address, + read_only_accounts: None, }; let mut inputs = Vec::new(); InstructionDataInvokeCpiWithReadOnlyAddress::serialize(&inputs_struct, &mut inputs)