diff --git a/nssa/src/state.rs b/nssa/src/state.rs index a81e5364..f525c4a2 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -14,10 +14,13 @@ use nssa_core::{ }; use crate::{ - error::NssaError, merkle_tree::MerkleTree, - privacy_preserving_transaction::PrivacyPreservingTransaction, program::Program, + error::NssaError, + merkle_tree::MerkleTree, + privacy_preserving_transaction::PrivacyPreservingTransaction, + program::Program, program_deployment_transaction::ProgramDeploymentTransaction, - public_transaction::PublicTransaction, validated_state_diff::ValidatedStateDiff, + public_transaction::PublicTransaction, + validated_state_diff::{StateDiff, ValidatedStateDiff}, }; pub const MAX_NUMBER_CHAINED_CALLS: usize = 10; @@ -188,8 +191,13 @@ impl V03State { } pub fn apply_state_diff(&mut self, diff: ValidatedStateDiff) { - let (signer_account_ids, public_diff, new_commitments, new_nullifiers, program) = - diff.into_parts(); + let StateDiff { + signer_account_ids, + public_diff, + new_commitments, + new_nullifiers, + program, + } = diff.into_state_diff(); #[expect( clippy::iter_over_hash_type, reason = "Iteration order doesn't matter here" diff --git a/nssa/src/validated_state_diff.rs b/nssa/src/validated_state_diff.rs index e4e0cacc..4ac0306a 100644 --- a/nssa/src/validated_state_diff.rs +++ b/nssa/src/validated_state_diff.rs @@ -24,17 +24,19 @@ use crate::{ state::MAX_NUMBER_CHAINED_CALLS, }; +pub struct StateDiff { + pub signer_account_ids: Vec, + pub public_diff: HashMap, + pub new_commitments: Vec, + pub new_nullifiers: Vec, + pub program: Option, +} + /// The validated output of executing or verifying a transaction, ready to be applied to the state. /// /// Can only be constructed by the transaction validation functions inside this crate, ensuring the /// diff has been cryptographically checked before any state mutation occurs. -pub struct ValidatedStateDiff { - signer_account_ids: Vec, - public_diff: HashMap, - new_commitments: Vec, - new_nullifiers: Vec, - program: Option, -} +pub struct ValidatedStateDiff(StateDiff); impl ValidatedStateDiff { pub fn from_public_transaction( @@ -243,13 +245,13 @@ impl ValidatedStateDiff { ); } - Ok(Self { + Ok(Self(StateDiff { signer_account_ids, public_diff: state_diff, new_commitments: vec![], new_nullifiers: vec![], program: None, - }) + })) } pub fn from_privacy_preserving_transaction( @@ -359,13 +361,13 @@ impl ValidatedStateDiff { .map(|(nullifier, _)| nullifier) .collect(); - Ok(Self { + Ok(Self(StateDiff { signer_account_ids, public_diff, new_commitments: message.new_commitments.clone(), new_nullifiers, program: None, - }) + })) } pub fn from_program_deployment_transaction( @@ -377,13 +379,13 @@ impl ValidatedStateDiff { if state.programs().contains_key(&program.id()) { return Err(NssaError::ProgramAlreadyExists); } - Ok(Self { + Ok(Self(StateDiff { signer_account_ids: vec![], public_diff: HashMap::new(), new_commitments: vec![], new_nullifiers: vec![], program: Some(program), - }) + })) } /// Returns the public account changes produced by this transaction. @@ -392,25 +394,11 @@ impl ValidatedStateDiff { /// to enforce that system accounts are not modified by user transactions. #[must_use] pub fn public_diff(&self) -> HashMap { - self.public_diff.clone() + self.0.public_diff.clone() } - pub(crate) fn into_parts( - self, - ) -> ( - Vec, - HashMap, - Vec, - Vec, - Option, - ) { - ( - self.signer_account_ids, - self.public_diff, - self.new_commitments, - self.new_nullifiers, - self.program, - ) + pub(crate) fn into_state_diff(self) -> StateDiff { + self.0 } } diff --git a/programs/clock/core/src/lib.rs b/programs/clock/core/src/lib.rs index 1a32f0f9..77f2ff6e 100644 --- a/programs/clock/core/src/lib.rs +++ b/programs/clock/core/src/lib.rs @@ -21,7 +21,6 @@ pub const CLOCK_PROGRAM_ACCOUNT_IDS: [AccountId; 3] = [ /// The instruction type for the Clock Program. The sequencer passes the current block timestamp. pub type Instruction = Timestamp; - /// The data stored in a clock account: `[block_id: u64 LE | timestamp: u64 LE]`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ClockAccountData { diff --git a/sequencer/core/src/lib.rs b/sequencer/core/src/lib.rs index 9d4c71c8..193edb8c 100644 --- a/sequencer/core/src/lib.rs +++ b/sequencer/core/src/lib.rs @@ -259,7 +259,10 @@ impl SequencerCore tx, - _ => unreachable!("clock_invocation always returns Public"), + NSSATransaction::PrivacyPreserving(_) + | NSSATransaction::ProgramDeployment(_) => { + unreachable!("clock_invocation always returns Public") + } }, new_block_height, new_block_timestamp,