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

chore: remove warnings from noir protocol circuits #11803

Merged
merged 2 commits into from
Feb 11, 2025
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
18 changes: 10 additions & 8 deletions noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ use crate::{
};

use bigint::{BigNum, BigNumTrait};
// Fixed hash method:
use types::hash::poseidon2_hash_subarray;
// Variable hash method:
// use types::hash::poseidon2_cheaper_variable_hash;
use std::ops::{Mul, Neg};
use types::{
abis::sponge_blob::SpongeBlob,
constants::{BLOBS_PER_BLOCK, FIELDS_PER_BLOB, TWO_POW_64},
hash::poseidon2_hash_subarray,
traits::Empty,
utils::arrays::array_splice,
};

Expand Down Expand Up @@ -70,6 +68,7 @@ unconstrained fn __field_to_bignum_limbs(x: Field) -> [Field; 3] {
// Only works for bignums with modulus larger than the BN Fr size (which is true
// for the bls12-381 Fr field).
fn field_to_bignum(x: Field) -> F {
/// Safety: we constrain the limbs below
let __x_limbs = unsafe { __field_to_bignum_limbs(x) };

let mut check = __x_limbs[3 - 1];
Expand Down Expand Up @@ -484,14 +483,16 @@ mod tests {
config::{D, D_INV, F, ROOTS},
};
use super::{__compute_partial_sums, __compute_sum};
use bigint::{BigNum, fields::bls12_381Fr::BLS12_381_Fr_Params};
use bigint::bignum::BigNumTrait;
use bigint::{
BigNum, bignum::BigNumTrait, fields::bls12_381Fr::BLS12_381_Fr_Params,
params::BigNumParamsGetter,
};
use types::{
abis::sponge_blob::SpongeBlob,
constants::{BLOBS_PER_BLOCK, FIELDS_PER_BLOB},
tests::{fixture_builder::FixtureBuilder, utils::pad_end},
traits::Serialize,
};
use types::traits::Serialize;

#[test]
unconstrained fn test_one_note() {
Expand Down Expand Up @@ -525,7 +526,7 @@ mod tests {
//* d
//
let rhs = super::compute_factor(challenge_z);
let z_minus_1 = unsafe { challenge_z.__sub(BigNum::one()) };
let z_minus_1 = challenge_z.__sub(BigNum::one());
let lhs = y.__mul(z_minus_1);
assert_eq(lhs, rhs);
}
Expand Down Expand Up @@ -725,6 +726,7 @@ mod tests {
for i in 0..FIELDS_PER_BLOB {
fields[i] = field_to_bignum(i as Field);
}
/// Safety: this is a test
unsafe {
let partial_sums = __compute_partial_sums(fields, ROOTS);
let sum = __compute_sum(fields, ROOTS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::config::F;
use bigint::BigNum;
use bigint::{BigNum, bignum::BigNumTrait};
use std::ops::Add;
use types::{
constants::{BLOB_PUBLIC_INPUTS, BLOBS_PER_BLOCK},
traits::{Deserialize, Empty, Serialize},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod blob_public_inputs;
pub mod blob_public_inputs;
mod blob;
mod mock_blob_oracle;
mod config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::blob_public_inputs::{BlobCommitment, BlockBlobPublicInputs};
use super::blob_public_inputs::Deserialize;
use types::{
abis::sponge_blob::SpongeBlob,
constants::{BLOB_PUBLIC_INPUTS, BLOBS_PER_BLOCK, FIELDS_PER_BLOB},
traits::Deserialize,
};

// TODO(#10323): this was added to save simulation time (~1min in ACVM, ~3mins in wasm -> 500ms).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dep::types::{
traits::Verifiable,
verification_key::{HonkVerificationKey, VerificationKey},
},
traits::Empty,
traits::{Empty, Serialize},
};

pub struct RootParityInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
parity_public_inputs::ParityPublicInputs, root::root_parity_input::RootParityInput,
utils::sha256_merkle_tree::Sha256MerkleTree,
};
use dep::types::merkle_tree::MerkleTree;
use dep::types::{merkle_tree::MerkleTree, proof::traits::Verifiable};

global NUM_BASE_PARITY_PER_ROOT_PARITY: u32 = 4;

Expand Down Expand Up @@ -59,13 +59,13 @@ mod tests {
parity_public_inputs::ParityPublicInputs,
root::{root_parity_input::RootParityInput, root_parity_inputs::RootParityInputs},
};
use dep::types::constants::BASE_PARITY_INDEX;
use dep::types::proof::{recursive_proof::RecursiveProof, verification_key::VerificationKey};
use dep::types::tests::fixtures;

use super::NUM_BASE_PARITY_PER_ROOT_PARITY;
use types::hash::verification_key_hash;
use types::tests::fixtures::vk_tree::generate_fake_honk_vk_for_index;
use types::{
constants::{BASE_PARITY_INDEX, NUM_BASE_PARITY_PER_ROOT_PARITY},
hash::verification_key_hash,
proof::{recursive_proof::RecursiveProof, verification_key::VerificationKey},
tests::fixtures::vk_tree::{generate_fake_honk_vk_for_index, get_vk_merkle_tree},
traits::Empty,
};

fn test_setup() -> [RootParityInput; NUM_BASE_PARITY_PER_ROOT_PARITY] {
// 31 byte test SHA roots
Expand All @@ -76,7 +76,7 @@ mod tests {
0x53042d820859d80c474d4694e03778f8dc0ac88fc1c3a97b4369c1096e904a,
];

let vk_tree = fixtures::vk_tree::get_vk_merkle_tree();
let vk_tree = get_vk_merkle_tree();

let vk_path = vk_tree.get_sibling_path(BASE_PARITY_INDEX);
let vk_tree_root = vk_tree.get_root();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dep::types::{
traits::Verifiable,
verification_key::{HonkVerificationKey, VerificationKey},
},
traits::Empty,
traits::{Empty, Serialize},
};

pub struct RootRollupParityInput {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod previous_kernel_validator_hints;

use dep::types::{
abis::private_kernel_data::PrivateKernelData, address::AztecAddress, traits::is_empty,
abis::{private_kernel_data::PrivateKernelData, side_effect::{Ordered, OrderedValue}},
address::AztecAddress,
traits::is_empty,
utils::arrays::array_length,
};
use previous_kernel_validator_hints::{
Expand All @@ -15,6 +17,7 @@ pub struct PreviousKernelValidator {

impl PreviousKernelValidator {
pub fn new(previous_kernel: PrivateKernelData) -> Self {
/// Safety: the below hints are constrained by the following methods. See private_kernel_inner for use.
let hints =
unsafe { generate_previous_kernel_validator_hints(previous_kernel.public_inputs) };
PreviousKernelValidator { previous_kernel, hints }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dep::types::{
abis::{
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, note_hash::ScopedNoteHash,
side_effect::OrderedValue,
},
constants::{MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX},
utils::arrays::find_index_hint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use dep::types::{
},
address::AztecAddress,
constants::{MAX_FIELD_VALUE, REGISTERER_CONTRACT_ADDRESS},
traits::FromField,
transaction::tx_request::TxRequest,
utils::arrays::find_index_hint,
};
Expand Down Expand Up @@ -257,6 +258,7 @@ impl PrivateCallDataValidator {
// 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;
/// Safety: the index is constrained in validate_split_ranges below.
let first_revertible_index = unsafe {
find_first_revertible_item_index(
public_inputs.min_revertible_side_effect_counter,
Expand Down Expand Up @@ -375,6 +377,7 @@ impl PrivateCallDataValidator {
for i in 0..logs.len() {
let log = logs[i];
if log.note_hash_counter != 0 {
/// Safety: the index is constrained by the checks below.
let note_index = unsafe {
find_index_hint(
accumulated_note_hashes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mod tests {

pub fn execute_to_equal(self, expected: u32) {
let private_call = self.private_call.to_private_circuit_public_inputs();
/// Safety: this is a test
let index = unsafe {
find_first_revertible_item_index(
private_call.min_revertible_side_effect_counter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::types::{
abis::private_kernel::private_call_data::PrivateCallData, address::AztecAddress,
constants::MAX_PROTOCOL_CONTRACTS, merkle_tree::root::root_from_sibling_path,
constants::MAX_PROTOCOL_CONTRACTS, merkle_tree::root::root_from_sibling_path, traits::ToField,
};

pub fn validate_contract_address(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use dep::types::{
max_block_number::MaxBlockNumber,
nullifier::{Nullifier, ScopedNullifier},
private_circuit_public_inputs::PrivateCircuitPublicInputs,
side_effect::Ordered,
side_effect::{Ordered, OrderedValue},
tx_constant_data::TxConstantData,
},
address::AztecAddress,
traits::{Empty, is_empty},
traits::{Empty, Hash, is_empty},
transaction::tx_request::TxRequest,
utils::arrays::{array_length, array_to_bounded_vec, sort_by_counter_asc, sort_by_counter_desc},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ use crate::components::reset_output_composer::reset_output_hints::generate_reset
use dep::reset_kernel_lib::{PrivateValidationRequestProcessor, TransientDataIndexHint};
use dep::types::{
abis::{
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs, note_hash::ScopedNoteHash,
nullifier::ScopedNullifier, private_log::PrivateLogData, side_effect::scoped::Scoped,
kernel_circuit_public_inputs::PrivateKernelCircuitPublicInputs,
note_hash::ScopedNoteHash,
nullifier::ScopedNullifier,
private_log::PrivateLogData,
side_effect::{Ordered, scoped::Scoped},
},
address::AztecAddress,
constants::{MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX},
hash::{
compute_siloed_private_log_field, compute_unique_siloed_note_hash, silo_note_hash,
silo_nullifier,
},
traits::{Deserialize, Serialize},
utils::arrays::sort_by_counter_asc,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use dep::reset_kernel_lib::TransientDataIndexHint;
use dep::types::{
abis::{note_hash::ScopedNoteHash, private_log::PrivateLogData, side_effect::scoped::Scoped},
abis::{
note_hash::ScopedNoteHash,
private_log::PrivateLogData,
side_effect::{Ordered, scoped::Scoped},
},
utils::arrays::find_index_hint,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use dep::reset_kernel_lib::TransientDataIndexHint;
use dep::types::abis::{
note_hash::ScopedNoteHash, nullifier::ScopedNullifier, private_log::PrivateLogData,
side_effect::scoped::Scoped,
note_hash::ScopedNoteHash,
nullifier::ScopedNullifier,
private_log::PrivateLogData,
side_effect::{Ordered, scoped::Scoped},
};

pub unconstrained fn squash_transient_data<let M: u32, let N: u32, let P: u32, let NUM_TRANSIENT_DATA_INDEX_HINTS: u32>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dep::types::{
note_hash::ScopedNoteHash,
nullifier::ScopedNullifier,
private_log::{PrivateLog, PrivateLogData},
side_effect::scoped::Scoped,
side_effect::{Ordered, OrderedValue, scoped::Scoped},
},
constants::PRIVATE_LOG_SIZE_IN_FIELDS,
hash::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use dep::types::{
side_effect::scoped::Scoped,
},
messaging::l2_to_l1_message::ScopedL2ToL1Message,
traits::Empty,
};
pub use meter_gas_used::meter_gas_used;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dep::types::{
},
log_hash::ScopedLogHash,
private_log::PrivateLogData,
side_effect::scoped::Scoped,
side_effect::{OrderedValue, scoped::Scoped},
},
messaging::l2_to_l1_message::ScopedL2ToL1Message,
utils::arrays::assert_exposed_sorted_transformed_value_array,
Expand All @@ -26,6 +26,7 @@ impl TailOutputValidator {
output: PrivateToRollupKernelCircuitPublicInputs,
previous_kernel: PrivateKernelCircuitPublicInputs,
) -> Self {
/// Safety: the below hints are constrained by calling validate(). See private_kernel_tail for use.
let hints = unsafe { generate_tail_output_hints(previous_kernel) };
TailOutputValidator::new_with_hints(output, previous_kernel, hints)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dep::types::{
L2_GAS_PER_LOG_BYTE, L2_GAS_PER_NOTE_HASH, L2_GAS_PER_NULLIFIER, L2_GAS_PER_PRIVATE_LOG,
PRIVATE_LOG_SIZE_IN_FIELDS,
},
traits::is_empty,
traits::{Empty, is_empty},
utils::arrays::array_length,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use dep::types::abis::accumulated_data::{
private_accumulated_data_builder::PrivateAccumulatedDataBuilder,
private_to_public_accumulated_data::PrivateToPublicAccumulatedData,
private_to_public_accumulated_data_builder::PrivateToPublicAccumulatedDataBuilder,
use dep::types::{
abis::{
accumulated_data::{
private_accumulated_data_builder::PrivateAccumulatedDataBuilder,
private_to_public_accumulated_data::PrivateToPublicAccumulatedData,
private_to_public_accumulated_data_builder::PrivateToPublicAccumulatedDataBuilder,
},
side_effect::{Ordered, OrderedValue},
},
traits::Empty,
};

pub unconstrained fn split_to_public(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl TailToPublicOutputValidator {
output: PrivateToPublicKernelCircuitPublicInputs,
previous_kernel: PrivateKernelCircuitPublicInputs,
) -> Self {
/// Safety: the below hints are constrained by calling .validate(). See private_kernel_tail_to_public for use.
let hints = unsafe { generate_tail_to_public_output_hints(previous_kernel) };
TailToPublicOutputValidator { output, previous_kernel, hints }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl PrivateKernelInitCircuitPrivateInputs {
}

// Generate output.
/// Safety: The output is validated below by PrivateKernelCircuitOutputValidator.
let output = unsafe { self.generate_output() };

// Validate inputs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use dep::types::{
private_kernel_data::{PrivateKernelData, PrivateKernelDataWithoutPublicInputs},
},
constants::{PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_INDEX},
proof::traits::Verifiable,
};

global ALLOWED_PREVIOUS_CIRCUITS: [u32; 3] =
Expand Down Expand Up @@ -53,6 +54,7 @@ impl PrivateKernelInnerCircuitPrivateInputs {
}

// Generate output.
/// Safety: The output is validated below by PrivateKernelCircuitOutputValidator.
let output = unsafe { self.generate_output() };

// Validate inputs.
Expand Down
Loading
Loading