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

refactor: private tail circuits #7148

Merged
merged 21 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d017c95
Build hints for private init in noir.
LeilaWang Jun 5, 2024
304e5b9
Build private tail hints in noir.
LeilaWang Jun 16, 2024
609af30
Merge remote-tracking branch 'origin/master' into lw/build_hints_in_noir
LeilaWang Jun 16, 2024
b9c2823
Update type.
LeilaWang Jun 16, 2024
3050229
Private tail to public output composer.
LeilaWang Jun 19, 2024
3d921ca
Merge remote-tracking branch 'origin/master' into lw/build_hints_in_noir
LeilaWang Jun 19, 2024
c089385
Verify the output of private_tail_to_public against previous kernel.
LeilaWang Jun 27, 2024
b91742f
Move util.
LeilaWang Jun 27, 2024
c2435ef
Test tail circuits in constrained mode to run output validator.
LeilaWang Jun 27, 2024
af8f82f
Fix test.
LeilaWang Jun 27, 2024
a4ae476
Merge remote-tracking branch 'origin/master' into lw/build_hints_in_noir
LeilaWang Jun 27, 2024
86bfffe
Remove hints for private tail circuit from ts.
LeilaWang Jun 27, 2024
59dbfa3
Revert changes to public call stack.
LeilaWang Jun 29, 2024
1afa3fd
Reverse public call requests.
LeilaWang Jun 29, 2024
201c1b4
Update fixture.
LeilaWang Jun 30, 2024
c2b19a4
Increase timeout.
LeilaWang Jun 30, 2024
e7ba8bc
Add script for generating flamegraph.
LeilaWang Jul 1, 2024
e510c66
Merge remote-tracking branch 'origin/master' into lw/build_hints_in_noir
LeilaWang Jul 1, 2024
267516c
Rename files.
LeilaWang Jul 1, 2024
e1252ba
Update assert_split_sorted_transformed_value_arrays and tests.
LeilaWang Jul 1, 2024
5828970
Merge remote-tracking branch 'origin/master' into lw/build_hints_in_noir
LeilaWang Jul 1, 2024
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mod kernel_circuit_output_hints;
mod kernel_circuit_output_validator;
mod kernel_circuit_public_inputs_composer;
mod previous_kernel_validator;
mod private_call_data_validator;
mod private_kernel_circuit_output_validator;
mod private_kernel_circuit_public_inputs_composer;
mod tail_output_composer;
mod tail_output_validator;
mod tail_to_public_output_composer;
mod tail_to_public_output_validator;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ impl PreviousKernelValidator {
}

pub fn validate_for_private_tail(self) {
self.validate_empty_private_call_stack();
self.validate_common();
self.validate_empty_public_call_stack();
self.verify_empty_validation_requests();
self.verify_no_transient_data();
}

pub fn validate_for_private_tail_to_public(self) {
self.validate_empty_private_call_stack();
self.validate_common();
self.validate_non_empty_public_call_stack();
}

fn validate_common(self) {
self.validate_empty_private_call_stack();
self.verify_empty_validation_requests();
self.verify_no_transient_data();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
mod find_first_revertible_item_index;
mod validate_split_ranges;

use crate::components::private_call_data_validator::{
find_first_revertible_item_index::find_first_revertible_item_index,
validate_split_ranges::validate_split_ranges
};
use dep::types::{
abis::{
call_context::CallContext, call_request::CallRequest, caller_context::CallerContext,
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, log_hash::NoteLogHash,
note_hash::ScopedNoteHash, private_call_request::ScopedPrivateCallRequest,
private_call_stack_item::PrivateCallStackItem,
private_circuit_public_inputs::PrivateCircuitPublicInputsArrayLengths,
private_circuit_public_inputs::{PrivateCircuitPublicInputs, PrivateCircuitPublicInputsArrayLengths},
private_kernel::private_call_data::PrivateCallData, side_effect::{Ordered, RangeOrdered}
},
address::{AztecAddress, PartialAddress}, contract_class_id::ContractClassId,
hash::{private_functions_root_from_siblings, stdlib_recursion_verification_key_compress_native_vk},
traits::is_empty, transaction::tx_request::TxRequest, utils::arrays::find_index
};

unconstrained fn match_log_to_note<N>(note_log: NoteLogHash, accumulated_note_hashes: [ScopedNoteHash; N]) -> u32 {
unconstrained fn match_log_to_note<N>(
note_log: NoteLogHash,
accumulated_note_hashes: [ScopedNoteHash; N]
) -> u32 {
find_index(
accumulated_note_hashes,
|n: ScopedNoteHash| n.counter() == note_log.note_hash_counter
)
}

unconstrained fn find_first_revertible_private_call_request_index(public_inputs: PrivateCircuitPublicInputs) -> u32 {
find_first_revertible_item_index(
public_inputs.min_revertible_side_effect_counter,
public_inputs.private_call_requests
)
}

fn validate_caller_context(caller_context: CallerContext, this_context: CallContext) {
let matching_caller_context = caller_context.msg_sender.eq(this_context.msg_sender)
& caller_context.storage_contract_address.eq(this_context.storage_contract_address);
Expand All @@ -38,12 +55,7 @@ fn validate_call_request(request: CallRequest, hash: Field, caller: PrivateCallS
}
}

fn validate_incrementing_counters_within_range<T, N>(
counter_start: u32,
counter_end: u32,
items: [T; N],
num_items: u32
) where T: Ordered {
fn validate_incrementing_counters_within_range<T, N>(counter_start: u32, counter_end: u32, items: [T; N], num_items: u32) where T: Ordered {
let mut prev_counter = counter_start;
let mut should_check = true;
for i in 0..N {
Expand Down Expand Up @@ -83,27 +95,6 @@ fn validate_incrementing_counter_ranges_within_range<T, N>(
);
}

fn validate_clean_split_ranges<T, N>(
min_revertible_side_effect_counter: u32,
first_revertible_item_index: u32,
items: [T; N],
num_items: u32
) where T: RangeOrdered {
if first_revertible_item_index != 0 {
let last_non_revertible_item_index = first_revertible_item_index - 1;
let item = items[last_non_revertible_item_index];
assert(
min_revertible_side_effect_counter > item.counter_end(), "min_revertible_side_effect_counter must be greater than the end counter of the last non revertible item"
);
}
if first_revertible_item_index != num_items {
let item = items[first_revertible_item_index];
assert(
min_revertible_side_effect_counter <= item.counter_start(), "min_revertible_side_effect_counter must be less than or equal to the start counter of the first revertible item"
);
}
}

struct PrivateCallDataValidator {
data: PrivateCallData,
array_lengths: PrivateCircuitPublicInputsArrayLengths,
Expand All @@ -125,18 +116,19 @@ impl PrivateCallDataValidator {
self.validate_note_logs(accumulated_note_hashes);
}

pub fn validate_as_first_call(self, first_revertible_private_call_request_index: u32) {
pub fn validate_as_first_call(self) {
let public_inputs = self.data.call_stack_item.public_inputs;
let call_context = public_inputs.call_context;
assert(call_context.is_delegate_call == false, "Users cannot make a delegatecall");
assert(call_context.is_static_call == false, "Users cannot make a static call");

let min_revertible_side_effect_counter = public_inputs.min_revertible_side_effect_counter;
let first_revertible_index = find_first_revertible_private_call_request_index(public_inputs);
// No need to check that the min_revertible_side_effect_counter falls in the counter range of the private call.
// It is valid as long as it does not fall in the middle of any nested call.
validate_clean_split_ranges(
validate_split_ranges(
min_revertible_side_effect_counter,
first_revertible_private_call_request_index,
first_revertible_index,
public_inputs.private_call_requests,
self.array_lengths.private_call_requests
);
Expand Down
Loading
Loading