From ad0d643b8779dc3ea0032dd9b4eeb434cdcbfeff Mon Sep 17 00:00:00 2001 From: ananas Date: Sat, 28 Feb 2026 23:29:15 +0000 Subject: [PATCH 1/5] fix: batched address tree init assert tree and queue index are the same --- .../system/src/processor/create_address_cpi_data.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/programs/system/src/processor/create_address_cpi_data.rs b/programs/system/src/processor/create_address_cpi_data.rs index 7decd5da0a..88a1ae9e33 100644 --- a/programs/system/src/processor/create_address_cpi_data.rs +++ b/programs/system/src/processor/create_address_cpi_data.rs @@ -83,6 +83,16 @@ pub fn derive_new_addresses<'info, 'a, 'b: 'a, const ADDRESS_ASSIGNMENT: bool>( tree.queue_batches.next_index, ); + // For batched address trees the queue is embedded in the tree + // account so both indices must point to the same account. + if new_address_params.address_queue_index() + != new_address_params.address_merkle_tree_account_index() + { + return Err(ProgramError::from( + SystemProgramError::AddressMerkleTreeAccountDiscriminatorMismatch, + )); + } + ( derive_address( &new_address_params.seed(), From 0a67ddd214b0e0dbd4f1c82655354119133d19fc Mon Sep 17 00:00:00 2001 From: ananas Date: Sun, 1 Mar 2026 00:03:00 +0000 Subject: [PATCH 2/5] fix: add cpi ix data address queue index assignment --- programs/system/src/processor/create_address_cpi_data.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/programs/system/src/processor/create_address_cpi_data.rs b/programs/system/src/processor/create_address_cpi_data.rs index 88a1ae9e33..aa0a6d2885 100644 --- a/programs/system/src/processor/create_address_cpi_data.rs +++ b/programs/system/src/processor/create_address_cpi_data.rs @@ -66,11 +66,13 @@ pub fn derive_new_addresses<'info, 'a, 'b: 'a, const ADDRESS_ASSIGNMENT: bool>( Err(SystemProgramError::DeriveAddressError) }?; - cpi_ix_data.addresses[i].tree_index = context.get_index_or_insert( + let tree_index = context.get_index_or_insert( new_address_params.address_merkle_tree_account_index(), remaining_accounts, "V2 address tree", )?; + cpi_ix_data.addresses[i].tree_index = tree_index; + cpi_ix_data.addresses[i].queue_index = tree_index; context.set_address_fee( tree.metadata.rollover_metadata.network_fee, From d8620fee2eb7fa501606c8d25aeb5e7c613ba326 Mon Sep 17 00:00:00 2001 From: ananas Date: Sun, 1 Mar 2026 00:27:34 +0000 Subject: [PATCH 3/5] fix --- .../compressed-account/src/instruction_data/zero_copy_set.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program-libs/compressed-account/src/instruction_data/zero_copy_set.rs b/program-libs/compressed-account/src/instruction_data/zero_copy_set.rs index b5d382a271..8f7ebc6ddc 100644 --- a/program-libs/compressed-account/src/instruction_data/zero_copy_set.rs +++ b/program-libs/compressed-account/src/instruction_data/zero_copy_set.rs @@ -169,7 +169,7 @@ impl ZNewAddressParamsAssignedPackedMut<'_> { ) { self.seed = seed; self.address_merkle_tree_root_index = address_merkle_tree_root_index; - self.address_queue_account_index = 0; // always 0 for v2 address trees. + self.address_queue_account_index = address_merkle_tree_account_index; if let Some(assigned_account_index) = assigned_account_index { self.assigned_account_index = assigned_account_index; self.assigned_to_account = 1; // set to true From e11fb25abcabd6ddc975cf01d85a98bd3b93aa80 Mon Sep 17 00:00:00 2001 From: ananas Date: Sun, 1 Mar 2026 00:51:44 +0000 Subject: [PATCH 4/5] fix tests --- .../compressed-account/tests/zero_copy_set.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/program-libs/compressed-account/tests/zero_copy_set.rs b/program-libs/compressed-account/tests/zero_copy_set.rs index 80c944072c..b852a7ede1 100644 --- a/program-libs/compressed-account/tests/zero_copy_set.rs +++ b/program-libs/compressed-account/tests/zero_copy_set.rs @@ -539,7 +539,7 @@ fn test_new_address_set_success_with_assigned_account() { assert_eq!(z_new_address.assigned_account_index, 7); assert_eq!(z_new_address.address_merkle_tree_account_index, 10); assert_eq!(z_new_address.assigned_to_account, 1); - assert_eq!(z_new_address.address_queue_account_index, 0); // Invariant: always 0 + assert_eq!(z_new_address.address_queue_account_index, 10); } #[test] @@ -567,7 +567,7 @@ fn test_new_address_set_success_without_assigned_account() { assert_eq!(z_new_address.assigned_account_index, 0); assert_eq!(z_new_address.address_merkle_tree_account_index, 10); assert_eq!(z_new_address.assigned_to_account, 0); - assert_eq!(z_new_address.address_queue_account_index, 0); // Invariant: always 0 + assert_eq!(z_new_address.address_queue_account_index, 10); } #[test] @@ -580,16 +580,16 @@ fn test_new_address_set_invariant_address_queue_account_index() { NewAddressParamsAssignedPacked::zero_copy_at_mut(&mut data).unwrap(); // Execute multiple times with different inputs + // Invariant: address_queue_account_index == address_merkle_tree_account_index + // for v2 batched address trees (queue is embedded in the tree account). z_new_address.set([1u8; 32], U16::new(100), Some(5), 10); - assert_eq!(z_new_address.address_queue_account_index, 0); + assert_eq!(z_new_address.address_queue_account_index, 10); z_new_address.set([2u8; 32], U16::new(200), None, 20); - assert_eq!(z_new_address.address_queue_account_index, 0); + assert_eq!(z_new_address.address_queue_account_index, 20); z_new_address.set([3u8; 32], U16::new(300), Some(50), 30); - assert_eq!(z_new_address.address_queue_account_index, 0); - - // Assert invariant: address_queue_account_index always 0 for v2 address trees + assert_eq!(z_new_address.address_queue_account_index, 30); } // ============================================================================= From a0783bd73638e5b4839970ec2ee258f5707c2819 Mon Sep 17 00:00:00 2001 From: ananas Date: Sun, 1 Mar 2026 01:02:51 +0000 Subject: [PATCH 5/5] fix lint --- .../csdk-anchor-full-derived-test/tests/integration_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-tests/csdk-anchor-full-derived-test/tests/integration_tests.rs b/sdk-tests/csdk-anchor-full-derived-test/tests/integration_tests.rs index 9b40b900e5..2c3e82972a 100644 --- a/sdk-tests/csdk-anchor-full-derived-test/tests/integration_tests.rs +++ b/sdk-tests/csdk-anchor-full-derived-test/tests/integration_tests.rs @@ -3863,7 +3863,7 @@ async fn test_d9_edge_many_literals() { #[tokio::test] async fn test_d9_edge_mixed() { use csdk_anchor_full_derived_test::d9_seeds::{ - edge_cases::{AB, SEED_123, _UNDERSCORE_CONST}, + edge_cases::{_UNDERSCORE_CONST, AB, SEED_123}, D9EdgeMixedParams, };