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

Implemented OutputNote::hash #782

Merged
merged 2 commits into from
Jul 2, 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
17 changes: 15 additions & 2 deletions objects/src/notes/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,26 @@ impl NoteHeader {
///
/// > hash(NOTE_ID || NOTE_METADATA)
///
/// This value is used primarily for authenticating notes consumed when the are consumed
/// This value is used primarily for authenticating notes consumed when they are consumed
/// in a transaction.
pub fn hash(&self) -> Digest {
Hasher::merge(&[self.id().inner(), Word::from(self.metadata()).into()])
compute_note_hash(self.id(), self.metadata())
}
}

// UTILITIES
// ================================================================================================

/// Returns a commitment to the note and its metadata.
///
/// > hash(NOTE_ID || NOTE_METADATA)
///
/// This value is used primarily for authenticating notes consumed when they are consumed
/// in a transaction.
pub fn compute_note_hash(id: NoteId, metadata: &NoteMetadata) -> Digest {
Hasher::merge(&[id.inner(), Word::from(metadata).into()])
}

// CONVERSIONS FROM NOTE HEADER
// ================================================================================================

Expand Down
2 changes: 1 addition & 1 deletion objects/src/notes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod details;
pub use details::NoteDetails;

mod header;
pub use header::NoteHeader;
pub use header::{compute_note_hash, NoteHeader};

mod inputs;
pub use inputs::NoteInputs;
Expand Down
10 changes: 8 additions & 2 deletions objects/src/transaction/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use vm_processor::DeserializationError;

use crate::{
accounts::AccountStub,
notes::{Note, NoteAssets, NoteHeader, NoteId, NoteMetadata, PartialNote},
notes::{compute_note_hash, Note, NoteAssets, NoteHeader, NoteId, NoteMetadata, PartialNote},
Digest, Felt, Hasher, TransactionOutputError, Word, MAX_OUTPUT_NOTES_PER_TX,
};

// TRANSACTION OUTPUTS
// ================================================================================================

Expand Down Expand Up @@ -205,6 +204,13 @@ impl OutputNote {
_ => self.clone(),
}
}

/// Returns a commitment to the note and its metadata.
///
/// > hash(NOTE_ID || NOTE_METADATA)
pub fn hash(&self) -> Digest {
compute_note_hash(self.id(), self.metadata())
}
}

// CONVERSIONS
Expand Down
Loading