Skip to content
Merged
379 changes: 244 additions & 135 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions anchor-programs/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ pub mod instructions;
pub mod utils;
pub use instructions::*;
pub mod cpi_context_account;
use light_compressed_account::instruction_data::with_account_info::InstructionDataInvokeCpiWithAccountInfo;
use light_compressed_account::instruction_data::{
with_account_info::InstructionDataInvokeCpiWithAccountInfo,
with_readonly::InstructionDataInvokeCpiWithReadOnly,
};

declare_id!("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");

#[program]
Expand All @@ -30,12 +34,10 @@ pub mod light_system_program {

pub fn invoke_cpi_with_read_only(
ctx: Context<InvokeCpiInstruction>,
// TODO: revert once parse_batched_event_functional is migrated to manual cpi
inputs: Vec<u8>, // inputs: InstructionDataInvokeCpiWithReadOnly,
inputs: InstructionDataInvokeCpiWithReadOnly,
) -> Result<()> {
unimplemented!("anchor wrapper not implemented")
}

pub fn invoke_cpi_with_account_info(
ctx: Context<InvokeCpiInstruction>,
inputs: InstructionDataInvokeCpiWithAccountInfo,
Expand Down
7 changes: 6 additions & 1 deletion forester/tests/address_v2_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashMap, sync::Arc, time::Duration};

use anchor_lang::Discriminator;
use borsh::BorshSerialize;
use create_address_test_program::create_invoke_cpi_instruction;
use forester::{config::GeneralConfig, epoch_manager::WorkReport, run_pipeline, ForesterConfig};
Expand Down Expand Up @@ -395,7 +396,11 @@ async fn create_v2_addresses<R: Rpc + MerkleTreeExt + Indexer>(

let instruction = create_invoke_cpi_instruction(
payer.pubkey(),
ix_data.try_to_vec()?,
[
light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.to_vec(),
ix_data.try_to_vec()?,
]
.concat(),
remaining_accounts,
None,
);
Expand Down
1 change: 0 additions & 1 deletion js/compressed-token/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export type BatchCompressInstructionData = {
bump: number;
};


export type MintToInstructionData = {
recipients: PublicKey[];
amounts: BN[];
Expand Down
3 changes: 2 additions & 1 deletion js/stateless.js/src/programs/system/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { LightSystemProgram } from '.';
import {
INVOKE_CPI_DISCRIMINATOR,
INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR,
INVOKE_DISCRIMINATOR,
} from '../../constants';

Expand Down Expand Up @@ -232,7 +233,7 @@ export const InstructionDataInvokeCpiWithReadOnlyLayout = struct([

export function decodeInstructionDataInvokeCpiWithReadOnly(buffer: Buffer) {
return InstructionDataInvokeCpiWithReadOnlyLayout.decode(
buffer.slice(INVOKE_DISCRIMINATOR.length + 4),
buffer.slice(INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR.length),
);
}

Expand Down
82 changes: 41 additions & 41 deletions js/stateless.js/tests/unit/utils/conversion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,48 +81,48 @@ describe('deserialize apc cpi', () => {

describe('deserialize InstructionDataInvokeCpiWithReadOnly', () => {
it('should deserialize the complete InstructionDataInvokeCpiWithReadOnly structure', () => {
// first 12 bytes are skipped.
// first 8 bytes are skipped.
const data = [
1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 148, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 90, 70, 83, 164, 216, 39, 10, 106, 0, 0, 1, 0, 1, 83, 0, 3, 0, 0,
0, 91, 97, 69, 180, 246, 54, 236, 250, 62, 116, 95, 226, 176, 250,
172, 150, 38, 157, 38, 110, 3, 110, 130, 133, 102, 14, 42, 118, 151,
177, 74, 49, 180, 127, 245, 54, 1, 13, 208, 197, 129, 101, 36, 193,
85, 161, 48, 175, 182, 23, 26, 150, 52, 204, 60, 96, 233, 248, 140,
33, 212, 16, 175, 111, 218, 54, 195, 97, 239, 148, 66, 48, 24, 183,
0, 254, 113, 31, 157, 136, 188, 202, 183, 37, 203, 248, 36, 216,
177, 227, 159, 93, 238, 171, 167, 173, 224, 196, 144, 193, 203, 88,
88, 133, 174, 71, 142, 254, 17, 121, 254, 208, 0, 153, 1, 0, 0, 0,
237, 83, 2, 61, 227, 140, 40, 48, 68, 54, 55, 57, 228, 108, 104, 1,
19, 138, 156, 96, 249, 111, 250, 212, 130, 57, 47, 54, 4, 5, 48,
192, 174, 157, 141, 112, 18, 255, 0, 64, 136, 164, 130, 37, 210, 47,
0, 253, 75, 4, 203, 167, 187, 45, 253, 192, 154, 0, 4, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 201, 78, 254, 108, 214, 2, 223, 68, 0, 0,
43, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 17, 123, 28, 100, 171, 124,
219, 0, 0, 253, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126, 220, 103, 34, 32,
110, 222, 30, 0, 0, 197, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 198, 75,
26, 237, 186, 126, 74, 0, 1, 19, 61, 250, 254, 150, 6, 163, 86, 0,
0, 0, 0, 156, 9, 53, 70, 77, 194, 172, 226, 190, 160, 23, 141, 31,
196, 236, 120, 84, 107, 116, 110, 205, 212, 164, 48, 143, 224, 119,
115, 144, 225, 207, 228, 49, 3, 0, 0, 0, 39, 168, 127, 189, 18, 209,
50, 130, 61, 249, 224, 77, 91, 119, 75, 140, 171, 218, 60, 106, 84,
193, 224, 111, 159, 45, 25, 182, 255, 151, 70, 104, 70, 51, 175, 83,
83, 120, 178, 62, 215, 154, 181, 237, 76, 231, 56, 133, 102, 223,
246, 189, 104, 18, 195, 42, 151, 220, 240, 78, 245, 64, 112, 90,
139, 200, 70, 9, 144, 245, 142, 205, 162, 130, 217, 110, 191, 231,
184, 36, 71, 173, 105, 78, 104, 199, 27, 1, 160, 6, 177, 68, 34, 22,
224, 174, 159, 50, 42, 53, 143, 251, 61, 65, 82, 2, 0, 0, 0, 139,
161, 56, 237, 157, 233, 116, 185, 12, 196, 217, 30, 184, 96, 146,
164, 150, 251, 140, 3, 158, 71, 77, 130, 169, 233, 128, 60, 221,
108, 98, 247, 124, 28, 145, 30, 204, 146, 1, 14, 104, 21, 236, 252,
114, 187, 150, 4, 37, 93, 254, 107, 46, 123, 96, 206, 209, 39, 91,
61, 214, 71, 4, 118, 24, 221, 216, 152, 135, 71, 93, 155, 81, 50,
14, 128, 30, 108, 170, 1, 235, 59,
1, 0, 0, 0, 1, 0, 0, 0, 0, 148, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 70,
83, 164, 216, 39, 10, 106, 0, 0, 1, 0, 1, 83, 0, 3, 0, 0, 0, 91, 97,
69, 180, 246, 54, 236, 250, 62, 116, 95, 226, 176, 250, 172, 150,
38, 157, 38, 110, 3, 110, 130, 133, 102, 14, 42, 118, 151, 177, 74,
49, 180, 127, 245, 54, 1, 13, 208, 197, 129, 101, 36, 193, 85, 161,
48, 175, 182, 23, 26, 150, 52, 204, 60, 96, 233, 248, 140, 33, 212,
16, 175, 111, 218, 54, 195, 97, 239, 148, 66, 48, 24, 183, 0, 254,
113, 31, 157, 136, 188, 202, 183, 37, 203, 248, 36, 216, 177, 227,
159, 93, 238, 171, 167, 173, 224, 196, 144, 193, 203, 88, 88, 133,
174, 71, 142, 254, 17, 121, 254, 208, 0, 153, 1, 0, 0, 0, 237, 83,
2, 61, 227, 140, 40, 48, 68, 54, 55, 57, 228, 108, 104, 1, 19, 138,
156, 96, 249, 111, 250, 212, 130, 57, 47, 54, 4, 5, 48, 192, 174,
157, 141, 112, 18, 255, 0, 64, 136, 164, 130, 37, 210, 47, 0, 253,
75, 4, 203, 167, 187, 45, 253, 192, 154, 0, 4, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 201, 78, 254, 108, 214, 2, 223, 68, 0, 0, 43, 0, 0,
0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 78, 17, 123, 28, 100, 171, 124, 219, 0, 0, 253,
0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 126, 220, 103, 34, 32, 110, 222, 30, 0,
0, 197, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 198, 75, 26, 237, 186, 126,
74, 0, 1, 19, 61, 250, 254, 150, 6, 163, 86, 0, 0, 0, 0, 156, 9, 53,
70, 77, 194, 172, 226, 190, 160, 23, 141, 31, 196, 236, 120, 84,
107, 116, 110, 205, 212, 164, 48, 143, 224, 119, 115, 144, 225, 207,
228, 49, 3, 0, 0, 0, 39, 168, 127, 189, 18, 209, 50, 130, 61, 249,
224, 77, 91, 119, 75, 140, 171, 218, 60, 106, 84, 193, 224, 111,
159, 45, 25, 182, 255, 151, 70, 104, 70, 51, 175, 83, 83, 120, 178,
62, 215, 154, 181, 237, 76, 231, 56, 133, 102, 223, 246, 189, 104,
18, 195, 42, 151, 220, 240, 78, 245, 64, 112, 90, 139, 200, 70, 9,
144, 245, 142, 205, 162, 130, 217, 110, 191, 231, 184, 36, 71, 173,
105, 78, 104, 199, 27, 1, 160, 6, 177, 68, 34, 22, 224, 174, 159,
50, 42, 53, 143, 251, 61, 65, 82, 2, 0, 0, 0, 139, 161, 56, 237,
157, 233, 116, 185, 12, 196, 217, 30, 184, 96, 146, 164, 150, 251,
140, 3, 158, 71, 77, 130, 169, 233, 128, 60, 221, 108, 98, 247, 124,
28, 145, 30, 204, 146, 1, 14, 104, 21, 236, 252, 114, 187, 150, 4,
37, 93, 254, 107, 46, 123, 96, 206, 209, 39, 91, 61, 214, 71, 4,
118, 24, 221, 216, 152, 135, 71, 93, 155, 81, 50, 14, 128, 30, 108,
170, 1, 235, 59,
];

const buffer = Buffer.from(data);
Expand Down
7 changes: 4 additions & 3 deletions program-libs/compressed-account/src/indexer_event/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,16 @@ fn deserialize_instruction<'a>(
));
}
let instruction_discriminator = instruction[0..8].try_into().unwrap();
let instruction = instruction.split_at(12).1;
let instruction = instruction.split_at(8).1;
match instruction_discriminator {
// Cannot be exucted with cpi context -> executing tx
DISCRIMINATOR_INVOKE => {
if accounts.len() < 9 {
return Err(ParseIndexerEventError::DeserializeSystemInstructionError);
}
let accounts = accounts.split_at(9).1;
let data = InstructionDataInvoke::deserialize(&mut &instruction[..])?;
// Skips vec size bytes
let data = InstructionDataInvoke::deserialize(&mut &instruction[4..])?;
Ok(ExecutingSystemInstruction {
output_compressed_accounts: data.output_compressed_accounts,
input_compressed_accounts: data.input_compressed_accounts_with_merkle_context,
Expand All @@ -311,7 +312,7 @@ fn deserialize_instruction<'a>(
}
let accounts = accounts.split_at(11).1;
let data = crate::instruction_data::invoke_cpi::InstructionDataInvokeCpi::deserialize(
&mut &instruction[..],
&mut &instruction[4..],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

critical for indexing.
Here we are eliminating skip vec size bytes for the new instructions and keeping it for the old instructions.

)?;
Ok(ExecutingSystemInstruction {
output_compressed_accounts: data.output_compressed_accounts,
Expand Down
34 changes: 26 additions & 8 deletions program-tests/create-address-test-program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,34 @@ pub fn process_invoke_cpi<'info>(
};
let seeds: [&[u8]; 2] = [CPI_AUTHORITY_PDA_SEED, &[bump]];
let signer_seeds: [&[&[u8]]; 1] = [&seeds[..]];
let mut account_infos = cpi_accounts.to_account_infos();

// Add remaining accounts
account_infos.extend_from_slice(ctx.remaining_accounts);

// Create instruction
let mut account_metas = cpi_accounts.to_account_metas(None);
ctx.remaining_accounts.iter().for_each(|account| {
account_metas.push(AccountMeta {
pubkey: *account.key,
is_signer: account.is_signer,
is_writable: account.is_writable,
});
});
let instruction = Instruction {
program_id: ctx.accounts.light_system_program.key(),
accounts: account_metas,
data: inputs,
};

let mut cpi_ctx = CpiContext::new_with_signer(
ctx.accounts.light_system_program.to_account_info(),
cpi_accounts,
&signer_seeds,
);

cpi_ctx.remaining_accounts = ctx.remaining_accounts.to_vec();
anchor_lang::solana_program::log::sol_log_compute_units();
light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, inputs)?;

// Invoke the instruction with signer seeds
anchor_lang::solana_program::program::invoke_signed(
&instruction,
&account_infos,
&signer_seeds,
)?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion program-tests/sdk-pinocchio-test/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #![cfg(feature = "test-sbf")]
#![cfg(feature = "test-sbf")]

use borsh::BorshSerialize;
use light_compressed_account::{
Expand Down
5 changes: 1 addition & 4 deletions program-tests/system-cpi-test/src/create_pda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,7 @@ fn cpi_compressed_pda_transfer_as_program<'info>(

cpi_ctx.remaining_accounts = remaining_accounts;

light_system_program::cpi::invoke_cpi_with_read_only(
cpi_ctx,
inputs_struct.try_to_vec().unwrap(),
)?;
light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, inputs_struct)?;
} else {
let cpi_accounts = light_system_program::cpi::accounts::InvokeCpiInstruction {
fee_payer: ctx.accounts.signer.to_account_info(),
Expand Down
8 changes: 6 additions & 2 deletions program-tests/system-cpi-v2-test/tests/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::collections::HashMap;

use anchor_lang::prelude::borsh::BorshSerialize;
use anchor_lang::{prelude::borsh::BorshSerialize, Discriminator};
use create_address_test_program::create_invoke_cpi_instruction;
use light_client::{
indexer::{AddressWithTree, Indexer},
Expand Down Expand Up @@ -722,7 +722,11 @@ pub async fn perform_test_transaction<R: Rpc>(
let remaining_accounts = to_account_metas(remaining_accounts);
let instruction = create_invoke_cpi_instruction(
payer.pubkey(),
ix_data.try_to_vec().unwrap(),
[
light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.to_vec(),
ix_data.try_to_vec().unwrap(),
]
.concat(),
remaining_accounts,
num_cpis,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3019,9 +3019,9 @@ pub mod local_sdk {

let instruction_discriminator = if account_infos.is_none() {
// INVOKE_CPI_WITH_READ_ONLY_INSTRUCTIOM
[86, 47, 163, 166, 21, 223, 92, 8, 0, 0, 0, 0]
[86, 47, 163, 166, 21, 223, 92, 8]
} else {
[228, 34, 128, 84, 47, 139, 86, 240, 0, 0, 0, 0]
[228, 34, 128, 84, 47, 139, 86, 240]
// INVOKE_CPI_WITH_ACCOUNT_INFO_INSTRUCTION
};
let mut onchain_config = CpiAccountsConfig::new(LIGHT_CPI_SIGNER);
Expand Down
8 changes: 6 additions & 2 deletions program-tests/utils/src/e2e_test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use account_compression::{
AddressMerkleTreeConfig, AddressQueueConfig, NullifierQueueConfig, StateMerkleTreeConfig,
SAFETY_MARGIN,
};
use anchor_lang::{prelude::AccountMeta, AnchorSerialize};
use anchor_lang::{prelude::AccountMeta, AnchorSerialize, Discriminator};
use create_address_test_program::create_invoke_cpi_instruction;
use forester_utils::{
account_zero_copy::AccountZeroCopy,
Expand Down Expand Up @@ -2794,7 +2794,11 @@ where

let instruction = create_invoke_cpi_instruction(
user.pubkey(),
ix_data.try_to_vec().unwrap(),
[
light_system_program::instruction::InvokeCpiWithReadOnly::DISCRIMINATOR.to_vec(),
ix_data.try_to_vec().unwrap(),
]
.concat(),
remaining_accounts,
None,
);
Expand Down
12 changes: 6 additions & 6 deletions programs/compressed-token/src/process_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,6 @@ pub fn cpi_execute_compressed_transaction_transfer<
compress_or_decompress_lamports: 0,
is_compress: false,
};
let mut inputs = Vec::new();
InstructionDataInvokeCpiWithReadOnly::serialize(&inputs_struct, &mut inputs)
.map_err(ProgramError::from)?;

#[cfg(not(feature = "cpi-without-program-ids"))]
{
Expand Down Expand Up @@ -459,16 +456,19 @@ pub fn cpi_execute_compressed_transaction_transfer<
bench_sbf_end!("t_cpi_prep");

bench_sbf_start!("t_invoke_cpi");
light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, inputs)?;
light_system_program::cpi::invoke_cpi_with_read_only(cpi_ctx, inputs_struct)?;
bench_sbf_end!("t_invoke_cpi");
}
#[cfg(feature = "cpi-without-program-ids")]
{
let mut data = Vec::with_capacity(8 + 4 + inputs.len());
let mut inputs = Vec::new();
InstructionDataInvokeCpiWithReadOnly::serialize(&inputs_struct, &mut inputs)
.map_err(ProgramError::from)?;

let mut data = Vec::with_capacity(8 + inputs.len());
data.extend_from_slice(
&light_compressed_account::discriminators::DISCRIMINATOR_INVOKE_CPI_WITH_READ_ONLY,
);
data.extend_from_slice(&(inputs.len() as u32).to_le_bytes());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

critical

data.extend(inputs);

// 4 static accounts
Expand Down
2 changes: 0 additions & 2 deletions programs/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ pub fn invoke_cpi_with_read_only<'a, 'b, 'c: 'info, 'info>(
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> Result<()> {
let instruction_data = &instruction_data[4..];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

critical

msg!("invoke_cpi_with_read_only");
let (inputs, _) = InstructionDataInvokeCpiWithReadOnly::zero_copy_at(instruction_data)
.map_err(ProgramError::from)?;
Expand All @@ -152,7 +151,6 @@ pub fn invoke_cpi_with_account_info<'a, 'b, 'c: 'info, 'info>(
instruction_data: &[u8],
) -> Result<()> {
msg!("invoke_cpi_with_account_info");
let instruction_data = &instruction_data[4..];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

critical


let (inputs, _) = InstructionDataInvokeCpiWithAccountInfo::zero_copy_at(instruction_data)
.map_err(ProgramError::from)?;
Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ install_rust() {
export PATH="${PREFIX}/cargo/bin:${PATH}"
rustup component add --toolchain 1.86-x86_64-unknown-linux-gnu clippy
cargo install cargo-expand --locked
cargo install --git https://github.com/helius-labs/photon.git --rev cf58facb4e0521843e3afd21d09d8e7e7f772140 --locked
cargo install --git https://github.com/helius-labs/photon.git --rev dbeb89e639bda78f0e135b9b1aa75bfe16618cb4 --locked
log "rust"
fi
}
Expand Down
Loading