Skip to content

Commit

Permalink
rename errors with consistency + per david's PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed Jul 19, 2023
1 parent 8bb1a45 commit 23de89d
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 38 deletions.
9 changes: 5 additions & 4 deletions circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ void common_update_end_values(DummyBuilder& builder,
// No state changes are allowed for static calls:
builder.do_assert(is_array_empty(new_commitments) == true,
"new_commitments must be empty for static calls",
CircuitErrorCode::PRIVATE_KERNEL__NEW_COMMITMENTS_NOT_EMPTY_FOR_STATIC_CALL);
CircuitErrorCode::PRIVATE_KERNEL__NEW_COMMITMENTS_PROHIBITED_IN_STATIC_CALL);
builder.do_assert(is_array_empty(new_nullifiers) == true,
"new_nullifiers must be empty for static calls",
CircuitErrorCode::PRIVATE_KERNEL__NEW_NULLIFIERS_NOT_EMPTY_FOR_STATIC_CALL);
CircuitErrorCode::PRIVATE_KERNEL__NEW_NULLIFIERS_PROHIBITED_IN_STATIC_CALL);
}

const auto& storage_contract_address = private_call_public_inputs.call_context.storage_contract_address;
Expand All @@ -199,12 +199,13 @@ void common_update_end_values(DummyBuilder& builder,
array_push(builder,
public_inputs.end.read_requests,
siloed_read_request,
format(PRIVATE_KERNEL_CIRCUIT_ERROR_MESSAGE_BEGINNING, "too many read requests in one tx"));
format(PRIVATE_KERNEL_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"too many transient read requests in one tx"));
array_push(builder,
public_inputs.end.read_request_membership_witnesses,
witness,
format(PRIVATE_KERNEL_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"too many read request membership witnesses in one tx"));
"too many transient read request membership witnesses in one tx"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ void validate_this_private_call_against_tx_request(DummyBuilder& builder,
"call_stack_item.function_data)",
CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM);

builder.do_assert(tx_request.args_hash == call_stack_item.public_inputs.args_hash,
"user's intent does not match initial private call (args passed to tx_request must match "
"args in the call_stack_item)",
CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM);
builder.do_assert(
tx_request.args_hash == call_stack_item.public_inputs.args_hash,
"user's intent does not match initial private call (noir function args passed to tx_request must match "
"args in the call_stack_item)",
CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM);
};

void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInit<NT> const& private_inputs)
Expand Down Expand Up @@ -119,7 +120,7 @@ void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInit<NT> const& p
// The below also prevents delegatecall/staticcall in the base case
builder.do_assert(this_call_stack_item.public_inputs.call_context.storage_contract_address ==
this_call_stack_item.contract_address,
"contract address in the call_context must be that of the called contract",
"Storage contract address must be that of the called contract",
CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH);
}

Expand Down Expand Up @@ -157,8 +158,7 @@ void update_end_values(DummyBuilder& builder,
public_inputs.end.new_nullifiers,
private_inputs.tx_request.hash(),
format(PRIVATE_KERNEL_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"could not push tx hash nullifier into new_nullifiers array. Could happen because there are too "
"many nullifiers already"));
"could not push tx hash nullifier into new_nullifiers array. Too many new nullifiers in one tx"));

// Note that we do not need to nullify the transaction request nonce anymore.
// Should an account want to additionally use nonces for replay protection or handling cancellations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_args_hash_mismatch_
EXPECT_EQ(builder.get_first_failure().code,
CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM);
EXPECT_EQ(builder.get_first_failure().message,
"user's intent does not match initial private call (args passed to tx_request must match "
"user's intent does not match initial private call (noir function args passed to tx_request must match "
"args in the call_stack_item)");
}

Expand Down Expand Up @@ -297,8 +297,7 @@ TEST_F(native_private_kernel_init_tests, private_function_incorrect_storage_cont
// Assertion checks
EXPECT_TRUE(builder.failed());
EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH);
EXPECT_EQ(builder.get_first_failure().message,
"contract address in the call_context must be that of the called contract");
EXPECT_EQ(builder.get_first_failure().message, "Storage contract address must be that of the called contract");
}

TEST_F(native_private_kernel_init_tests, native_read_request_bad_request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInner<NT> const&
NT::fr const start_private_call_stack_length = array_length(start.private_call_stack);

builder.do_assert(private_inputs.previous_kernel.public_inputs.is_private == true,
"Cannot execute a non-private kernel in the private kernel circuit",
"Cannot verify a non-private kernel snark in the private kernel circuit",
CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_KERNEL_VERIFIED_WITH_PRIVATE_KERNEL);
builder.do_assert(this_call_stack_item.function_data.is_constructor == false,
"A constructor must be executed as the first tx in the recursion",
Expand Down
14 changes: 8 additions & 6 deletions circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,10 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati
aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs);

ASSERT_TRUE(builder.failed());
ASSERT_EQ(builder.get_first_failure().message,
"Membership check failed: base_rollup_circuit: historical root in rollup constants not in historic "
"private data tree roots at kernel index 0");
ASSERT_EQ(
builder.get_first_failure().message,
"Membership check failed: base_rollup_circuit: historical root is in rollup constants but not in historic "
"private data tree roots at kernel input 0 to this base rollup circuit");
}

TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negative)
Expand Down Expand Up @@ -689,9 +690,10 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negat
aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs);

ASSERT_TRUE(builder.failed());
ASSERT_EQ(builder.get_first_failure().message,
"Membership check failed: base_rollup_circuit: historical root in rollup constants not in historic "
"contract data tree roots at kernel index 0");
ASSERT_EQ(
builder.get_first_failure().message,
"Membership check failed: base_rollup_circuit: historical root is in rollup constants but not in historic "
"contract data tree roots at kernel input 0 to this base rollup circuit");
}

TEST_F(base_rollup_tests, native_constants_dont_change)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ void perform_historical_private_data_tree_membership_checks(DummyBuilder& builde
historic_root_witness.leaf_index,
historic_root_witness.sibling_path,
historic_root,
format(BASE_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"historical root in rollup constants not in historic private data tree roots at kernel index ",
i));
format(
BASE_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"historical root is in rollup constants but not in historic private data tree roots at kernel input ",
i,
" to this base rollup circuit"));
}
}

Expand All @@ -175,9 +177,11 @@ void perform_historical_contract_data_tree_membership_checks(DummyBuilder& build
historic_root_witness.leaf_index,
historic_root_witness.sibling_path,
historic_root,
format(BASE_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"historical root in rollup constants not in historic contract data tree roots at kernel index ",
i));
format(
BASE_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"historical root is in rollup constants but not in historic contract data tree roots at kernel input ",
i,
" to this base rollup circuit"));
}
}

Expand All @@ -199,9 +203,11 @@ void perform_historical_l1_to_l2_message_tree_membership_checks(DummyBuilder& bu
historic_root_witness.leaf_index,
historic_root_witness.sibling_path,
historic_root,
format(BASE_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"historical root in rollup constants not in historic l1 to l2 data tree roots at kernel index ",
i));
format(
BASE_CIRCUIT_ERROR_MESSAGE_BEGINNING,
"historical root is in rollup constants but not in historic l1 to l2 data tree roots at kernel input ",
i,
" to this base rollup circuit"));
}
}

Expand Down
11 changes: 6 additions & 5 deletions circuits/cpp/src/aztec3/utils/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void array_push(Builder& builder, std::array<T, SIZE>& arr, T const& value, std:
}
}
builder.do_assert(false,
format(error_message, "array_push: capacity exceeded. Limit: ", arr.size()),
format(error_message, " - array_push: capacity exceeded. Limit: ", arr.size()),
CircuitErrorCode::ARRAY_OVERFLOW);
};

Expand Down Expand Up @@ -176,17 +176,18 @@ void push_array_to_array(Builder& builder,

builder.do_assert(source_size <= size_2 - target_size,
format(error_message,
"push_array_to_array exceeded capacity. Limit: ",
" - push_array_to_array exceeded capacity. Limit: ",
size_2 - target_size,
" but required size: ",
source_size),
CircuitErrorCode::ARRAY_OVERFLOW);

// Ensure that there are no non-zero values in the `target` array after the first zero-valued index
for (size_t i = target_size; i < size_2; i++) {
builder.do_assert(is_empty(target[i]),
format(error_message, "push_array_to_array inserting into a non empty space at index, ", i),
CircuitErrorCode::ARRAY_OVERFLOW);
builder.do_assert(
is_empty(target[i]),
format(error_message, " - push_array_to_array inserting into a non empty space at index, ", i),
CircuitErrorCode::ARRAY_OVERFLOW);
}
// Copy the non-zero elements of the `source` array to the `target` array at the first zero-valued index
auto zero_index = target_size;
Expand Down
4 changes: 2 additions & 2 deletions circuits/cpp/src/aztec3/utils/circuit_errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ enum CircuitErrorCode : uint16_t {
PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS = 2002,
PRIVATE_KERNEL__PURPORTED_CONTRACT_TREE_ROOT_AND_PREVIOUS_KERNEL_CONTRACT_TREE_ROOT_MISMATCH = 2003,
PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH = 2004,
PRIVATE_KERNEL__NEW_COMMITMENTS_NOT_EMPTY_FOR_STATIC_CALL = 2005,
PRIVATE_KERNEL__NEW_NULLIFIERS_NOT_EMPTY_FOR_STATIC_CALL = 2006,
PRIVATE_KERNEL__NEW_COMMITMENTS_PROHIBITED_IN_STATIC_CALL = 2005,
PRIVATE_KERNEL__NEW_NULLIFIERS_PROHIBITED_IN_STATIC_CALL = 2006,
PRIVATE_KERNEL__CALCULATED_PRIVATE_CALL_HASH_AND_PROVIDED_PRIVATE_CALL_HASH_MISMATCH = 2007,
PRIVATE_KERNEL__PRIVATE_CALL_STACK_ITEM_HASH_MISMATCH = 2008,
PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL = 2009,
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/circuits.js/src/kernel/public_kernel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ describe('kernel/public_kernel', () => {
input.previousKernel.publicInputs.end.publicDataReads = fullStateReadsObject;

await expect(simulatePublicKernelCircuit(input)).rejects.toThrow(
new CircuitError(7009, 'array_push cannot push to a full array'),
new CircuitError(
7009,
'public_kernel_circuit: too many public data reads in one tx - array_push: capacity exceeded. Limit: 4',
),
);
});
});

0 comments on commit 23de89d

Please sign in to comment.