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 more aztec-nr warnings (numerics and unused variables) #7519

Merged
merged 2 commits into from
Jul 18, 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
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub fn assert_inner_hash_valid_authwit_public(context: &mut PublicContext, on_be
* @param args The arguments of the function that is being called
*/
// docs:start:compute_authwit_message_hash_from_call
pub fn compute_authwit_message_hash_from_call<N>(
pub fn compute_authwit_message_hash_from_call<let N: u32>(
caller: AztecAddress,
consumer: AztecAddress,
chain_id: Field,
Expand All @@ -307,7 +307,7 @@ pub fn compute_authwit_message_hash_from_call<N>(
*
* @param args The arguments to hash
*/
pub fn compute_inner_authwit_hash<N>(args: [Field; N]) -> Field {
pub fn compute_inner_authwit_hash<let N: u32>(args: [Field; N]) -> Field {
pedersen_hash(args, GENERATOR_INDEX__AUTHWIT_INNER)
}

Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/auth_witness.nr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[oracle(getAuthWitness)]
unconstrained fn get_auth_witness_oracle<N>(_message_hash: Field) -> [Field; N] {}
unconstrained fn get_auth_witness_oracle<let N: u32>(_message_hash: Field) -> [Field; N] {}

/**
* Oracle wrapper to fetch an `auth_witness` for a given `message_hash` from the PXE.
*
* @param message_hash The hash of the message for which the `auth_witness` is to be fetched.
* @return The `auth_witness` for the given `message_hash` as Field array.
*/
unconstrained pub fn get_auth_witness<N>(message_hash: Field) -> [Field; N] {
unconstrained pub fn get_auth_witness<let N: u32>(message_hash: Field) -> [Field; N] {
get_auth_witness_oracle(message_hash)
}
52 changes: 26 additions & 26 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ impl PublicContext {
PublicContext { inputs }
}

pub fn emit_unencrypted_log<T, let N: u32>(&mut self, log: T) where T: Serialize<N> {
pub fn emit_unencrypted_log<T, let N: u32>(_self: &mut Self, log: T) where T: Serialize<N> {
emit_unencrypted_log(Serialize::serialize(log).as_slice());
}

pub fn note_hash_exists(self, note_hash: Field, leaf_index: Field) -> bool {
pub fn note_hash_exists(_self: Self, note_hash: Field, leaf_index: Field) -> bool {
note_hash_exists(note_hash, leaf_index) == 1
}

pub fn l1_to_l2_msg_exists(self, msg_hash: Field, msg_leaf_index: Field) -> bool {
pub fn l1_to_l2_msg_exists(_self: Self, msg_hash: Field, msg_leaf_index: Field) -> bool {
l1_to_l2_msg_exists(msg_hash, msg_leaf_index) == 1
}

fn nullifier_exists(self, unsiloed_nullifier: Field, address: AztecAddress) -> bool {
fn nullifier_exists(_self: Self, unsiloed_nullifier: Field, address: AztecAddress) -> bool {
nullifier_exists(unsiloed_nullifier, address.to_field()) == 1
}

Expand Down Expand Up @@ -60,12 +60,12 @@ impl PublicContext {
self.push_nullifier(nullifier, 0);
}

fn message_portal(&mut self, recipient: EthAddress, content: Field) {
fn message_portal(_self: &mut Self, recipient: EthAddress, content: Field) {
send_l2_to_l1_msg(recipient, content);
}

fn call_public_function<let RETURNS_COUNT: u32>(
self: &mut Self,
_self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field],
Expand All @@ -85,7 +85,7 @@ impl PublicContext {
}

fn static_call_public_function<let RETURNS_COUNT: u32>(
self: &mut Self,
_self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field],
Expand All @@ -103,65 +103,65 @@ impl PublicContext {
}

fn delegate_call_public_function<let RETURNS_COUNT: u32>(
self: &mut Self,
contract_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field]
_self: &mut Self,
_contract_address: AztecAddress,
_function_selector: FunctionSelector,
_args: [Field]
) -> FunctionReturns<RETURNS_COUNT> {
assert(false, "'delegate_call_public_function' not implemented!");
FunctionReturns::new([0; RETURNS_COUNT])
}

fn push_note_hash(&mut self, note_hash: Field) {
fn push_note_hash(_self: &mut Self, note_hash: Field) {
emit_note_hash(note_hash);
}
fn push_nullifier(&mut self, nullifier: Field, _nullified_commitment: Field) {
fn push_nullifier(_self: &mut Self, nullifier: Field, _nullified_commitment: Field) {
// Cannot nullify pending commitments in AVM, so `nullified_commitment` is not used
emit_nullifier(nullifier);
}

fn this_address(self) -> AztecAddress {
fn this_address(_self: Self) -> AztecAddress {
address()
}
pub fn storage_address(self) -> AztecAddress {
pub fn storage_address(_self: Self) -> AztecAddress {
storage_address()
}
fn msg_sender(self) -> AztecAddress {
fn msg_sender(_self: Self) -> AztecAddress {
sender()
}
fn selector(self) -> FunctionSelector {
fn selector(_self: Self) -> FunctionSelector {
FunctionSelector::from_u32(function_selector())
}
fn get_args_hash(self) -> Field {
self.inputs.args_hash
}
fn transaction_fee(self) -> Field {
fn transaction_fee(_self: Self) -> Field {
transaction_fee()
}

fn chain_id(self) -> Field {
fn chain_id(_self: Self) -> Field {
chain_id()
}
fn version(self) -> Field {
fn version(_self: Self) -> Field {
version()
}
fn block_number(self) -> Field {
fn block_number(_self: Self) -> Field {
block_number()
}
fn timestamp(self) -> u64 {
fn timestamp(_self: Self) -> u64 {
timestamp()
}
pub fn fee_per_l2_gas(self) -> Field {
pub fn fee_per_l2_gas(_self: Self) -> Field {
fee_per_l2_gas()
}
pub fn fee_per_da_gas(self) -> Field {
pub fn fee_per_da_gas(_self: Self) -> Field {
fee_per_da_gas()
}

fn l2_gas_left(self) -> Field {
fn l2_gas_left(_self: Self) -> Field {
l2_gas_left()
}
fn da_gas_left(self) -> Field {
fn da_gas_left(_self: Self) -> Field {
da_gas_left()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod test {
global ADDRESS_NOTE_BYTES_LEN = 32 * 3 + 64;

impl NoteInterface<ADDRESS_NOTE_LEN, ADDRESS_NOTE_BYTES_LEN> for AddressNote {
fn compute_note_content_hash(self) -> Field {1}
fn compute_note_content_hash(_self: Self) -> Field {1}

fn get_note_type_id() -> Field {
1
Expand All @@ -70,11 +70,11 @@ mod test {

fn set_header(&mut self, header: NoteHeader) {self.header = header; }

fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) {
fn compute_note_hash_and_nullifier(_self: Self, _context: &mut PrivateContext) -> (Field, Field) {
(1, 1)
}

fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) {(1,1)}
fn compute_note_hash_and_nullifier_without_context(_self: Self) -> (Field, Field) {(1,1)}

fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN] { [self.address.to_field(), self.owner.to_field(), self.randomness]}

Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ mod test {
let note = MockNoteBuilder::new(note_value).contract_address(contract_address).storage_slot(storage_slot).build();

let eph_sk = 0x1358d15019d4639393d62b97e1588c095957ce74a1c32d6ec7d62fe6705d9538;
OracleMock::mock("getRandomField").returns(eph_sk);
let _ = OracleMock::mock("getRandomField").returns(eph_sk);

let recipient = AztecAddress::from_field(0x10ee41ee4b62703b16f61e03cb0d88c4b306a9eb4a6ceeb2aff13428541689a2);

Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/note/note_emission.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<Note> NoteEmission<Note> {
_emit(self);
}

pub fn discard(self) {}
pub fn discard(_self: Self) {}
}

/**
Expand All @@ -41,5 +41,5 @@ impl<Note> OuterNoteEmission<Note> {
}
}

pub fn discard(self) {}
pub fn discard(_self: Self) {}
}
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/note/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn compute_inner_note_hash_from_preimage(storage_slot: Field, note_content_h
)
}

fn compute_inner_note_hash<Note, let N: u32, let M: u32>(note: Note) -> Field where Note: NoteInterface<N, M> {
pub fn compute_inner_note_hash<Note, let N: u32, let M: u32>(note: Note) -> Field where Note: NoteInterface<N, M> {
let header = note.get_header();
let note_hash = note.compute_note_content_hash();

Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/encryption.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[oracle(aes128Encrypt)]
pub fn aes128_encrypt_oracle<let N: u32, let M: u32>(
unconstrained pub fn aes128_encrypt_oracle<let N: u32, let M: u32>(
input: [u8; N],
iv: [u8; 16],
key: [u8; 16]
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ unconstrained fn get_public_keys_and_partial_address_oracle_wrapper(address: Azt
get_public_keys_and_partial_address_oracle(address)
}

fn get_public_keys_and_partial_address(address: AztecAddress) -> (PublicKeys, PartialAddress) {
pub fn get_public_keys_and_partial_address(address: AztecAddress) -> (PublicKeys, PartialAddress) {
let result = get_public_keys_and_partial_address_oracle_wrapper(address);

let keys = PublicKeys {
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/logs_traits.nr
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ impl<let N: u32, let M: u32, let L: u32> ToBytesForUnencryptedLog<N, M> for str<
fn to_be_bytes_arr(self) -> [u8; N] {
str_to_be_bytes_arr(self)
}
fn output_bytes(self) -> [u8; M] {
fn output_bytes(_self: Self) -> [u8; M] {
[0; M]
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::protocol_types::{address::AztecAddress, point::Point};
use crate::{context::PrivateContext, state_vars::private_mutable::PrivateMutable};
use crate::test::{mocks::mock_note::MockNote, helpers::{cheatcodes, test_environment::TestEnvironment}};
use std::{unsafe::zeroed, test::OracleMock};
use std::test::OracleMock;

global storage_slot = 17;

Expand All @@ -13,7 +13,7 @@ fn in_private(env: &mut TestEnvironment) -> PrivateMutable<MockNote, &mut Privat
let state_var = PrivateMutable::new(&mut env.private(), storage_slot);

// This oracle is called for its side effects alone - it's always expected to return 0.
OracleMock::mock("notifyCreatedNote").returns(0);
let _ = OracleMock::mock("notifyCreatedNote").returns(0);

state_var
}
Expand All @@ -23,13 +23,10 @@ fn test_initialize_or_replace_without_nullifier() {
let mut env = setup();
let state_var = in_private(&mut env);

let ovpk_m: Point = zeroed();
let ivpk_m: Point = zeroed();

let value = 42;
let mut note = MockNote::new(value).contract_address(cheatcodes::get_contract_address()).storage_slot(storage_slot).build();

OracleMock::mock("checkNullifierExists").returns(0);
let _ = OracleMock::mock("checkNullifierExists").returns(0);
state_var.initialize_or_replace(&mut note).discard();

// Since we reported there was no nullifier, we should initialize and see the following side-effects:
Expand Down
48 changes: 24 additions & 24 deletions noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -123,77 +123,77 @@ unconstrained pub fn set_fn_selector(selector: FunctionSelector) {
}

#[oracle(reset)]
fn oracle_reset() {}
unconstrained fn oracle_reset() {}

#[oracle(getChainId)]
fn oracle_get_chain_id() -> Field {}
unconstrained fn oracle_get_chain_id() -> Field {}

#[oracle(getVersion)]
fn oracle_get_version() -> Field {}
unconstrained fn oracle_get_version() -> Field {}

#[oracle(getContractAddress)]
fn oracle_get_contract_address() -> AztecAddress {}
unconstrained fn oracle_get_contract_address() -> AztecAddress {}

#[oracle(setContractAddress)]
fn oracle_set_contract_address(address: AztecAddress) {}
unconstrained fn oracle_set_contract_address(address: AztecAddress) {}

#[oracle(getBlockNumber)]
fn oracle_get_block_number() -> u32 {}
unconstrained fn oracle_get_block_number() -> u32 {}

#[oracle(advanceBlocksBy)]
fn oracle_advance_blocks_by(blocks: u32) {}
unconstrained fn oracle_advance_blocks_by(blocks: u32) {}

#[oracle(getPrivateContextInputs)]
fn oracle_get_private_context_inputs(historical_block_number: u32) -> PrivateContextInputs {}
unconstrained fn oracle_get_private_context_inputs(historical_block_number: u32) -> PrivateContextInputs {}

#[oracle(getPublicContextInputs)]
fn oracle_get_public_context_inputs() -> PublicContextInputs {}
unconstrained fn oracle_get_public_context_inputs() -> PublicContextInputs {}

#[oracle(deploy)]
fn oracle_deploy<let N: u32, let M: u32>(
unconstrained fn oracle_deploy<let N: u32, let M: u32>(
path: str<N>,
initializer: str<M>,
args: [Field],
public_keys_hash: Field
) -> [Field; CONTRACT_INSTANCE_LENGTH] {}

#[oracle(directStorageWrite)]
fn direct_storage_write_oracle<let N: u32>(
unconstrained fn direct_storage_write_oracle<let N: u32>(
_contract_address: AztecAddress,
_storage_slot: Field,
_values: [Field; N]
) -> [Field; N] {}

#[oracle(createAccount)]
fn oracle_create_account() -> TestAccount {}
unconstrained fn oracle_create_account() -> TestAccount {}

#[oracle(addAccount)]
fn oracle_add_account(secret: Field, partial_address: PartialAddress) -> TestAccount {}
unconstrained fn oracle_add_account(secret: Field, partial_address: PartialAddress) -> TestAccount {}

#[oracle(deriveKeys)]
fn oracle_derive_keys(secret: Field) -> PublicKeys {}
unconstrained fn oracle_derive_keys(secret: Field) -> PublicKeys {}

#[oracle(getMsgSender)]
fn oracle_get_msg_sender() -> AztecAddress {}
unconstrained fn oracle_get_msg_sender() -> AztecAddress {}

#[oracle(setMsgSender)]
fn oracle_set_msg_sender(msg_sender: AztecAddress) {}
unconstrained fn oracle_set_msg_sender(msg_sender: AztecAddress) {}

#[oracle(getSideEffectsCounter)]
fn oracle_get_side_effects_counter() -> u32 {}
unconstrained fn oracle_get_side_effects_counter() -> u32 {}

#[oracle(addAuthWitness)]
fn orable_add_authwit(address: AztecAddress, message_hash: Field) {}
unconstrained fn orable_add_authwit(address: AztecAddress, message_hash: Field) {}

#[oracle(assertPublicCallFails)]
fn oracle_assert_public_call_fails(
unconstrained fn oracle_assert_public_call_fails(
target_address: AztecAddress,
function_selector: FunctionSelector,
args: [Field]
) {}

#[oracle(assertPrivateCallFails)]
fn oracle_assert_private_call_fails(
unconstrained fn oracle_assert_private_call_fails(
target_address: AztecAddress,
function_selector: FunctionSelector,
argsHash: Field,
Expand All @@ -203,13 +203,13 @@ fn oracle_assert_private_call_fails(
) {}

#[oracle(addNullifiers)]
fn oracle_add_nullifiers(contractAddress: AztecAddress, nullifiers: [Field]) {}
unconstrained fn oracle_add_nullifiers(contractAddress: AztecAddress, nullifiers: [Field]) {}

#[oracle(addNoteHashes)]
fn oracle_add_note_hashes(contractAddress: AztecAddress, inner_note_hashes: [Field]) {}
unconstrained fn oracle_add_note_hashes(contractAddress: AztecAddress, inner_note_hashes: [Field]) {}

#[oracle(getFunctionSelector)]
fn oracle_get_function_selector() -> FunctionSelector {}
unconstrained fn oracle_get_function_selector() -> FunctionSelector {}

#[oracle(setFunctionSelector)]
fn oracle_set_function_selector(selector: FunctionSelector) {}
unconstrained fn oracle_set_function_selector(selector: FunctionSelector) {}
Loading
Loading