From 80505f0440aeecc92c0acda433aea7a30bbcb4e4 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Tue, 9 Sep 2025 17:03:58 -0300 Subject: [PATCH] rollback to is_authorized field --- nssa/core/src/account.rs | 1 + nssa/core/src/circuit_io.rs | 2 ++ nssa/core/src/program.rs | 1 - .../src/privacy_preserving_transaction/circuit.rs | 6 ++++-- .../privacy_preserving_transaction/transaction.rs | 1 + nssa/src/program.rs | 15 +++++++-------- nssa/src/public_transaction/transaction.rs | 1 + nssa/src/state.rs | 6 ++++++ 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/nssa/core/src/account.rs b/nssa/core/src/account.rs index 1932de0..94986c2 100644 --- a/nssa/core/src/account.rs +++ b/nssa/core/src/account.rs @@ -20,6 +20,7 @@ pub type FingerPrint = [u8; 32]; #[cfg_attr(any(feature = "host", test), derive(Debug, PartialEq, Eq))] pub struct AccountWithMetadata { pub account: Account, + pub is_authorized: bool, pub fingerprint: FingerPrint, } diff --git a/nssa/core/src/circuit_io.rs b/nssa/core/src/circuit_io.rs index da989f0..194b371 100644 --- a/nssa/core/src/circuit_io.rs +++ b/nssa/core/src/circuit_io.rs @@ -56,6 +56,7 @@ mod tests { data: b"test data".to_vec(), nonce: 18446744073709551614, }, + is_authorized: true, fingerprint: [0; 32], }, AccountWithMetadata { @@ -65,6 +66,7 @@ mod tests { data: b"test data".to_vec(), nonce: 9999999999999999999999, }, + is_authorized: false, fingerprint: [1; 32], }, ], diff --git a/nssa/core/src/program.rs b/nssa/core/src/program.rs index aa2684e..48593d8 100644 --- a/nssa/core/src/program.rs +++ b/nssa/core/src/program.rs @@ -22,7 +22,6 @@ pub struct ProgramOutput { pub fn read_nssa_inputs() -> ProgramInput { let pre_states: Vec = env::read(); let instruction_words: InstructionData = env::read(); - let authorized_fingerprints: Vec = env::read(); let instruction = T::deserialize(&mut Deserializer::new(instruction_words.as_ref())).unwrap(); ProgramInput { pre_states, diff --git a/nssa/src/privacy_preserving_transaction/circuit.rs b/nssa/src/privacy_preserving_transaction/circuit.rs index e681c78..ba7647c 100644 --- a/nssa/src/privacy_preserving_transaction/circuit.rs +++ b/nssa/src/privacy_preserving_transaction/circuit.rs @@ -72,14 +72,12 @@ fn execute_and_prove_program( program: &Program, pre_states: &[AccountWithMetadata], instruction_data: &InstructionData, - authorized_fingerprints: &[FingerPrint], ) -> Result { // Write inputs to the program let mut env_builder = ExecutorEnv::builder(); Program::write_inputs( pre_states, instruction_data, - authorized_fingerprints, &mut env_builder, )?; let env = env_builder.build().unwrap(); @@ -118,11 +116,13 @@ mod tests { balance: 100, ..Account::default() }, + is_authorized: true, fingerprint: [0; 32], }; let recipient = AccountWithMetadata { account: Account::default(), + is_authorized: false, fingerprint: [1; 32], }; @@ -187,6 +187,7 @@ mod tests { nonce: 0xdeadbeef, ..Account::default() }, + is_authorized: true, fingerprint: [0; 32], }; let sender_keys = test_private_account_keys_1(); @@ -195,6 +196,7 @@ mod tests { let recipient = AccountWithMetadata { account: Account::default(), + is_authorized: false, fingerprint: [1; 32], }; let balance_to_move: u128 = 37; diff --git a/nssa/src/privacy_preserving_transaction/transaction.rs b/nssa/src/privacy_preserving_transaction/transaction.rs index c782d01..ee8eeba 100644 --- a/nssa/src/privacy_preserving_transaction/transaction.rs +++ b/nssa/src/privacy_preserving_transaction/transaction.rs @@ -92,6 +92,7 @@ impl PrivacyPreservingTransaction { .iter() .map(|address| AccountWithMetadata { account: state.get_account_by_address(address), + is_authorized: signer_addresses.contains(address), fingerprint: *address.value(), }) .collect(); diff --git a/nssa/src/program.rs b/nssa/src/program.rs index a40fdf9..0c05902 100644 --- a/nssa/src/program.rs +++ b/nssa/src/program.rs @@ -33,11 +33,10 @@ impl Program { &self, pre_states: &[AccountWithMetadata], instruction_data: &InstructionData, - authorized_fingerprints: &[FingerPrint] ) -> Result, NssaError> { // Write inputs to the program let mut env_builder = ExecutorEnv::builder(); - Self::write_inputs(pre_states, instruction_data, authorized_fingerprints, &mut env_builder)?; + Self::write_inputs(pre_states, instruction_data, &mut env_builder)?; let env = env_builder.build().unwrap(); // Execute the program (without proving) @@ -59,13 +58,11 @@ impl Program { pub(crate) fn write_inputs( pre_states: &[AccountWithMetadata], instruction_data: &[u32], - authorized_fingerprints: &[FingerPrint], env_builder: &mut ExecutorEnvBuilder, ) -> Result<(), NssaError> { let pre_states = pre_states.to_vec(); - let authorized_fingerprints = authorized_fingerprints.to_vec(); env_builder - .write(&(pre_states, instruction_data, authorized_fingerprints)) + .write(&(pre_states, instruction_data)) .map_err(|e| NssaError::ProgramWriteInputFailed(e.to_string()))?; Ok(()) } @@ -176,11 +173,13 @@ mod tests { balance: 77665544332211, ..Account::default() }, - fingerprint: [0; 32] + is_authorized: true, + fingerprint: [0; 32], }; let recipient = AccountWithMetadata { account: Account::default(), - fingerprint: [1; 32] + is_authorized: false, + fingerprint: [1; 32], }; let expected_sender_post = Account { @@ -192,7 +191,7 @@ mod tests { ..Account::default() }; let [sender_post, recipient_post] = program - .execute(&[sender, recipient], &instruction_data, &[]) + .execute(&[sender, recipient], &instruction_data) .unwrap() .try_into() .unwrap(); diff --git a/nssa/src/public_transaction/transaction.rs b/nssa/src/public_transaction/transaction.rs index bce7eaa..f3a8ed6 100644 --- a/nssa/src/public_transaction/transaction.rs +++ b/nssa/src/public_transaction/transaction.rs @@ -93,6 +93,7 @@ impl PublicTransaction { .iter() .map(|address| AccountWithMetadata { account: state.get_account_by_address(address), + is_authorized: signer_addresses.contains(address), fingerprint: *address.value() }) .collect(); diff --git a/nssa/src/state.rs b/nssa/src/state.rs index 5ed4252..8662323 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -778,6 +778,7 @@ pub mod tests { ) -> PrivacyPreservingTransaction { let sender = AccountWithMetadata { account: state.get_account_by_address(&sender_keys.address()), + is_authorized: true, fingerprint: *sender_keys.address().value(), }; @@ -785,6 +786,7 @@ pub mod tests { let recipient = AccountWithMetadata { account: Account::default(), + is_authorized: false, fingerprint: recipient_keys.npk().to_byte_array(), }; @@ -827,10 +829,12 @@ pub mod tests { let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account); let sender_pre = AccountWithMetadata { account: sender_private_account.clone(), + is_authorized: true, fingerprint: sender_keys.npk().to_byte_array(), }; let recipient_pre = AccountWithMetadata { account: Account::default(), + is_authorized: false, fingerprint: recipient_keys.npk().to_byte_array(), }; @@ -887,10 +891,12 @@ pub mod tests { let sender_commitment = Commitment::new(&sender_keys.npk(), sender_private_account); let sender_pre = AccountWithMetadata { account: sender_private_account.clone(), + is_authorized: true, fingerprint: sender_keys.npk().to_byte_array(), }; let recipient_pre = AccountWithMetadata { account: state.get_account_by_address(recipient_address), + is_authorized: false, fingerprint: *recipient_address.value(), };