Skip to content

Commit

Permalink
1407 - remove assertions and tests which are not relevant anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Sep 1, 2023
1 parent aa36af2 commit 439bcdb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 199 deletions.
10 changes: 0 additions & 10 deletions circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ void common_validate_read_requests(DummyBuilder& builder,
std::array<ReadRequestMembershipWitness<NT, PRIVATE_DATA_TREE_HEIGHT>,
MAX_READ_REQUESTS_PER_CALL> const& read_request_membership_witnesses)
{
// Arrays read_request and read_request_membership_witnesses must be of the same length. Otherwise,
// we might get into trouble when accumulating them in public_inputs.end
builder.do_assert(array_length(read_requests) == array_length(read_request_membership_witnesses),
format("[private kernel circuit] mismatch array length between read_requests and witnesses - "
"read_requests length: ",
array_length(read_requests),
" witnesses length: ",
array_length(read_request_membership_witnesses)),
CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_WITNESSES_ARRAY_LENGTH_MISMATCH);

// membership witnesses must resolve to the same private data root
// for every request in all kernel iterations
for (size_t rr_idx = 0; rr_idx < aztec3::MAX_READ_REQUESTS_PER_CALL; rr_idx++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,62 +596,6 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_works)
// Check enforcement that inner iterations' read_requests match root in constants
// https://github.com/AztecProtocol/aztec-packages/issues/786

TEST_F(native_private_kernel_init_tests, native_read_requests_less_than_witnesses)
{
auto private_inputs = do_private_call_get_kernel_inputs_init(false, deposit, standard_test_args());

auto const& contract_address =
private_inputs.private_call.call_stack_item.public_inputs.call_context.storage_contract_address;

auto const first_nullifier = silo_nullifier<NT>(contract_address, private_inputs.tx_request.hash());
auto [read_requests,
read_request_membership_witnesses,
_transient_read_requests,
_transient_read_request_membership_witnesses,
root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL);

read_requests[MAX_READ_REQUESTS_PER_CALL - 1] = fr(0);
private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root;
private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests;
private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses;

DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_requests_less_than_witnesses");
native_private_kernel_circuit_initial(builder, private_inputs);

ASSERT_TRUE(builder.failed());
ASSERT_EQ(builder.get_first_failure().code,
CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_WITNESSES_ARRAY_LENGTH_MISMATCH);
}

TEST_F(native_private_kernel_init_tests, native_read_requests_more_than_witnesses)
{
auto private_inputs = do_private_call_get_kernel_inputs_init(false, deposit, standard_test_args());

auto const& contract_address =
private_inputs.private_call.call_stack_item.public_inputs.call_context.storage_contract_address;

auto const first_nullifier = silo_nullifier<NT>(contract_address, private_inputs.tx_request.hash());
auto [read_requests,
read_request_membership_witnesses,
_transient_read_requests,
_transient_read_request_membership_witnesses,
root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL);

read_request_membership_witnesses[MAX_READ_REQUESTS_PER_CALL - 1] =
ReadRequestMembershipWitness<NT, PRIVATE_DATA_TREE_HEIGHT>{};

private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root;
private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests;
private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses;

DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_requests_more_than_witnesses");
native_private_kernel_circuit_initial(builder, private_inputs);

ASSERT_TRUE(builder.failed());
ASSERT_EQ(builder.get_first_failure().code,
CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_WITNESSES_ARRAY_LENGTH_MISMATCH);
}

TEST_F(native_private_kernel_init_tests, native_one_transient_read_requests_works)
{
// one transient read request should work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,78 +568,6 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_works)
ASSERT_EQ(array_length(public_inputs.end.read_requests), 0);
}

TEST_F(native_private_kernel_inner_tests, native_read_requests_less_than_witnesses)
{
auto private_inputs = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args());

auto const& contract_address =
private_inputs.private_call.call_stack_item.public_inputs.call_context.storage_contract_address;

auto const first_nullifier =
silo_nullifier<NT>(contract_address, private_inputs.previous_kernel.public_inputs.end.new_nullifiers[0]);
auto [read_requests,
read_request_membership_witnesses,
_transient_read_requests,
_transient_read_request_membership_witnesses,
root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL);

read_requests[MAX_READ_REQUESTS_PER_CALL - 1] = fr(0);
private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root;
private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root;
private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests;
private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses;

// We need to update the previous_kernel's private_call_stack because the current_call_stack_item has changed
// i.e. we changed the public_inputs->read_requests and public_inputs->historic_private_data_tree_root of the
// current_call_stack_item
private_inputs.previous_kernel.public_inputs.end.private_call_stack[0] =
private_inputs.private_call.call_stack_item.hash();

DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_requests_less_than_witnesses");
native_private_kernel_circuit_inner(builder, private_inputs);

ASSERT_TRUE(builder.failed());
ASSERT_EQ(builder.get_first_failure().code,
CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_WITNESSES_ARRAY_LENGTH_MISMATCH);
}

TEST_F(native_private_kernel_inner_tests, native_read_requests_more_than_witnesses)
{
auto private_inputs = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args());

auto const& contract_address =
private_inputs.private_call.call_stack_item.public_inputs.call_context.storage_contract_address;

auto const first_nullifier =
silo_nullifier<NT>(contract_address, private_inputs.previous_kernel.public_inputs.end.new_nullifiers[0]);
auto [read_requests,
read_request_membership_witnesses,
_transient_read_requests,
_transient_read_request_membership_witnesses,
root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL);

read_request_membership_witnesses[MAX_READ_REQUESTS_PER_CALL - 1] =
ReadRequestMembershipWitness<NT, PRIVATE_DATA_TREE_HEIGHT>{};

private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root;
private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root;
private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests;
private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses;

// We need to update the previous_kernel's private_call_stack because the current_call_stack_item has changed
// i.e. we changed the public_inputs->read_requests and public_inputs->historic_private_data_tree_root of the
// current_call_stack_item
private_inputs.previous_kernel.public_inputs.end.private_call_stack[0] =
private_inputs.private_call.call_stack_item.hash();

DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_requests_more_than_witnesses");
native_private_kernel_circuit_inner(builder, private_inputs);

ASSERT_TRUE(builder.failed());
ASSERT_EQ(builder.get_first_failure().code,
CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_WITNESSES_ARRAY_LENGTH_MISMATCH);
}

TEST_F(native_private_kernel_inner_tests, native_one_transient_read_requests_works)
{
// one transient read request should work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ using aztec3::circuits::abis::KernelCircuitPublicInputsFinal;
using aztec3::circuits::abis::PreviousKernelData;
using aztec3::circuits::abis::private_kernel::PrivateKernelInputsOrdering;
using aztec3::circuits::kernel::private_kernel::common_initialise_end_values;
using aztec3::utils::array_length;
using aztec3::utils::array_rearrange;
using aztec3::utils::CircuitErrorCode;
using aztec3::utils::DummyCircuitBuilder;
Expand All @@ -43,42 +42,34 @@ void match_reads_to_commitments(DummyCircuitBuilder& builder,
std::array<NT::fr, MAX_READ_REQUESTS_PER_TX> const& hint_to_commitments,
std::array<NT::fr, MAX_NEW_COMMITMENTS_PER_TX> const& new_commitments)
{
// Arrays read_request and read_request_membership_witnesses must be of the same length. Otherwise,
// we might get into trouble when accumulating them in public_inputs.end
builder.do_assert(array_length(read_requests) == array_length(hint_to_commitments),
format("[private ordering circuit] mismatch array length between read_requests and witnesses - "
"read_requests length: ",
array_length(read_requests),
" witnesses length: ",
array_length(hint_to_commitments)),
CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_WITNESSES_ARRAY_LENGTH_MISMATCH);

// match reads to commitments from the previous call(s)
for (size_t rr_idx = 0; rr_idx < MAX_READ_REQUESTS_PER_TX; rr_idx++) {
const auto& read_request = read_requests[rr_idx];
const auto& hint_to_commitment = hint_to_commitments[rr_idx];

size_t match_pos = MAX_NEW_COMMITMENTS_PER_TX;
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/892): inefficient
// O(n^2) inner loop will be optimized via matching hints
for (size_t c_idx = 0; c_idx < MAX_NEW_COMMITMENTS_PER_TX; c_idx++) {
match_pos = (read_request == new_commitments[c_idx]) ? c_idx : match_pos;
}
if (read_request != 0) {
size_t match_pos = MAX_NEW_COMMITMENTS_PER_TX;
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/892): inefficient
// O(n^2) inner loop will be optimized via matching hints
for (size_t c_idx = 0; c_idx < MAX_NEW_COMMITMENTS_PER_TX; c_idx++) {
match_pos = (read_request == new_commitments[c_idx]) ? c_idx : match_pos;
}

// Transient reads MUST match a pending commitment
builder.do_assert(
match_pos != MAX_NEW_COMMITMENTS_PER_TX,
format("read_request at position [",
rr_idx,
"]* is transient but does not match any new commitment.",
"\n\tread_request: ",
read_request,
"\n\thint_to_commitment: ",
hint_to_commitment,
"\n\t* the read_request position/index is not expected to match position in app-circuit "
"outputs because kernel iterations gradually remove non-transient read_requests as "
"membership checks are resolved."),
CircuitErrorCode::PRIVATE_KERNEL__TRANSIENT_READ_REQUEST_NO_MATCH);
// Transient reads MUST match a pending commitment
builder.do_assert(
match_pos != MAX_NEW_COMMITMENTS_PER_TX,
format("read_request at position [",
rr_idx,
"]* is transient but does not match any new commitment.",
"\n\tread_request: ",
read_request,
"\n\thint_to_commitment: ",
hint_to_commitment,
"\n\t* the read_request position/index is not expected to match position in app-circuit "
"outputs because kernel iterations gradually remove non-transient read_requests as "
"membership checks are resolved."),
CircuitErrorCode::PRIVATE_KERNEL__TRANSIENT_READ_REQUEST_NO_MATCH);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,36 +148,6 @@ TEST_F(native_private_kernel_ordering_tests, native_read_request_unknown_fails)
ASSERT_EQ(failure.code, CircuitErrorCode::PRIVATE_KERNEL__TRANSIENT_READ_REQUEST_NO_MATCH);
}

TEST_F(native_private_kernel_ordering_tests, native_unresolved_non_transient_read_fails)
{
auto private_inputs_inner = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args());

std::array<fr, MAX_NEW_COMMITMENTS_PER_TX> siloed_commitments{};
std::array<fr, MAX_READ_REQUESTS_PER_TX> read_requests{};
std::array<ReadRequestMembershipWitness<NT, PRIVATE_DATA_TREE_HEIGHT>, MAX_READ_REQUESTS_PER_TX>
read_request_membership_witnesses{};

siloed_commitments[0] = NT::fr::random_element();


read_requests[0] = siloed_commitments[0];
read_request_membership_witnesses[0].is_transient = false; // ordering circuit only allows transient reads

auto& previous_kernel = private_inputs_inner.previous_kernel;

previous_kernel.public_inputs.end.new_commitments = siloed_commitments;
previous_kernel.public_inputs.end.read_requests = read_requests;

PrivateKernelInputsOrdering<NT> private_inputs{ previous_kernel, std::array<fr, MAX_READ_REQUESTS_PER_TX>{} };

DummyBuilder builder =
DummyBuilder("native_private_kernel_ordering_tests__native_unresolved_non_transient_read_fails");
native_private_kernel_circuit_ordering(builder, private_inputs);

auto failure = builder.get_first_failure();
ASSERT_EQ(failure.code, CircuitErrorCode::PRIVATE_KERNEL__UNRESOLVED_NON_TRANSIENT_READ_REQUEST);
}

TEST_F(native_private_kernel_ordering_tests, native_squash_one_of_one_transient_matches_works)
{
auto private_inputs_inner = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args());
Expand Down

0 comments on commit 439bcdb

Please sign in to comment.