-
Notifications
You must be signed in to change notification settings - Fork 598
feat: aztec nr lib constraining nullifier key is fresh #5939
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
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
3acc686
Initial
1f53bd5
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
177445f
fix
fdbb60a
good
2d3a95f
asdf
58f9650
working tests
42a9c35
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
f82d1c8
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
ea93350
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
781bbe3
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 3201fd4
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 1b13804
cleanup
211a060
yarn format
29bfb80
fix
7d1620d
change some stuff
f0ece69
fix
0461006
fix
e4f6d15
asdf
f9a844b
fix
0e0b63e
fix
7572be2
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 9051c8e
format
6e3509a
test
6fbd1d9
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 711afac
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 7f5dbfc
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 0ca8578
Addressing comments
c852740
Apply suggestions from code review
sklppy88 3b9e7ba
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 b76ab1a
fix
7eb2366
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 e2a479a
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 59a4c18
format
194df19
Address comments
938761a
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 0baf281
Merge branch 'master' into ek/feat/constrain-keys-are-fresh-lib
sklppy88 a85f513
fix
94db9f5
Okay
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| mod point_to_symmetric_key; | ||
| mod getters; | ||
| mod point_to_symmetric_key; | ||
|
|
||
| use crate::keys::getters::get_fresh_nullifier_public_key_hash; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| use dep::protocol_types::{ | ||
| address::{ | ||
| AztecAddress, | ||
| PartialAddress | ||
| }, | ||
| constants::{ | ||
| GENERATOR_INDEX__PUBLIC_KEYS_HASH, | ||
| GENERATOR_INDEX__CONTRACT_ADDRESS_V1, | ||
| CANONICAL_KEY_REGISTRY_ADDRESS | ||
| }, | ||
| grumpkin_point::GrumpkinPoint, | ||
| }; | ||
|
|
||
| use crate::context::PrivateContext; | ||
| use crate::hash::{ | ||
| pedersen_hash, | ||
| poseidon2_hash, | ||
| }; | ||
| use crate::oracle::keys::get_public_keys_and_partial_address; | ||
| use crate::state_vars::{ | ||
| map::derive_storage_slot_in_map, | ||
| shared_mutable::shared_mutable_private_getter::SharedMutablePrivateGetter, | ||
| }; | ||
|
|
||
| struct PublicKeyTypeEnum { | ||
| NULLIFIER: u8, | ||
| } | ||
|
|
||
| global PublicKeyType = PublicKeyTypeEnum { | ||
| NULLIFIER: 0, | ||
| }; | ||
|
|
||
| pub fn get_fresh_nullifier_public_key_hash( | ||
| context: &mut PrivateContext, | ||
| address: AztecAddress, | ||
| ) -> Field { | ||
| // This is the storage slot of the nullifier_public_key inside the key registry contract | ||
| // TODO: (#6133) We should have this be directly imported from the other contract if possible, or at least this should not be this brittle | ||
| let storage_slot_of_nullifier_public_key = 1; | ||
|
|
||
| let derived_slot = derive_storage_slot_in_map(storage_slot_of_nullifier_public_key, address); | ||
|
|
||
| // We read from the canonical Key Registry | ||
| // TODO: (#6134) It's a bit wonky because we need to know the delay for get_current_value_in_private to work correctly. | ||
| // We should allow for this usecase without needing to hard code it here. | ||
| let registry_private_getter: SharedMutablePrivateGetter<Field, 5> = SharedMutablePrivateGetter::new(*context, AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS), derived_slot); | ||
| let nullifier_public_key_hash_in_registry = registry_private_getter.get_current_value_in_private(); | ||
|
|
||
| let nullifier_public_key_hash = if nullifier_public_key_hash_in_registry == 0 { | ||
| let keys = get_original_public_keys_internal(address); | ||
| poseidon2_hash(keys[PublicKeyType.NULLIFIER].serialize()) | ||
LHerskind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| nullifier_public_key_hash_in_registry | ||
| }; | ||
|
|
||
| nullifier_public_key_hash | ||
| } | ||
|
|
||
| // This constraint only works on keys that have not been rotated, otherwise this call will fail as the public keys are not constrained | ||
| fn get_original_public_keys_internal(address: AztecAddress) -> [GrumpkinPoint; 4] { | ||
| let (public_keys, partial_address) = get_public_keys_and_partial_address(address); | ||
|
|
||
| let nullifier_pub_key = public_keys[0]; | ||
| let incoming_pub_key = public_keys[1]; | ||
| let outgoing_pub_key = public_keys[2]; | ||
| let tagging_pub_key = public_keys[3]; | ||
|
|
||
| let computed_address = AztecAddress::compute_from_public_keys_and_partial_address( | ||
| nullifier_pub_key, | ||
| incoming_pub_key, | ||
| outgoing_pub_key, | ||
| tagging_pub_key, | ||
| partial_address, | ||
| ); | ||
|
|
||
| assert(computed_address.eq(address)); | ||
|
|
||
| [nullifier_pub_key, incoming_pub_key, outgoing_pub_key, tagging_pub_key] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| use dep::protocol_types::{ | ||
| address::{ | ||
| AztecAddress, | ||
| PartialAddress, | ||
| }, | ||
| grumpkin_point::GrumpkinPoint, | ||
| }; | ||
|
|
||
| use crate::hash::poseidon2_hash; | ||
|
|
||
| #[oracle(getPublicKeysAndPartialAddress)] | ||
| fn get_public_keys_and_partial_address_oracle(_address: AztecAddress) -> [Field; 9] {} | ||
|
|
||
| unconstrained fn get_public_keys_and_partial_address_oracle_wrapper(address: AztecAddress) -> [Field; 9] { | ||
| get_public_keys_and_partial_address_oracle(address) | ||
| } | ||
|
|
||
| fn get_public_keys_and_partial_address(address: AztecAddress) -> ([GrumpkinPoint; 4], PartialAddress) { | ||
| let result = get_public_keys_and_partial_address_oracle_wrapper(address); | ||
|
|
||
| let nullifier_pub_key = GrumpkinPoint::new(result[0], result[1]); | ||
| let incoming_pub_key = GrumpkinPoint::new(result[2], result[3]); | ||
| let outgoing_pub_key = GrumpkinPoint::new(result[4], result[5]); | ||
| let tagging_pub_key = GrumpkinPoint::new(result[6], result[7]); | ||
| let partial_address = PartialAddress::from_field(result[8]); | ||
|
|
||
| ([nullifier_pub_key, incoming_pub_key, outgoing_pub_key, tagging_pub_key], partial_address) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.