Skip to content

Commit

Permalink
feat: added conversion from Nullifier for InputNoteCommitment (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
polydez authored and bobbinth committed Jul 4, 2024
1 parent f432ee1 commit 053eca0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Added ability for users to set the aux field when creating a note (#752).
- Created `get_serial_number` procedure to get the serial num of the currently processed note (#760).
- [BREAKING] Added support for input notes with delayed verification of inclusion proofs (#724, #732, #759, #770, #772).
- [BREAKING] Added support for conversion from `Nullifier` to `InputNoteCommitment`, commitment header return reference (#774).

## 0.3.1 (2024-06-12)
* Replaced `cargo-make` with just `make` for running tasks (#696).
Expand Down
6 changes: 3 additions & 3 deletions objects/src/transaction/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl TransactionInputs {
/// The commitment is composed of:
///
/// - nullifier, which prevents double spend and provides unlinkability.
/// - an optional note_id, which allows for delayed note authentication.
/// - an optional note hash, which allows for delayed note authentication.
pub trait ToInputNoteCommitments {
fn nullifier(&self) -> Nullifier;
fn note_hash(&self) -> Option<Digest>;
Expand Down Expand Up @@ -304,11 +304,11 @@ fn build_input_note_commitment<T: ToInputNoteCommitments>(notes: &[T]) -> Digest
let mut elements: Vec<Felt> = Vec::with_capacity(notes.len() * 2);
for commitment_data in notes {
let nullifier = commitment_data.nullifier();
let zero_or_notehash =
let zero_or_note_hash =
&commitment_data.note_hash().map_or(Word::default(), |note_id| note_id.into());

elements.extend_from_slice(nullifier.as_elements());
elements.extend_from_slice(zero_or_notehash);
elements.extend_from_slice(zero_or_note_hash);
}
Hasher::hash_elements(&elements)
}
Expand Down
22 changes: 20 additions & 2 deletions objects/src/transaction/proven_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ impl ProvenTransaction {
self.block_ref
}

/// Returns an iterator of the headers of unauthenticated input notes in this transaction.
pub fn get_unauthenticated_notes(&self) -> impl Iterator<Item = &NoteHeader> {
self.input_notes.iter().filter_map(|note| note.header())
}

/// Returns an iterator over the nullifiers of all input notes in this transaction.
///
/// This includes both authenticated and unauthenticated notes.
pub fn get_nullifiers(&self) -> impl Iterator<Item = Nullifier> + '_ {
self.input_notes.iter().map(InputNoteCommitment::nullifier)
}

// HELPER METHODS
// --------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -394,8 +406,8 @@ impl InputNoteCommitment {
self.nullifier
}

pub fn header(&self) -> Option<NoteHeader> {
self.header
pub fn header(&self) -> Option<&NoteHeader> {
self.header.as_ref()
}
}

Expand All @@ -420,6 +432,12 @@ impl From<&InputNote> for InputNoteCommitment {
}
}

impl From<Nullifier> for InputNoteCommitment {
fn from(nullifier: Nullifier) -> Self {
Self { nullifier, header: None }
}
}

impl ToInputNoteCommitments for InputNoteCommitment {
fn nullifier(&self) -> Nullifier {
self.nullifier
Expand Down

0 comments on commit 053eca0

Please sign in to comment.