Skip to content

Commit e208fa1

Browse files
perf: indexed array remove next index (#1629)
* created separate indexed array crate, updated MockBatchedAddressForester, created indexed tree in test mt * refactor: remove next_index from non-inclusion circuit * chore: debugged tests: batched merkle tree, light-prover-client, added new reference indexed array and Merkle tree * stash, empty_address_queue_test v1 wip * more fixes, e2e tests work * fix: e2e, registry tests * fix: concurrent tree tests * chore: clean up light-indexed-array * cleanup and regenerate batched address tree account * chore: updated proving keys download url * Update GitHub Actions to use 8vCPU runner for prover tests * remove warnings * Update prover/server/prover/proving_keys_utils.go * chore: add comma for ,input Co-authored-by: Sergey Timoshin <sergeytimoshin@proton.me> * chore: remove leftover * remove unwrap * remove legacy tests --------- Co-authored-by: Sergey Timoshin <sergeytimoshin@proton.me>
1 parent 8917d70 commit e208fa1

File tree

102 files changed

+4746
-2447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+4746
-2447
lines changed

.github/workflows/prover-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
jobs:
2525
build-and-test:
2626
if: github.event.pull_request.draft == false
27-
runs-on: buildjet-4vcpu-ubuntu-2204
27+
runs-on: buildjet-8vcpu-ubuntu-2204
2828
timeout-minutes: 120
2929
steps:
3030
- name: Checkout sources

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ output.txt
8383
.nx/cache
8484
.nx/workspace-data
8585
output1.txt
86+
.zed

Cargo.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ members = [
1212
"program-libs/concurrent-merkle-tree",
1313
"program-libs/hash-set",
1414
"program-libs/indexed-merkle-tree",
15+
"program-libs/indexed-array",
1516
"programs/account-compression",
1617
"programs/system",
1718
"programs/compressed-token",
@@ -145,6 +146,7 @@ light-bloom-filter = { path = "program-libs/bloom-filter", version = "0.1.0" }
145146
light-bounded-vec = { version = "1.1.0" }
146147
light-poseidon = { version = "0.3.0" }
147148
light-test-utils = { path = "program-tests/utils", version = "1.2.1" }
149+
light-indexed-array = { path = "program-libs/indexed-array", version = "0.1.0" }
148150
create-address-program-test = { path = "program-tests/create-address-test-program", version = "1.0.0" }
149151
groth16-solana = { version = "0.0.3" }
150152
# anchor 0.29 requires 1.19

cli/accounts/batch_address_merkle_tree_EzKE84aVTkCUhDHLELqyJaq1Y7UVVmqxXqZjVHwHY3rK.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

forester-utils/src/instructions.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ pub enum ForesterUtilsError {
4040
RpcError(String),
4141
#[error("indexer error: {0:?}")]
4242
IndexerError(String),
43+
#[error("Converted indexer error: {0}")]
44+
ConvertedIndexerError(#[from] light_client::indexer::IndexerError),
45+
#[error("Converted rpc error: {0}")]
46+
ConvertedRpcError(#[from] light_client::rpc::RpcError),
47+
#[error("Batched Merkle tree error: {0}")]
48+
BatchedMerkleTreeError(#[from] light_batched_merkle_tree::errors::BatchedMerkleTreeError),
4349
}
4450

4551
pub async fn create_batch_update_address_tree_instruction_data<R, I>(
@@ -65,8 +71,7 @@ where
6571
let merkle_tree = BatchedMerkleTreeAccount::address_from_bytes(
6672
merkle_tree_account.data.as_mut_slice(),
6773
&merkle_tree_pubkey.into(),
68-
)
69-
.unwrap();
74+
)?;
7075

7176
let full_batch_index = merkle_tree.queue_batches.pending_batch_index;
7277
let batch = &merkle_tree.queue_batches.batches[full_batch_index as usize];
@@ -85,7 +90,11 @@ where
8590
.iter()
8691
.find(|x| x.accounts.merkle_tree == merkle_tree_pubkey)
8792
.unwrap()
88-
.merkle_tree
93+
.get_v2_indexed_merkle_tree()
94+
.ok_or(ForesterUtilsError::IndexerError(format!(
95+
"Merkle tree {:?} is not a batched address Merkle tree",
96+
merkle_tree_pubkey
97+
)))?
8998
.merkle_tree
9099
.rightmost_index;
91100

@@ -221,8 +230,7 @@ pub async fn create_append_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
221230
let merkle_tree = BatchedMerkleTreeAccount::state_from_bytes(
222231
merkle_tree_account.data.as_mut_slice(),
223232
&merkle_tree_pubkey.into(),
224-
)
225-
.unwrap();
233+
)?;
226234

227235
(
228236
merkle_tree.next_index,
@@ -239,8 +247,7 @@ pub async fn create_append_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
239247
let (zkp_batch_size, leaves_hash_chain) = {
240248
let mut output_queue_account = rpc.get_account(output_queue_pubkey).await.unwrap().unwrap();
241249
let output_queue =
242-
BatchedQueueAccount::output_from_bytes(output_queue_account.data.as_mut_slice())
243-
.unwrap();
250+
BatchedQueueAccount::output_from_bytes(output_queue_account.data.as_mut_slice())?;
244251

245252
let full_batch_index = output_queue.batch_metadata.pending_batch_index;
246253
let zkp_batch_size = output_queue.batch_metadata.zkp_batch_size;
@@ -366,8 +373,7 @@ pub async fn create_nullify_batch_ix_data<R: RpcConnection, I: Indexer<R>>(
366373
let merkle_tree = BatchedMerkleTreeAccount::state_from_bytes(
367374
account.data.as_mut_slice(),
368375
&merkle_tree_pubkey.into(),
369-
)
370-
.unwrap();
376+
)?;
371377

372378
log::debug!("queue_batches: {:?}", merkle_tree.queue_batches);
373379

program-libs/batched-merkle-tree/src/constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub const DEFAULT_ZKP_BATCH_SIZE: u64 = 500;
1919
pub const DEFAULT_CPI_CONTEXT_ACCOUNT_SIZE: u64 = 20 * 1024 + 8;
2020

2121
pub const ADDRESS_TREE_INIT_ROOT_40: [u8; 32] = [
22-
12, 181, 82, 66, 55, 110, 245, 173, 233, 250, 111, 145, 10, 171, 183, 79, 64, 245, 169, 160, 8,
23-
34, 54, 170, 14, 74, 170, 75, 72, 147, 141, 17,
22+
28, 65, 107, 255, 208, 234, 51, 3, 131, 95, 62, 130, 202, 177, 176, 26, 216, 81, 64, 184, 200,
23+
25, 95, 124, 248, 129, 44, 109, 229, 146, 106, 76,
2424
];
2525

2626
pub const ACCOUNT_COMPRESSION_PROGRAM_ID: solana_program::pubkey::Pubkey =

program-libs/batched-merkle-tree/src/merkle_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
298298
// 2. element:
299299
// H(452312848583266388373324160190187140051835877600158453279131187530910662655, 0, 0)
300300
// ... other elements: 0
301-
account_metadata.next_index = 2;
301+
account_metadata.next_index = 1;
302302
}
303303
let next_index = account_metadata.next_index;
304304

program-libs/batched-merkle-tree/src/merkle_tree_metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl BatchedMerkleTreeMetadata {
104104
rollover_fee,
105105
);
106106
// inited address tree contains two elements.
107-
tree.next_index = 2;
107+
tree.next_index = 1;
108108
tree
109109
}
110110

@@ -154,7 +154,7 @@ impl BatchedMerkleTreeMetadata {
154154
zkp_batch_size,
155155
num_iters,
156156
if tree_type == TreeType::BatchedAddress {
157-
2
157+
1
158158
} else {
159159
0
160160
},

program-libs/batched-merkle-tree/tests/merkle_tree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,14 +1300,15 @@ pub async fn perform_address_update(
13001300
account.get_metadata().queue_batches.batch_size as u32,
13011301
account.get_metadata().queue_batches.zkp_batch_size as u32,
13021302
*leaves_hash_chain,
1303-
next_index as usize, // % batch.zkp_batch_size as usize
1303+
next_index as usize,
13041304
batch_start_index as usize,
13051305
*current_root,
13061306
)
13071307
.await
13081308
.unwrap();
13091309

13101310
mock_indexer.finalize_batch_address_update(10);
1311+
assert_eq!(mock_indexer.merkle_tree.root(), new_root);
13111312
let instruction_data = InstructionDataBatchNullifyInputs {
13121313
new_root,
13131314
compressed_proof: CompressedProof {

0 commit comments

Comments
 (0)