Skip to content

Commit ef0dd04

Browse files
authored
fix: zeroed root issue (#1842)
* fix: zeroed root issue * chore: bump versions
1 parent ccb898f commit ef0dd04

File tree

6 files changed

+119
-12
lines changed

6 files changed

+119
-12
lines changed

Cargo.lock

Lines changed: 4 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ light-hash-set = { version = "2.1.0", path = "program-libs/hash-set" }
153153
light-indexed-merkle-tree = { version = "2.1.0", path = "program-libs/indexed-merkle-tree" }
154154
light-concurrent-merkle-tree = { version = "2.1.0", path = "program-libs/concurrent-merkle-tree" }
155155
light-sparse-merkle-tree = { version = "0.1.0", path = "sparse-merkle-tree" }
156-
light-client = { path = "sdk-libs/client", version = "0.13.0" }
156+
light-client = { path = "sdk-libs/client", version = "0.13.1" }
157157
light-hasher = { path = "program-libs/hasher", version = "3.1.0" }
158158
light-macros = { path = "program-libs/macros", version = "2.1.0" }
159159
light-merkle-tree-reference = { path = "program-tests/merkle-tree", version = "2.0.0" }

program-tests/client-test/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ light-zero-copy = { workspace = true }
2525
light-hasher = { workspace = true }
2626
light-compressed-account = { workspace = true }
2727
light-compressed-token = { workspace = true }
28+
light-indexed-array = { workspace = true }
29+
light-merkle-tree-reference = { workspace = true }
2830

2931
tokio = { workspace = true }
3032
rand = { workspace = true }
33+
num-bigint = { workspace = true }
3134

3235
solana-sdk = { workspace = true }
3336
spl-token = { workspace = true }

program-tests/client-test/tests/light_client.rs

Lines changed: 109 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
use light_client::{
22
indexer::{
3-
AddressWithTree, GetCompressedTokenAccountsByOwnerOrDelegateOptions, Hash, Indexer,
4-
IndexerRpcConfig, PaginatedOptions, RetryConfig,
3+
AccountProofInputs, AddressProofInputs, AddressWithTree,
4+
GetCompressedTokenAccountsByOwnerOrDelegateOptions, Hash, Indexer, IndexerRpcConfig,
5+
MerkleProof, PaginatedOptions, RetryConfig, RootIndex, TreeInfo, ValidityProofWithContext,
56
},
67
local_test_validator::{spawn_validator, LightValidatorConfig},
78
rpc::{LightClient, LightClientConfig},
89
};
9-
use light_compressed_account::hash_to_bn254_field_size_be;
10+
use light_compressed_account::{hash_to_bn254_field_size_be, TreeType};
1011
use light_compressed_token::mint_sdk::{
1112
create_create_token_pool_instruction, create_mint_to_instruction,
1213
};
14+
use light_hasher::Poseidon;
15+
use light_merkle_tree_reference::{indexed::IndexedMerkleTree, MerkleTree};
1316
use light_program_test::accounts::test_accounts::TestAccounts;
1417
use light_prover_client::prover::ProverConfig;
1518
use light_sdk::{
@@ -66,6 +69,7 @@ async fn test_all_endpoints() {
6669
.await
6770
.unwrap();
6871
let mt = test_accounts.v1_state_trees[0].merkle_tree;
72+
let _address_mt = test_accounts.v1_address_trees[0].merkle_tree;
6973

7074
let lamports = LAMPORTS_PER_SOL / 2;
7175
let lamports_1 = LAMPORTS_PER_SOL / 2 + 1;
@@ -109,12 +113,21 @@ async fn test_all_endpoints() {
109113
};
110114

111115
let account_hashes: Vec<Hash> = initial_accounts.items.iter().map(|a| a.hash).collect();
116+
let mut reference_tree = MerkleTree::<Poseidon>::new(26, 10);
117+
for hash in &account_hashes {
118+
reference_tree.append(hash).unwrap();
119+
}
112120
let account_addresses: Vec<Hash> = initial_accounts
113121
.items
114122
.iter()
115123
.map(|a| a.address.unwrap())
116124
.collect();
117125

126+
// Create reference address tree and add the addresses
127+
let _reference_address_tree = IndexedMerkleTree::<Poseidon, usize>::new(26, 10).unwrap();
128+
129+
// Don't add the test address to the reference tree since we want non-inclusion proof
130+
118131
// 2. get_multiple_compressed_accounts
119132
let accounts = rpc
120133
.get_multiple_compressed_accounts(None, Some(account_hashes.clone()), None)
@@ -158,6 +171,53 @@ async fn test_all_endpoints() {
158171
.value;
159172
assert_eq!(result.accounts.len(), account_hashes.len());
160173
assert_eq!(result.addresses.len(), new_addresses.len());
174+
175+
println!("account_proof {:?}", result);
176+
177+
// Build expected ValidityProofWithContext using reference tree
178+
let expected_result = ValidityProofWithContext {
179+
proof: result.proof, // Keep the actual proof as-is
180+
accounts: account_hashes
181+
.iter()
182+
.enumerate()
183+
.map(|(i, &hash)| AccountProofInputs {
184+
hash,
185+
root: reference_tree.root(),
186+
root_index: RootIndex::new_some(2),
187+
leaf_index: i as u64,
188+
tree_info: TreeInfo {
189+
cpi_context: None,
190+
next_tree_info: None,
191+
queue: test_accounts.v1_state_trees[0].nullifier_queue,
192+
tree: mt,
193+
tree_type: TreeType::StateV1,
194+
},
195+
})
196+
.collect(),
197+
addresses: new_addresses
198+
.iter()
199+
.enumerate()
200+
.map(|(i, addr_with_tree)| {
201+
// TODO: enable once photon bug is fixed
202+
// let address_bigint = BigUint::from_bytes_be(&addr_with_tree.address);
203+
// let non_inclusion_proof = reference_address_tree.get_non_inclusion_proof(&address_bigint).unwrap();
204+
AddressProofInputs {
205+
address: addr_with_tree.address,
206+
root: result.addresses[i].root,
207+
root_index: 3,
208+
tree_info: TreeInfo {
209+
cpi_context: None,
210+
next_tree_info: None,
211+
queue: test_accounts.v1_address_trees[0].queue,
212+
tree: addr_with_tree.tree,
213+
tree_type: TreeType::AddressV1,
214+
},
215+
}
216+
})
217+
.collect(),
218+
};
219+
220+
assert_eq!(result, expected_result);
161221
}
162222
// 4. get_compressed_account
163223
let first_account = rpc
@@ -252,21 +312,62 @@ async fn test_all_endpoints() {
252312
assert!(!proofs.items.is_empty());
253313
assert_eq!(proofs.items[0].hash, account_hashes[0]);
254314

315+
// Build expected Vec<MerkleProof> using reference tree
316+
let expected_proofs: Vec<MerkleProof> = account_hashes
317+
.iter()
318+
.enumerate()
319+
.map(|(i, &hash)| {
320+
let expected_proof = reference_tree.get_proof_of_leaf(i, false).unwrap();
321+
MerkleProof {
322+
hash,
323+
leaf_index: i as u64,
324+
merkle_tree: mt,
325+
proof: expected_proof,
326+
root_seq: 2,
327+
root: reference_tree.root(),
328+
}
329+
})
330+
.collect();
331+
332+
assert_eq!(proofs.items, expected_proofs);
333+
255334
// 12. get_multiple_new_address_proofs
256335
let addresses = vec![address];
257336
let new_address_proofs = rpc
258337
.get_multiple_new_address_proofs(
259338
test_accounts.v1_address_trees[0].merkle_tree.to_bytes(),
260-
addresses,
339+
addresses.clone(),
261340
None,
262341
)
263342
.await
264343
.unwrap();
265344
assert!(!new_address_proofs.value.items.is_empty());
266-
assert_eq!(
267-
new_address_proofs.value.items[0].merkle_tree.to_bytes(),
268-
test_accounts.v1_address_trees[0].merkle_tree.to_bytes()
269-
);
345+
// TODO: update once photon is ready
346+
// Build expected Vec<NewAddressProofWithContext> using reference address tree
347+
// let expected_address_proofs: Vec<NewAddressProofWithContext> = addresses
348+
// .iter()
349+
// .map(|&addr| {
350+
// let address_bigint = BigUint::from_bytes_be(&addr);
351+
// let non_inclusion_proof = reference_address_tree
352+
// .get_non_inclusion_proof(&address_bigint)
353+
// .unwrap();
354+
355+
// NewAddressProofWithContext {
356+
// merkle_tree: address_mt,
357+
// root: non_inclusion_proof.root,
358+
// root_seq: 3,
359+
// low_address_index: non_inclusion_proof.leaf_index as u64,
360+
// low_address_value: non_inclusion_proof.leaf_lower_range_value,
361+
// low_address_next_index: non_inclusion_proof.next_index as u64,
362+
// low_address_next_value: non_inclusion_proof.leaf_higher_range_value,
363+
// low_address_proof: non_inclusion_proof.merkle_proof,
364+
// new_low_element: None,
365+
// new_element: None,
366+
// new_element_next_value: None,
367+
// }
368+
// })
369+
// .collect();
370+
assert_eq!(new_address_proofs.value.items.len(), 1);
270371
}
271372

272373
test_token_api(&rpc, &test_accounts).await;

sdk-libs/client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "light-client"
3-
version = "0.13.0"
3+
version = "0.13.1"
44
edition = "2021"
55
license = "Apache-2.0"
66
repository = "https://github.com/lightprotocol/light-protocol"

sdk-libs/client/src/indexer/photon_indexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ impl Indexer for PhotonIndexer {
11911191
merkle_tree: Pubkey::from_str_const(x.merkle_tree.as_str()),
11921192
proof,
11931193
root_seq: x.root_seq,
1194-
root: [0u8; 32],
1194+
root: <[u8; 32] as Base58Conversions>::from_base58(&x.root)?,
11951195
})
11961196
})
11971197
.collect::<Result<Vec<MerkleProof>, IndexerError>>()?;

0 commit comments

Comments
 (0)