Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
989 changes: 444 additions & 545 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ solana-security-txt = "1.1.1"
spl-token = "7.0.0"
spl-token-2022 = { version = "7.0.0", features = ["no-entrypoint"] }
spl-pod = "0.5.1"
pinocchio = { version = "0.8.4" }
pinocchio = { version = "0.9" }
pinocchio-pubkey = { version = "0.3.0" }
bs58 = "^0.5.1"
litesvm = "0.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ pub mod pinocchio {
let mut raw_data = vec![0u8; account_size + data.len()];

// Set the boolean flags - use 1 for true as the AccountInfo implementation checks for non-zero
raw_data[0] = 0; // borrow_state
// IMPORTANT: borrow_state needs to be 0xFF (all bits set) to indicate unborrowed state
raw_data[0] = 0xFF; // borrow_state - all bits set means unborrowed
raw_data[1] = if is_signer { 1 } else { 0 }; // is_signer
raw_data[2] = if is_writable { 1 } else { 0 }; // is_writable
raw_data[3] = if is_executable { 1 } else { 0 }; // executable

// original_data_len at offset 4
raw_data[4..8].copy_from_slice(&0u32.to_le_bytes());
// resize_delta at offset 4 (changed from original_data_len in pinocchio 0.9)
raw_data[4..8].copy_from_slice(&0i32.to_le_bytes());

// key at offset 8
raw_data[8..40].copy_from_slice(address.as_ref());
Expand Down
2 changes: 1 addition & 1 deletion programs/system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ light-zero-copy = { workspace = true, features = ["pinocchio"] }
zerocopy = { workspace = true }
light-account-checks = { workspace = true, features = ["pinocchio"] }
pinocchio = { workspace = true }
pinocchio-system = { version = "0.2.3" }
pinocchio-system = { version = "0.3.0" }
solana-pubkey = { workspace = true, features = ["curve25519", "sha2"] }
pinocchio-pubkey = { workspace = true }
solana-msg = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion programs/system/src/accounts/account_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn check_option_cpi_context_account<'a>(
"ERROR: check_owner {:?} owner: {:?} for cpi_context failed. {}:{}:{}",
solana_pubkey::Pubkey::new_from_array(*account_info.key()),
// SAFETY: owner() returns a valid pointer to a 32-byte aligned Pubkey
solana_pubkey::Pubkey::new_from_array(unsafe { *account_info.owner() }),
solana_pubkey::Pubkey::new_from_array(*account_info.owner()),
location.file(),
location.line(),
location.column()
Expand Down
16 changes: 8 additions & 8 deletions programs/system/tests/invoke_cpi_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,42 +228,42 @@ fn failing_from_account_infos() {
}
// 2. Authority mutable
{
let mut account_info_array = account_info_array.clone();
let mut account_info_array = account_info_array;
account_info_array[1] = get_fee_payer_account_info();
let res = InvokeCpiInstruction::from_account_infos(account_info_array.as_slice());
assert!(res == Err(ProgramError::from(AccountError::AccountMutable)));
}
// 3. Registered Program Pda mutable
{
let mut account_info_array = account_info_array.clone();
let mut account_info_array = account_info_array;
account_info_array[2] = get_mut_account_info();
let res = InvokeCpiInstruction::from_account_infos(account_info_array.as_slice());
assert!(res == Err(ProgramError::from(AccountError::AccountMutable)));
}
// 4. account_compression_authority mutable
{
let mut account_info_array = account_info_array.clone();
let mut account_info_array = account_info_array;
account_info_array[4] = get_mut_account_info();
let res = InvokeCpiInstruction::from_account_infos(account_info_array.as_slice());
assert!(res == Err(ProgramError::from(AccountError::AccountMutable)));
}
// 5. account_compression_program invalid program id
{
let mut account_info_array = account_info_array.clone();
let mut account_info_array = account_info_array;
account_info_array[5] = get_mut_account_info();
let res = InvokeCpiInstruction::from_account_infos(account_info_array.as_slice());
assert!(res == Err(ProgramError::from(AccountError::InvalidProgramId)));
}
// 6. account_compression_program not executable
{
let mut account_info_array = account_info_array.clone();
let mut account_info_array = account_info_array;
account_info_array[5] = get_non_executable_account_compression_program_account_info();
let res = InvokeCpiInstruction::from_account_infos(account_info_array.as_slice());
assert!(res == Err(ProgramError::from(AccountError::ProgramNotExecutable)));
}
// 7. sol_pool_pda invalid address
{
let mut account_info_array = account_info_array.clone();
let mut account_info_array = account_info_array;
account_info_array[7] = get_mut_account_info();
// Panics with Unable to find a viable program address bump seed
let result = catch_unwind(|| {
Expand All @@ -277,14 +277,14 @@ fn failing_from_account_infos() {
}
// 8. system_program invalid program id
{
let mut account_info_array = account_info_array.clone();
let mut account_info_array = account_info_array;
account_info_array[9] = get_mut_account_info();
let res = InvokeCpiInstruction::from_account_infos(account_info_array.as_slice());
assert!(res == Err(ProgramError::from(AccountError::InvalidProgramId)));
}
// 9. cpi_context_account invalid address
{
let mut account_info_array = account_info_array.clone();
let mut account_info_array = account_info_array;
account_info_array[10] = get_mut_account_info();
// Panics with Unable to find a viable program address bump seed
let result = catch_unwind(|| {
Expand Down
120 changes: 60 additions & 60 deletions programs/system/tests/invoke_cpi_instruction_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ fn functional_from_account_infos_v2() {
};

let account_info_array = [
fee_payer.clone(),
authority.clone(),
registered_program_pda.clone(),
account_compression_authority.clone(),
account_compression_program.clone(),
system_program.clone(),
fee_payer,
authority,
registered_program_pda,
account_compression_authority,
account_compression_program,
system_program,
get_mut_account_info(), // Dummy remaining account
get_mut_account_info(), // Another dummy remaining account
];
Expand Down Expand Up @@ -142,13 +142,13 @@ fn functional_from_account_infos_v2() {
};

let account_info_array = [
fee_payer.clone(),
authority.clone(),
registered_program_pda.clone(),
account_compression_authority.clone(),
account_compression_program.clone(),
system_program.clone(),
decompression_recipient.clone(),
fee_payer,
authority,
registered_program_pda,
account_compression_authority,
account_compression_program,
system_program,
decompression_recipient,
get_mut_account_info(), // Remaining account required for CPI
];

Expand Down Expand Up @@ -195,13 +195,13 @@ fn functional_from_account_infos_v2() {
};

let account_info_array = [
fee_payer.clone(),
authority.clone(),
registered_program_pda.clone(),
account_compression_authority.clone(),
account_compression_program.clone(),
system_program.clone(),
cpi_context_account.clone(),
fee_payer,
authority,
registered_program_pda,
account_compression_authority,
account_compression_program,
system_program,
cpi_context_account,
get_mut_account_info(), // Remaining account required for CPI
];

Expand Down Expand Up @@ -252,13 +252,13 @@ fn test_cpi_context_account_error_handling() {
let account_compression_program = get_account_compression_program_account_info();
let system_program = get_system_program_account_info();
let account_info_array = [
fee_payer.clone(),
authority.clone(),
registered_program_pda.clone(),
account_compression_authority.clone(),
account_compression_program.clone(),
system_program.clone(),
invalid_cpi_context_account.clone(),
fee_payer,
authority,
registered_program_pda,
account_compression_authority,
account_compression_program,
system_program,
invalid_cpi_context_account,
get_mut_account_info(), // Remaining account required for CPI
];

Expand All @@ -276,13 +276,13 @@ fn test_cpi_context_account_error_handling() {
let account_compression_program = get_account_compression_program_account_info();
let system_program = get_system_program_account_info();
let account_info_array = [
fee_payer.clone(),
authority.clone(),
registered_program_pda.clone(),
account_compression_authority.clone(),
account_compression_program.clone(),
system_program.clone(),
invalid_cpi_context_account.clone(),
fee_payer,
authority,
registered_program_pda,
account_compression_authority,
account_compression_program,
system_program,
invalid_cpi_context_account,
get_mut_account_info(), // Remaining account required for CPI
];

Expand Down Expand Up @@ -316,14 +316,14 @@ fn test_decompression_recipient_and_cpi_context_validation() {
let system_program = get_system_program_account_info();

let account_info_array = [
fee_payer.clone(),
authority.clone(),
registered_program_pda.clone(),
account_compression_authority.clone(),
account_compression_program.clone(),
system_program.clone(),
decompression_recipient.clone(),
cpi_context_account.clone(),
fee_payer,
authority,
registered_program_pda,
account_compression_authority,
account_compression_program,
system_program,
decompression_recipient,
cpi_context_account,
get_mut_account_info(), // Remaining account required for CPI
];

Expand Down Expand Up @@ -368,12 +368,12 @@ fn failing_from_account_infos_v2() {

// Base array for tests
let account_info_array = [
fee_payer.clone(),
authority.clone(),
registered_program_pda.clone(),
account_compression_authority.clone(),
account_compression_program.clone(),
system_program.clone(),
fee_payer,
authority,
registered_program_pda,
account_compression_authority,
account_compression_program,
system_program,
get_mut_account_info(), // Remaining account required for CPI
];

Expand Down Expand Up @@ -402,7 +402,7 @@ fn failing_from_account_infos_v2() {
write_to_cpi_context: false,
};

let mut account_info_array_clone = account_info_array.clone();
let mut account_info_array_clone = account_info_array;
account_info_array_clone[1] = get_fee_payer_account_info(); // Use a mutable account

let result = InvokeCpiInstructionV2::from_account_infos(
Expand All @@ -425,7 +425,7 @@ fn failing_from_account_infos_v2() {
write_to_cpi_context: false,
};

let mut account_info_array_clone = account_info_array.clone();
let mut account_info_array_clone = account_info_array;
account_info_array_clone[2] = get_mut_account_info();

let result = InvokeCpiInstructionV2::from_account_infos(
Expand All @@ -448,7 +448,7 @@ fn failing_from_account_infos_v2() {
write_to_cpi_context: false,
};

let mut account_info_array_clone = account_info_array.clone();
let mut account_info_array_clone = account_info_array;
account_info_array_clone[3] = get_mut_account_info();

let result = InvokeCpiInstructionV2::from_account_infos(
Expand All @@ -474,8 +474,8 @@ fn failing_from_account_infos_v2() {
};

let insufficient_array = [
fee_payer.clone(),
authority.clone(),
fee_payer,
authority,
// Missing registered_program_pda and account_compression_authority
];

Expand All @@ -501,13 +501,13 @@ fn failing_from_account_infos_v2() {
};

let account_array_with_decompression = [
fee_payer.clone(),
authority.clone(),
registered_program_pda.clone(),
account_compression_authority.clone(),
account_compression_program.clone(),
system_program.clone(),
decompression_recipient.clone(),
fee_payer,
authority,
registered_program_pda,
account_compression_authority,
account_compression_program,
system_program,
decompression_recipient,
get_mut_account_info(), // Remaining account required for CPI
];

Expand Down
Loading
Loading