Skip to content

Commit e065e05

Browse files
authored
chore: remove warnings from protocol circuits (#10556)
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`.
1 parent e21069d commit e065e05

File tree

84 files changed

+559
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+559
-465
lines changed

cspell.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"comlink",
5656
"composability",
5757
"composablity",
58+
"comptime",
5859
"concat",
5960
"cond",
6061
"counterparty",
@@ -245,6 +246,7 @@
245246
"stdlib",
246247
"struct",
247248
"structs",
249+
"subarray",
248250
"subarrays",
249251
"subdir",
250252
"sublabel",
@@ -276,6 +278,8 @@
276278
"unzipit",
277279
"updateable",
278280
"upperfirst",
281+
"unshift",
282+
"unshifted",
279283
"usecase",
280284
"usecases",
281285
"utxo",
@@ -319,7 +323,5 @@
319323
"lib",
320324
"*.cmake"
321325
],
322-
"flagWords": [
323-
"anonymous"
324-
]
326+
"flagWords": ["anonymous"]
325327
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mod base_parity_inputs;
1+
pub mod base_parity_inputs;

noir-projects/noir-protocol-circuits/crates/parity-lib/src/parity_public_inputs.nr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use dep::types::traits::{Deserialize, Empty, Serialize};
22

33
pub struct ParityPublicInputs {
4-
sha_root: Field,
5-
converted_root: Field,
6-
vk_tree_root: Field,
4+
pub sha_root: Field,
5+
pub converted_root: Field,
6+
pub vk_tree_root: Field,
77
}
88

99
impl Empty for ParityPublicInputs {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mod root_parity_input;
2-
mod root_parity_inputs;
3-
mod root_rollup_parity_input;
1+
pub(crate) mod root_parity_input;
2+
pub mod root_parity_inputs;
3+
pub mod root_rollup_parity_input;

noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_parity_input.nr

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use dep::types::{
1111
};
1212

1313
pub struct RootParityInput {
14-
proof: RecursiveProof,
15-
verification_key: HonkVerificationKey,
16-
vk_path: [Field; VK_TREE_HEIGHT],
17-
public_inputs: ParityPublicInputs,
14+
pub proof: RecursiveProof,
15+
pub verification_key: HonkVerificationKey,
16+
pub vk_path: [Field; VK_TREE_HEIGHT],
17+
pub public_inputs: ParityPublicInputs,
1818
}
1919

2020
impl Empty for RootParityInput {
@@ -41,7 +41,7 @@ impl Verifiable for RootParityInput {
4141
}
4242

4343
impl RootParityInput {
44-
fn validate_in_vk_tree(self) {
44+
pub fn validate_in_vk_tree(self) {
4545
self.verification_key.check_hash();
4646
assert_check_membership(
4747
self.verification_key.hash,

noir-projects/noir-protocol-circuits/crates/parity-lib/src/root/root_rollup_parity_input.nr

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use dep::types::{
1111
};
1212

1313
pub struct RootRollupParityInput {
14-
proof: NestedRecursiveProof,
15-
verification_key: HonkVerificationKey,
16-
vk_path: [Field; VK_TREE_HEIGHT],
17-
public_inputs: ParityPublicInputs,
14+
pub proof: NestedRecursiveProof,
15+
pub verification_key: HonkVerificationKey,
16+
pub vk_path: [Field; VK_TREE_HEIGHT],
17+
pub public_inputs: ParityPublicInputs,
1818
}
1919

2020
impl Empty for RootRollupParityInput {
@@ -41,7 +41,7 @@ impl Verifiable for RootRollupParityInput {
4141
}
4242

4343
impl RootRollupParityInput {
44-
fn validate_in_vk_tree(self) {
44+
pub fn validate_in_vk_tree(self) {
4545
self.verification_key.check_hash();
4646
assert_check_membership(
4747
self.verification_key.hash,
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mod sha256_merkle_tree;
1+
pub mod sha256_merkle_tree;

noir-projects/noir-protocol-circuits/crates/parity-lib/src/utils/sha256_merkle_tree.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<let N: u32> Sha256MerkleTree<N> {
3030
Sha256MerkleTree { leaves, nodes }
3131
}
3232

33-
fn get_root(self) -> Field {
33+
pub fn get_root(self) -> Field {
3434
self.nodes[N - 2]
3535
}
3636
}

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator.nr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
mod previous_kernel_validator_hints;
22

3-
use crate::components::previous_kernel_validator::previous_kernel_validator_hints::{
4-
generate_previous_kernel_validator_hints, PreviousKernelValidatorHints,
5-
};
63
use dep::types::{
74
abis::private_kernel_data::PrivateKernelData, address::AztecAddress, traits::is_empty,
85
utils::arrays::array_length,
96
};
7+
use previous_kernel_validator_hints::{
8+
generate_previous_kernel_validator_hints, PreviousKernelValidatorHints,
9+
};
1010

1111
pub struct PreviousKernelValidator {
1212
previous_kernel: PrivateKernelData,

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/previous_kernel_validator/previous_kernel_validator_hints.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use dep::types::{
77
};
88

99
pub struct PreviousKernelValidatorHints {
10-
note_hash_indexes_for_nullifiers: [u32; MAX_NULLIFIERS_PER_TX],
10+
pub note_hash_indexes_for_nullifiers: [u32; MAX_NULLIFIERS_PER_TX],
1111
}
1212

1313
pub unconstrained fn generate_previous_kernel_validator_hints(

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ mod find_first_revertible_item_index;
22
mod validate_contract_address;
33
mod validate_split_ranges;
44

5-
use crate::components::private_call_data_validator::{
6-
find_first_revertible_item_index::find_first_revertible_item_index,
7-
validate_contract_address::validate_contract_address,
8-
validate_split_ranges::validate_split_ranges,
9-
};
105
use dep::types::{
116
abis::{
127
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs,
@@ -22,6 +17,9 @@ use dep::types::{
2217
transaction::tx_request::TxRequest,
2318
utils::arrays::find_index_hint,
2419
};
20+
use find_first_revertible_item_index::find_first_revertible_item_index;
21+
use validate_contract_address::validate_contract_address;
22+
use validate_split_ranges::validate_split_ranges;
2523

2624
fn validate_incrementing_counters_within_range<T, let N: u32>(
2725
counter_start: u32,
@@ -82,7 +80,7 @@ where
8280

8381
pub struct PrivateCallDataValidator {
8482
data: PrivateCallData,
85-
array_lengths: PrivateCircuitPublicInputsArrayLengths,
83+
pub array_lengths: PrivateCircuitPublicInputsArrayLengths,
8684
}
8785

8886
impl PrivateCallDataValidator {

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_contract_address.nr

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use dep::types::{
22
abis::private_kernel::private_call_data::PrivateCallData, address::AztecAddress,
33
constants::MAX_PROTOCOL_CONTRACTS, merkle_tree::root::root_from_sibling_path,
44
};
5-
use types::debug_log::debug_log_format;
65

76
pub fn validate_contract_address(
87
private_call_data: PrivateCallData,

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator/validate_split_ranges.nr

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ mod tests {
5050
pub fn add_private_call_request(&mut self, counter_start: u32, counter_end: u32) {
5151
let index = self.private_call.private_call_requests.len();
5252
self.private_call.append_private_call_requests(1);
53-
self.private_call.private_call_requests.storage[index].start_side_effect_counter =
54-
counter_start;
55-
self.private_call.private_call_requests.storage[index].end_side_effect_counter =
56-
counter_end;
53+
let mut call_request = self.private_call.private_call_requests.get(index);
54+
call_request.start_side_effect_counter = counter_start;
55+
call_request.end_side_effect_counter = counter_end;
56+
self.private_call.private_call_requests.set(index, call_request);
5757
self.private_call.counter = counter_end + 1;
5858
}
5959

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_kernel_circuit_public_inputs_composer.nr

+32-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use dep::types::{
66
max_block_number::MaxBlockNumber,
77
nullifier::{Nullifier, ScopedNullifier},
88
private_circuit_public_inputs::PrivateCircuitPublicInputs,
9+
side_effect::Ordered,
910
tx_constant_data::TxConstantData,
1011
},
1112
address::AztecAddress,
12-
traits::is_empty,
13+
traits::{Empty, is_empty},
1314
transaction::tx_request::TxRequest,
1415
utils::arrays::{array_length, array_to_bounded_vec, sort_by_counter_asc, sort_by_counter_desc},
1516
};
@@ -18,8 +19,26 @@ pub fn create_first_nullifier(tx_request: TxRequest) -> ScopedNullifier {
1819
Nullifier { value: tx_request.hash(), note_hash: 0, counter: 0 }.scope(AztecAddress::zero())
1920
}
2021

22+
unconstrained fn transform_vec<T, let N: u32, Env>(
23+
vec: BoundedVec<T, N>,
24+
f: unconstrained fn[Env]([T; N]) -> [T; N],
25+
) -> BoundedVec<T, N>
26+
where
27+
T: Ordered + Empty + Eq,
28+
{
29+
let len = vec.len();
30+
let transformed = f(vec.storage());
31+
let mut transformed_vec = vec;
32+
for i in 0..N {
33+
if i < len {
34+
transformed_vec.set_unchecked(i, transformed[i]);
35+
}
36+
}
37+
transformed_vec
38+
}
39+
2140
pub struct PrivateKernelCircuitPublicInputsComposer {
22-
public_inputs: PrivateKernelCircuitPublicInputsBuilder,
41+
pub public_inputs: PrivateKernelCircuitPublicInputsBuilder,
2342
}
2443

2544
impl PrivateKernelCircuitPublicInputsComposer {
@@ -47,7 +66,7 @@ impl PrivateKernelCircuitPublicInputsComposer {
4766
PrivateKernelCircuitPublicInputsComposer { public_inputs }
4867
}
4968

50-
pub fn new_from_previous_kernel(
69+
pub unconstrained fn new_from_previous_kernel(
5170
previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs,
5271
) -> Self {
5372
let mut public_inputs = PrivateKernelCircuitPublicInputsBuilder::empty();
@@ -98,12 +117,16 @@ impl PrivateKernelCircuitPublicInputsComposer {
98117

99118
pub unconstrained fn sort_ordered_values(&mut self) {
100119
// Note hashes, nullifiers, and private logs are sorted in the reset circuit.
101-
self.public_inputs.end.l2_to_l1_msgs.storage =
102-
sort_by_counter_asc(self.public_inputs.end.l2_to_l1_msgs.storage);
103-
self.public_inputs.end.contract_class_logs_hashes.storage =
104-
sort_by_counter_asc(self.public_inputs.end.contract_class_logs_hashes.storage);
105-
self.public_inputs.end.public_call_requests.storage =
106-
sort_by_counter_desc(self.public_inputs.end.public_call_requests.storage);
120+
self.public_inputs.end.l2_to_l1_msgs =
121+
transform_vec(self.public_inputs.end.l2_to_l1_msgs, sort_by_counter_asc);
122+
self.public_inputs.end.contract_class_logs_hashes = transform_vec(
123+
self.public_inputs.end.contract_class_logs_hashes,
124+
sort_by_counter_asc,
125+
);
126+
self.public_inputs.end.public_call_requests = transform_vec(
127+
self.public_inputs.end.public_call_requests,
128+
sort_by_counter_desc,
129+
);
107130
}
108131

109132
pub fn finish(self) -> PrivateKernelCircuitPublicInputs {

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_composer.nr

+8-7
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ impl TailOutputComposer {
4545
unconstrained fn build_combined_accumulated_data(self) -> CombinedAccumulatedData {
4646
let source = self.output_composer.public_inputs.end;
4747
let mut data = CombinedAccumulatedData::empty();
48-
data.note_hashes = source.note_hashes.storage.map(|n: ScopedNoteHash| n.note_hash.value);
49-
data.nullifiers = source.nullifiers.storage.map(|n: ScopedNullifier| n.nullifier.value);
48+
data.note_hashes = source.note_hashes.storage().map(|n: ScopedNoteHash| n.note_hash.value);
49+
data.nullifiers = source.nullifiers.storage().map(|n: ScopedNullifier| n.nullifier.value);
5050
data.l2_to_l1_msgs =
51-
source.l2_to_l1_msgs.storage.map(|m: ScopedL2ToL1Message| m.expose_to_public());
51+
source.l2_to_l1_msgs.storage().map(|m: ScopedL2ToL1Message| m.expose_to_public());
5252
data.private_logs =
53-
source.private_logs.storage.map(|l: Scoped<PrivateLogData>| l.inner.log);
54-
data.contract_class_logs_hashes =
55-
source.contract_class_logs_hashes.storage.map(|l: ScopedLogHash| l.expose_to_public());
56-
data.contract_class_log_preimages_length = source.contract_class_logs_hashes.storage.fold(
53+
source.private_logs.storage().map(|l: Scoped<PrivateLogData>| l.inner.log);
54+
data.contract_class_logs_hashes = source.contract_class_logs_hashes.storage().map(
55+
|l: ScopedLogHash| l.expose_to_public(),
56+
);
57+
data.contract_class_log_preimages_length = source.contract_class_logs_hashes.storage().fold(
5758
0,
5859
|len, l: ScopedLogHash| len + l.log_hash.length,
5960
);

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator.nr

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod tail_output_hints;
1+
pub mod tail_output_hints;
22

33
use crate::components::tail_output_composer::meter_gas_used;
44
use dep::types::{
@@ -26,6 +26,14 @@ impl TailOutputValidator {
2626
previous_kernel: PrivateKernelCircuitPublicInputs,
2727
) -> Self {
2828
let hints = unsafe { generate_tail_output_hints(previous_kernel) };
29+
TailOutputValidator::new_with_hints(output, previous_kernel, hints)
30+
}
31+
32+
pub fn new_with_hints(
33+
output: KernelCircuitPublicInputs,
34+
previous_kernel: PrivateKernelCircuitPublicInputs,
35+
hints: TailOutputHints,
36+
) -> Self {
2937
TailOutputValidator { output, previous_kernel, hints }
3038
}
3139

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_output_validator/tail_output_hints.nr

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use dep::types::{
66

77
pub struct TailOutputHints {
88
// L2 to l1 msgs.
9-
sorted_l2_to_l1_msg_hints: [OrderHint; MAX_L2_TO_L1_MSGS_PER_TX],
9+
pub sorted_l2_to_l1_msg_hints: [OrderHint; MAX_L2_TO_L1_MSGS_PER_TX],
1010
// Contract class log hashes.
11-
sorted_contract_class_log_hashes: [ScopedLogHash; MAX_CONTRACT_CLASS_LOGS_PER_TX],
12-
sorted_contract_class_log_hash_hints: [OrderHint; MAX_CONTRACT_CLASS_LOGS_PER_TX],
11+
pub sorted_contract_class_log_hashes: [ScopedLogHash; MAX_CONTRACT_CLASS_LOGS_PER_TX],
12+
pub sorted_contract_class_log_hash_hints: [OrderHint; MAX_CONTRACT_CLASS_LOGS_PER_TX],
1313
}
1414

1515
pub unconstrained fn generate_tail_output_hints(

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_composer.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::components::private_kernel_circuit_public_inputs_composer::PrivateKer
55
use dep::types::abis::kernel_circuit_public_inputs::{
66
PrivateKernelCircuitPublicInputs, PrivateToPublicKernelCircuitPublicInputs,
77
};
8-
use split_to_public::split_to_public;
98
pub use meter_gas_used::meter_gas_used;
9+
pub use split_to_public::split_to_public;
1010

1111
pub struct TailToPublicOutputComposer {
1212
output_composer: PrivateKernelCircuitPublicInputsComposer,

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/tail_to_public_output_validator/tail_to_public_output_hints.nr

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use dep::types::{
88

99
pub struct TailToPublicOutputHints {
1010
// L2 to l1 msgs.
11-
sorted_l2_to_l1_msg_hints: SplitOrderHints<MAX_L2_TO_L1_MSGS_PER_TX>,
11+
pub sorted_l2_to_l1_msg_hints: SplitOrderHints<MAX_L2_TO_L1_MSGS_PER_TX>,
1212
// Contract class log hashes.
13-
sorted_contract_class_log_hash_hints: SplitOrderHints<MAX_CONTRACT_CLASS_LOGS_PER_TX>,
13+
pub sorted_contract_class_log_hash_hints: SplitOrderHints<MAX_CONTRACT_CLASS_LOGS_PER_TX>,
1414
// Public call requests.
15-
sorted_public_call_request_hints: SplitOrderHints<MAX_ENQUEUED_CALLS_PER_TX>,
15+
pub sorted_public_call_request_hints: SplitOrderHints<MAX_ENQUEUED_CALLS_PER_TX>,
1616
}
1717

1818
pub unconstrained fn generate_tail_to_public_output_hints(

noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_inner.nr

+3-2
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ mod tests {
127127

128128
// note_hash_read_requests
129129
builder.previous_kernel.append_note_hash_read_requests(1);
130-
let prev_note_hash_read_requests = builder.previous_kernel.note_hash_read_requests.storage;
130+
let prev_note_hash_read_requests =
131+
builder.previous_kernel.note_hash_read_requests.storage();
131132
builder.private_call.append_note_hash_read_requests(2);
132-
let curr_note_hash_read_requests = builder.private_call.note_hash_read_requests.storage;
133+
let curr_note_hash_read_requests = builder.private_call.note_hash_read_requests.storage();
133134

134135
// private_logs
135136
builder.previous_kernel.append_private_logs(2);

0 commit comments

Comments
 (0)