Skip to content

Commit

Permalink
refactor!: replace Note::compute_note_hash with Note::compute_note_co…
Browse files Browse the repository at this point in the history
…ntent_hash (AztecProtocol#4342)

Part of AztecProtocol#4199.

Discussions with @sirasistant and others lead to updating the `compute_note_hash` function name to `compute_note_content_hash` to avoid confusion with the actual note hash.
  • Loading branch information
LHerskind committed Jan 31, 2024
1 parent 13f709b commit 8368659
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 57 deletions.
8 changes: 2 additions & 6 deletions boxes/token/src/contracts/src/types/token_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,9 @@ impl Deserialize<TOKEN_NOTE_LEN> for TokenNote {
}

impl NoteInterface for TokenNote {
fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
self.amount.value as Field,
self.owner.to_field(),
self.randomness,
],0)
pedersen_hash(self.serialize(), 0)
}

// docs:start:nullifier
Expand Down
7 changes: 2 additions & 5 deletions boxes/token/src/contracts/src/types/transparent_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ impl Deserialize<TRANSPARENT_NOTE_LEN> for TransparentNote {

impl NoteInterface for TransparentNote {

fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
self.amount,
self.secret_hash,
],0)
pedersen_hash(self.serialize(), 0)
}

fn compute_nullifier(self, _context: &mut PrivateContext) -> Field {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sequenceDiagram
Set->>LifeCycle: create_note(derived_slot, note)
LifeCycle->>LifeCycle: note.header = NoteHeader { contract_address, <br> storage_slot: derived_slot, nonce: 0, is_transient: true }
LifeCycle->>Utils: compute_inner_note_hash(note)
Utils->>TokenNote: compute_note_hash(note)
Utils->>TokenNote: note.compute_note_content_hash()
TokenNote->>Utils: note_hash = H(amount, to, randomness)
Utils->>NoteHash: compute_inner_hash(derived_slot, note_hash)
NoteHash->>LifeCycle: inner_note_hash = H(derived_slot, note_hash)
Expand Down
25 changes: 25 additions & 0 deletions docs/docs/misc/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ keywords: [sandbox, cli, aztec, notes, migration, updating, upgrading]

Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them.

## TBD

### `Note::compute_note_hash` renamed to `Note::compute_note_content_hash`
The `compute_note_hash` function in of the `Note` trait has been renamed to `compute_note_content_hash` to avoid being confused with the actual note hash.

Before:
```rust
impl NoteInterface for CardNote {
fn compute_note_hash(self) -> Field {
pedersen_hash([
self.owner.to_field(),
], 0)
}
```

Now:
```rust
impl NoteInterface for CardNote {
fn compute_note_content_hash(self) -> Field {
pedersen_hash([
self.owner.to_field(),
], 0)
}
``````

## 0.22.0

### [Aztec.nr] `Serialize`, `Deserialize`, `NoteInterface` as Traits, removal of SerializationMethods and SERIALIZED_LEN
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Deserialize<ADDRESS_NOTE_LEN> for AddressNote {
}

impl NoteInterface for AddressNote {
fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash(self.serialize(), 0)
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/aztec/src/note/note_interface.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::note::note_header::NoteHeader;

// docs:start:note_interface
trait NoteInterface {
fn compute_note_hash(self) -> Field;
fn compute_note_content_hash(self) -> Field;

fn get_header(self) -> NoteHeader;

Expand Down
13 changes: 4 additions & 9 deletions yarn-project/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ use dep::protocol_types::{
traits::{Deserialize, Serialize},
};

fn compute_inner_hash(storage_slot: Field, note_hash: Field) -> Field {
// TODO(#1205) Do we need a generator index here?
pedersen_hash([storage_slot, note_hash], 0)
}

fn compute_siloed_hash(contract_address: AztecAddress, inner_note_hash: Field) -> Field {
let inputs = [contract_address.to_field(), inner_note_hash];
pedersen_hash(inputs, GENERATOR_INDEX__SILOED_COMMITMENT)
Expand All @@ -35,9 +30,10 @@ fn compute_unique_hash(nonce: Field, siloed_note_hash: Field) -> Field {

fn compute_inner_note_hash<Note, N>(note: Note) -> Field where Note: NoteInterface {
let header = note.get_header();
let note_hash = note.compute_note_hash();
let note_hash = note.compute_note_content_hash();

compute_inner_hash(header.storage_slot, note_hash)
// TODO(#1205) Do we need a generator index here?
pedersen_hash([header.storage_slot, note_hash], 0)
}

fn compute_siloed_note_hash<Note>(note_with_header: Note) -> Field where Note: NoteInterface {
Expand Down Expand Up @@ -95,8 +91,7 @@ pub fn compute_note_hash_and_nullifier<T, N, S>(
// TODO: change this to note.setHeader(header) once https://github.com/noir-lang/noir/issues/4095 is fixed
T::set_header((&mut note), note_header);

let note_hash = note.compute_note_hash();
let inner_note_hash = compute_inner_hash(note_header.storage_slot, note_hash);
let inner_note_hash = compute_inner_note_hash(note);

let siloed_note_hash = compute_siloed_hash(note_header.contract_address, inner_note_hash);

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/field-note/src/field_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Deserialize<FIELD_NOTE_LEN> for FieldNote {
}

impl NoteInterface for FieldNote {
fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash(self.serialize(), 0)
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Deserialize<VALUE_NOTE_LEN> for ValueNote {

impl NoteInterface for ValueNote {

fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash(self.serialize(),0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ impl Deserialize<CARD_NOTE_LEN> for CardNote {
}

impl NoteInterface for CardNote {
fn compute_note_hash(self) -> Field {
pedersen_hash([
self.points as Field,
self.randomness,
self.owner.to_field(),
],0)
fn compute_note_content_hash(self) -> Field {
pedersen_hash(self.serialize(), 0)
}

fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Deserialize<ECDSA_PUBLIC_KEY_NOTE_LEN> for EcdsaPublicKeyNote {
}

impl NoteInterface for EcdsaPublicKeyNote {
fn compute_note_hash(note: EcdsaPublicKeyNote) -> Field {
fn compute_note_content_hash(note: EcdsaPublicKeyNote) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash(note.serialize(), 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl NoteInterface for PublicKeyNote {
],0)
}

fn compute_note_hash(note: PublicKeyNote) -> Field {
fn compute_note_content_hash(note: PublicKeyNote) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash(note.serialize(), 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ impl Deserialize<TOKEN_NOTE_LEN> for TokenNote {
}

impl NoteInterface for TokenNote {
fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
self.amount.value as Field,
self.owner.to_field(),
self.randomness,
],0)
pedersen_hash(self.serialize(), 0)
}

// docs:start:nullifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ impl Deserialize<TRANSPARENT_NOTE_LEN> for TransparentNote {

impl NoteInterface for TransparentNote {

fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
self.amount,
self.secret_hash,
],0)
pedersen_hash(self.serialize(), 0)
}

fn compute_nullifier(self, _context: &mut PrivateContext) -> Field {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,9 @@ impl Deserialize<TOKEN_NOTE_LEN> for TokenNote {
}

impl NoteInterface for TokenNote {
fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
self.amount.value as Field,
self.owner.to_field(),
self.randomness,
],0)
pedersen_hash(self.serialize(), 0)
}

// docs:start:nullifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,20 @@ impl Empty for TransparentNote {
fn empty() -> Self {
TransparentNote::new(0, 0)
}

}

impl NoteInterface for TransparentNote {

fn compute_note_hash(self) -> Field {
fn compute_note_content_hash(self) -> Field {
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([
self.amount,
self.secret_hash,
],0)
pedersen_hash(self.serialize(), 0)
}

fn compute_nullifier(self, _context: &mut PrivateContext) -> Field {
self.compute_nullifier_without_context()
}

fn compute_nullifier_without_context(self) -> Field {
// TODO(#1386): should use `compute_note_hash_for_read_or_nullify` once public functions inject nonce!
let siloed_note_hash = compute_note_hash_for_read_or_nullify(self);
// TODO(#1205) Should use a non-zero generator index.
pedersen_hash([self.secret, siloed_note_hash],0)
Expand Down

0 comments on commit 8368659

Please sign in to comment.