From 5eeb92538409c94bb3adb7346fa9e1dbbd2a9333 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Fri, 5 Sep 2025 16:21:46 -0400 Subject: [PATCH 1/6] added comments related to commitments --- nssa/core/src/commitment.rs | 4 ++++ nssa/src/state.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/nssa/core/src/commitment.rs b/nssa/core/src/commitment.rs index bc22c8f..8e66941 100644 --- a/nssa/core/src/commitment.rs +++ b/nssa/core/src/commitment.rs @@ -8,6 +8,8 @@ use crate::{NullifierPublicKey, account::Account}; pub struct Commitment(pub(super) [u8; 32]); impl Commitment { + //generate new commitment to a private account owned by user with npk. + //hash(npk || program_owner || balance || nonce || data) pub fn new(npk: &NullifierPublicKey, account: &Account) -> Self { let mut bytes = Vec::new(); bytes.extend_from_slice(&npk.to_byte_array()); @@ -34,6 +36,8 @@ pub type CommitmentSetDigest = [u8; 32]; pub type MembershipProof = (usize, Vec<[u8; 32]>); +/// computes the resulting digest/root hash for a membership proof +/// and its corresponding commitment. pub fn compute_digest_for_path( commitment: &Commitment, proof: &MembershipProof, diff --git a/nssa/src/state.rs b/nssa/src/state.rs index f975804..e27b00c 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -21,6 +21,7 @@ impl CommitmentSet { self.merkle_tree.root() } + /// queries the CommitmentSet for membership proof of commitment pub fn get_proof_for(&self, commitment: &Commitment) -> Option { let index = *self.commitments.get(commitment)?; @@ -29,6 +30,7 @@ impl CommitmentSet { .map(|path| (index, path)) } + /// appends a list of commitments to the CommitmentSet. pub(crate) fn extend(&mut self, commitments: &[Commitment]) { for commitment in commitments.iter().cloned() { let index = self.merkle_tree.insert(commitment.to_byte_array()); @@ -41,6 +43,9 @@ impl CommitmentSet { self.commitments.contains_key(commitment) } + /// Initializes a CommitmentState with a given capacity. + /// if capacity is not a power_of_two, then capacity is taken + /// to be the next power_of_two. pub(crate) fn with_capacity(capacity: usize) -> CommitmentSet { Self { merkle_tree: MerkleTree::with_capacity(capacity), From 5dea03027aa83e3d7beea5fcc44bcc45dca4556f Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Fri, 5 Sep 2025 16:38:34 -0400 Subject: [PATCH 2/6] minor corrections --- nssa/core/src/commitment.rs | 7 +++---- nssa/src/state.rs | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/nssa/core/src/commitment.rs b/nssa/core/src/commitment.rs index 8e66941..760aa91 100644 --- a/nssa/core/src/commitment.rs +++ b/nssa/core/src/commitment.rs @@ -8,8 +8,8 @@ use crate::{NullifierPublicKey, account::Account}; pub struct Commitment(pub(super) [u8; 32]); impl Commitment { - //generate new commitment to a private account owned by user with npk. - //hash(npk || program_owner || balance || nonce || data) + // Generates the commitment to a private account owned by user for npk: + // hash(npk || program_owner || balance || nonce || data) pub fn new(npk: &NullifierPublicKey, account: &Account) -> Self { let mut bytes = Vec::new(); bytes.extend_from_slice(&npk.to_byte_array()); @@ -36,8 +36,7 @@ pub type CommitmentSetDigest = [u8; 32]; pub type MembershipProof = (usize, Vec<[u8; 32]>); -/// computes the resulting digest/root hash for a membership proof -/// and its corresponding commitment. +/// Computes the resulting digest for the given membership proof and corresponding commitment pub fn compute_digest_for_path( commitment: &Commitment, proof: &MembershipProof, diff --git a/nssa/src/state.rs b/nssa/src/state.rs index e27b00c..77495e9 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -21,7 +21,7 @@ impl CommitmentSet { self.merkle_tree.root() } - /// queries the CommitmentSet for membership proof of commitment + /// Queries the CommitmentSet for a membership proof of commitment pub fn get_proof_for(&self, commitment: &Commitment) -> Option { let index = *self.commitments.get(commitment)?; @@ -30,7 +30,7 @@ impl CommitmentSet { .map(|path| (index, path)) } - /// appends a list of commitments to the CommitmentSet. + /// Inserts a list of commitments to the CommitmentSet. pub(crate) fn extend(&mut self, commitments: &[Commitment]) { for commitment in commitments.iter().cloned() { let index = self.merkle_tree.insert(commitment.to_byte_array()); @@ -44,7 +44,7 @@ impl CommitmentSet { } /// Initializes a CommitmentState with a given capacity. - /// if capacity is not a power_of_two, then capacity is taken + /// If the capacity is not a power_of_two, then capacity is taken /// to be the next power_of_two. pub(crate) fn with_capacity(capacity: usize) -> CommitmentSet { Self { From 49019eaee270e880f4ae98dfd85923fe59393f9c Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Fri, 5 Sep 2025 20:48:11 -0400 Subject: [PATCH 3/6] Update nssa/core/src/commitment.rs Co-authored-by: Sergio Chouhy <41742639+schouhy@users.noreply.github.com> --- nssa/core/src/commitment.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nssa/core/src/commitment.rs b/nssa/core/src/commitment.rs index 760aa91..1eb8c98 100644 --- a/nssa/core/src/commitment.rs +++ b/nssa/core/src/commitment.rs @@ -8,8 +8,8 @@ use crate::{NullifierPublicKey, account::Account}; pub struct Commitment(pub(super) [u8; 32]); impl Commitment { - // Generates the commitment to a private account owned by user for npk: - // hash(npk || program_owner || balance || nonce || data) + /// Generates the commitment to a private account owned by user for npk: + /// SHA256(npk || program_owner || balance || nonce || data) pub fn new(npk: &NullifierPublicKey, account: &Account) -> Self { let mut bytes = Vec::new(); bytes.extend_from_slice(&npk.to_byte_array()); From 4ae2af21a578f73ddc0fe7cca340ca89ca3792c6 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Fri, 5 Sep 2025 20:48:26 -0400 Subject: [PATCH 4/6] Update nssa/src/state.rs Co-authored-by: Sergio Chouhy <41742639+schouhy@users.noreply.github.com> --- nssa/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nssa/src/state.rs b/nssa/src/state.rs index 77495e9..1817445 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -43,7 +43,7 @@ impl CommitmentSet { self.commitments.contains_key(commitment) } - /// Initializes a CommitmentState with a given capacity. + /// Initializes an empty `CommitmentSet` with a given capacity. /// If the capacity is not a power_of_two, then capacity is taken /// to be the next power_of_two. pub(crate) fn with_capacity(capacity: usize) -> CommitmentSet { From 4a0a99e26486b72493910ae933c06661aec48c8f Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Fri, 5 Sep 2025 20:48:47 -0400 Subject: [PATCH 5/6] Update nssa/src/state.rs Co-authored-by: Sergio Chouhy <41742639+schouhy@users.noreply.github.com> --- nssa/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nssa/src/state.rs b/nssa/src/state.rs index 1817445..8641e14 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -30,7 +30,7 @@ impl CommitmentSet { .map(|path| (index, path)) } - /// Inserts a list of commitments to the CommitmentSet. + /// Inserts a list of commitments to the `CommitmentSet`. pub(crate) fn extend(&mut self, commitments: &[Commitment]) { for commitment in commitments.iter().cloned() { let index = self.merkle_tree.insert(commitment.to_byte_array()); From c055941738f8b9d9263c5e3262b16e7865e59c33 Mon Sep 17 00:00:00 2001 From: jonesmarvin8 <83104039+jonesmarvin8@users.noreply.github.com> Date: Fri, 5 Sep 2025 20:48:56 -0400 Subject: [PATCH 6/6] Update nssa/src/state.rs Co-authored-by: Sergio Chouhy <41742639+schouhy@users.noreply.github.com> --- nssa/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nssa/src/state.rs b/nssa/src/state.rs index 8641e14..f980370 100644 --- a/nssa/src/state.rs +++ b/nssa/src/state.rs @@ -21,7 +21,7 @@ impl CommitmentSet { self.merkle_tree.root() } - /// Queries the CommitmentSet for a membership proof of commitment + /// Queries the `CommitmentSet` for a membership proof of commitment pub fn get_proof_for(&self, commitment: &Commitment) -> Option { let index = *self.commitments.get(commitment)?;