Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added conversion from Nullifier for InputNoteCommitment #774

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0 (2024-05-14)

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
Loading