Skip to content

Commit 79880dd

Browse files
committed
fix
1 parent 8c37f59 commit 79880dd

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

Cargo.lock

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

sdk-libs/sdk/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ v2 = ["light-sdk-types/v2"]
2222
cpi-context = ["light-sdk-types/cpi-context"]
2323
devnet = []
2424
poseidon = ["light-hasher/poseidon", "light-compressed-account/poseidon"]
25-
merkle-tree = ["light-concurrent-merkle-tree", "account-compression"]
25+
merkle-tree = ["light-concurrent-merkle-tree/solana"]
2626

2727

2828
[dependencies]
@@ -47,7 +47,6 @@ light-hasher = { workspace = true, features = ["std"] }
4747
light-account-checks = { workspace = true, features = ["solana"] }
4848
light-zero-copy = { workspace = true }
4949
light-concurrent-merkle-tree = { workspace = true, optional = true }
50-
account-compression = { workspace = true, features = ["cpi"], optional = true }
5150

5251
[dev-dependencies]
5352
num-bigint = { workspace = true }

sdk-libs/sdk/src/instruction/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ mod system_accounts;
4949
mod tree_info;
5050

5151
/// Zero-knowledge proof to prove the validity of existing compressed accounts and new addresses.
52-
pub use light_compressed_account::instruction_data::compressed_proof::ValidityProof;
52+
pub use light_compressed_account::instruction_data::compressed_proof::{
53+
CompressedProof, ValidityProof,
54+
};
5355
pub use light_sdk_types::instruction::*;
5456
pub use pack_accounts::*;
5557
pub use system_accounts::*;

sdk-libs/sdk/src/merkle_tree.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
1-
use account_compression::state_merkle_tree_from_bytes_zero_copy;
21
use solana_account_info::AccountInfo;
32
use solana_msg::msg;
43
use solana_program_error::ProgramError;
54

6-
use crate::error::LightSdkError;
75
pub mod v1 {
6+
use super::*;
87
use light_account_checks::checks::check_owner;
8+
use light_concurrent_merkle_tree::zero_copy::ConcurrentMerkleTreeZeroCopy;
9+
use light_hasher::Poseidon;
910
use light_sdk_types::ACCOUNT_COMPRESSION_PROGRAM_ID;
1011

11-
use super::*;
12-
1312
/// StateMerkleTreeAccount discriminator
1413
pub const STATE_MERKLE_TREE_DISCRIMINATOR: [u8; 8] = [172, 43, 172, 186, 29, 73, 219, 84];
14+
pub const STATE_MERKLE_TREE_ACCOUNT_METADATA_LEN: usize = 224;
1515

1616
/// Reads a root from the concurrent state merkle tree by index
1717
pub fn read_state_merkle_tree_root(
1818
account_info: &AccountInfo,
1919
root_index: u16,
20-
) -> Result<[u8; 32], LightSdkError> {
20+
) -> Result<[u8; 32], ProgramError> {
2121
if root_index as usize >= 2400 {
2222
msg!(
2323
"Invalid root index: {} greater than max root index {}",
2424
root_index,
2525
2400
2626
);
27-
return Err(LightSdkError::from(ProgramError::InvalidArgument));
27+
return Err(ProgramError::InvalidArgument);
2828
}
2929
check_owner(&ACCOUNT_COMPRESSION_PROGRAM_ID, account_info)?;
3030
let account_data = account_info.try_borrow_data()?;
3131

3232
// Check discriminator
3333
if account_data.len() < 8 {
3434
msg!("StateMerkleTreeAccount data too short for discriminator");
35-
return Err(LightSdkError::from(ProgramError::InvalidAccountData));
35+
return Err(ProgramError::InvalidAccountData);
3636
}
3737

3838
let discriminator = &account_data[0..8];
3939
if discriminator != STATE_MERKLE_TREE_DISCRIMINATOR {
4040
msg!("Invalid StateMerkleTreeAccount discriminator");
41-
return Err(LightSdkError::from(ProgramError::InvalidAccountData));
41+
return Err(ProgramError::InvalidAccountData);
42+
}
43+
let required_size = STATE_MERKLE_TREE_ACCOUNT_METADATA_LEN;
44+
if account_data.len() < required_size {
45+
msg!("StateMerkleTreeAccount data too short for discriminator");
46+
return Err(ProgramError::InvalidAccountData);
4247
}
4348

44-
let merkle_tree = state_merkle_tree_from_bytes_zero_copy(&account_data)
45-
.map_err(|_| LightSdkError::from(ProgramError::InvalidAccountData))?;
49+
let data = &account_data[required_size..];
50+
let merkle_tree = ConcurrentMerkleTreeZeroCopy::<Poseidon, 26>::from_bytes_zero_copy(data)?;
4651

4752
Ok(merkle_tree.roots[root_index as usize])
4853
}

0 commit comments

Comments
 (0)