From bfe38b012ef691eeaf5339d30570bb0b020ecf98 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Sat, 22 Nov 2025 16:39:34 -0300 Subject: [PATCH] small refactor --- .../src/bin/privacy_preserving_circuit.rs | 2 +- .../privacy_preserving_transaction/circuit.rs | 27 +++++++++++++++---- nssa/src/program.rs | 21 --------------- nssa/src/state.rs | 12 +++------ 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/nssa/program_methods/guest/src/bin/privacy_preserving_circuit.rs b/nssa/program_methods/guest/src/bin/privacy_preserving_circuit.rs index 888cb5b..a4ed28b 100644 --- a/nssa/program_methods/guest/src/bin/privacy_preserving_circuit.rs +++ b/nssa/program_methods/guest/src/bin/privacy_preserving_circuit.rs @@ -34,7 +34,7 @@ fn main() { } for i in 0..(program_outputs.len() - 1) { - let Some(chained_call) = program_outputs[i].chained_call.clone() else { + let Some(chained_call) = &program_outputs[i].chained_call else { panic!("Expected chained call"); }; diff --git a/nssa/src/privacy_preserving_transaction/circuit.rs b/nssa/src/privacy_preserving_transaction/circuit.rs index 2b5c655..bd786b1 100644 --- a/nssa/src/privacy_preserving_transaction/circuit.rs +++ b/nssa/src/privacy_preserving_transaction/circuit.rs @@ -8,11 +8,7 @@ use nssa_core::{ }; use risc0_zkvm::{ExecutorEnv, InnerReceipt, Receipt, default_prover}; -use crate::{ - error::NssaError, - program::{Program, ProgramWithDependencies}, - state::MAX_NUMBER_CHAINED_CALLS, -}; +use crate::{error::NssaError, program::Program, state::MAX_NUMBER_CHAINED_CALLS}; use crate::program_methods::{PRIVACY_PRESERVING_CIRCUIT_ELF, PRIVACY_PRESERVING_CIRCUIT_ID}; @@ -20,6 +16,27 @@ use crate::program_methods::{PRIVACY_PRESERVING_CIRCUIT_ELF, PRIVACY_PRESERVING_ #[derive(Debug, Clone, PartialEq, Eq)] pub struct Proof(pub(crate) Vec); +pub struct ProgramWithDependencies { + pub program: Program, + // TODO: this will have a copy of each dependency bytecode in each program + pub dependencies: HashMap, +} + +impl ProgramWithDependencies { + pub fn new(program: Program, dependencies: HashMap) -> Self { + Self { + program, + dependencies, + } + } +} + +impl From for ProgramWithDependencies { + fn from(program: Program) -> Self { + ProgramWithDependencies::new(program, HashMap::new()) + } +} + /// Generates a proof of the execution of a NSSA program inside the privacy preserving execution /// circuit pub fn execute_and_prove( diff --git a/nssa/src/program.rs b/nssa/src/program.rs index bca6fb9..91fada4 100644 --- a/nssa/src/program.rs +++ b/nssa/src/program.rs @@ -98,27 +98,6 @@ impl Program { } } -pub struct ProgramWithDependencies { - pub program: Program, - // TODO: this will have a copy of each dependency bytecode in each program - pub dependencies: HashMap, -} - -impl ProgramWithDependencies { - pub fn new(program: Program, dependencies: HashMap) -> Self { - Self { - program, - dependencies, - } - } -} - -impl From for ProgramWithDependencies { - fn from(program: Program) -> Self { - ProgramWithDependencies::new(program, HashMap::new()) - } -} - // TODO: Testnet only. Refactor to prevent compilation on mainnet. impl Program { pub fn pinata() -> Self { diff --git a/nssa/src/state.rs b/nssa/src/state.rs index 726ff77..0f83a15 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -244,15 +244,9 @@ pub mod tests { use std::collections::HashMap; use crate::{ - Address, PublicKey, PublicTransaction, V02State, - error::NssaError, - execute_and_prove, - privacy_preserving_transaction::{ - PrivacyPreservingTransaction, circuit, message::Message, witness_set::WitnessSet, - }, - program::{Program, ProgramWithDependencies}, - public_transaction, - signature::PrivateKey, + error::NssaError, execute_and_prove, privacy_preserving_transaction::{ + circuit::{self, ProgramWithDependencies}, message::Message, witness_set::WitnessSet, PrivacyPreservingTransaction + }, program::Program, public_transaction, signature::PrivateKey, Address, PublicKey, PublicTransaction, V02State }; use nssa_core::{