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: prepare circuit output for validation #6678

Merged
merged 25 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2aa7ed2
Verify built output for private init.
LeilaWang May 23, 2024
4bf7ad5
Tests for private kernel circuit public inputs composer.
LeilaWang May 24, 2024
cfb64c1
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 24, 2024
90681c8
Fixes after merge.
LeilaWang May 24, 2024
5a5bbd8
Update tests.
LeilaWang May 24, 2024
e07cef8
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 24, 2024
92c792f
Move tests to folder.
LeilaWang May 24, 2024
5354e92
Merge branch 'master' into lw/circuit_output_validation
ludamad May 24, 2024
85f68c3
Use fixture builder for private call.
LeilaWang May 26, 2024
2774eb2
Merge remote-tracking branch 'origin/lw/circuit_output_validation' in…
LeilaWang May 26, 2024
4f54da1
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 27, 2024
7b9504e
Fix after merge.
LeilaWang May 27, 2024
026f359
Update tests.
LeilaWang May 27, 2024
b47042e
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 27, 2024
7b4584b
Fix fixtures.
LeilaWang May 28, 2024
611726a
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 28, 2024
3dfd361
Move components to folder.
LeilaWang May 28, 2024
50702a7
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 28, 2024
7d06e86
Address feedback.
LeilaWang May 28, 2024
3c245ae
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 28, 2024
b97e523
Check note logs in private call data validator.
LeilaWang May 28, 2024
1901d3b
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 28, 2024
f3895fa
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 29, 2024
09805ad
Merge remote-tracking branch 'origin/master' into lw/circuit_output_v…
LeilaWang May 29, 2024
02fd639
Fix.
LeilaWang May 29, 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
Expand Up @@ -2,5 +2,5 @@ use dep::private_kernel_lib::PrivateKernelInitCircuitPrivateInputs;
use dep::types::PrivateKernelCircuitPublicInputs;

unconstrained fn main(input: PrivateKernelInitCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs {
input.native_private_kernel_circuit_initial()
input.execute()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use dep::types::PrivateKernelCircuitPublicInputs;

#[recursive]
fn main(input: PrivateKernelInitCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs {
input.native_private_kernel_circuit_initial()
input.execute()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use dep::private_kernel_lib::PrivateKernelInnerCircuitPrivateInputs;
use dep::types::PrivateKernelCircuitPublicInputs;

unconstrained fn main(input: PrivateKernelInnerCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs {
input.native_private_kernel_circuit_inner()
input.execute()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use dep::types::PrivateKernelCircuitPublicInputs;

#[recursive]
fn main(input: PrivateKernelInnerCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs {
input.native_private_kernel_circuit_inner()
input.execute()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod kernel_circuit_public_inputs_composer;
mod private_call_data_validator;
mod private_kernel_circuit_output_validator;
mod private_kernel_circuit_public_inputs_composer;
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
use dep::types::{
abis::{
call_context::CallContext, call_request::CallRequest, caller_context::CallerContext,
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs,
private_call_request::ScopedPrivateCallRequest, private_call_stack_item::PrivateCallStackItem,
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_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
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]) -> u64 {
find_index(
accumulated_note_hashes,
|n: ScopedNoteHash| n.counter() == note_log.note_hash_counter
)
}

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 Down Expand Up @@ -107,13 +115,14 @@ impl PrivateCallDataValidator {
PrivateCallDataValidator { data, array_lengths }
}

pub fn validate(self) {
pub fn validate<N>(self, accumulated_note_hashes: [ScopedNoteHash; N]) {
self.validate_contract_address();
self.validate_call();
self.validate_private_call_requests();
self.validate_public_call_requests();
self.validate_teardown_call_request();
self.validate_counters();
self.validate_note_logs(accumulated_note_hashes);
}

pub fn validate_as_first_call(self, first_revertible_private_call_request_index: u64) {
Expand Down Expand Up @@ -188,8 +197,7 @@ impl PrivateCallDataValidator {
let public_inputs = self.data.call_stack_item.public_inputs;
assert_eq(public_inputs.historical_header, constants.historical_header, "mismatch historical header");
assert_eq(public_inputs.tx_context, constants.tx_context, "mismatch tx context");
// constants.global_variables refers to the states shared among all txs in a block.
// It should be empty when executing private functions (initialized in PrivateKernelCircuitPublicInputsComposer.new_from_tx_request()).
// constants.global_variables is not relevant to private functions and is ensured to be empty in PrivateKernelCircuitOutputValidator.
}

fn validate_contract_address(self) {
Expand Down Expand Up @@ -252,6 +260,9 @@ impl PrivateCallDataValidator {
assert_eq(
self.array_lengths.new_l2_to_l1_msgs, 0, "new_l2_to_l1_msgs must be empty for static calls"
);
assert_eq(
self.array_lengths.note_encrypted_logs_hashes, 0, "note_encrypted_logs_hashes must be empty for static calls"
);
assert_eq(
self.array_lengths.encrypted_logs_hashes, 0, "encrypted_logs_hashes must be empty for static calls"
);
Expand Down Expand Up @@ -368,4 +379,25 @@ impl PrivateCallDataValidator {
teardown_call_request_count
);
}

fn validate_note_logs<N>(self, accumulated_note_hashes: [ScopedNoteHash; N]) {
let note_logs = self.data.call_stack_item.public_inputs.note_encrypted_logs_hashes;
let num_logs = self.array_lengths.note_encrypted_logs_hashes;
let storage_contract_address = self.data.call_stack_item.public_inputs.call_context.storage_contract_address;
let mut should_check = true;
for i in 0..note_logs.len() {
should_check &= i != num_logs;
if should_check {
let note_index = match_log_to_note(note_logs[i], accumulated_note_hashes);
assert(note_index != N, "could not find note hash linked to note log");
assert_eq(
note_logs[i].note_hash_counter, accumulated_note_hashes[note_index].counter(), "could not find note hash linked to note log"
);
// If the note_index points to an empty note hash, the following check will fail.
assert_eq(
accumulated_note_hashes[note_index].contract_address, storage_contract_address, "could not link a note log to a note hash in another contract"
);
}
}
}
}
Loading
Loading