mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-03 14:53:50 +00:00
use validity window as intstruction type in test programs
This commit is contained in:
parent
25a86d4bac
commit
e618e08bdc
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -1957,7 +1957,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "7ab67060fc6b8ef687992d439ca0fa36e7ed17e9a0b16b25b601e8757df720de"
|
checksum = "7ab67060fc6b8ef687992d439ca0fa36e7ed17e9a0b16b25b601e8757df720de"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
"syn 1.0.109",
|
"syn 2.0.117",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2106,7 +2106,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"option-ext",
|
"option-ext",
|
||||||
"redox_users",
|
"redox_users",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2407,7 +2407,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -5951,7 +5951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d"
|
checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"itertools 0.10.5",
|
"itertools 0.11.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.117",
|
"syn 2.0.117",
|
||||||
@ -5964,7 +5964,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b"
|
checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"itertools 0.10.5",
|
"itertools 0.11.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.117",
|
"syn 2.0.117",
|
||||||
@ -6882,7 +6882,7 @@ dependencies = [
|
|||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys",
|
"linux-raw-sys",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -7810,7 +7810,7 @@ dependencies = [
|
|||||||
"getrandom 0.4.2",
|
"getrandom 0.4.2",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix",
|
"rustix",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -8963,7 +8963,7 @@ version = "0.1.11"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@ -308,9 +308,9 @@ impl Display for ValidityWindow {
|
|||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
(Some(start), Some(end)) => write!(f, "[{start}, {end})"),
|
(Some(start), Some(end)) => write!(f, "[{start}, {end})"),
|
||||||
(Some(start), None) => write!(f, "[{start}, ∞)"),
|
(Some(start), None) => write!(f, "[{start}, \u{221e})"),
|
||||||
(None, Some(end)) => write!(f, "(-∞, {end})"),
|
(None, Some(end)) => write!(f, "(-\u{221e}, {end})"),
|
||||||
(None, None) => write!(f, "(-∞, ∞)"),
|
(None, None) => write!(f, "(-\u{221e}, \u{221e})"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -341,7 +341,7 @@ pub mod tests {
|
|||||||
Commitment, Nullifier, NullifierPublicKey, NullifierSecretKey, SharedSecretKey,
|
Commitment, Nullifier, NullifierPublicKey, NullifierSecretKey, SharedSecretKey,
|
||||||
account::{Account, AccountId, AccountWithMetadata, Nonce, data::Data},
|
account::{Account, AccountId, AccountWithMetadata, Nonce, data::Data},
|
||||||
encryption::{EphemeralPublicKey, Scalar, ViewingPublicKey},
|
encryption::{EphemeralPublicKey, Scalar, ViewingPublicKey},
|
||||||
program::{BlockId, PdaSeed, ProgramId},
|
program::{BlockId, PdaSeed, ProgramId, ValidityWindow},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -3018,6 +3018,7 @@ pub mod tests {
|
|||||||
validity_window: (Option<BlockId>, Option<BlockId>),
|
validity_window: (Option<BlockId>, Option<BlockId>),
|
||||||
block_id: BlockId,
|
block_id: BlockId,
|
||||||
) {
|
) {
|
||||||
|
let validity_window: ValidityWindow = validity_window.try_into().unwrap();
|
||||||
let validity_window_program = Program::validity_window();
|
let validity_window_program = Program::validity_window();
|
||||||
let account_keys = test_public_account_keys_1();
|
let account_keys = test_public_account_keys_1();
|
||||||
let pre = AccountWithMetadata::new(Account::default(), false, account_keys.account_id());
|
let pre = AccountWithMetadata::new(Account::default(), false, account_keys.account_id());
|
||||||
@ -3037,7 +3038,7 @@ pub mod tests {
|
|||||||
PublicTransaction::new(message, witness_set)
|
PublicTransaction::new(message, witness_set)
|
||||||
};
|
};
|
||||||
let result = state.transition_from_public_transaction(&tx, block_id);
|
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), Some(e)) => s <= block_id && block_id < e,
|
||||||
(Some(s), None) => s <= block_id,
|
(Some(s), None) => s <= block_id,
|
||||||
(None, Some(e)) => block_id < e,
|
(None, Some(e)) => block_id < e,
|
||||||
@ -3067,6 +3068,7 @@ pub mod tests {
|
|||||||
validity_window: (Option<BlockId>, Option<BlockId>),
|
validity_window: (Option<BlockId>, Option<BlockId>),
|
||||||
block_id: BlockId,
|
block_id: BlockId,
|
||||||
) {
|
) {
|
||||||
|
let validity_window: ValidityWindow = validity_window.try_into().unwrap();
|
||||||
let validity_window_program = Program::validity_window();
|
let validity_window_program = Program::validity_window();
|
||||||
let account_keys = test_private_account_keys_1();
|
let account_keys = test_private_account_keys_1();
|
||||||
let pre = AccountWithMetadata::new(Account::default(), false, &account_keys.npk());
|
let pre = AccountWithMetadata::new(Account::default(), false, &account_keys.npk());
|
||||||
@ -3099,7 +3101,7 @@ pub mod tests {
|
|||||||
PrivacyPreservingTransaction::new(message, witness_set)
|
PrivacyPreservingTransaction::new(message, witness_set)
|
||||||
};
|
};
|
||||||
let result = state.transition_from_privacy_preserving_transaction(&tx, block_id);
|
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), Some(e)) => s <= block_id && block_id < e,
|
||||||
(Some(s), None) => s <= block_id,
|
(Some(s), None) => s <= block_id,
|
||||||
(None, Some(e)) => block_id < e,
|
(None, Some(e)) => block_id < e,
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
use nssa_core::program::{
|
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() {
|
fn main() {
|
||||||
let (
|
let (
|
||||||
ProgramInput {
|
ProgramInput {
|
||||||
pre_states,
|
pre_states,
|
||||||
instruction: (from_id, until_id),
|
instruction: validity_window,
|
||||||
},
|
},
|
||||||
instruction_words,
|
instruction_words,
|
||||||
) = read_nssa_inputs::<Instruction>();
|
) = read_nssa_inputs::<Instruction>();
|
||||||
@ -24,7 +24,6 @@ fn main() {
|
|||||||
vec![pre],
|
vec![pre],
|
||||||
vec![AccountPostState::new(post)],
|
vec![AccountPostState::new(post)],
|
||||||
)
|
)
|
||||||
.try_with_validity_window((from_id, until_id))
|
.with_validity_window(validity_window)
|
||||||
.unwrap()
|
|
||||||
.write();
|
.write();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use nssa_core::program::{
|
use nssa_core::program::{
|
||||||
AccountPostState, BlockId, ChainedCall, ProgramId, ProgramInput, ProgramOutput,
|
AccountPostState, ChainedCall, ProgramId, ProgramInput, ProgramOutput, ValidityWindow,
|
||||||
read_nssa_inputs,
|
read_nssa_inputs,
|
||||||
};
|
};
|
||||||
use risc0_zkvm::serde::to_vec;
|
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
|
/// A program that sets a validity window on its output and chains to another program with a
|
||||||
/// potentially different validity window.
|
/// potentially different validity window.
|
||||||
///
|
///
|
||||||
/// Instruction: (`from_id`, `until_id`, `chained_program_id`, `chained_from`, `chained_until`)
|
/// Instruction: (`window`, `chained_program_id`, `chained_window`)
|
||||||
/// The initial output uses [`from_id`, `until_id`) and chains to `chained_program_id` with
|
/// The initial output uses `window` and chains to `chained_program_id` with `chained_window`.
|
||||||
/// [`chained_from`, `chained_until`).
|
type Instruction = (ValidityWindow, ProgramId, ValidityWindow);
|
||||||
type Instruction = (
|
|
||||||
Option<BlockId>,
|
|
||||||
Option<BlockId>,
|
|
||||||
ProgramId,
|
|
||||||
Option<BlockId>,
|
|
||||||
Option<BlockId>,
|
|
||||||
);
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (
|
let (
|
||||||
ProgramInput {
|
ProgramInput {
|
||||||
pre_states,
|
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,
|
instruction_words,
|
||||||
) = read_nssa_inputs::<Instruction>();
|
) = read_nssa_inputs::<Instruction>();
|
||||||
|
|
||||||
let [pre] = <[_; 1]>::try_from(pre_states.clone())
|
let [pre] = <[_; 1]>::try_from(pre_states.clone()).expect("Expected exactly one pre state");
|
||||||
.unwrap_or_else(|_| panic!("Expected exactly one pre state"));
|
|
||||||
let post = pre.account.clone();
|
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 {
|
let chained_call = ChainedCall {
|
||||||
program_id: chained_program_id,
|
program_id: chained_program_id,
|
||||||
instruction_data: chained_instruction,
|
instruction_data: chained_instruction,
|
||||||
@ -44,8 +36,7 @@ fn main() {
|
|||||||
vec![pre],
|
vec![pre],
|
||||||
vec![AccountPostState::new(post)],
|
vec![AccountPostState::new(post)],
|
||||||
)
|
)
|
||||||
.try_with_validity_window((from_id, until_id))
|
.with_validity_window(validity_window)
|
||||||
.unwrap()
|
|
||||||
.with_chained_calls(vec![chained_call])
|
.with_chained_calls(vec![chained_call])
|
||||||
.write();
|
.write();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user