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

refactor: remove warnings from protocol circuits #8420

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 2 additions & 6 deletions noir-projects/aztec-nr/aztec/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ use dep::protocol_types::{
GENERATOR_INDEX__SECRET_HASH, GENERATOR_INDEX__MESSAGE_NULLIFIER, ARGS_HASH_CHUNK_COUNT,
GENERATOR_INDEX__FUNCTION_ARGS, ARGS_HASH_CHUNK_LENGTH, MAX_ARGS_LENGTH
},
traits::Hash,
hash::{
pedersen_hash, compute_siloed_nullifier, sha256_to_field, pedersen_commitment,
poseidon2_hash_with_separator
}
traits::Hash, hash::{sha256_to_field, poseidon2_hash_with_separator}
};
// Note: pedersen_commitment is used only as a re-export here
use crate::oracle::logs_traits::{LensForEncryptedLog, ToBytesForUnencryptedLog};
use crate::oracle::logs_traits::ToBytesForUnencryptedLog;

pub fn compute_secret_hash(secret: Field) -> Field {
poseidon2_hash_with_separator([secret], GENERATOR_INDEX__SECRET_HASH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ struct PreviousKernelValidator {

impl PreviousKernelValidator {
pub fn new(previous_kernel: PrivateKernelCircuitPublicInputs) -> Self {
let hints = generate_previous_kernel_validator_hints(previous_kernel);
let hints = unsafe {
generate_previous_kernel_validator_hints(previous_kernel)
};
PreviousKernelValidator { previous_kernel, hints }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,16 @@ use crate::components::private_call_data_validator::{
use dep::types::{
abis::{
call_context::CallContext, kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs,
log_hash::NoteLogHash, note_hash::ScopedNoteHash, private_call_request::PrivateCallRequest,
private_circuit_public_inputs::{PrivateCircuitPublicInputs, PrivateCircuitPublicInputsArrayLengths},
note_hash::ScopedNoteHash, private_call_request::PrivateCallRequest,
private_circuit_public_inputs::PrivateCircuitPublicInputsArrayLengths,
private_kernel::private_call_data::PrivateCallData, side_effect::{Ordered, RangeOrdered}
},
address::{AztecAddress, PartialAddress}, contract_class_id::ContractClassId,
constants::MAX_FIELD_VALUE,
hash::{private_functions_root_from_siblings, stdlib_recursion_verification_key_compress_native_vk},
traits::is_empty, transaction::tx_request::TxRequest, utils::arrays::find_index_hint
transaction::tx_request::TxRequest, utils::arrays::find_index_hint
};

unconstrained fn find_first_revertible_private_call_request_index(public_inputs: PrivateCircuitPublicInputs) -> u32 {
find_first_revertible_item_index(
public_inputs.min_revertible_side_effect_counter,
public_inputs.private_call_requests
)
}

fn validate_call_context(
target_contract: AztecAddress,
target_context: CallContext,
Expand Down Expand Up @@ -261,15 +254,20 @@ impl PrivateCallDataValidator {

// Check that the min_revertible_side_effect_counter does not fall in the middle of any nested calls.
// If it is possible, one can create a custom account contract, set the min_revertible_side_effect_counter to a
// value that falls in a transfer function, make the tx revert which then preserves the note hashes and discards
// value that falls in a transfer function, make the tx revert which then preserves the note hashes and discards
// the nullifiers.
//
//
// We don't have to use the aggregated min_revertible_side_effect_counter in the output for the below check.
// If the current call's min_revertible_side_effect_counter is 0, it means the counter might be set by another
// function. This check for that function guarantees that the counter won't fall into one of its nested calls.
// function. This check for that function guarantees that the counter won't fall into one of its nested calls.
// In this case, we can simply use 0 and make the following check pass.
let min_revertible_side_effect_counter = public_inputs.min_revertible_side_effect_counter;
let first_revertible_index = find_first_revertible_private_call_request_index(public_inputs);
let first_revertible_index = unsafe {
find_first_revertible_item_index(
public_inputs.min_revertible_side_effect_counter,
public_inputs.private_call_requests
)
};
validate_split_ranges(
min_revertible_side_effect_counter,
first_revertible_index,
Expand Down Expand Up @@ -393,10 +391,12 @@ impl PrivateCallDataValidator {
should_check &= i != num_logs;
if should_check {
let note_log = note_logs[i];
let note_index = find_index_hint(
accumulated_note_hashes,
|n: ScopedNoteHash| n.counter() == note_log.note_hash_counter
);
let note_index = unsafe {
find_index_hint(
accumulated_note_hashes,
|n: ScopedNoteHash| n.counter() == note_log.note_hash_counter
)
};
assert(note_index != N, "could not find note hash linked to note log");
assert_eq(
note_log.note_hash_counter, accumulated_note_hashes[note_index].counter(), "could not find note hash linked to note log"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::types::{abis::side_effect::Ordered, traits::Empty, utils::arrays::array_length};

pub fn find_first_revertible_item_index<T, N>(
unconstrained pub fn find_first_revertible_item_index<T, let N: u32>(
min_revertible_side_effect_counter: u32,
items: [T; N]
) -> u32 where T: Ordered + Empty + Eq {
Expand Down Expand Up @@ -31,20 +31,22 @@ mod tests {
TestBuilder { private_call }
}

pub fn execute(self) -> u32 {
pub fn execute_to_equal(self, expected: u32) {
let private_call = self.private_call.to_private_circuit_public_inputs();
find_first_revertible_item_index(
private_call.min_revertible_side_effect_counter,
private_call.private_call_requests
)
let index = unsafe {
find_first_revertible_item_index(
private_call.min_revertible_side_effect_counter,
private_call.private_call_requests
)
};
assert_eq(index, expected);
}
}

#[test]
fn find_first_revertible_item_index_empty() {
let builder = TestBuilder::new();
let index = builder.execute();
assert_eq(index, 0);
builder.execute_to_equal(0);
}

#[test]
Expand All @@ -53,8 +55,7 @@ mod tests {

builder.private_call.min_revertible_side_effect_counter = 5;

let index = builder.execute();
assert_eq(index, 0);
builder.execute_to_equal(0);
}

#[test]
Expand All @@ -65,8 +66,7 @@ mod tests {
builder.private_call.end_setup();
builder.private_call.append_private_call_requests(3);

let index = builder.execute();
assert_eq(index, 0);
builder.execute_to_equal(0);
}

#[test]
Expand All @@ -77,8 +77,7 @@ mod tests {
builder.private_call.append_private_call_requests(2);
builder.private_call.end_setup();

let index = builder.execute();
assert_eq(index, 2);
builder.execute_to_equal(2);
}

#[test]
Expand All @@ -91,7 +90,6 @@ mod tests {
builder.private_call.end_setup();
builder.private_call.append_private_call_requests(3);

let index = builder.execute();
assert_eq(index, 2);
builder.execute_to_equal(2);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::types::abis::side_effect::RangeOrdered;

pub fn validate_split_ranges<T, N>(
pub fn validate_split_ranges<T, let N: u32>(
min_revertible_side_effect_counter: u32,
first_revertible_item_index: u32,
items: [T; N],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dep::types::{
kernel_circuit_public_inputs::{PrivateKernelCircuitPublicInputs, PrivateKernelCircuitPublicInputsArrayLengths},
max_block_number::MaxBlockNumber,
private_circuit_public_inputs::{PrivateCircuitPublicInputs, PrivateCircuitPublicInputsArrayLengths},
private_kernel::private_call_data::PrivateCallData, side_effect::Scoped
side_effect::Scoped
},
address::AztecAddress, traits::{Empty, is_empty}, transaction::tx_request::TxRequest
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ use dep::types::{
max_block_number::MaxBlockNumber, nullifier::{Nullifier, ScopedNullifier},
private_circuit_public_inputs::PrivateCircuitPublicInputs
},
address::AztecAddress,
constants::{
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTE_HASHES_PER_TX,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL
},
traits::is_empty, transaction::tx_request::TxRequest,
address::AztecAddress, traits::is_empty, transaction::tx_request::TxRequest,
utils::arrays::{array_length, array_to_bounded_vec, sort_by_counter_asc, sort_by_counter_desc}
};

Expand Down Expand Up @@ -99,7 +94,7 @@ impl PrivateKernelCircuitPublicInputsComposer {
*self
}

pub fn sort_ordered_values(&mut self) {
unconstrained pub fn sort_ordered_values(&mut self) {
// Note hashes, nullifiers, note_encrypted_logs_hashes, and encrypted_logs_hashes are sorted in the reset circuit.
self.public_inputs.end.l2_to_l1_msgs.storage = sort_by_counter_asc(self.public_inputs.end.l2_to_l1_msgs.storage);
self.public_inputs.end.unencrypted_logs_hashes.storage = sort_by_counter_asc(self.public_inputs.end.unencrypted_logs_hashes.storage);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
mod reset_output_hints;

use crate::components::reset_output_composer::{reset_output_hints::{generate_reset_output_hints, ResetOutputHints}};
use dep::reset_kernel_lib::{
KeyValidationHint, NoteHashReadRequestHints, NullifierReadRequestHints, TransientDataIndexHint,
PrivateValidationRequestProcessor
};
pub use reset_output_hints::ResetOutputHints;

use crate::components::reset_output_composer::{reset_output_hints::generate_reset_output_hints};
use dep::reset_kernel_lib::{TransientDataIndexHint, PrivateValidationRequestProcessor};
use dep::types::{
abis::{
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs,
log_hash::{NoteLogHash, ScopedEncryptedLogHash}, note_hash::ScopedNoteHash,
nullifier::ScopedNullifier, validation_requests::PrivateValidationRequests
nullifier::ScopedNullifier
},
address::AztecAddress,
constants::{
Expand Down Expand Up @@ -47,7 +46,7 @@ impl<
NLL_RR_SETTLED,
KEY_VALIDATION_REQUESTS,
> {
pub fn new<let TRANSIENT_DATA_AMOUNT: u32>(
unconstrained pub fn new<let TRANSIENT_DATA_AMOUNT: u32>(
previous_kernel: PrivateKernelCircuitPublicInputs,
validation_request_processor: PrivateValidationRequestProcessor<NH_RR_PENDING, NH_RR_SETTLED, NLL_RR_PENDING, NLL_RR_SETTLED, KEY_VALIDATION_REQUESTS>,
transient_data_index_hints: [TransientDataIndexHint; TRANSIENT_DATA_AMOUNT],
Expand All @@ -66,7 +65,7 @@ impl<
}
}

pub fn finish(self) -> PrivateKernelCircuitPublicInputs {
unconstrained pub fn finish(self) -> PrivateKernelCircuitPublicInputs {
let mut output = self.previous_kernel;

output.validation_requests = self.validation_request_processor.compose();
Expand Down Expand Up @@ -98,7 +97,7 @@ impl<
output
}

fn get_sorted_siloed_note_hashes(self) -> [ScopedNoteHash; MAX_NOTE_HASHES_PER_TX] {
unconstrained fn get_sorted_siloed_note_hashes(self) -> [ScopedNoteHash; MAX_NOTE_HASHES_PER_TX] {
let mut note_hashes = sort_by_counter_asc(self.hints.kept_note_hashes);
let first_nullifier = self.previous_kernel.end.nullifiers[0].value();
for i in 0..note_hashes.len() {
Expand All @@ -112,7 +111,7 @@ impl<
note_hashes
}

fn get_sorted_siloed_nullifiers(self) -> [ScopedNullifier; MAX_NULLIFIERS_PER_TX] {
unconstrained fn get_sorted_siloed_nullifiers(self) -> [ScopedNullifier; MAX_NULLIFIERS_PER_TX] {
let mut nullifiers = sort_by_counter_asc(self.hints.kept_nullifiers);
for i in 0..nullifiers.len() {
nullifiers[i].nullifier.value = silo_nullifier(nullifiers[i]);
Expand All @@ -121,15 +120,15 @@ impl<
nullifiers
}

fn get_sorted_note_encrypted_log_hashes(self) -> [NoteLogHash; MAX_NOTE_ENCRYPTED_LOGS_PER_TX] {
unconstrained fn get_sorted_note_encrypted_log_hashes(self) -> [NoteLogHash; MAX_NOTE_ENCRYPTED_LOGS_PER_TX] {
let mut log_hashes = sort_by_counter_asc(self.hints.kept_note_encrypted_log_hashes);
for i in 0..log_hashes.len() {
log_hashes[i].note_hash_counter = 0;
}
log_hashes
}

fn get_sorted_masked_encrypted_log_hashes(self) -> [ScopedEncryptedLogHash; MAX_ENCRYPTED_LOGS_PER_TX] {
unconstrained fn get_sorted_masked_encrypted_log_hashes(self) -> [ScopedEncryptedLogHash; MAX_ENCRYPTED_LOGS_PER_TX] {
let mut log_hashes = sort_by_counter_asc(self.previous_kernel.end.encrypted_logs_hashes);
for i in 0..log_hashes.len() {
log_hashes[i].contract_address = mask_encrypted_log_hash(log_hashes[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ struct TailOutputComposer {
}

impl TailOutputComposer {
pub fn new(previous_kernel: PrivateKernelCircuitPublicInputs) -> Self {
unconstrained pub fn new(previous_kernel: PrivateKernelCircuitPublicInputs) -> Self {
let mut output_composer = PrivateKernelCircuitPublicInputsComposer::new_from_previous_kernel(previous_kernel);
output_composer.sort_ordered_values();

TailOutputComposer { output_composer }
}

pub fn finish(self) -> KernelCircuitPublicInputs {
unconstrained pub fn finish(self) -> KernelCircuitPublicInputs {
let source = self.output_composer.finish();
let mut output = KernelCircuitPublicInputs::empty();
output.rollup_validation_requests = source.validation_requests.for_rollup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dep::types::{
utils::arrays::array_length
};

fn meter_gas_used(data: CombinedAccumulatedData, gas_settings: GasSettings) -> Gas {
pub fn meter_gas_used(data: CombinedAccumulatedData, gas_settings: GasSettings) -> Gas {
let mut metered_da_bytes = 0;
let mut metered_l2_gas = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::components::{
use dep::types::{
abis::{
kernel_circuit_public_inputs::{KernelCircuitPublicInputs, PrivateKernelCircuitPublicInputs},
log_hash::{LogHash, NoteLogHash, ScopedEncryptedLogHash, ScopedLogHash}
log_hash::{NoteLogHash, ScopedEncryptedLogHash, ScopedLogHash}
},
messaging::l2_to_l1_message::ScopedL2ToL1Message, traits::is_empty,
utils::arrays::assert_exposed_sorted_transformed_value_array
Expand All @@ -24,7 +24,9 @@ impl TailOutputValidator {
output: KernelCircuitPublicInputs,
previous_kernel: PrivateKernelCircuitPublicInputs
) -> Self {
let hints = generate_tail_output_hints(previous_kernel);
let hints = unsafe {
generate_tail_output_hints(previous_kernel)
};
TailOutputValidator { output, previous_kernel, hints }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ struct TailToPublicOutputComposer {
}

impl TailToPublicOutputComposer {
pub fn new(previous_kernel: PrivateKernelCircuitPublicInputs) -> Self {
unconstrained pub fn new(previous_kernel: PrivateKernelCircuitPublicInputs) -> Self {
let mut output_composer = PrivateKernelCircuitPublicInputsComposer::new_from_previous_kernel(previous_kernel);
output_composer.sort_ordered_values();

TailToPublicOutputComposer { output_composer }
}

pub fn finish(self) -> PublicKernelCircuitPublicInputs {
unconstrained pub fn finish(self) -> PublicKernelCircuitPublicInputs {
let source = self.output_composer.public_inputs;

let mut validation_requests = PublicValidationRequests::empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use dep::types::{
abis::{
accumulated_data::{public_accumulated_data_builder::PublicAccumulatedData}, gas::Gas,
log_hash::{LogHash, ScopedLogHash}
},
abis::{accumulated_data::PublicAccumulatedData, gas::Gas, log_hash::{LogHash, ScopedLogHash}},
constants::{
DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, FIXED_AVM_STARTUP_L2_GAS, L2_GAS_PER_NOTE_HASH,
L2_GAS_PER_NULLIFIER, L2_GAS_PER_LOG_BYTE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use dep::types::abis::{
}
};

pub fn split_to_public(
unconstrained pub fn split_to_public(
data: PrivateAccumulatedDataBuilder,
min_revertible_side_effect_counter: u32
) -> (PublicAccumulatedData, PublicAccumulatedData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use dep::types::{
log_hash::{LogHash, ScopedEncryptedLogHash, NoteLogHash, ScopedLogHash}, note_hash::ScopedNoteHash,
nullifier::{Nullifier, ScopedNullifier}, public_call_request::PublicCallRequest
},
messaging::l2_to_l1_message::ScopedL2ToL1Message, address::AztecAddress,
traits::{is_empty, is_empty_array},
messaging::l2_to_l1_message::ScopedL2ToL1Message, traits::{is_empty, is_empty_array},
utils::arrays::{
assert_split_sorted_transformed_value_arrays_asc, assert_split_sorted_transformed_value_arrays_desc,
assert_split_transformed_value_arrays, validate_array
assert_split_transformed_value_arrays
}
};

Expand All @@ -29,7 +28,9 @@ impl TailToPublicOutputValidator {
output: PublicKernelCircuitPublicInputs,
previous_kernel: PrivateKernelCircuitPublicInputs
) -> Self {
let hints = generate_tail_to_public_output_hints(previous_kernel);
let hints = unsafe {
generate_tail_to_public_output_hints(previous_kernel)
};
TailToPublicOutputValidator { output, previous_kernel, hints }
}

Expand Down
Loading