Skip to content

Commit

Permalink
compute_nullifier_without_context --> compute_note_hash_and_nullifier…
Browse files Browse the repository at this point in the history
…_without_context
  • Loading branch information
benesjan committed Jun 19, 2024
1 parent 8504d27 commit 7f0af1b
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 41 deletions.
7 changes: 4 additions & 3 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ impl NoteInterface<ADDRESS_NOTE_LEN, ADDRESS_NOTE_BYTES_LEN> for AddressNote {
[note_hash_for_nullify, nullifier]
}

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod test {
[1, 1]
}

fn compute_nullifier_without_context(self) -> Field {1}
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {[1,1]}

fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN] { [self.address.to_field(), self.owner.to_field(), self.randomness]}

Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/note/note_interface.nr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use dep::protocol_types::grumpkin_point::GrumpkinPoint;
trait NoteInterface<N, M> {
fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> [Field; 2];

fn compute_nullifier_without_context(self) -> Field;
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2];

// Autogenerated by the #[aztec(note)] macro unless it is overridden by a custom implementation
fn serialize_content(self) -> [Field; N];
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn compute_note_hash_and_optionally_a_nullifier<T, N, M, S>(
let siloed_note_hash = compute_siloed_hash(note_header.contract_address, unique_note_hash);

let inner_nullifier = if compute_nullifier {
note.compute_nullifier_without_context()
note.compute_note_hash_and_nullifier_without_context()[1]
} else {
0
};
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl NoteInterface<MOCK_NOTE_LENGTH, MOCK_NOTE_BYTES_LENGTH> for MockNote {
[0, 0]
}

fn compute_nullifier_without_context(self) -> Field {
0
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
[0, 0]
}

fn to_be_bytes(self, storage_slot: Field) -> [u8; MOCK_NOTE_BYTES_LENGTH] {
Expand Down
7 changes: 4 additions & 3 deletions noir-projects/aztec-nr/value-note/src/value_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ impl NoteInterface<VALUE_NOTE_LEN, VALUE_NOTE_BYTES_LEN> for ValueNote {

// docs:end:nullifier

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ impl NoteInterface<SUBSCRIPTION_NOTE_LEN, SUBSCRIPTION_NOTE_BYTES_LEN> for Subsc
[note_hash_for_nullify, nullifier]
}

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ impl NoteInterface<CARD_NOTE_LEN, CARD_NOTE_BYTES_LEN> for CardNote {
[note_hash_for_nullify, nullifier]
}

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN, ECDSA_PUBLIC_KEY_NOTE_BYTES_LEN> f
[note_hash_for_nullify, nullifier]
}

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ impl NoteInterface<PUBLIC_KEY_NOTE_LEN, PUBLIC_KEY_NOTE_BYTES_LEN> for PublicKey
[note_hash_for_nullify, nullifier]
}

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ impl NoteInterface<TEST_NOTE_LEN, TEST_NOTE_BYTES_LENGTH> for TestNote {
[0, 0]
}

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
// This note is expected to be shared between users and for this reason can't be nullified using a secret.
0
[0, 0]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ impl NoteInterface<TOKEN_NOTE_LEN, TOKEN_NOTE_BYTES_LEN> for TokenNote {
}
// docs:end:nullifier

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN, TRANSPARENT_NOTE_BYTES_LEN> for Transpa

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): Ensure nullifier collisions are prevented
fn compute_note_hash_and_nullifier(self, _context: &mut PrivateContext) -> [Field; 2] {
// TODO(benesjan): Can we really return 0 for note hash here? Try just asser(false) here.
[0, self.compute_nullifier_without_context()]
self.compute_note_hash_and_nullifier_without_context()
}

// Computing a nullifier in a transparent note is not guarded by making secret a part of the nullifier preimage (as
Expand All @@ -54,12 +53,13 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN, TRANSPARENT_NOTE_BYTES_LEN> for Transpa
// 3) the "get_notes" oracle constrains that the secret hash in the returned note matches the one computed in
// circuit.
// This achieves that the note can only be spent by the party that knows the secret.
fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ impl NoteInterface<TOKEN_NOTE_LEN, TOKEN_NOTE_BYTES_LEN> for TokenNote {
}
// docs:end:nullifier

fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
secret,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN, TRANSPARENT_NOTE_BYTES_LEN> for Transpa

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): Ensure nullifier collisions are prevented
fn compute_note_hash_and_nullifier(self, _context: &mut PrivateContext) -> [Field; 2] {
// TODO(benesjan): Can we really return 0 for note hash here?
[0, self.compute_nullifier_without_context()]
self.compute_note_hash_and_nullifier_without_context()
}

// Computing a nullifier in a transparent note is not guarded by making secret a part of the nullifier preimage (as
Expand All @@ -54,12 +53,13 @@ impl NoteInterface<TRANSPARENT_NOTE_LEN, TRANSPARENT_NOTE_BYTES_LEN> for Transpa
// 3) the "get_notes" oracle constrains that the secret hash in the returned note matches the one computed in
// circuit.
// This achieves that the note can only be spent by the party that knows the secret.
fn compute_nullifier_without_context(self) -> Field {
fn compute_note_hash_and_nullifier_without_context(self) -> [Field; 2] {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
poseidon2_hash([
let nullifier = poseidon2_hash([
note_hash_for_nullify,
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
])
]);
[note_hash_for_nullify, nullifier]
}
}

Expand Down

0 comments on commit 7f0af1b

Please sign in to comment.