-
Notifications
You must be signed in to change notification settings - Fork 265
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: verify public data reads #5701
Merged
Merged
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3cf9add
Move public request validation to its own file.
LeilaWang d9760a7
Validate public data reads.
LeilaWang b5e53c1
Build hints in ts.
LeilaWang 25dfd75
Merge remote-tracking branch 'origin/master' into lw/public_read_write
LeilaWang ad686b5
Fix.
LeilaWang 4344962
Update mock data.
LeilaWang 2d1152a
Prove public data against current state.
LeilaWang fe1bce6
Allow all-zero low leaf.
LeilaWang 6ad22e9
Silo storage slot with correct address.
LeilaWang f86ce26
Prove nullifier (non-)membership against latest root.
LeilaWang 972a59d
Merge remote-tracking branch 'origin/master' into lw/public_read_write
LeilaWang c4ff245
Fixes.
LeilaWang 5364801
Merge remote-tracking branch 'origin/master' into lw/public_read_write
LeilaWang c78aa16
Fix formatting.
LeilaWang 92b4589
Update names.
LeilaWang f9a85f5
Fix.
LeilaWang f44354a
Remove end state from kernel circuit public inputs.
LeilaWang 7610799
Merge remote-tracking branch 'origin/master' into lw/public_read_write
LeilaWang 4b29a2a
Merge remote-tracking branch 'origin/master' into lw/public_read_write
LeilaWang 0ee2eaa
Stop propagating public data reads in tail.
LeilaWang 99cdc7b
Merge remote-tracking branch 'origin/master' into lw/public_read_write
LeilaWang 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 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
325 changes: 238 additions & 87 deletions
325
noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr
Large diffs are not rendered by default.
Oops, something went wrong.
11 changes: 7 additions & 4 deletions
11
noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/lib.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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
use non_existent_read_request_reset::reset_non_existent_read_requests; | ||
use nullifier_non_existent_read_request_reset::NullifierNonExistentReadRequestHints; | ||
use nullifier_read_request_reset::NullifierReadRequestHints; | ||
use private_validation_request_processor::PrivateValidationRequestProcessor; | ||
use read_request_reset::reset_read_requests; | ||
use public_data_read_request_reset::PublicDataReadRequestHints; | ||
use public_validation_request_processor::PublicValidationRequestProcessor; | ||
use types::public_data_hint::PublicDataHint; | ||
|
||
mod non_existent_read_request_reset; | ||
mod nullifier_non_existent_read_request_reset; | ||
mod nullifier_read_request_reset; | ||
mod private_validation_request_processor; | ||
mod read_request_reset; | ||
mod public_data_read_request_reset; | ||
mod public_validation_request_processor; | ||
mod reset; | ||
mod tests; | ||
mod types; |
4 changes: 2 additions & 2 deletions
4
...rotocol-circuits/crates/reset-kernel-lib/src/nullifier_non_existent_read_request_reset.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
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
2 changes: 1 addition & 1 deletion
2
...oir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.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
9 changes: 9 additions & 0 deletions
9
...ects/noir-protocol-circuits/crates/reset-kernel-lib/src/public_data_read_request_reset.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,9 @@ | ||
use crate::reset::{mutable_data_read_request::LeafDataReadHint, read_request::{PendingReadHint, ReadRequestStatus}}; | ||
use dep::types::constants::MAX_PUBLIC_DATA_READS_PER_TX; | ||
|
||
// The MAX_PUBLIC_DATA_READS_PER_TX for pending_read_hints and leaf_data_read_hints can change if we create various circuits that deal with different number of reads. | ||
struct PublicDataReadRequestHints { | ||
read_request_statuses: [ReadRequestStatus; MAX_PUBLIC_DATA_READS_PER_TX], | ||
pending_read_hints: [PendingReadHint; MAX_PUBLIC_DATA_READS_PER_TX], | ||
leaf_data_read_hints: [LeafDataReadHint; MAX_PUBLIC_DATA_READS_PER_TX], | ||
} |
127 changes: 127 additions & 0 deletions
127
...noir-protocol-circuits/crates/reset-kernel-lib/src/public_validation_request_processor.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,127 @@ | ||
use crate::{ | ||
reset::{ | ||
non_existent_read_request::reset_non_existent_read_requests, | ||
mutable_data_read_request::reset_mutable_data_read_requests, read_request::reset_read_requests | ||
}, | ||
nullifier_read_request_reset::NullifierReadRequestHints, | ||
nullifier_non_existent_read_request_reset::NullifierNonExistentReadRequestHints, | ||
public_data_read_request_reset::PublicDataReadRequestHints, types::public_data_hint::PublicDataHint | ||
}; | ||
use dep::types::{ | ||
abis::{ | ||
kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs, | ||
public_data_update_request::PublicDataUpdateRequest, side_effect::SideEffectLinkedToNoteHash, | ||
validation_requests::ValidationRequests | ||
}, | ||
constants::{MAX_NEW_NULLIFIERS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX}, | ||
hash::silo_nullifier, traits::is_empty, | ||
utils::arrays::{array_merge, array_to_bounded_vec, assert_sorted_array} | ||
}; | ||
|
||
struct PublicValidationRequestProcessor<N> { | ||
validation_requests: ValidationRequests, | ||
pending_nullifiers: [SideEffectLinkedToNoteHash; MAX_NEW_NULLIFIERS_PER_TX], | ||
pending_public_data_writes: [PublicDataUpdateRequest; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX], | ||
nullifier_read_request_hints: NullifierReadRequestHints, | ||
nullifier_non_existent_read_request_hints: NullifierNonExistentReadRequestHints, | ||
nullifier_tree_root: Field, | ||
public_data_read_request_hints: PublicDataReadRequestHints, | ||
public_data_hints: [PublicDataHint; N], | ||
} | ||
|
||
impl<N> PublicValidationRequestProcessor<N> { | ||
pub fn new( | ||
public_inputs: PublicKernelCircuitPublicInputs, | ||
nullifier_read_request_hints: NullifierReadRequestHints, | ||
nullifier_non_existent_read_request_hints: NullifierNonExistentReadRequestHints, | ||
nullifier_tree_root: Field, | ||
public_data_read_request_hints: PublicDataReadRequestHints, | ||
public_data_hints: [PublicDataHint; N] | ||
) -> Self { | ||
let end_non_revertible = public_inputs.end_non_revertible; | ||
let end = public_inputs.end; | ||
|
||
let pending_nullifiers = array_merge(end_non_revertible.new_nullifiers, end.new_nullifiers); | ||
|
||
let pending_public_data_writes = array_merge( | ||
end_non_revertible.public_data_update_requests, | ||
end.public_data_update_requests | ||
); | ||
|
||
PublicValidationRequestProcessor { | ||
validation_requests: public_inputs.validation_requests, | ||
pending_nullifiers, | ||
pending_public_data_writes, | ||
nullifier_read_request_hints, | ||
nullifier_non_existent_read_request_hints, | ||
nullifier_tree_root, | ||
public_data_read_request_hints, | ||
public_data_hints | ||
} | ||
} | ||
|
||
pub fn validate(self) { | ||
self.validate_nullifier_read_requests(); | ||
self.validate_nullifier_non_existent_read_requests(); | ||
self.validate_public_data_read_requests(); | ||
} | ||
|
||
fn validate_nullifier_read_requests(self) { | ||
let requests = self.validation_requests.nullifier_read_requests; | ||
let hints = self.nullifier_read_request_hints; | ||
let unverified_nullifier_read_requests = reset_read_requests( | ||
requests, | ||
self.pending_nullifiers, | ||
hints.read_request_statuses, | ||
hints.pending_read_hints, | ||
hints.settled_read_hints, | ||
self.nullifier_tree_root | ||
); | ||
assert( | ||
unverified_nullifier_read_requests.len() == 0, "All nullifier read requests must be verified" | ||
); | ||
} | ||
|
||
fn validate_nullifier_non_existent_read_requests(self) { | ||
// The values of the read requests here need to be siloed. | ||
// Notice that it's not the case for regular read requests, which can be run between two kernel iterations, and will to be verified against unsiloed pending values. | ||
let mut read_requests = self.validation_requests.nullifier_non_existent_read_requests; | ||
for i in 0..read_requests.len() { | ||
let read_request = read_requests[i]; | ||
if !is_empty(read_request) { | ||
read_requests[i].value = silo_nullifier(read_request.contract_address, read_request.value); | ||
} | ||
} | ||
|
||
let hints = self.nullifier_non_existent_read_request_hints; | ||
|
||
assert_sorted_array( | ||
self.pending_nullifiers, | ||
hints.sorted_pending_values, | ||
hints.sorted_pending_value_index_hints, | ||
|a: SideEffectLinkedToNoteHash, b: SideEffectLinkedToNoteHash| a.value.lt(b.value) | ||
); | ||
let sorted_pending_nullifiers = array_to_bounded_vec(hints.sorted_pending_values); | ||
|
||
reset_non_existent_read_requests( | ||
read_requests, | ||
hints.non_membership_hints, | ||
self.nullifier_tree_root, | ||
sorted_pending_nullifiers, | ||
hints.next_pending_value_indices | ||
); | ||
} | ||
|
||
fn validate_public_data_read_requests(self) { | ||
let hints = self.public_data_read_request_hints; | ||
|
||
reset_mutable_data_read_requests( | ||
self.validation_requests.public_data_reads, | ||
hints.read_request_statuses, | ||
self.pending_public_data_writes, | ||
self.public_data_hints, | ||
hints.pending_read_hints, | ||
hints.leaf_data_read_hints | ||
); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/reset.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,3 @@ | ||
mod mutable_data_read_request; | ||
mod non_existent_read_request; | ||
mod read_request; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and
validate_nullifier_non_existent_read_requests
below are copied from public tail.