Skip to content

Commit 9e45ef1

Browse files
benesjannventuro
andauthored
chore: fixing noir warnings (#15856)
Fixing the vast majority of compiler warnings in `noir-projects`. Tackling this now as incoming Noir release will disallow accessing of private fields and private functionality. These warnings are remaining: <img width="1128" height="523" alt="image" src="https://github.com/user-attachments/assets/a9372a2b-ce93-41f3-9a4b-ffa96b60ba5f" /> The first one is impractical to fix, the 2nd, 3rd and 4th I am not sure how to fix and the last one I plan on making the AVM team fix. --------- Co-authored-by: Nicolás Venturo <[email protected]>
1 parent 2b3d58b commit 9e45ef1

File tree

64 files changed

+251
-237
lines changed

Some content is hidden

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

64 files changed

+251
-237
lines changed

noir-projects/aztec-nr/address-note/src/address_note.nr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ impl AddressNote {
2222
let randomness = unsafe { random() };
2323
AddressNote { address, owner, randomness }
2424
}
25+
26+
pub fn get_address(self) -> AztecAddress {
27+
self.address
28+
}
2529
}
2630
// docs:end:address_note_def

noir-projects/aztec-nr/aztec/src/context/private_context.nr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,10 @@ impl PrivateContext {
550550
};
551551
}
552552

553-
fn next_counter(&mut self) -> u32 {
553+
// This function got exposed publicly to be able to access it in ContractClassRegistry.
554+
// TODO(#15980): Implement a method for pushing contract class log hashes to the context and un-expose this
555+
// function.
556+
pub fn next_counter(&mut self) -> u32 {
554557
let counter = self.side_effect_counter;
555558
self.side_effect_counter += 1;
556559
counter

noir-projects/aztec-nr/aztec/src/context/public_context.nr

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,10 @@ unconstrained fn l1_to_l2_msg_exists(msg_hash: Field, msg_leaf_index: u64) -> u1
321321
unconstrained fn send_l2_to_l1_msg(recipient: EthAddress, content: Field) {
322322
send_l2_to_l1_msg_opcode(recipient, content)
323323
}
324-
unconstrained fn call(
324+
325+
// This function is temporarily exposed publicly to be able to test it in AVMTest contract.
326+
// TODO(#15980): Refactor tests to keep this implementation detail private within the crate.
327+
pub unconstrained fn call(
325328
l2_gas_allocation: u32,
326329
da_gas_allocation: u32,
327330
address: AztecAddress,
@@ -344,15 +347,22 @@ pub unconstrained fn calldata_copy<let N: u32>(cdoffset: u32, copy_size: u32) ->
344347
}
345348

346349
// `success_copy` is placed immediately after the CALL opcode to get the success value
347-
unconstrained fn success_copy() -> bool {
350+
//
351+
// This function is temporarily exposed publicly to be able to test it in AVMTest contract.
352+
// TODO: Refactor tests to keep this implementation detail private within the crate.
353+
pub unconstrained fn success_copy() -> bool {
348354
success_copy_opcode()
349355
}
350356

351-
unconstrained fn returndata_size() -> u32 {
357+
// This function is temporarily exposed publicly to be able to test it in AVMTest contract.
358+
// TODO: Refactor tests to keep this implementation detail private within the crate.
359+
pub unconstrained fn returndata_size() -> u32 {
352360
returndata_size_opcode()
353361
}
354362

355-
unconstrained fn returndata_copy(rdoffset: u32, copy_size: u32) -> [Field] {
363+
// This function is temporarily exposed publicly to be able to test it in AVMTest contract.
364+
// TODO: Refactor tests to keep this implementation detail private within the crate.
365+
pub unconstrained fn returndata_copy(rdoffset: u32, copy_size: u32) -> [Field] {
356366
returndata_copy_opcode(rdoffset, copy_size)
357367
}
358368

@@ -364,7 +374,10 @@ pub unconstrained fn avm_return(returndata: [Field]) {
364374
// to do rethrows, where the revert data is the same as the original revert data.
365375
// For normal reverts, use Noir's `assert` which, on top of reverting, will also add
366376
// an error selector to the revert data.
367-
unconstrained fn avm_revert(revertdata: [Field]) {
377+
//
378+
// This function is temporarily exposed publicly to be able to test it in AVMTest contract.
379+
// TODO: Refactor tests to keep this implementation detail private within the crate.
380+
pub unconstrained fn avm_revert(revertdata: [Field]) {
368381
revert_opcode(revertdata)
369382
}
370383

noir-projects/aztec-nr/aztec/src/macros/functions/mod.nr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
pub(crate) mod abi_export;
22
pub(crate) mod call_interface_stubs;
3-
pub(crate) mod initialization_utils;
3+
// TODO: Move initialization_utils out of this crate
4+
// See https://github.com/AztecProtocol/aztec-packages/pull/15856#discussion_r2229134689 for more details
5+
pub mod initialization_utils;
46
pub(crate) mod stub_registry;
57
pub(crate) mod auth_registry;
68
pub(crate) mod utils;

noir-projects/aztec-nr/aztec/src/note/note_emission.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<Note> NoteEmission<Note> {
2929
* a change note in a token's transfer function only when there is "change" left).
3030
*/
3131
pub struct OuterNoteEmission<Note> {
32-
emission: Option<NoteEmission<Note>>,
32+
pub emission: Option<NoteEmission<Note>>,
3333
}
3434

3535
impl<Note> OuterNoteEmission<Note> {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pub(crate) mod mock_note;
2-
pub(crate) mod mock_struct;
1+
pub mod mock_note;
2+
pub mod mock_struct;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod helpers;
2-
pub(crate) mod mocks;
2+
pub mod mocks;

noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use dep::aztec::{
2-
context::PrivateContext,
2+
context::{PrivateContext, UtilityContext},
33
messages::logs::note::encode_and_encrypt_note,
44
note::note_getter_options::NoteGetterOptions,
55
protocol_types::address::AztecAddress,
66
state_vars::{PrivateSet, storage::HasStorageSlot},
77
};
8-
use dep::value_note::{filter::filter_notes_min_sum, value_note::ValueNote};
8+
use dep::value_note::{balance_utils, filter::filter_notes_min_sum, value_note::ValueNote};
99

1010
pub struct EasyPrivateUint<Context> {
1111
context: Context,
@@ -61,3 +61,9 @@ impl EasyPrivateUint<&mut PrivateContext> {
6161
self.set.insert(result_note).emit(encode_and_encrypt_note(self.context, owner));
6262
}
6363
}
64+
65+
impl EasyPrivateUint<UtilityContext> {
66+
pub unconstrained fn get_value(self) -> Field {
67+
balance_utils::get_balance(self.set)
68+
}
69+
}

noir-projects/aztec-nr/uint-note/src/uint_note.nr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ impl UintNote {
104104
self.value
105105
}
106106

107+
pub fn get_owner(self) -> AztecAddress {
108+
self.owner
109+
}
110+
107111
/// Creates a partial note that will hide the owner and storage slot but not the value, since the note will be later
108112
/// completed in public. This is a powerful technique for scenarios in which the value cannot be known in private
109113
/// (e.g. because it depends on some public state, such as a DEX).
@@ -329,7 +333,7 @@ mod test {
329333
};
330334
use dep::aztec::{
331335
note::note_interface::NoteHash,
332-
protocol_types::{address::AztecAddress, traits::{FromField, Packable}},
336+
protocol_types::{address::AztecAddress, traits::{Deserialize, FromField, Packable}},
333337
utils::array::subarray,
334338
};
335339

@@ -373,7 +377,9 @@ mod test {
373377
randomness,
374378
public_log_tag: commitment,
375379
};
376-
let partial_note = PartialUintNote { commitment };
380+
// The following is a misuse of the `deserialize` function, but this is just a test and it's better than
381+
// letting devs manually construct it when they shouldn't be able to.
382+
let partial_note = PartialUintNote::deserialize([commitment]);
377383

378384
// The first field of the partial note private content is the public completion log tag, so it should match the
379385
// first field of the public log.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod balance_utils;
1+
pub mod balance_utils;
22
mod filter;
33
mod utils;
44
mod value_note;

0 commit comments

Comments
 (0)