Skip to content

Commit

Permalink
2612 - add validation in native private kernel circuit of arrays in a…
Browse files Browse the repository at this point in the history
…ccumulated data
  • Loading branch information
jeanmon committed Oct 2, 2023
1 parent 78bd1a3 commit 94a2c58
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
40 changes: 32 additions & 8 deletions circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,48 @@ void common_validate_arrays(DummyBuilder& builder, PrivateCircuitPublicInputs<NT
// Each of the following arrays is expected to be zero-padded.
// In addition, some of the following arrays (new_commitments, etc...) are passed
// to push_array_to_array() routines which rely on the passed arrays to be well-formed.
validate_array(builder, app_public_inputs.return_values, "Return values");
validate_array(builder, app_public_inputs.read_requests, "Read requests");
validate_array(builder, app_public_inputs.new_commitments, "New commitments");
validate_array(builder, app_public_inputs.new_nullifiers, "New nullifiers");
validate_array(builder, app_public_inputs.nullified_commitments, "Nullified commitments");
validate_array(builder, app_public_inputs.private_call_stack, "Private Call Stack");
validate_array(builder, app_public_inputs.public_call_stack, "Public Call Stack");
validate_array(builder, app_public_inputs.new_l2_to_l1_msgs, "New L2 to L1 messages");
validate_array(builder, app_public_inputs.return_values, "App public inputs - Return values");
validate_array(builder, app_public_inputs.read_requests, "App public inputs - Read requests");
validate_array(builder, app_public_inputs.new_commitments, "App public inputs - New commitments");
validate_array(builder, app_public_inputs.new_nullifiers, "App public inputs - New nullifiers");
validate_array(builder, app_public_inputs.nullified_commitments, "App public inputs - Nullified commitments");
validate_array(builder, app_public_inputs.private_call_stack, "App public inputs - Private call stack");
validate_array(builder, app_public_inputs.public_call_stack, "App public inputs - Public call stack");
validate_array(builder, app_public_inputs.new_l2_to_l1_msgs, "App public inputs - New L2 to L1 messages");
// encrypted_logs_hash and unencrypted_logs_hash have their own integrity checks.
}

/**
* @brief We validate that relevant arrays assumed to be zero-padded on the right comply to this format.
*
* @param builder
* @param end Reference to previous_kernel.public_inputs.end.
*/
void common_validate_end_arrays(DummyBuilder& builder, CombinedAccumulatedData<NT> const& end)
{
// Each of the following arrays is expected to be zero-padded.
validate_array(builder, end.read_requests, "Accumulated data - Read Requests");
validate_array(builder, end.new_commitments, "Accumulated data - New commitments");
validate_array(builder, end.new_nullifiers, "Accumulated data - New nullifiers");
validate_array(builder, end.nullified_commitments, "Accumulated data - Nullified commitments");
validate_array(builder, end.private_call_stack, "Accumulated data - Private call stack");
validate_array(builder, end.public_call_stack, "Accumulated data - Public call stack");
validate_array(builder, end.new_l2_to_l1_msgs, "Accumulated data - New L2 to L1 messages");
}

void common_validate_0th_nullifier(DummyBuilder& builder, CombinedAccumulatedData<NT> const& end)
{
builder.do_assert(end.new_nullifiers[0] != 0,
"The 0th nullifier in the accumulated nullifier array is zero",
CircuitErrorCode::PRIVATE_KERNEL__0TH_NULLLIFIER_IS_ZERO);
}

void common_validate_end_values(DummyBuilder& builder, CombinedAccumulatedData<NT> const& end)
{
common_validate_end_arrays(builder, end);
common_validate_0th_nullifier(builder, end);
}

void common_update_end_values(DummyBuilder& builder,
PrivateCallData<NT> const& private_call,
KernelCircuitPublicInputs<NT>& public_inputs)
Expand Down
2 changes: 2 additions & 0 deletions circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void common_validate_read_requests(DummyBuilder& builder,
MAX_READ_REQUESTS_PER_CALL> const& read_request_membership_witnesses);

void common_validate_arrays(DummyBuilder& builder, PrivateCircuitPublicInputs<NT> const& app_public_inputs);
void common_validate_end_arrays(DummyBuilder& builder, CombinedAccumulatedData<NT> const& end);
void common_validate_end_values(DummyBuilder& builder, CombinedAccumulatedData<NT> const& end);
void common_validate_0th_nullifier(DummyBuilder& builder, CombinedAccumulatedData<NT> const& end);

void common_update_end_values(DummyBuilder& builder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ void validate_inputs(DummyCircuitBuilder& builder, PrivateKernelInputsInner<NT>
builder.do_assert(start_private_call_stack_length != 0,
"Cannot execute private kernel circuit with an empty private call stack",
CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_EMPTY);

common_validate_0th_nullifier(builder, private_inputs.previous_kernel.public_inputs.end);
}

KernelCircuitPublicInputs<NT> native_private_kernel_circuit_inner(DummyCircuitBuilder& builder,
Expand All @@ -101,6 +99,8 @@ KernelCircuitPublicInputs<NT> native_private_kernel_circuit_inner(DummyCircuitBu
// We'll be pushing data to this during execution of this circuit.
KernelCircuitPublicInputs<NT> public_inputs{};

common_validate_end_values(builder, private_inputs.previous_kernel.public_inputs.end);

// Do this before any functions can modify the inputs.
initialise_end_values(private_inputs.previous_kernel, public_inputs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ KernelCircuitPublicInputsFinal<NT> native_private_kernel_circuit_ordering(
// We'll be pushing data to this during execution of this circuit.
KernelCircuitPublicInputsFinal<NT> public_inputs{};

common_validate_end_values(builder, private_inputs.previous_kernel.public_inputs.end);

// Do this before any functions can modify the inputs.
initialise_end_values(private_inputs.previous_kernel, public_inputs);

Expand Down

0 comments on commit 94a2c58

Please sign in to comment.