2025-10-29 15:34:11 -03:00
|
|
|
use nssa_core::program::{
|
|
|
|
|
ChainedCall, ProgramId, ProgramInput, read_nssa_inputs, write_nssa_outputs_with_chained_call,
|
|
|
|
|
};
|
|
|
|
|
use risc0_zkvm::serde::to_vec;
|
|
|
|
|
|
2025-11-12 19:55:02 -03:00
|
|
|
type Instruction = (u128, ProgramId, u32);
|
2025-10-29 15:34:11 -03:00
|
|
|
|
2025-11-12 19:55:02 -03:00
|
|
|
/// A program that calls another program `num_chain_calls` times.
|
2025-10-30 10:52:31 -03:00
|
|
|
/// It permutes the order of the input accounts on the subsequent call
|
2025-10-29 15:34:11 -03:00
|
|
|
fn main() {
|
|
|
|
|
let ProgramInput {
|
|
|
|
|
pre_states,
|
2025-11-12 19:55:02 -03:00
|
|
|
instruction: (balance, program_id, num_chain_calls),
|
2025-10-29 15:34:11 -03:00
|
|
|
} = read_nssa_inputs::<Instruction>();
|
|
|
|
|
|
|
|
|
|
let [sender_pre, receiver_pre] = match pre_states.try_into() {
|
|
|
|
|
Ok(array) => array,
|
|
|
|
|
Err(_) => return,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let instruction_data = to_vec(&balance).unwrap();
|
|
|
|
|
|
2025-11-12 19:55:02 -03:00
|
|
|
let mut chained_call = vec![
|
2025-11-12 19:08:46 -03:00
|
|
|
ChainedCall {
|
|
|
|
|
program_id,
|
|
|
|
|
instruction_data: instruction_data.clone(),
|
2025-11-17 15:43:01 -03:00
|
|
|
pre_states: vec![receiver_pre.clone(), sender_pre.clone()], // <- Account order permutation here
|
2025-11-27 12:08:27 -03:00
|
|
|
pda_seeds: vec![]
|
2025-11-12 19:55:02 -03:00
|
|
|
};
|
|
|
|
|
num_chain_calls as usize - 1
|
2025-11-12 19:08:46 -03:00
|
|
|
];
|
2025-10-29 15:34:11 -03:00
|
|
|
|
2025-11-12 19:55:02 -03:00
|
|
|
chained_call.push(ChainedCall {
|
|
|
|
|
program_id,
|
|
|
|
|
instruction_data,
|
2025-11-17 15:43:01 -03:00
|
|
|
pre_states: vec![receiver_pre.clone(), sender_pre.clone()], // <- Account order permutation here
|
2025-11-27 12:08:27 -03:00
|
|
|
pda_seeds: vec![],
|
2025-11-12 19:55:02 -03:00
|
|
|
});
|
|
|
|
|
|
2025-10-29 15:34:11 -03:00
|
|
|
write_nssa_outputs_with_chained_call(
|
|
|
|
|
vec![sender_pre.clone(), receiver_pre.clone()],
|
|
|
|
|
vec![sender_pre.account, receiver_pre.account],
|
|
|
|
|
chained_call,
|
|
|
|
|
);
|
|
|
|
|
}
|