Skip to content

chore: simplify lightprograminterface trait#19

Open
SwenSchaeferjohann wants to merge 3 commits intomainfrom
simplify-trait
Open

chore: simplify lightprograminterface trait#19
SwenSchaeferjohann wants to merge 3 commits intomainfrom
simplify-trait

Conversation

@SwenSchaeferjohann
Copy link
Contributor

@SwenSchaeferjohann SwenSchaeferjohann commented Feb 10, 2026

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 5 additional findings in Devin Review.

Open in Devin Review

let pool_state = PoolState::deserialize(&mut &data[8..])
/// Construct from pool state pubkey and its account data.
pub fn new(pool_state_pubkey: Pubkey, pool_data: &[u8]) -> Result<Self, SwapSdkError> {
let pool = PoolState::deserialize(&mut &pool_data[8..])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 SwapSdk::new panics on short input data instead of returning an error

The SwapSdk::new constructor at pinocchio/swap/tests/sdk.rs:52 does pool_data[8..] without checking that pool_data has at least 8 bytes. If pool_data.len() < 8, this will panic with an index-out-of-bounds error instead of returning Err(SwapSdkError::ParseError(...)).

Root Cause

The old code (parse_pool_state) had an explicit bounds check:

if data.len() < 8 {
    return Err(SwapSdkError::ParseError("Account data too short".to_string()));
}

The new code removed this check and directly indexes into the slice:

let pool = PoolState::deserialize(&mut &pool_data[8..])

Since the function returns Result<Self, SwapSdkError>, callers expect errors to be returned gracefully, not as panics. The same issue exists in load_specs at line 135 (account.data()[8..]) where short pool state data would also cause a panic.

Impact: Any caller passing data shorter than 8 bytes will get an unrecoverable panic instead of a handleable error. While this is test SDK code, it's still a regression in error handling robustness.

Suggested change
let pool = PoolState::deserialize(&mut &pool_data[8..])
if pool_data.len() < 8 {
return Err(SwapSdkError::ParseError("Account data too short".to_string()));
}
let pool = PoolState::deserialize(&mut &pool_data[8..])
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

SwenSchaeferjohann and others added 2 commits February 10, 2026 13:31
Includes multi-pass cold account lookup fix in test indexer.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant