Files
logos-execution-zone/test_programs/guest/src/bin/chain_caller.rs
T
Marvin Jones 90a3ee7812 refactor(lee): migrate program self/caller identity from ProgramId to AccountId
ProgramInput/ProgramOutput.self_program_id/caller_program_id, and the
dispatcher's CallerData.program_id, now carry AccountId (renamed to
self_account_id/caller_account_id) instead of ProgramId. These fields
are self-reported/cross-checked dispatch bookkeeping, not RISC0 image
identity, and AccountId already crosses the guest/host boundary this
way via every pre_state.account_id.

ProgramId is now confined to what's actually image-id-keyed:
env::verify, Program.id (from compute_image_id()), and the
for_public_pda/for_private_pda derivation formulas, each recovering
the real ProgramId from AccountId via the existing bijection exactly
where needed.

Rebuilds artifacts and the prebuilt sequencer db fixture to match.
2026-08-22 16:58:50 -04:00

72 lines
2.5 KiB
Rust

use authenticated_transfer_core::Instruction as AuthTransferInstruction;
use lee_core::program::{
AccountPostState, ChainedCall, PdaSeed, ProgramId, ProgramInput, ProgramOutput, read_lee_inputs,
};
use risc0_zkvm::serde::to_vec;
type Instruction = (u128, ProgramId, u32, Option<PdaSeed>);
/// A program that calls another program `num_chain_calls` times.
/// It permutes the order of the input accounts on the subsequent call
/// The `ProgramId` in the instruction must be the `program_id` of the authenticated transfers
/// program.
fn main() {
let (
ProgramInput {
self_account_id,
caller_account_id,
pre_states,
instruction: (balance, auth_transfer_id, num_chain_calls, pda_seed),
},
instruction_words,
) = read_lee_inputs::<Instruction>();
let Ok([recipient_pre, sender_pre]) = <[_; 2]>::try_from(pre_states) else {
return;
};
let instruction_data = to_vec(&AuthTransferInstruction::Transfer { amount: balance }).unwrap();
let mut running_recipient_pre = recipient_pre.clone();
let mut running_sender_pre = sender_pre.clone();
if pda_seed.is_some() {
running_sender_pre.is_authorized = true;
}
let mut chained_calls = Vec::new();
for _i in 0..num_chain_calls {
let new_chained_call = ChainedCall {
program_account_id: auth_transfer_id.into(),
instruction_data: instruction_data.clone(),
pre_states: vec![running_sender_pre.clone(), running_recipient_pre.clone()], /* <- Account order permutation here */
pda_seeds: pda_seed.iter().copied().collect(),
};
chained_calls.push(new_chained_call);
running_sender_pre.account.balance =
match running_sender_pre.account.balance.checked_sub(balance) {
Some(new_balance) => new_balance,
None => return,
};
running_recipient_pre.account.balance =
match running_recipient_pre.account.balance.checked_add(balance) {
Some(new_balance) => new_balance,
None => return,
};
}
ProgramOutput::new(
self_account_id,
caller_account_id,
instruction_words,
vec![sender_pre.clone(), recipient_pre.clone()],
vec![
AccountPostState::new(sender_pre.account),
AccountPostState::new(recipient_pre.account),
],
)
.with_chained_calls(chained_calls)
.write();
}