mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-04 06:13:10 +00:00
Merge pull request #113 from vacp2p/comments_commitments
added comments related to commitments
This commit is contained in:
commit
df2026f107
@ -8,6 +8,8 @@ use crate::{NullifierPublicKey, account::Account};
|
|||||||
pub struct Commitment(pub(super) [u8; 32]);
|
pub struct Commitment(pub(super) [u8; 32]);
|
||||||
|
|
||||||
impl Commitment {
|
impl Commitment {
|
||||||
|
/// 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 {
|
pub fn new(npk: &NullifierPublicKey, account: &Account) -> Self {
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
bytes.extend_from_slice(&npk.to_byte_array());
|
bytes.extend_from_slice(&npk.to_byte_array());
|
||||||
@ -34,6 +36,7 @@ pub type CommitmentSetDigest = [u8; 32];
|
|||||||
|
|
||||||
pub type MembershipProof = (usize, Vec<[u8; 32]>);
|
pub type MembershipProof = (usize, Vec<[u8; 32]>);
|
||||||
|
|
||||||
|
/// Computes the resulting digest for the given membership proof and corresponding commitment
|
||||||
pub fn compute_digest_for_path(
|
pub fn compute_digest_for_path(
|
||||||
commitment: &Commitment,
|
commitment: &Commitment,
|
||||||
proof: &MembershipProof,
|
proof: &MembershipProof,
|
||||||
|
|||||||
@ -21,6 +21,7 @@ impl CommitmentSet {
|
|||||||
self.merkle_tree.root()
|
self.merkle_tree.root()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Queries the `CommitmentSet` for a membership proof of commitment
|
||||||
pub fn get_proof_for(&self, commitment: &Commitment) -> Option<MembershipProof> {
|
pub fn get_proof_for(&self, commitment: &Commitment) -> Option<MembershipProof> {
|
||||||
let index = *self.commitments.get(commitment)?;
|
let index = *self.commitments.get(commitment)?;
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ impl CommitmentSet {
|
|||||||
.map(|path| (index, path))
|
.map(|path| (index, path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Inserts a list of commitments to the `CommitmentSet`.
|
||||||
pub(crate) fn extend(&mut self, commitments: &[Commitment]) {
|
pub(crate) fn extend(&mut self, commitments: &[Commitment]) {
|
||||||
for commitment in commitments.iter().cloned() {
|
for commitment in commitments.iter().cloned() {
|
||||||
let index = self.merkle_tree.insert(commitment.to_byte_array());
|
let index = self.merkle_tree.insert(commitment.to_byte_array());
|
||||||
@ -41,6 +43,9 @@ impl CommitmentSet {
|
|||||||
self.commitments.contains_key(commitment)
|
self.commitments.contains_key(commitment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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 {
|
pub(crate) fn with_capacity(capacity: usize) -> CommitmentSet {
|
||||||
Self {
|
Self {
|
||||||
merkle_tree: MerkleTree::with_capacity(capacity),
|
merkle_tree: MerkleTree::with_capacity(capacity),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user