Merge branch 'main' into marvin/nonce

This commit is contained in:
jonesmarvin8
2026-03-17 16:45:08 -04:00
215 changed files with 6869 additions and 5994 deletions
+3
View File
@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2024"
license = { workspace = true }
[lints]
workspace = true
[dependencies]
nssa.workspace = true
nssa_core.workspace = true
@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2024"
license = { workspace = true }
[lints]
workspace = true
[build-dependencies]
risc0-build.workspace = true
@@ -4,6 +4,9 @@ version = "0.1.0"
edition = "2024"
license = { workspace = true }
[lints]
workspace = true
[dependencies]
nssa_core.workspace = true
@@ -36,9 +36,7 @@ fn main() {
// Fail if the input account is not authorized
// The `is_authorized` field will be correctly populated or verified by the system if
// authorization is provided.
if !pre_state.is_authorized {
panic!("Missing required authorization");
}
assert!(pre_state.is_authorized, "Missing required authorization");
// ####
// Construct the post state account values
@@ -1,5 +1,5 @@
use nssa_core::{
account::{Account, AccountWithMetadata},
account::{Account, AccountWithMetadata, Data},
program::{
AccountPostState, DEFAULT_PROGRAM_ID, ProgramInput, read_nssa_inputs, write_nssa_outputs,
},
@@ -21,10 +21,11 @@ use nssa_core::{
// In case an input account is uninitialized, the program will claim it when
// producing the post-state.
type Instruction = (u8, Vec<u8>);
const WRITE_FUNCTION_ID: u8 = 0;
const MOVE_DATA_FUNCTION_ID: u8 = 1;
type Instruction = (u8, Vec<u8>);
fn build_post_state(post_account: Account) -> AccountPostState {
if post_account.program_owner == DEFAULT_PROGRAM_ID {
// This produces a claim request
@@ -35,12 +36,12 @@ fn build_post_state(post_account: Account) -> AccountPostState {
}
}
fn write(pre_state: AccountWithMetadata, greeting: Vec<u8>) -> AccountPostState {
fn write(pre_state: AccountWithMetadata, greeting: &[u8]) -> AccountPostState {
// Construct the post state account values
let post_account = {
let mut this = pre_state.account.clone();
let mut this = pre_state.account;
let mut bytes = this.data.into_inner();
bytes.extend_from_slice(&greeting);
bytes.extend_from_slice(greeting);
this.data = bytes
.try_into()
.expect("Data should fit within the allowed limits");
@@ -50,21 +51,18 @@ fn write(pre_state: AccountWithMetadata, greeting: Vec<u8>) -> AccountPostState
build_post_state(post_account)
}
fn move_data(
from_pre: &AccountWithMetadata,
to_pre: &AccountWithMetadata,
) -> Vec<AccountPostState> {
fn move_data(from_pre: AccountWithMetadata, to_pre: AccountWithMetadata) -> Vec<AccountPostState> {
// Construct the post state account values
let from_data: Vec<u8> = from_pre.account.data.clone().into();
let from_post = {
let mut this = from_pre.account.clone();
this.data = Default::default();
let mut this = from_pre.account;
this.data = Data::default();
build_post_state(this)
};
let to_post = {
let mut this = to_pre.account.clone();
let mut this = to_pre.account;
let mut bytes = this.data.into_inner();
bytes.extend_from_slice(&from_data);
this.data = bytes
@@ -88,11 +86,11 @@ fn main() {
let post_states = match (pre_states.as_slice(), function_id, data.len()) {
([account_pre], WRITE_FUNCTION_ID, _) => {
let post = write(account_pre.clone(), data);
let post = write(account_pre.clone(), &data);
vec![post]
}
([account_from_pre, account_to_pre], MOVE_DATA_FUNCTION_ID, 0) => {
move_data(account_from_pre, account_to_pre)
move_data(account_from_pre.clone(), account_to_pre.clone())
}
_ => panic!("invalid params"),
};
@@ -29,7 +29,7 @@ fn main() {
let (
ProgramInput {
pre_states,
instruction: _,
instruction: (),
},
instruction_data,
) = read_nssa_inputs::<()>();
@@ -34,14 +34,13 @@ fn main() {
let (
ProgramInput {
pre_states,
instruction: _,
instruction: (),
},
instruction_data,
) = read_nssa_inputs::<()>();
// Unpack the input account pre state
let [pre_state] = pre_states
.clone()
.try_into()
.unwrap_or_else(|_| panic!("Input pre states should consist of a single account"));
@@ -48,7 +48,7 @@ async fn main() {
let hello_world_bytecode: Vec<u8> = std::fs::read(hello_world_path).unwrap();
let hello_world = Program::new(hello_world_bytecode).unwrap();
let dependencies: HashMap<ProgramId, Program> =
[(hello_world.id(), hello_world)].into_iter().collect();
std::iter::once((hello_world.id(), hello_world)).collect();
let program_with_dependencies = ProgramWithDependencies::new(simple_tail_call, dependencies);
let accounts = vec![PrivacyPreservingAccount::PrivateOwned(account_id)];
@@ -1,3 +1,8 @@
#![expect(
clippy::print_stdout,
reason = "This is an example program, it's fine to print to stdout"
)]
use nssa::{
AccountId, PublicTransaction,
program::Program,
@@ -19,13 +19,14 @@ use wallet::{PrivacyPreservingAccount, WalletCore};
// methods/guest/target/riscv32im-risc0-zkvm-elf/docker/hello_world_with_move_function.bin \
// write-public Ds8q5PjLcKwwV97Zi7duhRVF9uwA2PuYMoLL7FwCzsXE Hola
type Instruction = (u8, Vec<u8>);
const WRITE_FUNCTION_ID: u8 = 0;
const MOVE_DATA_FUNCTION_ID: u8 = 1;
type Instruction = (u8, Vec<u8>);
#[derive(Parser, Debug)]
struct Cli {
/// Path to program binary
/// Path to program binary.
program_path: String,
#[command(subcommand)]
@@ -34,7 +35,7 @@ struct Cli {
#[derive(Subcommand, Debug)]
enum Command {
/// Write instruction into one account
/// Write instruction into one account.
WritePublic {
account_id: String,
greeting: String,
@@ -43,7 +44,7 @@ enum Command {
account_id: String,
greeting: String,
},
/// Move data between two accounts
/// Move data between two accounts.
MoveDataPublicToPublic {
from: String,
to: String,
@@ -148,5 +149,5 @@ async fn main() {
.await
.unwrap();
}
};
}
}