Skip to content
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 21 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ library Constants {
uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4;
uint256 internal constant NUM_ENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant NUM_UNENCRYPTED_LOGS_HASHES_PER_TX = 1;
uint256 internal constant MAX_PUBLIC_DATA_HINTS = 64;
uint256 internal constant NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16;
uint256 internal constant VK_TREE_HEIGHT = 3;
uint256 internal constant FUNCTION_TREE_HEIGHT = 5;
Expand Down
1 change: 1 addition & 0 deletions noir-projects/noir-protocol-circuits/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"crates/public-kernel-teardown-simulated",
"crates/public-kernel-tail",
"crates/public-kernel-tail-simulated",
"crates/reset-kernel-lib",
"crates/rollup-lib",
"crates/rollup-merge",
"crates/rollup-base",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod tests {
use crate::private_kernel_tail::PrivateKernelTailCircuitPrivateInputs;
use dep::reset_kernel_lib::{
tests::nullifier_read_request_hints_builder::NullifierReadRequestHintsBuilder,
read_request_reset::{PendingReadHint, ReadRequestState, ReadRequestStatus}
reset::read_request::{PendingReadHint, ReadRequestState, ReadRequestStatus}
};
use dep::types::constants::{
MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX,
Expand Down Expand Up @@ -177,6 +177,15 @@ mod tests {
}
}

#[test]
unconstrained fn execution_succeeded() {
let mut builder = PrivateKernelTailInputsBuilder::new();
let public_inputs = builder.execute();

assert(is_empty(public_inputs.start_state));
assert(is_empty(public_inputs.end_state));
}

#[test]
unconstrained fn native_matching_one_read_request_to_commitment_works() {
let mut builder = PrivateKernelTailInputsBuilder::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod tests {
use crate::private_kernel_tail_to_public::PrivateKernelTailToPublicCircuitPrivateInputs;
use dep::reset_kernel_lib::{
tests::nullifier_read_request_hints_builder::NullifierReadRequestHintsBuilder,
read_request_reset::{PendingReadHint, ReadRequestState, ReadRequestStatus}
reset::read_request::{PendingReadHint, ReadRequestState, ReadRequestStatus}
};
use dep::types::constants::{
MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX,
Expand Down

Large diffs are not rendered by default.

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;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::non_existent_read_request_reset::{NonMembershipHint};
use crate::reset::non_existent_read_request::NonMembershipHint;
use dep::types::{
abis::{nullifier_leaf_preimage::NullifierLeafPreimage, side_effect::SideEffectLinkedToNoteHash},
merkle_tree::{MembershipWitness},
merkle_tree::MembershipWitness,
constants::{MAX_NEW_NULLIFIERS_PER_TX, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, NULLIFIER_TREE_HEIGHT}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This will be moved to a separate Read Request Reset Circuit.
use crate::read_request_reset::{PendingReadHint, ReadRequestStatus, ReadValueHint, SettledReadHint};
use crate::reset::read_request::{PendingReadHint, ReadRequestStatus, ReadValueHint, SettledReadHint};
use dep::types::{
abis::{nullifier_leaf_preimage::NullifierLeafPreimage},
constants::{MAX_NULLIFIER_READ_REQUESTS_PER_TX, NULLIFIER_TREE_HEIGHT},
Expand Down Expand Up @@ -44,7 +44,7 @@ struct NullifierReadRequestHints {

mod tests {
use crate::nullifier_read_request_reset::NullifierSettledReadHint;
use crate::read_request_reset::{PendingReadHint, ReadRequestState, ReadRequestStatus, reset_read_requests};
use crate::reset::read_request::{PendingReadHint, ReadRequestState, ReadRequestStatus, reset_read_requests};
use dep::types::{
address::AztecAddress,
abis::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{nullifier_read_request_reset::NullifierReadRequestHints, read_request_reset::reset_read_requests};
use crate::{nullifier_read_request_reset::NullifierReadRequestHints, reset::read_request::reset_read_requests};
use dep::types::{
abis::{side_effect::{SideEffect, SideEffectLinkedToNoteHash}, validation_requests::ValidationRequests},
constants::{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::reset::{mutable_data_read_request::SettledDataReadHint, 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 settled_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],
settled_read_hints: [SettledDataReadHint; MAX_PUBLIC_DATA_READS_PER_TX],
}
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) {
Copy link
Collaborator Author

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.

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.settled_read_hints
);
}
}
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;
Loading
Loading