-
Notifications
You must be signed in to change notification settings - Fork 597
feat: introduce initialize_or_replace #6519
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
7 commits
Select commit
Hold shift + click to select a range
2a19444
Introduce initialize_or_replace
nventuro acead3c
Restore is_initializaed
nventuro 21f6597
Apply formatting
nventuro 72e7bfe
Merge branch 'master' into nv/immut-init-or-replace
nventuro b2a7c61
Merge branch 'master' into nv/immut-init-or-replace
nventuro 41a7b2e
Add simple tests
nventuro 0aab394
Fix nargo formatting
nventuro 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
53 changes: 53 additions & 0 deletions
53
noir-projects/aztec-nr/aztec/src/state_vars/private_mutable/test.nr
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,53 @@ | ||
| use dep::protocol_types::{address::AztecAddress, grumpkin_point::GrumpkinPoint}; | ||
| use crate::{context::PrivateContext, state_vars::private_mutable::PrivateMutable}; | ||
| use crate::test::{mocks::mock_note::MockNote, helpers::context_builder::ContextBuilder}; | ||
| use dep::std::{unsafe::zeroed, test::OracleMock}; | ||
|
|
||
| global contract_address = AztecAddress::from_field(13); | ||
| global storage_slot = 17; | ||
|
|
||
| fn setup() -> PrivateMutable<MockNote, &mut PrivateContext> { | ||
| let mut context = ContextBuilder::new().contract_address(contract_address).private(); | ||
| let state_var = PrivateMutable::new(&mut context, storage_slot); | ||
|
|
||
| // This oracle is called for its side effects alone - it's always expected to return 0. | ||
| OracleMock::mock("notifyCreatedNote").returns(0); | ||
|
|
||
| state_var | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_initialize_or_replace_without_nullifier() { | ||
| let state_var = setup(); | ||
|
|
||
| let ivpk_m: GrumpkinPoint = zeroed(); | ||
| let broadcast = false; | ||
|
|
||
| let value = 42; | ||
| let mut note = MockNote::new(value).contract_address(contract_address).storage_slot(storage_slot).build(); | ||
|
|
||
| OracleMock::mock("checkNullifierExists").returns(0); | ||
| state_var.initialize_or_replace(&mut note, broadcast, ivpk_m); | ||
|
|
||
| // Since we reported there was no nullifier, we should initialize and see the following side-effects: | ||
| // - a new note being created | ||
| // - no notes being read | ||
| // - the initialization nullifier being emitted | ||
| assert_eq(state_var.context.new_note_hashes.len(), 1); | ||
| assert_eq(state_var.context.note_hash_read_requests.len(), 0); | ||
| assert_eq(state_var.context.new_nullifiers.len(), 1); | ||
|
|
||
| // Note that if the oracle was wrong and the initialization nullifier did exist, this attempt to write it again | ||
| // would cause the sequencer to revert this transaction - we are therefore safe from bad oracles. | ||
| let nullifier = state_var.context.new_nullifiers.get(0); | ||
| assert_eq(nullifier.value, state_var.compute_initialization_nullifier()); | ||
| assert_eq(nullifier.note_hash, 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_initialize_or_replace_with_nullifier() { | ||
| // Here we'd want to test a scenario like the one above with the oracle indicating that the initialization | ||
| // nullifier does exist. Unfortunately that requires us to produce a valid oracle return value for getNotes, | ||
| // which is fairly involved as it deals with serialization of notes, and is relatively complicated to replicate | ||
| // in Noir. | ||
| } |
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
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.