-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: constrain note_getter filter (#6703)
The application of the filter was not constrained when reading notes, this PR changes that. While filtering can be thought of as assisting PXE during note retrieval to avoid unnecessary extra read requests, I think most users will also assume that the function will also lay down constrains. The biggest motivation for this change is that this is how `select()` work: instructions are sent to the PXE to only return certain notes, and we then verify that the oracle behaved as expected. `filter()` is simply an extension of this for conditions that cannot be expressed in a simple select: it is extremely unexpected that filtering would not be constrained when selects are. Consider the following example: ```rust // These guarantee that the retrieved notes have a value larger than 500 let opts = NoteGetterOptions::new().options.select(ValueNote::properties().value, 500, Comparator.GT); // These make a cooperative PXE retrieve notes with a value between 500 and 700, both provide no guarantees whatsoever let opts = NoteGetterOptions::with_filter(|opt_notes| { let mut filtered_notes = [0; opt_notes.len()]; for i in 0..opt_notes.len() { let note_value = opt_notes[i].unwrap_or(0); if (note_value > 500) & (note_value < 700) { filtered_notes[i] = Option::some(note_value); } } filtered_notes }); ``` An example is `filter_notes_min_sum`, which keeps notes until as long as the sum is below some minimum. Callers still have to process the sum again on their end however and compare it to the minimum, since the filter used to provide no guarantees. In some cases this was hidden behind multiple layers of indirection, and as a result `ValueNote::decrement_by_at_most` does not really uphold that the balance is decremented by less than `max_balance` - a very subtle bug.
- Loading branch information
Showing
6 changed files
with
155 additions
and
56 deletions.
There are no files selected for viewing
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
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