-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace assert_contains with assert_contains_and_remove. (#1636)
The previous `Set.assert_contains` can be misleading. A note in a Set might have been destroyed. But this could still generate a valid proof: ```rust set.assert_contains(note); do_something(); ``` However, the ability to check if a note hash exists is useful. Because a note might not be shared via log. In which case, the user gets the preimage offline, and should be able to call a contract function with the preimage to claim a note or do something. Before we add the [feature](#1635) properly, we can use `assert_contains_and_remove` to check that the note hash does exist, and destroy the note right after, to prevent developers making wrong assumption. # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist).
- Loading branch information
Showing
7 changed files
with
67 additions
and
39 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
yarn-project/noir-contracts/src/contracts/escrow_contract/src/address_note.nr
This file contains 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
22 changes: 22 additions & 0 deletions
22
yarn-project/noir-contracts/src/contracts/escrow_contract/src/address_note/filter.nr
This file contains 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,22 @@ | ||
use dep::aztec::constants_gen::MAX_READ_REQUESTS_PER_CALL; | ||
use dep::aztec::types::option::Option; | ||
|
||
use crate::address_note::AddressNote; | ||
|
||
fn filter_by_owner_and_address( | ||
notes: [Option<AddressNote>; MAX_READ_REQUESTS_PER_CALL], | ||
params: [Field; 2], | ||
) -> [Option<AddressNote>; 1] { | ||
let address = params[0]; | ||
let owner = params[1]; | ||
let mut owner_note = [Option::none(AddressNote::dummy())]; | ||
for i in 0..notes.len() { | ||
if notes[i].is_some() { | ||
let note = notes[i].unwrap_unchecked(); | ||
if (note.address == address) & (note.owner == owner) { | ||
owner_note[0] = notes[i]; | ||
} | ||
} | ||
} | ||
owner_note | ||
} |
This file contains 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 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 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 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 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