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

feat: npk_m_hash in all notes + key rotation test #6405

Merged
merged 190 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 188 commits
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
3acc686
Initial
sklppy88 Apr 22, 2024
1f53bd5
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 22, 2024
177445f
fix
sklppy88 Apr 22, 2024
fdbb60a
good
sklppy88 Apr 22, 2024
2d3a95f
asdf
sklppy88 Apr 22, 2024
58f9650
working tests
sklppy88 Apr 23, 2024
42a9c35
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 23, 2024
f82d1c8
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 23, 2024
ea93350
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 24, 2024
781bbe3
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 25, 2024
3201fd4
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 26, 2024
1b13804
cleanup
sklppy88 Apr 26, 2024
211a060
yarn format
sklppy88 Apr 26, 2024
29bfb80
fix
sklppy88 Apr 26, 2024
7d1620d
change some stuff
sklppy88 Apr 26, 2024
f0ece69
fix
sklppy88 Apr 26, 2024
0461006
fix
sklppy88 Apr 26, 2024
e4f6d15
asdf
sklppy88 Apr 26, 2024
f9a844b
fix
sklppy88 Apr 26, 2024
0e0b63e
fix
sklppy88 Apr 26, 2024
7572be2
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 26, 2024
9051c8e
format
sklppy88 Apr 26, 2024
6e3509a
test
sklppy88 Apr 26, 2024
6fbd1d9
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 26, 2024
711afac
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 29, 2024
7f5dbfc
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 Apr 29, 2024
afdd9df
initial
sklppy88 Apr 29, 2024
48b0626
initial
sklppy88 Apr 29, 2024
0ca8578
Addressing comments
sklppy88 May 1, 2024
c852740
Apply suggestions from code review
sklppy88 May 1, 2024
3b9e7ba
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 May 1, 2024
b76ab1a
fix
sklppy88 May 1, 2024
7eb2366
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 May 1, 2024
e2a479a
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 May 1, 2024
ede83f4
Merge branch 'ek/feat/constrain-keys-are-fresh-lib' into ek/feat/add-…
sklppy88 May 1, 2024
59a4c18
format
sklppy88 May 1, 2024
dd9ae57
test
sklppy88 May 1, 2024
32598c9
remove
sklppy88 May 1, 2024
0f0df81
another
sklppy88 May 1, 2024
7534a16
Merge remote-tracking branch 'origin/ek/feat/add-nullifying-public-ke…
sklppy88 May 1, 2024
cf27fc9
Add support for both
sklppy88 May 1, 2024
194df19
Address comments
sklppy88 May 1, 2024
938761a
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 May 1, 2024
0baf281
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 May 1, 2024
a85f513
fix
sklppy88 May 1, 2024
209fe0c
Merge branch 'ek/feat/constrain-keys-are-fresh-lib' into ek/feat/add-…
sklppy88 May 1, 2024
94db9f5
Okay
sklppy88 May 1, 2024
0c7dc94
Merge branch 'ek/feat/constrain-keys-are-fresh-lib' into ek/feat/add-…
sklppy88 May 1, 2024
6f0d457
fix
sklppy88 May 2, 2024
1cae18c
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 2, 2024
2f19996
fix
sklppy88 May 2, 2024
fffee53
fmt
sklppy88 May 2, 2024
167603b
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 2, 2024
4416ccb
fix
sklppy88 May 2, 2024
5d1b800
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 2, 2024
c4a745f
Fix
sklppy88 May 2, 2024
3c89a06
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 2, 2024
d69e112
fix
sklppy88 May 2, 2024
b954ecc
format
sklppy88 May 2, 2024
577b69c
one
sklppy88 May 2, 2024
11b4848
fix
sklppy88 May 2, 2024
435c9fd
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 2, 2024
a74311b
Fix
sklppy88 May 2, 2024
1d9964a
comments
sklppy88 May 3, 2024
5fa644d
format
sklppy88 May 3, 2024
227378c
testkeystore
sklppy88 May 3, 2024
ccbb5c9
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 3, 2024
f5659f5
format
sklppy88 May 3, 2024
c8901ff
Adding comments
sklppy88 May 3, 2024
ec75986
comments
sklppy88 May 3, 2024
4bfaefa
why
sklppy88 May 3, 2024
4604a29
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 3, 2024
53a443b
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 4, 2024
d9704ab
fix
sklppy88 May 4, 2024
7fd8b1d
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 6, 2024
b9733a0
Fix
sklppy88 May 6, 2024
9a3829c
fix
sklppy88 May 6, 2024
40ce5c6
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 8, 2024
b432ad2
Fix naming
sklppy88 May 8, 2024
f734d3f
address comments
sklppy88 May 8, 2024
bd7db1e
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 8, 2024
04f058f
fix
sklppy88 May 8, 2024
76850bd
fix
sklppy88 May 8, 2024
4f86276
fix
sklppy88 May 8, 2024
e47580f
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 8, 2024
b85388d
fix formatting
sklppy88 May 8, 2024
b4d24e1
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 8, 2024
29f4225
nargo fmt
sklppy88 May 8, 2024
af0ffd7
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 8, 2024
05f8fef
Fix
sklppy88 May 8, 2024
f8f27a7
fix
sklppy88 May 8, 2024
ded1ee3
format
sklppy88 May 8, 2024
2f76913
migration notes
sklppy88 May 9, 2024
bfe3f87
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 9, 2024
1ce4d63
Update migration_notes.md
sklppy88 May 9, 2024
3e6ec6f
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 9, 2024
2bd798e
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 9, 2024
ba7aa67
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 9, 2024
906e105
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 9, 2024
113b1e9
fmt
sklppy88 May 9, 2024
9fae196
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 10, 2024
e9f2326
Adapting
sklppy88 May 10, 2024
97a6c5a
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 10, 2024
fe73adb
fix
sklppy88 May 10, 2024
eb53c44
fix
sklppy88 May 10, 2024
b6b6969
Fixes
sklppy88 May 10, 2024
8ecec72
fix
sklppy88 May 10, 2024
730c842
Changes
sklppy88 May 10, 2024
1deda94
asfd
sklppy88 May 10, 2024
851c53e
asdf
sklppy88 May 10, 2024
5cee1ce
Fixes
sklppy88 May 10, 2024
a2eed7c
fix
sklppy88 May 10, 2024
1d52a38
format
sklppy88 May 10, 2024
6798917
fix
sklppy88 May 10, 2024
0a523d4
fix
sklppy88 May 10, 2024
06c4cc2
fix
sklppy88 May 10, 2024
a765ec7
asdf
sklppy88 May 10, 2024
5c63480
fix
sklppy88 May 10, 2024
993e33d
fix
sklppy88 May 10, 2024
31ec469
Refactors
sklppy88 May 10, 2024
a1f3f9b
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 10, 2024
f418d3e
fix comments
sklppy88 May 10, 2024
4511907
asdf
sklppy88 May 10, 2024
e9a1007
fmt
sklppy88 May 10, 2024
2478e6e
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 10, 2024
5ca32e2
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 11, 2024
34b8aa1
bump timeouts
sklppy88 May 11, 2024
6439607
Initial
sklppy88 May 11, 2024
44f8bf4
test
sklppy88 May 11, 2024
4aedd6a
Merge branch 'ek/feat/add-nullifying-public-key-to-token-note' into e…
sklppy88 May 11, 2024
e6425cf
Fix
sklppy88 May 11, 2024
28e5f1f
asdf
sklppy88 May 11, 2024
5a41082
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 13, 2024
3ef4856
Initial
sklppy88 May 11, 2024
3287585
fixing
sklppy88 May 13, 2024
dc1476a
format
sklppy88 May 13, 2024
18e050c
Merge branch 'ek/feat/add-nullifying-public-key-to-token-note' into e…
sklppy88 May 13, 2024
7c525ed
Merge branch 'ek/feat/allow-nullifying-notes-with-different-npk-m-has…
sklppy88 May 13, 2024
95906c4
format
sklppy88 May 13, 2024
79a5951
Merge branch 'ek/feat/allow-nullifying-notes-with-different-npk-m-has…
sklppy88 May 13, 2024
d3fd00d
format
sklppy88 May 13, 2024
c8885c7
Some comments
sklppy88 May 13, 2024
a3e0af3
Pass noir tests
sklppy88 May 13, 2024
af8a7e9
Fix
sklppy88 May 13, 2024
31092e5
Merge branch 'ek/feat/allow-nullifying-notes-with-different-npk-m-has…
sklppy88 May 13, 2024
23b721c
fix
sklppy88 May 13, 2024
53c72e1
fmt
sklppy88 May 13, 2024
f014dde
Addressing comments
sklppy88 May 14, 2024
84e53c3
Addressing comments
sklppy88 May 14, 2024
fee5a59
Apply suggestions from Jan
sklppy88 May 14, 2024
9563d94
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 14, 2024
071e7c4
format
sklppy88 May 14, 2024
3420a2f
Merge branch 'master' into ek/feat/add-nullifying-public-key-to-token…
sklppy88 May 14, 2024
4ea8ea7
Merge branch 'ek/feat/add-nullifying-public-key-to-token-note' into e…
sklppy88 May 14, 2024
930ced2
Merge branch 'ek/feat/allow-nullifying-notes-with-different-npk-m-has…
sklppy88 May 14, 2024
7fb8670
Working
sklppy88 May 14, 2024
348b371
renaming
sklppy88 May 14, 2024
7ae168a
Merge branch 'master' into ek/feat/allow-nullifying-notes-with-differ…
sklppy88 May 15, 2024
076fc10
Merge branch 'ek/feat/allow-nullifying-notes-with-different-npk-m-has…
sklppy88 May 15, 2024
cb3d183
Merge branch 'ek/feat/key-rotation-end-to-end-example' into ek/feat/a…
sklppy88 May 15, 2024
7cffd0f
fixing conflicts / formatting
sklppy88 May 15, 2024
9c91b24
fix snapshots
sklppy88 May 15, 2024
0d72bf4
yarn test
sklppy88 May 15, 2024
657d5cf
Addressing comments
sklppy88 May 15, 2024
5e5214b
format
sklppy88 May 15, 2024
d061a9c
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
sklppy88 May 15, 2024
c126db8
Addressing comments
sklppy88 May 15, 2024
0cd9d67
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
sklppy88 May 15, 2024
ef9ed1f
Addressing feedback
sklppy88 May 15, 2024
b182eab
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
sklppy88 May 15, 2024
bd788a0
comments
sklppy88 May 15, 2024
3e95366
fix
sklppy88 May 15, 2024
064bec3
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
sklppy88 May 15, 2024
0cfb14e
address comments
sklppy88 May 15, 2024
870e03c
comments
sklppy88 May 15, 2024
f4dc806
comment
sklppy88 May 15, 2024
e4866eb
Comments
sklppy88 May 15, 2024
d97c21e
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
sklppy88 May 15, 2024
3bdc063
comment
sklppy88 May 15, 2024
10e0f78
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
sklppy88 May 15, 2024
7d8864e
Addressing comments
sklppy88 May 15, 2024
b805a8d
format
sklppy88 May 15, 2024
a65be02
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
sklppy88 May 15, 2024
0294174
fix/ format
sklppy88 May 15, 2024
2d2455e
Addressing comments
sklppy88 May 15, 2024
5fb3e19
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
sklppy88 May 15, 2024
efc5428
Impl hash on Point
sklppy88 May 15, 2024
6989d9f
key store refactor
benesjan May 16, 2024
9680858
reworked key rotation test
benesjan May 16, 2024
c26064c
Merge branch 'master' into ek/feat/add-npk-m-hash-to-all-tokens
benesjan May 16, 2024
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
4 changes: 2 additions & 2 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ library Constants {
uint256 internal constant MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32;
uint256 internal constant MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 2;
uint256 internal constant MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL = 2;
uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 1;
uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 16;
uint256 internal constant MAX_ENCRYPTED_LOGS_PER_CALL = 4;
uint256 internal constant MAX_UNENCRYPTED_LOGS_PER_CALL = 4;
uint256 internal constant MAX_NEW_NOTE_HASHES_PER_TX = 64;
Expand All @@ -38,7 +38,7 @@ library Constants {
uint256 internal constant MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128;
uint256 internal constant MAX_NULLIFIER_READ_REQUESTS_PER_TX = 8;
uint256 internal constant MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX = 8;
uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4;
uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 64;
uint256 internal constant MAX_ENCRYPTED_LOGS_PER_TX = 8;
uint256 internal constant MAX_UNENCRYPTED_LOGS_PER_TX = 8;
uint256 internal constant NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
Expand Down
23 changes: 12 additions & 11 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use dep::aztec::{
keys::getters::get_ivpk_m,
protocol_types::{address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER},
protocol_types::{
address::AztecAddress, traits::Empty, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
grumpkin_point::GrumpkinPoint, hash::poseidon2_hash
},
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key},
context::PrivateContext, hash::poseidon2_hash
oracle::unsafe_rand::unsafe_rand, keys::getters::get_nsk_app, context::PrivateContext
};

global ADDRESS_NOTE_LEN: Field = 3;
Expand All @@ -13,15 +14,16 @@ global ADDRESS_NOTE_LEN: Field = 3;
#[aztec(note)]
struct AddressNote {
address: AztecAddress,
owner: AztecAddress,
// The nullifying public key hash is used with the nsk_app to ensure that the note can be privately spent.
npk_m_hash: Field,
randomness: Field,
}

impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {

fn compute_nullifier(self, context: &mut PrivateContext) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = context.request_app_nullifier_secret_key(self.owner);
let secret = context.request_nsk_app(self.npk_m_hash);
poseidon2_hash([
note_hash_for_nullify,
secret,
Expand All @@ -31,7 +33,7 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {

fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_consumption(self);
let secret = get_app_nullifier_secret_key(self.owner);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash([
note_hash_for_nullify,
secret,
Expand All @@ -40,8 +42,7 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
}

// Broadcasts the note as an encrypted log on L1.
fn broadcast(self, context: &mut PrivateContext, slot: Field) {
let ivpk_m = get_ivpk_m(context, self.owner);
fn broadcast(self, context: &mut PrivateContext, slot: Field, ivpk_m: GrumpkinPoint) {
// docs:start:encrypted
context.emit_encrypted_log(
(*context).this_address(),
Expand All @@ -55,9 +56,9 @@ impl NoteInterface<ADDRESS_NOTE_LEN> for AddressNote {
}

impl AddressNote {
pub fn new(address: AztecAddress, owner: AztecAddress) -> Self {
pub fn new(address: AztecAddress, npk_m_hash: Field) -> Self {
let randomness = unsafe_rand();
AddressNote { address, owner, randomness, header: NoteHeader::empty() }
AddressNote { address, npk_m_hash, randomness, header: NoteHeader::empty() }
}
// docs:end:address_note_def
}
56 changes: 17 additions & 39 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{
context::{inputs::PrivateContextInputs, interface::ContextInterface},
messaging::process_l1_to_l2_message,
keys::getters::get_nullifier_keys, messaging::process_l1_to_l2_message,
hash::{hash_args_array, ArgsHasher, compute_encrypted_log_hash, compute_unencrypted_log_hash},
oracle::{
arguments, returns, call_private_function::call_private_function_internal, header::get_header_at,
nullifier_keys::NullifierKeys, arguments, returns,
call_private_function::call_private_function_internal, header::get_header_at,
logs::emit_encrypted_log, logs_traits::{LensForEncryptedLog, ToBytesForUnencryptedLog},
nullifier_key::{get_nullifier_keys, get_nullifier_keys_with_npk_m_hash, NullifierKeys},
enqueue_public_function_call::{
enqueue_public_function_call_internal, set_public_teardown_function_call_internal,
parse_public_call_stack_item_from_oracle
Expand All @@ -31,7 +31,7 @@ use dep::protocol_types::{
contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest},
grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint, header::Header,
messaging::l2_to_l1_message::L2ToL1Message, utils::reader::Reader,
traits::{is_empty, Deserialize, Empty}, hash::poseidon2_hash
traits::{is_empty, Deserialize, Empty}
};

// When finished, one can call .finish() to convert back to the abi
Expand Down Expand Up @@ -203,47 +203,25 @@ impl PrivateContext {
self.nullifier_read_requests.push(request);
}

pub fn request_app_nullifier_secret_key(&mut self, account: AztecAddress) -> Field {
let keys = if self.nullifier_key.is_none() {
let keys = get_nullifier_keys(account);
let request = NullifierKeyValidationRequest {
master_nullifier_public_key: keys.master_nullifier_public_key,
app_nullifier_secret_key: keys.app_nullifier_secret_key
};
self.nullifier_key_validation_requests.push(request);
self.nullifier_key = Option::some(keys);
keys
} else {
let keys = self.nullifier_key.unwrap_unchecked();
// If MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL is larger than 1, need to update the way the key pair is cached.
assert(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL == 1);
assert(keys.account == account, "Cannot query nullifier key for more than one account per call");
keys
};
keys.app_nullifier_secret_key
}
pub fn request_nsk_app(&mut self, npk_m_hash: Field) -> Field {
// A value of empty nullifier keys will fail the key validation request.
let cached_nullifier_keys = self.nullifier_key.unwrap_or(NullifierKeys::empty());

// TODO(#5630) Replace request_app_nullifier_secret_key above with this once we no longer get app nullifier secret key with address
pub fn request_nsk_app_with_npk_m_hash(&mut self, npk_m_hash: Field) -> Field {
let keys = if self.nullifier_key.is_none() {
let keys = get_nullifier_keys_with_npk_m_hash(npk_m_hash);
let nullifier_keys = if cached_nullifier_keys.master_nullifier_public_key.hash() == npk_m_hash {
cached_nullifier_keys
} else {
let fetched_nullifier_keys = get_nullifier_keys(npk_m_hash);
let request = NullifierKeyValidationRequest {
master_nullifier_public_key: keys.master_nullifier_public_key,
app_nullifier_secret_key: keys.app_nullifier_secret_key
master_nullifier_public_key: fetched_nullifier_keys.master_nullifier_public_key,
app_nullifier_secret_key: fetched_nullifier_keys.app_nullifier_secret_key
};
self.nullifier_key_validation_requests.push(request);
self.nullifier_key = Option::some(keys);
keys
} else {
let keys = self.nullifier_key.unwrap_unchecked();
// If MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL is larger than 1, need to update the way the key pair is cached.
assert(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL == 1);
keys
self.nullifier_key = Option::some(fetched_nullifier_keys);
fetched_nullifier_keys
};

// We have to check if the key that was requested or cached corresponds to the one we request for
assert_eq(poseidon2_hash(keys.master_nullifier_public_key.serialize()), npk_m_hash);
keys.app_nullifier_secret_key
assert_eq(nullifier_keys.master_nullifier_public_key.hash(), npk_m_hash);
nullifier_keys.app_nullifier_secret_key
}

// docs:start:context_message_portal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ mod test {

use crate::{
note::{note_header::NoteHeader, note_interface::NoteInterface, utils::compute_note_hash_for_consumption},
oracle::{unsafe_rand::unsafe_rand, nullifier_key::get_app_nullifier_secret_key},
context::PrivateContext, hash::poseidon2_hash
oracle::unsafe_rand::unsafe_rand, context::PrivateContext
};

struct AddressNote {
Expand All @@ -93,7 +92,7 @@ mod test {

fn compute_nullifier_without_context(self) -> Field {1}

fn broadcast(self, context: &mut PrivateContext, slot: Field) {}
fn broadcast(self, context: &mut PrivateContext, slot: Field, ivpk_m: GrumpkinPoint) {}

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/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dep::protocol_types::{
GENERATOR_INDEX__SECRET_HASH, GENERATOR_INDEX__MESSAGE_NULLIFIER, ARGS_HASH_CHUNK_COUNT,
GENERATOR_INDEX__FUNCTION_ARGS, ARGS_HASH_CHUNK_LENGTH
},
traits::Hash, hash::{pedersen_hash, poseidon2_hash, silo_nullifier, sha256_to_field}
traits::Hash, hash::{pedersen_hash, silo_nullifier, sha256_to_field}
};
use crate::oracle::logs_traits::{LensForEncryptedLog, ToBytesForUnencryptedLog};

Expand Down
26 changes: 17 additions & 9 deletions noir-projects/aztec-nr/aztec/src/keys/getters.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use dep::protocol_types::{
address::AztecAddress, constants::CANONICAL_KEY_REGISTRY_ADDRESS, grumpkin_point::GrumpkinPoint,
hash::poseidon2_hash
};
use dep::protocol_types::{address::AztecAddress, constants::CANONICAL_KEY_REGISTRY_ADDRESS, grumpkin_point::GrumpkinPoint};
use crate::{
context::PrivateContext,
oracle::keys::{get_public_keys_and_partial_address, get_public_keys_and_partial_address_with_npk_m_hash},
oracle::{
keys::get_public_keys_and_partial_address,
nullifier_keys::{NullifierKeys, get_nullifier_keys as get_nullifier_keys_oracle}
},
keys::public_keys::{PublicKeys, NULLIFIER_INDEX, INCOMING_INDEX},
state_vars::{
map::derive_storage_slot_in_map,
Expand All @@ -19,7 +19,7 @@ pub fn get_npk_m(context: &mut PrivateContext, address: AztecAddress) -> Grumpki
}

pub fn get_npk_m_hash(context: &mut PrivateContext, address: AztecAddress) -> Field {
poseidon2_hash(get_master_key(context, address, NULLIFIER_INDEX).serialize())
get_master_key(context, address, NULLIFIER_INDEX).hash()
}

pub fn get_ivpk_m(context: &mut PrivateContext, address: AztecAddress) -> GrumpkinPoint {
Expand Down Expand Up @@ -89,7 +89,15 @@ fn fetch_and_constrain_keys(address: AztecAddress) -> PublicKeys {
public_keys
}

pub fn get_ivpk_m_with_npk_m_hash(npk_m_hash: Field) -> GrumpkinPoint {
let result = get_public_keys_and_partial_address_with_npk_m_hash(npk_m_hash);
result.0.ivpk_m
// We get the full struct Nullifier Keys here
pub fn get_nullifier_keys(npk_m_hash: Field) -> NullifierKeys {
let nullifier_keys = get_nullifier_keys_oracle(npk_m_hash);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been moved here from oracle

assert_eq(nullifier_keys.master_nullifier_public_key.hash(), npk_m_hash);

nullifier_keys
}

// We are only getting the app_nullifier_secret_key here
pub fn get_nsk_app(npk_m_hash: Field) -> Field {
get_nullifier_keys(npk_m_hash).app_nullifier_secret_key
}
6 changes: 4 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/lifecycle.nr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use dep::protocol_types::grumpkin_point::GrumpkinPoint;
use crate::context::{PrivateContext, PublicContext};
use crate::note::{
note_header::NoteHeader, note_interface::NoteInterface,
Expand All @@ -9,7 +10,8 @@ pub fn create_note<Note, N>(
context: &mut PrivateContext,
storage_slot: Field,
note: &mut Note,
broadcast: bool
broadcast: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should get rid of the bool. To follow the spec idea that it is always emitting, but that can be addressed in #6440.

ivpk_m: GrumpkinPoint
) where Note: NoteInterface<N> {
let contract_address = (*context).this_address();

Expand All @@ -36,7 +38,7 @@ pub fn create_note<Note, N>(
context.push_new_note_hash(inner_note_hash);

if broadcast {
Note::broadcast(*note, context, storage_slot);
Note::broadcast(*note, context, storage_slot, ivpk_m);
}
}

Expand Down
3 changes: 2 additions & 1 deletion noir-projects/aztec-nr/aztec/src/note/note_interface.nr
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::context::PrivateContext;
use crate::note::note_header::NoteHeader;
use dep::protocol_types::grumpkin_point::GrumpkinPoint;

// docs:start:note_interface
trait NoteInterface<N> {
fn compute_nullifier(self, context: &mut PrivateContext) -> Field;

fn compute_nullifier_without_context(self) -> Field;

fn broadcast(self, context: &mut PrivateContext, slot: Field) -> ();
fn broadcast(self, context: &mut PrivateContext, slot: Field, ivpk_m: GrumpkinPoint) -> ();

// 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/oracle.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod get_nullifier_membership_witness;
mod get_public_data_witness;
mod get_membership_witness;
mod keys;
mod nullifier_key;
mod nullifier_keys;
mod get_sibling_path;
mod unsafe_rand;
mod enqueue_public_function_call;
Expand Down
22 changes: 0 additions & 22 deletions noir-projects/aztec-nr/aztec/src/oracle/keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,3 @@ fn get_public_keys_and_partial_address(address: AztecAddress) -> (PublicKeys, Pa

(keys, partial_address)
}

#[oracle(getPublicKeysAndPartialAddressWithNpkMHash)]
fn get_public_keys_and_partial_address_with_npk_m_hash_oracle(_npk_m_hash: Field) -> [Field; 9] {}

unconstrained fn get_public_keys_and_partial_address_with_npk_m_hash_oracle_wrapper(npk_m_hash: Field) -> [Field; 9] {
get_public_keys_and_partial_address_with_npk_m_hash_oracle(npk_m_hash)
}

fn get_public_keys_and_partial_address_with_npk_m_hash(npk_m_hash: Field) -> (PublicKeys, PartialAddress) {
let result = get_public_keys_and_partial_address_with_npk_m_hash_oracle_wrapper(npk_m_hash);

let keys = PublicKeys {
npk_m: GrumpkinPoint::new(result[0], result[1]),
ivpk_m: GrumpkinPoint::new(result[2], result[3]),
ovpk_m: GrumpkinPoint::new(result[4], result[5]),
tpk_m: GrumpkinPoint::new(result[6], result[7])
};

let partial_address = PartialAddress::from_field(result[8]);

(keys, partial_address)
}
52 changes: 0 additions & 52 deletions noir-projects/aztec-nr/aztec/src/oracle/nullifier_key.nr

This file was deleted.

Loading
Loading