Skip to content

Commit

Permalink
chore: remove warnings from protocol circuits (#10556)
Browse files Browse the repository at this point in the history
Remove all warnings in `noir-protocol-circuits`. Except for
`poseidon2_hash_with_separator_slice`, which still calls private methods
on Poseidon2. This will be removed by the blob pr because sponge blob
also needs access to those.

Also updated `array_to_bounded_vec` to be unconstrained and use
`BoundedVec::from_parts_unchecked`.
  • Loading branch information
LeilaWang authored Dec 11, 2024
1 parent e21069d commit e065e05
Show file tree
Hide file tree
Showing 84 changed files with 559 additions and 465 deletions.
8 changes: 5 additions & 3 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"comlink",
"composability",
"composablity",
"comptime",
"concat",
"cond",
"counterparty",
Expand Down Expand Up @@ -245,6 +246,7 @@
"stdlib",
"struct",
"structs",
"subarray",
"subarrays",
"subdir",
"sublabel",
Expand Down Expand Up @@ -276,6 +278,8 @@
"unzipit",
"updateable",
"upperfirst",
"unshift",
"unshifted",
"usecase",
"usecases",
"utxo",
Expand Down Expand Up @@ -319,7 +323,5 @@
"lib",
"*.cmake"
],
"flagWords": [
"anonymous"
]
"flagWords": ["anonymous"]
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod base_parity_inputs;
pub mod base_parity_inputs;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use dep::types::traits::{Deserialize, Empty, Serialize};

pub struct ParityPublicInputs {
sha_root: Field,
converted_root: Field,
vk_tree_root: Field,
pub sha_root: Field,
pub converted_root: Field,
pub vk_tree_root: Field,
}

impl Empty for ParityPublicInputs {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod root_parity_input;
mod root_parity_inputs;
mod root_rollup_parity_input;
pub(crate) mod root_parity_input;
pub mod root_parity_inputs;
pub mod root_rollup_parity_input;
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use dep::types::{
};

pub struct RootParityInput {
proof: RecursiveProof,
verification_key: HonkVerificationKey,
vk_path: [Field; VK_TREE_HEIGHT],
public_inputs: ParityPublicInputs,
pub proof: RecursiveProof,
pub verification_key: HonkVerificationKey,
pub vk_path: [Field; VK_TREE_HEIGHT],
pub public_inputs: ParityPublicInputs,
}

impl Empty for RootParityInput {
Expand All @@ -41,7 +41,7 @@ impl Verifiable for RootParityInput {
}

impl RootParityInput {
fn validate_in_vk_tree(self) {
pub fn validate_in_vk_tree(self) {
self.verification_key.check_hash();
assert_check_membership(
self.verification_key.hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use dep::types::{
};

pub struct RootRollupParityInput {
proof: NestedRecursiveProof,
verification_key: HonkVerificationKey,
vk_path: [Field; VK_TREE_HEIGHT],
public_inputs: ParityPublicInputs,
pub proof: NestedRecursiveProof,
pub verification_key: HonkVerificationKey,
pub vk_path: [Field; VK_TREE_HEIGHT],
pub public_inputs: ParityPublicInputs,
}

impl Empty for RootRollupParityInput {
Expand All @@ -41,7 +41,7 @@ impl Verifiable for RootRollupParityInput {
}

impl RootRollupParityInput {
fn validate_in_vk_tree(self) {
pub fn validate_in_vk_tree(self) {
self.verification_key.check_hash();
assert_check_membership(
self.verification_key.hash,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod sha256_merkle_tree;
pub mod sha256_merkle_tree;
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<let N: u32> Sha256MerkleTree<N> {
Sha256MerkleTree { leaves, nodes }
}

fn get_root(self) -> Field {
pub fn get_root(self) -> Field {
self.nodes[N - 2]
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mod previous_kernel_validator_hints;

use crate::components::previous_kernel_validator::previous_kernel_validator_hints::{
generate_previous_kernel_validator_hints, PreviousKernelValidatorHints,
};
use dep::types::{
abis::private_kernel_data::PrivateKernelData, address::AztecAddress, traits::is_empty,
utils::arrays::array_length,
};
use previous_kernel_validator_hints::{
generate_previous_kernel_validator_hints, PreviousKernelValidatorHints,
};

pub struct PreviousKernelValidator {
previous_kernel: PrivateKernelData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dep::types::{
};

pub struct PreviousKernelValidatorHints {
note_hash_indexes_for_nullifiers: [u32; MAX_NULLIFIERS_PER_TX],
pub note_hash_indexes_for_nullifiers: [u32; MAX_NULLIFIERS_PER_TX],
}

pub unconstrained fn generate_previous_kernel_validator_hints(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ mod find_first_revertible_item_index;
mod validate_contract_address;
mod validate_split_ranges;

use crate::components::private_call_data_validator::{
find_first_revertible_item_index::find_first_revertible_item_index,
validate_contract_address::validate_contract_address,
validate_split_ranges::validate_split_ranges,
};
use dep::types::{
abis::{
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs,
Expand All @@ -22,6 +17,9 @@ use dep::types::{
transaction::tx_request::TxRequest,
utils::arrays::find_index_hint,
};
use find_first_revertible_item_index::find_first_revertible_item_index;
use validate_contract_address::validate_contract_address;
use validate_split_ranges::validate_split_ranges;

fn validate_incrementing_counters_within_range<T, let N: u32>(
counter_start: u32,
Expand Down Expand Up @@ -82,7 +80,7 @@ where

pub struct PrivateCallDataValidator {
data: PrivateCallData,
array_lengths: PrivateCircuitPublicInputsArrayLengths,
pub array_lengths: PrivateCircuitPublicInputsArrayLengths,
}

impl PrivateCallDataValidator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use dep::types::{
abis::private_kernel::private_call_data::PrivateCallData, address::AztecAddress,
constants::MAX_PROTOCOL_CONTRACTS, merkle_tree::root::root_from_sibling_path,
};
use types::debug_log::debug_log_format;

pub fn validate_contract_address(
private_call_data: PrivateCallData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ mod tests {
pub fn add_private_call_request(&mut self, counter_start: u32, counter_end: u32) {
let index = self.private_call.private_call_requests.len();
self.private_call.append_private_call_requests(1);
self.private_call.private_call_requests.storage[index].start_side_effect_counter =
counter_start;
self.private_call.private_call_requests.storage[index].end_side_effect_counter =
counter_end;
let mut call_request = self.private_call.private_call_requests.get(index);
call_request.start_side_effect_counter = counter_start;
call_request.end_side_effect_counter = counter_end;
self.private_call.private_call_requests.set(index, call_request);
self.private_call.counter = counter_end + 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use dep::types::{
max_block_number::MaxBlockNumber,
nullifier::{Nullifier, ScopedNullifier},
private_circuit_public_inputs::PrivateCircuitPublicInputs,
side_effect::Ordered,
tx_constant_data::TxConstantData,
},
address::AztecAddress,
traits::is_empty,
traits::{Empty, is_empty},
transaction::tx_request::TxRequest,
utils::arrays::{array_length, array_to_bounded_vec, sort_by_counter_asc, sort_by_counter_desc},
};
Expand All @@ -18,8 +19,26 @@ pub fn create_first_nullifier(tx_request: TxRequest) -> ScopedNullifier {
Nullifier { value: tx_request.hash(), note_hash: 0, counter: 0 }.scope(AztecAddress::zero())
}

unconstrained fn transform_vec<T, let N: u32, Env>(
vec: BoundedVec<T, N>,
f: unconstrained fn[Env]([T; N]) -> [T; N],
) -> BoundedVec<T, N>
where
T: Ordered + Empty + Eq,
{
let len = vec.len();
let transformed = f(vec.storage());
let mut transformed_vec = vec;
for i in 0..N {
if i < len {
transformed_vec.set_unchecked(i, transformed[i]);
}
}
transformed_vec
}

pub struct PrivateKernelCircuitPublicInputsComposer {
public_inputs: PrivateKernelCircuitPublicInputsBuilder,
pub public_inputs: PrivateKernelCircuitPublicInputsBuilder,
}

impl PrivateKernelCircuitPublicInputsComposer {
Expand Down Expand Up @@ -47,7 +66,7 @@ impl PrivateKernelCircuitPublicInputsComposer {
PrivateKernelCircuitPublicInputsComposer { public_inputs }
}

pub fn new_from_previous_kernel(
pub unconstrained fn new_from_previous_kernel(
previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs,
) -> Self {
let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::empty();
Expand Down Expand Up @@ -98,12 +117,16 @@ impl PrivateKernelCircuitPublicInputsComposer {

pub unconstrained fn sort_ordered_values(&mut self) {
// Note hashes, nullifiers, and private logs 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.contract_class_logs_hashes.storage =
sort_by_counter_asc(self.public_inputs.end.contract_class_logs_hashes.storage);
self.public_inputs.end.public_call_requests.storage =
sort_by_counter_desc(self.public_inputs.end.public_call_requests.storage);
self.public_inputs.end.l2_to_l1_msgs =
transform_vec(self.public_inputs.end.l2_to_l1_msgs, sort_by_counter_asc);
self.public_inputs.end.contract_class_logs_hashes = transform_vec(
self.public_inputs.end.contract_class_logs_hashes,
sort_by_counter_asc,
);
self.public_inputs.end.public_call_requests = transform_vec(
self.public_inputs.end.public_call_requests,
sort_by_counter_desc,
);
}

pub fn finish(self) -> PrivateKernelCircuitPublicInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ impl TailOutputComposer {
unconstrained fn build_combined_accumulated_data(self) -> CombinedAccumulatedData {
let source = self.output_composer.public_inputs.end;
let mut data = CombinedAccumulatedData::empty();
data.note_hashes = source.note_hashes.storage.map(|n: ScopedNoteHash| n.note_hash.value);
data.nullifiers = source.nullifiers.storage.map(|n: ScopedNullifier| n.nullifier.value);
data.note_hashes = source.note_hashes.storage().map(|n: ScopedNoteHash| n.note_hash.value);
data.nullifiers = source.nullifiers.storage().map(|n: ScopedNullifier| n.nullifier.value);
data.l2_to_l1_msgs =
source.l2_to_l1_msgs.storage.map(|m: ScopedL2ToL1Message| m.expose_to_public());
source.l2_to_l1_msgs.storage().map(|m: ScopedL2ToL1Message| m.expose_to_public());
data.private_logs =
source.private_logs.storage.map(|l: Scoped<PrivateLogData>| l.inner.log);
data.contract_class_logs_hashes =
source.contract_class_logs_hashes.storage.map(|l: ScopedLogHash| l.expose_to_public());
data.contract_class_log_preimages_length = source.contract_class_logs_hashes.storage.fold(
source.private_logs.storage().map(|l: Scoped<PrivateLogData>| l.inner.log);
data.contract_class_logs_hashes = source.contract_class_logs_hashes.storage().map(
|l: ScopedLogHash| l.expose_to_public(),
);
data.contract_class_log_preimages_length = source.contract_class_logs_hashes.storage().fold(
0,
|len, l: ScopedLogHash| len + l.log_hash.length,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod tail_output_hints;
pub mod tail_output_hints;

use crate::components::tail_output_composer::meter_gas_used;
use dep::types::{
Expand Down Expand Up @@ -26,6 +26,14 @@ impl TailOutputValidator {
previous_kernel: PrivateKernelCircuitPublicInputs,
) -> Self {
let hints = unsafe { generate_tail_output_hints(previous_kernel) };
TailOutputValidator::new_with_hints(output, previous_kernel, hints)
}

pub fn new_with_hints(
output: KernelCircuitPublicInputs,
previous_kernel: PrivateKernelCircuitPublicInputs,
hints: TailOutputHints,
) -> Self {
TailOutputValidator { output, previous_kernel, hints }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use dep::types::{

pub struct TailOutputHints {
// L2 to l1 msgs.
sorted_l2_to_l1_msg_hints: [OrderHint; MAX_L2_TO_L1_MSGS_PER_TX],
pub sorted_l2_to_l1_msg_hints: [OrderHint; MAX_L2_TO_L1_MSGS_PER_TX],
// Contract class log hashes.
sorted_contract_class_log_hashes: [ScopedLogHash; MAX_CONTRACT_CLASS_LOGS_PER_TX],
sorted_contract_class_log_hash_hints: [OrderHint; MAX_CONTRACT_CLASS_LOGS_PER_TX],
pub sorted_contract_class_log_hashes: [ScopedLogHash; MAX_CONTRACT_CLASS_LOGS_PER_TX],
pub sorted_contract_class_log_hash_hints: [OrderHint; MAX_CONTRACT_CLASS_LOGS_PER_TX],
}

pub unconstrained fn generate_tail_output_hints(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::components::private_kernel_circuit_public_inputs_composer::PrivateKer
use dep::types::abis::kernel_circuit_public_inputs::{
PrivateKernelCircuitPublicInputs, PrivateToPublicKernelCircuitPublicInputs,
};
use split_to_public::split_to_public;
pub use meter_gas_used::meter_gas_used;
pub use split_to_public::split_to_public;

pub struct TailToPublicOutputComposer {
output_composer: PrivateKernelCircuitPublicInputsComposer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use dep::types::{

pub struct TailToPublicOutputHints {
// L2 to l1 msgs.
sorted_l2_to_l1_msg_hints: SplitOrderHints<MAX_L2_TO_L1_MSGS_PER_TX>,
pub sorted_l2_to_l1_msg_hints: SplitOrderHints<MAX_L2_TO_L1_MSGS_PER_TX>,
// Contract class log hashes.
sorted_contract_class_log_hash_hints: SplitOrderHints<MAX_CONTRACT_CLASS_LOGS_PER_TX>,
pub sorted_contract_class_log_hash_hints: SplitOrderHints<MAX_CONTRACT_CLASS_LOGS_PER_TX>,
// Public call requests.
sorted_public_call_request_hints: SplitOrderHints<MAX_ENQUEUED_CALLS_PER_TX>,
pub sorted_public_call_request_hints: SplitOrderHints<MAX_ENQUEUED_CALLS_PER_TX>,
}

pub unconstrained fn generate_tail_to_public_output_hints(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ mod tests {

// note_hash_read_requests
builder.previous_kernel.append_note_hash_read_requests(1);
let prev_note_hash_read_requests = builder.previous_kernel.note_hash_read_requests.storage;
let prev_note_hash_read_requests =
builder.previous_kernel.note_hash_read_requests.storage();
builder.private_call.append_note_hash_read_requests(2);
let curr_note_hash_read_requests = builder.private_call.note_hash_read_requests.storage;
let curr_note_hash_read_requests = builder.private_call.note_hash_read_requests.storage();

// private_logs
builder.previous_kernel.append_private_logs(2);
Expand Down
Loading

0 comments on commit e065e05

Please sign in to comment.