use validity window as intstruction type in test programs

This commit is contained in:
Sergio Chouhy 2026-03-26 17:29:29 -03:00
parent 25a86d4bac
commit e618e08bdc
5 changed files with 28 additions and 36 deletions

16
Cargo.lock generated
View File

@ -1957,7 +1957,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ab67060fc6b8ef687992d439ca0fa36e7ed17e9a0b16b25b601e8757df720de"
dependencies = [
"data-encoding",
"syn 1.0.109",
"syn 2.0.117",
]
[[package]]
@ -2106,7 +2106,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@ -2407,7 +2407,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@ -5951,7 +5951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d"
dependencies = [
"anyhow",
"itertools 0.10.5",
"itertools 0.11.0",
"proc-macro2",
"quote",
"syn 2.0.117",
@ -5964,7 +5964,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b"
dependencies = [
"anyhow",
"itertools 0.10.5",
"itertools 0.11.0",
"proc-macro2",
"quote",
"syn 2.0.117",
@ -6882,7 +6882,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@ -7810,7 +7810,7 @@ dependencies = [
"getrandom 0.4.2",
"once_cell",
"rustix",
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]
@ -8963,7 +8963,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.61.2",
]
[[package]]

View File

@ -308,9 +308,9 @@ impl Display for ValidityWindow {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.0 {
(Some(start), Some(end)) => write!(f, "[{start}, {end})"),
(Some(start), None) => write!(f, "[{start}, )"),
(None, Some(end)) => write!(f, "(-, {end})"),
(None, None) => write!(f, "(-∞, ∞)"),
(Some(start), None) => write!(f, "[{start}, \u{221e})"),
(None, Some(end)) => write!(f, "(-\u{221e}, {end})"),
(None, None) => write!(f, "(-\u{221e}, \u{221e})"),
}
}
}

View File

@ -341,7 +341,7 @@ pub mod tests {
Commitment, Nullifier, NullifierPublicKey, NullifierSecretKey, SharedSecretKey,
account::{Account, AccountId, AccountWithMetadata, Nonce, data::Data},
encryption::{EphemeralPublicKey, Scalar, ViewingPublicKey},
program::{BlockId, PdaSeed, ProgramId},
program::{BlockId, PdaSeed, ProgramId, ValidityWindow},
};
use crate::{
@ -3018,6 +3018,7 @@ pub mod tests {
validity_window: (Option<BlockId>, Option<BlockId>),
block_id: BlockId,
) {
let validity_window: ValidityWindow = validity_window.try_into().unwrap();
let validity_window_program = Program::validity_window();
let account_keys = test_public_account_keys_1();
let pre = AccountWithMetadata::new(Account::default(), false, account_keys.account_id());
@ -3037,7 +3038,7 @@ pub mod tests {
PublicTransaction::new(message, witness_set)
};
let result = state.transition_from_public_transaction(&tx, block_id);
let is_inside_validity_window = match validity_window {
let is_inside_validity_window = match (validity_window.start(), validity_window.end()) {
(Some(s), Some(e)) => s <= block_id && block_id < e,
(Some(s), None) => s <= block_id,
(None, Some(e)) => block_id < e,
@ -3067,6 +3068,7 @@ pub mod tests {
validity_window: (Option<BlockId>, Option<BlockId>),
block_id: BlockId,
) {
let validity_window: ValidityWindow = validity_window.try_into().unwrap();
let validity_window_program = Program::validity_window();
let account_keys = test_private_account_keys_1();
let pre = AccountWithMetadata::new(Account::default(), false, &account_keys.npk());
@ -3099,7 +3101,7 @@ pub mod tests {
PrivacyPreservingTransaction::new(message, witness_set)
};
let result = state.transition_from_privacy_preserving_transaction(&tx, block_id);
let is_inside_validity_window = match validity_window {
let is_inside_validity_window = match (validity_window.start(), validity_window.end()) {
(Some(s), Some(e)) => s <= block_id && block_id < e,
(Some(s), None) => s <= block_id,
(None, Some(e)) => block_id < e,

View File

@ -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();
}

View File

@ -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();
}