-
Notifications
You must be signed in to change notification settings - Fork 90
fix: sdks #1998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: sdks #1998
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| use solana_account_info::AccountInfo; | ||
| use solana_msg::msg; | ||
| use solana_program_error::ProgramError; | ||
|
|
||
| pub mod v1 { | ||
| use light_account_checks::checks::check_owner; | ||
| use light_concurrent_merkle_tree::zero_copy::ConcurrentMerkleTreeZeroCopy; | ||
| use light_hasher::Poseidon; | ||
| use light_sdk_types::ACCOUNT_COMPRESSION_PROGRAM_ID; | ||
|
|
||
| use super::*; | ||
|
|
||
| /// StateMerkleTreeAccount discriminator | ||
| pub const STATE_MERKLE_TREE_DISCRIMINATOR: [u8; 8] = [172, 43, 172, 186, 29, 73, 219, 84]; | ||
| pub const STATE_MERKLE_TREE_ACCOUNT_METADATA_LEN: usize = 224; | ||
|
|
||
| /// Reads a root from the concurrent state merkle tree by index | ||
| pub fn read_state_merkle_tree_root( | ||
| account_info: &AccountInfo, | ||
| root_index: u16, | ||
| ) -> Result<[u8; 32], ProgramError> { | ||
| if root_index as usize >= 2400 { | ||
| msg!( | ||
| "Invalid root index: {} greater than max root index {}", | ||
| root_index, | ||
| 2400 | ||
| ); | ||
| return Err(ProgramError::InvalidArgument); | ||
| } | ||
| check_owner(&ACCOUNT_COMPRESSION_PROGRAM_ID, account_info)?; | ||
| let account_data = account_info.try_borrow_data()?; | ||
|
|
||
| // Check discriminator | ||
| if account_data.len() < 8 { | ||
| msg!("StateMerkleTreeAccount data too short for discriminator"); | ||
| return Err(ProgramError::InvalidAccountData); | ||
| } | ||
|
|
||
| let discriminator = &account_data[0..8]; | ||
| if discriminator != STATE_MERKLE_TREE_DISCRIMINATOR { | ||
| msg!("Invalid StateMerkleTreeAccount discriminator"); | ||
| return Err(ProgramError::InvalidAccountData); | ||
| } | ||
| let required_size = STATE_MERKLE_TREE_ACCOUNT_METADATA_LEN; | ||
| if account_data.len() < required_size { | ||
| msg!("StateMerkleTreeAccount data too short for metadata"); | ||
| return Err(ProgramError::InvalidAccountData); | ||
| } | ||
|
|
||
| let data = &account_data[required_size..]; | ||
| let merkle_tree = ConcurrentMerkleTreeZeroCopy::<Poseidon, 26>::from_bytes_zero_copy(data)?; | ||
|
|
||
| Ok(merkle_tree.roots[root_index as usize]) | ||
|
Comment on lines
+50
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify bounds safety when accessing merkle_tree.roots. The function validates 🏁 Script executed: #!/bin/bash
# Verify the ConcurrentMerkleTreeZeroCopy type definition and roots array size
rg -A 10 "struct ConcurrentMerkleTreeZeroCopy" --type rust
rg "roots.*\[" --type rust -A 3 | rg "2400|ROOTS"Length of output: 1813 [/run_scripts] 🏁 Script executed: #!/bin/bash
# Search for ConcurrentMerkleTree struct definition (the inner type)
rg -A 20 "struct ConcurrentMerkleTree[^Z]" --type rustLength of output: 3300 🏁 Script executed: #!/bin/bash
# Search for CyclicBoundedVec definition and its size/capacity
rg -A 15 "struct CyclicBoundedVec" --type rustLength of output: 0 🏁 Script executed: #!/bin/bash
# Search for CyclicBoundedVec definition or type alias
rg "type CyclicBoundedVec|CyclicBoundedVec.*=" --type rust -B 2 -A 5
# Also check the concurrent-merkle-tree lib.rs for imports
rg "use.*CyclicBoundedVec|mod.*" program-libs/concurrent-merkle-tree/src/lib.rs -A 2Length of output: 7239 🏁 Script executed: #!/bin/bash
# Search for CyclicBoundedVec implementation in offset module
rg "pub.*CyclicBoundedVec|impl.*CyclicBoundedVec" --type rust -A 5
# Also search for how roots capacity is set
rg "roots.*capacity|capacity.*2400|ROOTS_LEN" --type rustLength of output: 4860 🏁 Script executed: #!/bin/bash
# Find ROOTS constant
rg "const ROOTS|ROOTS\s*=" --type rust -B 2 -A 1
# Look at from_bytes_zero_copy implementation
rg -A 30 "pub fn from_bytes_zero_copy\(" program-libs/concurrent-merkle-tree/src/zero_copy.rs | head -50
# Check the actual merkle_tree.rs file around lines 50-53
cat sdk-libs/sdk/src/merkle_tree.rs | head -70 | tail -30Length of output: 19114 🏁 Script executed: #!/bin/bash
# Find check_size_constraints implementation
rg -A 20 "fn check_size_constraints" --type rust
# Also search for any validation of roots capacity
rg "roots.*capacity|roots_capacity.*=" --type rust -B 2 -A 2 | grep -A 5 "check_size_constraints\|validate\|assert"Length of output: 7256 Bounds safety issue confirmed: roots array capacity is not validated. The concern is valid. The code validates Recommended fix: Add validation in 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.