Skip to content

Commit 2022052

Browse files
authored
refactor: prover client (#1773)
* refactor: indexer in light-client refactor: light-client ProofRpcResultV2 refactor: add from v1 proof result refactor: light-client unify get_validity_proof and v2 refactor: light client unify get_compressed_account_by_owner and change return type to Account refactor: light-client get_compressed_token_accounts return type and unify v2 refactor: get compressed token balances stopped compiling conversion.rs refactor: light-client add response types to Indexer trait stash stash fix: lint in light client fixed forester-utils program test compiles fix: light-test-utils fix: forester system-cpi-test compiles fix: system-test fixed: light-compressed-token fixed: program-tests fix: forester test and lint uncomment test-sbf feature remove unused conversions.rs fix: forester test and lint fix: sdk test fix: tests fix: get_validity_proof feat: extend Indexer trait stash simplify ItemsWithCursor fixed forester utils fixed: light-program-test, light-test-utils, forester-utils fix: tests chore: rename get_compressed_token_balances_by_owner -> get_compressed_token_balances_by_owner_v2 use filter in get_compressed_accounts refactor: rename ValiditProofWithContext compressed_proof -> proof chore: add cpi context pubkeys to QUEUE_TREE_MAPPING and TreeInfo fix: compile error feat: add sparse Merkle tree crate refactor: light-prover-client structure fix: tests * fix: compilation * fix: system cpit test v2 * fix: compilation * fix: lint * fix
1 parent 14c9314 commit 2022052

File tree

124 files changed

+2476
-2238
lines changed

Some content is hidden

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

124 files changed

+2476
-2238
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
cargo test -p light-sdk
6363
cargo test -p light-program-test
6464
cargo test -p light-client
65+
cargo test -p light-sparse-merkle-tree
6566
cargo test -p light-batched-merkle-tree --features test-only -- --skip test_simulate_transactions --skip test_e2e
6667
6768
name: Test ${{ matrix.group.name }}

Cargo.lock

Lines changed: 21 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ members = [
4343
"program-tests/merkle-tree",
4444
"forester-utils",
4545
"forester",
46+
"sparse-merkle-tree",
4647
]
4748

4849
resolver = "2"
@@ -67,6 +68,8 @@ solana-client = "2.2.1"
6768
solana-cli-output = "2.2.1"
6869
solana-transaction-status = "2.2.1"
6970
solana-account-decoder = "2.2.1"
71+
solana-account-decoder-client-types = "2.2.1"
72+
solana-transaction-status-client-types = "2.2.1"
7073
solana-rpc = "2.2.1"
7174
solana-rpc-client-api = "2.2.1"
7275
solana-transaction-context = "2.2.1"
@@ -142,6 +145,7 @@ ark-std = "0.5"
142145
light-hash-set = { version = "2.0.0", path = "program-libs/hash-set" }
143146
light-indexed-merkle-tree = { version = "2.0.0", path = "program-libs/indexed-merkle-tree" }
144147
light-concurrent-merkle-tree = { version = "2.0.1", path = "program-libs/concurrent-merkle-tree" }
148+
light-sparse-merkle-tree = { version = "0.1.0", path = "sparse-merkle-tree" }
145149
light-client = { path = "sdk-libs/client", version = "0.9.1" }
146150
light-hasher = { path = "program-libs/hasher", version = "3.0.0" }
147151
light-macros = { path = "program-libs/macros", version = "2.0.0" }

anchor-programs/system/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test-sbf = []
2020
[dependencies]
2121
aligned-sized = { workspace = true }
2222
anchor-lang = { workspace = true }
23-
account-compression = { workspace = true }
23+
account-compression = { workspace = true, features = ["cpi"] }
2424
light-compressed-account = { workspace = true }
2525
light-zero-copy = { workspace = true }
2626
zerocopy = { workspace = true }

examples/anchor/memo/tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use light_program_test::{
1111
test_env::{setup_test_programs_with_accounts_v2, TestAccounts},
1212
program_test::LightProgramTest,
1313
};
14-
use light_prover_client::gnark::helpers::{spawn_prover, ProverConfig, ProverMode};
14+
use light_prover_client::prover::{spawn_prover, ProverConfig, ProverMode};
1515
use light_sdk::{
1616
account_meta::LightAccountMeta,
1717
address::derive_address,

examples/anchor/name-service-without-macros/tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use light_program_test::{
1313
test_env::{setup_test_programs_with_accounts_v2, TestAccounts},
1414
program_test::LightProgramTest,
1515
};
16-
use light_prover_client::gnark::helpers::{spawn_prover, ProverConfig};
16+
use light_prover_client::prover::{spawn_prover, ProverConfig};
1717
use light_sdk::{
1818
account_meta::LightAccountMeta,
1919
address::derive_address,

forester-utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ light-indexed-array = { workspace = true }
2121
light-compressed-account = { workspace = true }
2222
light-batched-merkle-tree = { workspace = true }
2323
light-merkle-tree-metadata = { workspace = true }
24-
light-merkle-tree-reference = { workspace = true }
24+
light-sparse-merkle-tree = { workspace = true }
2525
light-account-checks = { workspace = true }
2626
light-sdk = { workspace = true }
2727

forester-utils/src/instructions/address_batch_update.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use light_batched_merkle_tree::{
99
};
1010
use light_client::{indexer::Indexer, rpc::RpcConnection};
1111
use light_compressed_account::hash_chain::create_hash_chain_from_slice;
12-
use light_concurrent_merkle_tree::changelog::ChangelogEntry;
1312
use light_hasher::{bigint::bigint_to_be_bytes_array, Poseidon};
14-
use light_indexed_array::changelog::IndexedChangelogEntry;
15-
use light_merkle_tree_reference::sparse_merkle_tree::SparseMerkleTree;
1613
use light_prover_client::{
17-
batch_address_append::get_batch_address_append_circuit_inputs, proof_client::ProofClient,
14+
proof_client::ProofClient,
15+
proof_types::batch_address_append::get_batch_address_append_circuit_inputs,
16+
};
17+
use light_sdk::verifier::CompressedProof;
18+
use light_sparse_merkle_tree::{
19+
changelog::ChangelogEntry, indexed_changelog::IndexedChangelogEntry, SparseMerkleTree,
1820
};
1921
use tracing::{debug, error, info, warn};
2022

@@ -263,7 +265,11 @@ where
263265
debug!("Successfully generated proof for batch {}", i);
264266
instruction_data_vec.push(InstructionDataAddressAppendInputs {
265267
new_root,
266-
compressed_proof,
268+
compressed_proof: CompressedProof {
269+
a: compressed_proof.a,
270+
b: compressed_proof.b,
271+
c: compressed_proof.c,
272+
},
267273
});
268274
}
269275
Err(e) => {

forester-utils/src/instructions/state_batch_append.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use light_batched_merkle_tree::{
66
};
77
use light_client::{indexer::Indexer, rpc::RpcConnection};
88
use light_compressed_account::instruction_data::compressed_proof::CompressedProof;
9-
use light_concurrent_merkle_tree::changelog::ChangelogEntry;
109
use light_hasher::bigint::bigint_to_be_bytes_array;
1110
use light_merkle_tree_metadata::QueueType;
1211
use light_prover_client::{
13-
batch_append_with_proofs::{
12+
proof_client::ProofClient,
13+
proof_types::batch_append::{
1414
get_batch_append_with_proofs_inputs, BatchAppendWithProofsCircuitInputs,
1515
},
16-
proof_client::ProofClient,
1716
};
17+
use light_sparse_merkle_tree::changelog::ChangelogEntry;
1818
use tracing::{error, trace};
1919

2020
use crate::{error::ForesterUtilsError, utils::wait_for_indexer};
@@ -117,15 +117,15 @@ pub async fn create_append_batch_ix_data<R: RpcConnection, I: Indexer>(
117117
let adjusted_start_index =
118118
merkle_tree_next_index as u32 + (batch_idx * zkp_batch_size as usize) as u32;
119119

120-
let (circuit_inputs, batch_changelogs) = get_batch_append_with_proofs_inputs(
120+
let (circuit_inputs, batch_changelogs) = get_batch_append_with_proofs_inputs::<32>(
121121
current_root,
122122
adjusted_start_index,
123123
leaves,
124124
*leaves_hash_chain,
125125
old_leaves,
126126
merkle_proofs,
127127
zkp_batch_size as u32,
128-
&all_changelogs,
128+
all_changelogs.as_slice(),
129129
)
130130
.map_err(|e| {
131131
error!("Failed to get circuit inputs: {:?}", e);
@@ -166,10 +166,18 @@ async fn generate_zkp_proof(
166166
circuit_inputs: BatchAppendWithProofsCircuitInputs,
167167
) -> Result<(CompressedProof, [u8; 32]), ForesterUtilsError> {
168168
let proof_client = ProofClient::local();
169-
proof_client
169+
let (proof, new_root) = proof_client
170170
.generate_batch_append_proof(circuit_inputs)
171171
.await
172-
.map_err(|e| ForesterUtilsError::Prover(e.to_string()))
172+
.map_err(|e| ForesterUtilsError::Prover(e.to_string()))?;
173+
Ok((
174+
CompressedProof {
175+
a: proof.a,
176+
b: proof.b,
177+
c: proof.c,
178+
},
179+
new_root,
180+
))
173181
}
174182

175183
/// Get metadata from the Merkle tree account

forester-utils/src/instructions/state_batch_nullify.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use light_compressed_account::instruction_data::compressed_proof::CompressedProo
88
use light_hasher::{bigint::bigint_to_be_bytes_array, Hasher, Poseidon};
99
use light_merkle_tree_metadata::QueueType;
1010
use light_prover_client::{
11-
batch_update::{get_batch_update_inputs, BatchUpdateCircuitInputs},
1211
proof_client::ProofClient,
12+
proof_types::batch_update::{get_batch_update_inputs, BatchUpdateCircuitInputs},
1313
};
1414
use tracing::{error, trace};
1515

@@ -247,8 +247,16 @@ async fn generate_nullify_zkp_proof(
247247
inputs: BatchUpdateCircuitInputs,
248248
) -> Result<(CompressedProof, [u8; 32]), ForesterUtilsError> {
249249
let proof_client = ProofClient::local();
250-
proof_client
250+
let (proof, new_root) = proof_client
251251
.generate_batch_update_proof(inputs)
252252
.await
253-
.map_err(|e| ForesterUtilsError::Prover(e.to_string()))
253+
.map_err(|e| ForesterUtilsError::Prover(e.to_string()))?;
254+
Ok((
255+
CompressedProof {
256+
a: proof.a,
257+
b: proof.b,
258+
c: proof.c,
259+
},
260+
new_root,
261+
))
254262
}

0 commit comments

Comments
 (0)