Skip to content

Commit

Permalink
chore: reorder stuffs and update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant committed Oct 23, 2023
1 parent b8b8e02 commit fad3da4
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub fn initialize_end_values(previous_kernel : PreviousKernelData, public_inputs
// functions within this circuit:
let start = previous_kernel.public_inputs.end;

public_inputs.end.read_requests = arrays::array_to_bounded_vec(start.read_requests, arrays::is_empty, 0);
public_inputs.end.new_commitments = arrays::array_to_bounded_vec(start.new_commitments, arrays::is_empty, 0);
public_inputs.end.new_nullifiers = arrays::array_to_bounded_vec(start.new_nullifiers, arrays::is_empty, 0);
public_inputs.end.nullified_commitments = arrays::array_to_bounded_vec(start.nullified_commitments, arrays::is_empty, 0);
Expand All @@ -123,6 +124,7 @@ pub fn initialize_end_values(previous_kernel : PreviousKernelData, public_inputs
public_inputs.end.unencrypted_log_preimages_length = start.unencrypted_log_preimages_length;

public_inputs.end.optionally_revealed_data = start.optionally_revealed_data;
public_inputs.end.new_contracts = arrays::array_to_bounded_vec(previous_kernel.public_inputs.end.new_contracts, |ncd: NewContractData| ncd.is_empty(), NewContractData::default());
}

pub fn update_end_values(private_call : PrivateCallData, public_inputs : &mut KernelCircuitPublicInputsBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::abis::{
combined_constant_data::CombinedConstantData,
previous_kernel_data::PreviousKernelData,
private_kernel::private_call_data::PrivateCallData,
new_contract_data::NewContractData,
kernel_circuit_public_inputs::{KernelCircuitPublicInputs, KernelCircuitPublicInputsBuilder}
};
use crate::utils::{
Expand All @@ -20,16 +21,6 @@ struct PrivateKernelInputsInner {
}

impl PrivateKernelInputsInner {
fn initialize_end_values(self, public_inputs : &mut KernelCircuitPublicInputsBuilder) {
let previous_kernel = self.previous_kernel;

common::initialize_end_values(previous_kernel, public_inputs);

// Ensure the arrays are the same as previously, before we start pushing more data onto them in other
// functions within this circuit:
let start = previous_kernel.public_inputs.end;
public_inputs.end.read_requests = arrays::array_to_bounded_vec(start.read_requests, arrays::is_empty, 0);
}

// TODO: We can create a type alias for private call stack
fn pop_and_validate_this_private_call_hash(self, public_inputs : &mut KernelCircuitPublicInputsBuilder){
Expand Down Expand Up @@ -67,7 +58,7 @@ impl PrivateKernelInputsInner {
common::validate_previous_kernel_values(self.previous_kernel.public_inputs.end);

// Do this before any functions can modify the inputs.
self.initialize_end_values(&mut public_inputs);
common::initialize_end_values(self.previous_kernel, &mut public_inputs);

self.validate_inputs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::abis::{
combined_constant_data::CombinedConstantData,
previous_kernel_data::PreviousKernelData,
private_kernel::private_call_data::PrivateCallData,
new_contract_data::NewContractData,
kernel_circuit_public_inputs::{
KernelCircuitPublicInputs,
KernelCircuitPublicInputsBuilder,
Expand All @@ -37,18 +36,6 @@ struct PrivateKernelInputsOrdering {
}

impl PrivateKernelInputsOrdering {
fn initialize_end_values(self, public_inputs : &mut KernelCircuitPublicInputsBuilder) {
let previous_kernel = self.previous_kernel;

common::initialize_end_values(previous_kernel, public_inputs);

// Ensure the arrays are the same as previously, before we start pushing more data onto them in other
// functions within this circuit:
let start = previous_kernel.public_inputs.end;
public_inputs.end.read_requests = arrays::array_to_bounded_vec(start.read_requests, arrays::is_empty, 0);
public_inputs.end.new_contracts = arrays::array_to_bounded_vec(self.previous_kernel.public_inputs.end.new_contracts, |ncd: NewContractData| ncd.is_empty(), NewContractData::default());
}

fn match_reads_to_commitments(public_inputs : &mut KernelCircuitPublicInputsBuilder, read_commitment_hints :[Field; MAX_READ_REQUESTS_PER_TX]) {
let new_commitments = public_inputs.end.new_commitments;
let read_requests = public_inputs.end.read_requests;
Expand All @@ -74,8 +61,9 @@ impl PrivateKernelInputsOrdering {
public_inputs.end.read_requests = BoundedVec::new(0);
}

fn match_nullifiers_to_commitments_and_squash(public_inputs : &mut KernelCircuitPublicInputsBuilder, nullifier_commitment_hints : [Field; MAX_NEW_NULLIFIERS_PER_TX]) {
// match nullifiers/nullified_commitments to commitments from the previous call(s)
fn match_nullifiers_to_commitments_and_squash(public_inputs : &mut KernelCircuitPublicInputsBuilder, nullifier_commitment_hints : [Field; MAX_NEW_NULLIFIERS_PER_TX]) {
// Remark: The commitments in public_inputs.end have already been siloed by contract address!
// Match nullifiers/nullified_commitments to commitments from the previous call(s)
let nullified_commitments = public_inputs.end.nullified_commitments.storage;
let mut new_commitments = public_inputs.end.new_commitments.storage;
let mut new_nullifiers = public_inputs.end.new_nullifiers.storage;
Expand All @@ -90,8 +78,8 @@ impl PrivateKernelInputsOrdering {
// Non-empty nullified_commitment implies transient nullifier which MUST be matched to a commitment below!
// 0-valued nullified_commitment is empty and will be ignored
if (nullified_commitments[n_idx] != 0) & (nullified_commitments[n_idx] != EMPTY_NULLIFIED_COMMITMENT) {
assert(hint_pos < MAX_NEW_COMMITMENTS_PER_TX as u64, "New nullifier is transient but does not match any new commitment");
assert_eq(nullified_commitment, new_commitments[hint_pos], "Incorrect commitment hint");
assert(hint_pos < MAX_NEW_COMMITMENTS_PER_TX as u64, "New nullifier is transient but hint is invalid");
assert_eq(nullified_commitment, new_commitments[hint_pos], "Hinted commitment does not match");
// match found!
// squash both the nullifier and the commitment
// (set to 0 here and then rearrange array after loop)
Expand Down Expand Up @@ -125,6 +113,7 @@ impl PrivateKernelInputsOrdering {
}

fn apply_commitment_nonces(public_inputs : &mut KernelCircuitPublicInputsBuilder) {
// Remark: The commitments in public_inputs.end have already been siloed by contract address!
// tx hash
let first_nullifier = public_inputs.end.new_nullifiers.get(0);
let mut unique_commitments = public_inputs.end.new_commitments.storage;
Expand All @@ -150,23 +139,13 @@ impl PrivateKernelInputsOrdering {
common::validate_previous_kernel_values(self.previous_kernel.public_inputs.end);

// Do this before any functions can modify the inputs.
self.initialize_end_values(&mut public_inputs);
common::initialize_end_values(self.previous_kernel, &mut public_inputs);

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1486): validate that `len(new_nullifiers) ==
// len(nullified_commitments)`

// Matching read requests to pending commitments requires the full list of new commitments accumulated over
// all iterations of the private kernel. Therefore, we match reads against new_commitments in
// previous_kernel.public_inputs.end, where "previous kernel" is the last "inner" kernel iteration.
// Remark: The commitments in public_inputs.end have already been siloed by contract address!

PrivateKernelInputsOrdering::match_reads_to_commitments(&mut public_inputs, self.read_commitment_hints);

// Matching nullifiers to pending commitments requires the full list of new commitments accumulated over
// all iterations of the private kernel. Therefore, we match nullifiers (their nullified_commitments)
// against new_commitments in public_inputs.end which has been initialized to
// previous_kernel.public_inputs.end in common_initialize_*() above.
// Remark: The commitments in public_inputs.end have already been siloed by contract address!
PrivateKernelInputsOrdering::match_nullifiers_to_commitments_and_squash(&mut public_inputs, self.nullifier_commitment_hints);

PrivateKernelInputsOrdering::apply_commitment_nonces(&mut public_inputs);
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit fad3da4

Please sign in to comment.