Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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,078 changes: 936 additions & 142 deletions noir-projects/noir-protocol-circuits/crates/private-kernel-init/Prover.toml

Large diffs are not rendered by default.

1,290 changes: 1,042 additions & 248 deletions noir-projects/noir-protocol-circuits/crates/private-kernel-inner/Prover.toml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod assert_split_sorted_transformed_arrays;
pub mod assert_split_transformed_arrays_from_sorted_padded_array;
pub mod assert_transformed_array;
pub mod sort_by_counter;
pub mod validate_incrementing_counters;

pub use assert_array_appended::{
assert_array_appended, assert_array_appended_and_scoped,
Expand All @@ -25,7 +24,3 @@ pub use assert_split_sorted_transformed_arrays::assert_split_sorted_transformed_
pub use assert_split_transformed_arrays_from_sorted_padded_array::assert_split_transformed_arrays_from_sorted_padded_array;
pub use assert_transformed_array::assert_transformed_array;
pub use sort_by_counter::sort_by_counter;
pub use validate_incrementing_counters::{
validate_incrementing_call_request_counters_within_range,
validate_incrementing_counters_within_range,
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
pub(crate) mod find_index_of_first_fully_revertible_private_call_request;
mod validate_contract_address;
mod validate_min_revertible_side_effect_counter;
mod validate_side_effect_counters;

use crate::accumulated_data::{
validate_incrementing_call_request_counters_within_range,
validate_incrementing_counters_within_range,
};
use dep::types::{
abis::{
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs,
Expand All @@ -14,9 +11,11 @@ use dep::types::{
public_call_request::PublicCallRequest, transaction::tx_request::TxRequest,
},
constants::NULL_MSG_SENDER_CONTRACT_ADDRESS,
traits::Empty,
};
use validate_contract_address::validate_contract_address;
use validate_min_revertible_side_effect_counter::validate_no_phase_change_within_child_calls;
use validate_side_effect_counters::validate_unique_and_within_bounds_side_effect_counters;

pub struct PrivateCallDataValidator {
data: PrivateCallData,
Expand Down Expand Up @@ -47,7 +46,10 @@ impl PrivateCallDataValidator {
self.validate_private_call_requests();
self.validate_public_call_requests();

self.validate_that_side_effect_counters_are_strictly_increasing_and_within_bounds();
validate_unique_and_within_bounds_side_effect_counters(
self.data.public_inputs,
self.data.side_effect_uniqueness_hints,
);
}

/// For Init only.
Expand Down Expand Up @@ -265,7 +267,7 @@ impl PrivateCallDataValidator {
});

// We also process the enqueued teardown call request:
if !public_inputs.public_teardown_call_request.contract_address.is_zero() {
if !public_inputs.public_teardown_call_request.is_empty() {
self.validate_public_call_request(public_inputs.public_teardown_call_request);
}
}
Expand Down Expand Up @@ -297,63 +299,6 @@ impl PrivateCallDataValidator {
}
}

// Tested with validate_counters.nr
fn validate_that_side_effect_counters_are_strictly_increasing_and_within_bounds(self) {
let public_inputs = self.data.public_inputs;
let counter_start = public_inputs.start_side_effect_counter;
let counter_end = public_inputs.end_side_effect_counter;

assert(counter_start < counter_end, "private call has incorrect counter range");

validate_incrementing_counters_within_range(
counter_start,
counter_end,
public_inputs.note_hash_read_requests,
);
validate_incrementing_counters_within_range(
counter_start,
counter_end,
public_inputs.nullifier_read_requests,
);
validate_incrementing_counters_within_range(
counter_start,
counter_end,
public_inputs.note_hashes,
);
validate_incrementing_counters_within_range(
counter_start,
counter_end,
public_inputs.nullifiers,
);
validate_incrementing_counters_within_range(
counter_start,
counter_end,
public_inputs.l2_to_l1_msgs,
);
validate_incrementing_counters_within_range(
counter_start,
counter_end,
public_inputs.private_logs,
);
validate_incrementing_counters_within_range(
counter_start,
counter_end,
public_inputs.contract_class_logs_hashes,
);
validate_incrementing_call_request_counters_within_range(
counter_start,
counter_end,
public_inputs.private_call_requests,
);

// Validate the public call requests by checking their start counters only, as their end counters are unknown.
validate_incrementing_counters_within_range(
counter_start,
counter_end,
public_inputs.public_call_requests,
);
}

fn validate_expected_counters(self, claimed_revertible_counter: u32) {
let expected_non_revertible_side_effect_counter =
self.data.public_inputs.expected_non_revertible_side_effect_counter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
use types::{
abis::{
private_call_request::PrivateCallRequest,
private_circuit_public_inputs::PrivateCircuitPublicInputs,
private_kernel::private_call_data::{SideEffectCounterRange, SideEffectUniquenessHints},
},
constants::{
GLOBAL_INDEX_CONTRACT_CLASS_LOG_HASH_OFFSET, GLOBAL_INDEX_L2_TO_L1_MSG_OFFSET,
GLOBAL_INDEX_NOTE_HASH_OFFSET, GLOBAL_INDEX_NOTE_HASH_READ_REQUEST_OFFSET,
GLOBAL_INDEX_NULLIFIER_OFFSET, GLOBAL_INDEX_NULLIFIER_READ_REQUEST_OFFSET,
GLOBAL_INDEX_PRIVATE_CALL_REQUEST_OFFSET, GLOBAL_INDEX_PRIVATE_LOG_OFFSET,
GLOBAL_INDEX_PUBLIC_CALL_REQUEST_OFFSET, TOTAL_COUNTED_SIDE_EFFECTS_PER_CALL,
},
side_effect::Ordered,
utils::arrays::ClaimedLengthArray,
};

// Tested in tests/private_call_data_validator_builder/validate_side_effect_counters.nr
pub fn validate_unique_and_within_bounds_side_effect_counters(
public_inputs: PrivateCircuitPublicInputs,
side_effect_sorting_hints: SideEffectUniquenessHints,
) {
let side_effect_ranges = side_effect_sorting_hints.side_effect_ranges;

let total_side_effects = public_inputs.note_hash_read_requests.length
+ public_inputs.nullifier_read_requests.length
+ public_inputs.note_hashes.length
+ public_inputs.nullifiers.length
+ public_inputs.private_call_requests.length
+ public_inputs.public_call_requests.length
+ public_inputs.l2_to_l1_msgs.length
+ public_inputs.private_logs.length
+ public_inputs.contract_class_logs_hashes.length;

validate_side_effect_range(
public_inputs.note_hash_read_requests,
side_effect_sorting_hints.note_hash_read_request_indices,
side_effect_ranges,
GLOBAL_INDEX_NOTE_HASH_READ_REQUEST_OFFSET,
total_side_effects,
);
validate_side_effect_range(
public_inputs.nullifier_read_requests,
side_effect_sorting_hints.nullifier_read_request_indices,
side_effect_ranges,
GLOBAL_INDEX_NULLIFIER_READ_REQUEST_OFFSET,
total_side_effects,
);
validate_side_effect_range(
public_inputs.note_hashes,
side_effect_sorting_hints.note_hashes_indices,
side_effect_ranges,
GLOBAL_INDEX_NOTE_HASH_OFFSET,
total_side_effects,
);
validate_side_effect_range(
public_inputs.nullifiers,
side_effect_sorting_hints.nullifiers_indices,
side_effect_ranges,
GLOBAL_INDEX_NULLIFIER_OFFSET,
total_side_effects,
);
validate_side_effect_range_for_call_request(
public_inputs.private_call_requests,
side_effect_sorting_hints.private_call_requests_indices,
side_effect_ranges,
GLOBAL_INDEX_PRIVATE_CALL_REQUEST_OFFSET,
total_side_effects,
);
validate_side_effect_range(
public_inputs.public_call_requests,
side_effect_sorting_hints.public_call_requests_indices,
side_effect_ranges,
GLOBAL_INDEX_PUBLIC_CALL_REQUEST_OFFSET,
total_side_effects,
);
validate_side_effect_range(
public_inputs.l2_to_l1_msgs,
side_effect_sorting_hints.l2_to_l1_msgs_indices,
side_effect_ranges,
GLOBAL_INDEX_L2_TO_L1_MSG_OFFSET,
total_side_effects,
);
validate_side_effect_range(
public_inputs.private_logs,
side_effect_sorting_hints.private_logs_indices,
side_effect_ranges,
GLOBAL_INDEX_PRIVATE_LOG_OFFSET,
total_side_effects,
);
validate_side_effect_range(
public_inputs.contract_class_logs_hashes,
side_effect_sorting_hints.contract_class_logs_hashes_indices,
side_effect_ranges,
GLOBAL_INDEX_CONTRACT_CLASS_LOG_HASH_OFFSET,
total_side_effects,
);

let counter_start = public_inputs.start_side_effect_counter;
let counter_end = public_inputs.end_side_effect_counter;

assert(counter_start < counter_end, "private call has incorrect counter range");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check is redundant since it'd fail on validate_increasing_ranges, but it's cheap and we'd get a better error message


validate_increasing_ranges(
side_effect_ranges,
total_side_effects,
counter_start,
counter_end,
);
}

fn validate_side_effect_range<T, let N: u32>(
items: ClaimedLengthArray<T, N>,
indices: [u32; N],
side_effect_ranges: [SideEffectCounterRange; TOTAL_COUNTED_SIDE_EFFECTS_PER_CALL],
global_index_offset: u32,
total_side_effects: u32,
)
where
T: Ordered,
{
let mut should_check = true;
for i in 0..N {
let global_index = global_index_offset + i;
let index = indices[i];
let range = side_effect_ranges[index];
let counter = items.array[i].counter();

should_check &= i != items.length;

if should_check {
// Validate index
assert(index < total_side_effects, "side effect range index out of bounds");
// Validate that counter == range item
assert_eq(counter, range.start, "counter does not match start range item");
assert_eq(counter, range.end, "counter does not match end range item");
assert_eq(
global_index,
range.side_effect_global_index,
"range global index does not match side effect global index",
);
}
}
}

fn validate_side_effect_range_for_call_request<let N: u32>(
private_call_requests: ClaimedLengthArray<PrivateCallRequest, N>,
indices: [u32; N],
side_effect_ranges: [SideEffectCounterRange; TOTAL_COUNTED_SIDE_EFFECTS_PER_CALL],
global_index_offset: u32,
total_side_effects: u32,
) {
let mut should_check = true;
for i in 0..N {
let global_index = global_index_offset + i;
let index = indices[i];
let range = side_effect_ranges[index];
let item = private_call_requests.array[i];
let start_counter = item.start_side_effect_counter;
let end_counter = item.end_side_effect_counter;

should_check &= i != private_call_requests.length;

if should_check {
// Validate index
assert(index < total_side_effects, "side effect range index out of bounds");
// Validate that (start_counter, end_counter) == range item
assert_eq(start_counter, range.start, "start counter does not match range item");
assert_eq(end_counter, range.end, "end counter does not match range item");
assert(start_counter < end_counter, "nested call has incorrect counter range");

assert_eq(
global_index,
range.side_effect_global_index,
"range global index does not match side effect global index",
);
}
}
}

fn validate_increasing_ranges(
side_effect_ranges: [SideEffectCounterRange; TOTAL_COUNTED_SIDE_EFFECTS_PER_CALL],
total_side_effects: u32,
counter_start: u32,
counter_end: u32,
) {
let mut prev_counter = counter_start;
let mut should_check = true;
for i in 0..TOTAL_COUNTED_SIDE_EFFECTS_PER_CALL {
let range = side_effect_ranges[i];
should_check &= i != total_side_effects;

if should_check {
assert(
range.start > prev_counter,
"start counter must be greater than previous counter",
);
prev_counter = range.end;
}
}
assert(prev_counter < counter_end, "end counter must be less than the end counter of the call");
}
Loading
Loading