fix: set is_authorized on PDA accounts in flash swap chained calls

This commit is contained in:
Moudy
2026-04-03 15:18:23 +02:00
parent 02e336b240
commit bc0583368d
5 changed files with 15 additions and 9 deletions
@@ -67,12 +67,15 @@ fn main() {
if instruction.return_funds {
// Happy path: return the borrowed funds via a token transfer (receiver → vault).
// The receiver is a PDA of this callback program (seed = [1u8; 32]).
// Mark the receiver as authorized since it will be PDA-authorized in this chained call.
let mut receiver_authorized = receiver_pre.clone();
receiver_authorized.is_authorized = true;
let transfer_instruction = risc0_zkvm::serde::to_vec(&instruction.amount)
.expect("transfer instruction serialization");
chained_calls.push(ChainedCall {
program_id: instruction.token_program_id,
pre_states: vec![receiver_pre.clone(), vault_pre.clone()],
pre_states: vec![receiver_authorized, vault_pre.clone()],
instruction_data: transfer_instruction,
pda_seeds: vec![PdaSeed::new([1u8; 32])],
});
@@ -110,11 +110,14 @@ fn main() {
// Chained call 1: Token transfer (vault → receiver).
// The vault is a PDA of this initiator program (seed = [0u8; 32]), so we provide
// the PDA seed to authorize the token program to debit the vault on our behalf.
// Mark the vault as authorized since it will be PDA-authorized in this chained call.
let mut vault_authorized = vault_pre.clone();
vault_authorized.is_authorized = true;
let transfer_instruction =
risc0_zkvm::serde::to_vec(&amount_out).expect("transfer instruction serialization");
let call_1 = ChainedCall {
program_id: token_program_id,
pre_states: vec![vault_pre.clone(), receiver_pre.clone()],
pre_states: vec![vault_authorized, receiver_pre.clone()],
instruction_data: transfer_instruction,
pda_seeds: vec![PdaSeed::new([0u8; 32])],
};