use validity window as intstruction type in test programs

This commit is contained in:
Sergio Chouhy
2026-03-26 18:10:31 -03:00
parent 25a86d4bac
commit e618e08bdc
5 changed files with 28 additions and 36 deletions
@@ -1,14 +1,14 @@
use nssa_core::program::{
AccountPostState, BlockId, ProgramInput, ProgramOutput, read_nssa_inputs,
AccountPostState, ProgramInput, ProgramOutput, ValidityWindow, read_nssa_inputs,
};
type Instruction = (Option<BlockId>, Option<BlockId>);
type Instruction = ValidityWindow;
fn main() {
let (
ProgramInput {
pre_states,
instruction: (from_id, until_id),
instruction: validity_window,
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
@@ -24,7 +24,6 @@ fn main() {
vec![pre],
vec![AccountPostState::new(post)],
)
.try_with_validity_window((from_id, until_id))
.unwrap()
.with_validity_window(validity_window)
.write();
}
@@ -1,5 +1,5 @@
use nssa_core::program::{
AccountPostState, BlockId, ChainedCall, ProgramId, ProgramInput, ProgramOutput,
AccountPostState, ChainedCall, ProgramId, ProgramInput, ProgramOutput, ValidityWindow,
read_nssa_inputs,
};
use risc0_zkvm::serde::to_vec;
@@ -7,31 +7,23 @@ use risc0_zkvm::serde::to_vec;
/// A program that sets a validity window on its output and chains to another program with a
/// potentially different validity window.
///
/// Instruction: (`from_id`, `until_id`, `chained_program_id`, `chained_from`, `chained_until`)
/// The initial output uses [`from_id`, `until_id`) and chains to `chained_program_id` with
/// [`chained_from`, `chained_until`).
type Instruction = (
Option<BlockId>,
Option<BlockId>,
ProgramId,
Option<BlockId>,
Option<BlockId>,
);
/// Instruction: (`window`, `chained_program_id`, `chained_window`)
/// The initial output uses `window` and chains to `chained_program_id` with `chained_window`.
type Instruction = (ValidityWindow, ProgramId, ValidityWindow);
fn main() {
let (
ProgramInput {
pre_states,
instruction: (from_id, until_id, chained_program_id, chained_from, chained_until),
instruction: (validity_window, chained_program_id, chained_validity_window),
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
let [pre] = <[_; 1]>::try_from(pre_states.clone())
.unwrap_or_else(|_| panic!("Expected exactly one pre state"));
let [pre] = <[_; 1]>::try_from(pre_states.clone()).expect("Expected exactly one pre state");
let post = pre.account.clone();
let chained_instruction = to_vec(&(chained_from, chained_until)).unwrap();
let chained_instruction = to_vec(&chained_validity_window).unwrap();
let chained_call = ChainedCall {
program_id: chained_program_id,
instruction_data: chained_instruction,
@@ -44,8 +36,7 @@ fn main() {
vec![pre],
vec![AccountPostState::new(post)],
)
.try_with_validity_window((from_id, until_id))
.unwrap()
.with_validity_window(validity_window)
.with_chained_calls(vec![chained_call])
.write();
}