Skip to content

Commit 909206a

Browse files
authored
feat: merge-train/fairies (#21090)
See [merge-train-readme.md](https://github.com/AztecProtocol/aztec-packages/blob/next/.github/workflows/merge-train-readme.md). This is a merge-train.
2 parents 5b6966e + 49b07b1 commit 909206a

9 files changed

Lines changed: 137 additions & 52 deletions

File tree

noir-projects/aztec-nr/CLAUDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ Follow the Rust stdlib style roughly. See `PublicImmutable` in `state_vars/publi
3333
- **Be precise with terminology.** For example, messages sent onchain are "messages that use logs", not "logs" themselves.
3434
- **Show practical patterns in examples.** Don't just show the API call — show it in context (e.g. inside a `#[external("public")]` function with realistic variable names).
3535
- **Document cost for methods.** When relevant, note which AVM opcodes are invoked and how many times (e.g. "`SLOAD` is invoked a number of times equal to `T`'s packed length").
36+
37+
## Logging
38+
39+
- **Always use the prefixed logging functions** from `crate::logging` (e.g. `logging::aztecnr_debug_log!`, `logging::aztecnr_debug_log_format!`). These automatically prepend `[aztec-nr] ` to all messages at compile time.
40+
- **Never use `crate::protocol::logging` directly** — those functions have no prefix, making logs harder to filter and identify.

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
nullifiers::notify_created_nullifier,
1818
},
1919
};
20+
use crate::logging::aztecnr_trace_log_format;
2021
use crate::protocol::{
2122
abis::{
2223
block_header::BlockHeader,
@@ -527,7 +528,7 @@ impl PrivateContext {
527528
/// balance (>= the gas limits specified in the TxContext) by the time we reach the public setup phase of the tx.
528529
///
529530
pub fn set_as_fee_payer(&mut self) {
530-
crate::protocol::logging::debug_log_format("Setting {0} as fee payer", [self.this_address().to_field()]);
531+
aztecnr_trace_log_format!("Setting {0} as fee payer")([self.this_address().to_field()]);
531532
self.is_fee_payer = true;
532533
}
533534

@@ -576,10 +577,7 @@ impl PrivateContext {
576577
// Incrementing the side effect counter when ending setup ensures non ambiguity for the counter where we change
577578
// phases.
578579
self.side_effect_counter += 1;
579-
// crate::protocol::logging::debug_log_format(
580-
// "Ending setup at counter {0}",
581-
// [self.side_effect_counter as Field]
582-
// );
580+
aztecnr_trace_log_format!("Ending setup at counter {0}")([self.side_effect_counter as Field]);
583581
self.min_revertible_side_effect_counter = self.next_counter();
584582
notify_set_min_revertible_side_effect_counter(self.min_revertible_side_effect_counter);
585583
}

noir-projects/aztec-nr/aztec/src/lib.nr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub mod capsules;
4242
pub mod event;
4343
pub mod messages;
4444
pub use protocol_types as protocol;
45+
pub(crate) mod logging;
4546
pub mod utils;
4647
pub mod authwit;
4748
pub mod macros;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Not all log levels are currently used, but we provide the full set so that new call sites can use any level. Because
2+
// of that we tag all with `#[allow(dead_code)]` to prevent warnings.
3+
4+
use std::meta::ctstring::AsCtString;
5+
6+
comptime fn log_prefix<let N: u32>(msg: str<N>) -> CtString {
7+
"[aztec-nr] ".as_ctstring().append_str(msg)
8+
}
9+
10+
// --- No-args variants (direct call) ---
11+
12+
#[allow(dead_code)]
13+
pub(crate) comptime fn aztecnr_fatal_log<let N: u32>(msg: str<N>) -> Quoted {
14+
let msg = log_prefix(msg);
15+
quote { crate::protocol::logging::fatal_log($msg) }
16+
}
17+
18+
#[allow(dead_code)]
19+
pub(crate) comptime fn aztecnr_error_log<let N: u32>(msg: str<N>) -> Quoted {
20+
let msg = log_prefix(msg);
21+
quote { crate::protocol::logging::error_log($msg) }
22+
}
23+
24+
#[allow(dead_code)]
25+
pub(crate) comptime fn aztecnr_warn_log<let N: u32>(msg: str<N>) -> Quoted {
26+
let msg = log_prefix(msg);
27+
quote { crate::protocol::logging::warn_log($msg) }
28+
}
29+
30+
#[allow(dead_code)]
31+
pub(crate) comptime fn aztecnr_info_log<let N: u32>(msg: str<N>) -> Quoted {
32+
let msg = log_prefix(msg);
33+
quote { crate::protocol::logging::info_log($msg) }
34+
}
35+
36+
#[allow(dead_code)]
37+
pub(crate) comptime fn aztecnr_verbose_log<let N: u32>(msg: str<N>) -> Quoted {
38+
let msg = log_prefix(msg);
39+
quote { crate::protocol::logging::verbose_log($msg) }
40+
}
41+
42+
#[allow(dead_code)]
43+
pub(crate) comptime fn aztecnr_debug_log<let N: u32>(msg: str<N>) -> Quoted {
44+
let msg = log_prefix(msg);
45+
quote { crate::protocol::logging::debug_log($msg) }
46+
}
47+
48+
#[allow(dead_code)]
49+
pub(crate) comptime fn aztecnr_trace_log<let N: u32>(msg: str<N>) -> Quoted {
50+
let msg = log_prefix(msg);
51+
quote { crate::protocol::logging::trace_log($msg) }
52+
}
53+
54+
// --- Format variants (return lambda for runtime args) ---
55+
56+
#[allow(dead_code)]
57+
pub(crate) comptime fn aztecnr_fatal_log_format<let N: u32>(msg: str<N>) -> Quoted {
58+
let msg = log_prefix(msg);
59+
quote { (|args| crate::protocol::logging::fatal_log_format($msg, args)) }
60+
}
61+
62+
#[allow(dead_code)]
63+
pub(crate) comptime fn aztecnr_error_log_format<let N: u32>(msg: str<N>) -> Quoted {
64+
let msg = log_prefix(msg);
65+
quote { (|args| crate::protocol::logging::error_log_format($msg, args)) }
66+
}
67+
68+
#[allow(dead_code)]
69+
pub(crate) comptime fn aztecnr_warn_log_format<let N: u32>(msg: str<N>) -> Quoted {
70+
let msg = log_prefix(msg);
71+
quote { (|args| crate::protocol::logging::warn_log_format($msg, args)) }
72+
}
73+
74+
#[allow(dead_code)]
75+
pub(crate) comptime fn aztecnr_info_log_format<let N: u32>(msg: str<N>) -> Quoted {
76+
let msg = log_prefix(msg);
77+
quote { (|args| crate::protocol::logging::info_log_format($msg, args)) }
78+
}
79+
80+
#[allow(dead_code)]
81+
pub(crate) comptime fn aztecnr_verbose_log_format<let N: u32>(msg: str<N>) -> Quoted {
82+
let msg = log_prefix(msg);
83+
quote { (|args| crate::protocol::logging::verbose_log_format($msg, args)) }
84+
}
85+
86+
#[allow(dead_code)]
87+
pub(crate) comptime fn aztecnr_debug_log_format<let N: u32>(msg: str<N>) -> Quoted {
88+
let msg = log_prefix(msg);
89+
quote { (|args| crate::protocol::logging::debug_log_format($msg, args)) }
90+
}
91+
92+
#[allow(dead_code)]
93+
pub(crate) comptime fn aztecnr_trace_log_format<let N: u32>(msg: str<N>) -> Quoted {
94+
let msg = log_prefix(msg);
95+
quote { (|args| crate::protocol::logging::trace_log_format($msg, args)) }
96+
}

noir-projects/aztec-nr/aztec/src/messages/discovery/mod.nr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::protocol::{address::AztecAddress, logging::{debug_log, debug_log_format}};
1+
use crate::logging::{aztecnr_debug_log, aztecnr_debug_log_format};
2+
use crate::protocol::address::AztecAddress;
23

34
pub(crate) mod nonce_discovery;
45
pub(crate) mod partial_notes;
@@ -107,16 +108,13 @@ pub unconstrained fn do_sync_state<ComputeNoteHashAndNullifierEnv, CustomMessage
107108
compute_note_hash_and_nullifier: ComputeNoteHashAndNullifier<ComputeNoteHashAndNullifierEnv>,
108109
process_custom_message: Option<CustomMessageHandler<CustomMessageHandlerEnv>>,
109110
) {
110-
debug_log("Performing state synchronization");
111+
aztecnr_debug_log!("Performing state synchronization");
111112

112113
// First we process all private logs, which can contain different kinds of messages e.g. private notes, partial
113114
// notes, private events, etc.
114115
let logs = get_private_logs(contract_address);
115116
logs.for_each(|i, pending_tagged_log: PendingTaggedLog| {
116-
debug_log_format(
117-
"Processing log with tag {0}",
118-
[pending_tagged_log.log.get(0)],
119-
);
117+
aztecnr_debug_log_format!("Processing log with tag {0}")([pending_tagged_log.log.get(0)]);
120118

121119
// We remove the tag from the pending tagged log and process the message ciphertext contained in it.
122120
let message_ciphertext = array::subbvec(pending_tagged_log.log, 1);

noir-projects/aztec-nr/aztec/src/messages/discovery/nonce_discovery.nr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::messages::{discovery::ComputeNoteHashAndNullifier, logs::note::MAX_NOTE_PACKED_LEN};
22

3+
use crate::logging::aztecnr_debug_log_format;
34
use crate::protocol::{
45
address::AztecAddress,
56
constants::MAX_NOTE_HASHES_PER_TX,
67
hash::{compute_note_hash_nonce, compute_siloed_note_hash, compute_unique_note_hash},
7-
logging::debug_log_format,
88
traits::ToField,
99
};
1010

@@ -36,8 +36,9 @@ pub(crate) unconstrained fn attempt_note_nonce_discovery<Env>(
3636
) -> BoundedVec<DiscoveredNoteInfo, MAX_NOTE_HASHES_PER_TX> {
3737
let discovered_notes = &mut BoundedVec::new();
3838

39-
debug_log_format(
39+
aztecnr_debug_log_format!(
4040
"Attempting nonce discovery on {0} potential notes on contract {1} for storage slot {2}",
41+
)(
4142
[unique_note_hashes_in_tx.len() as Field, contract_address.to_field(), storage_slot],
4243
);
4344

@@ -90,10 +91,7 @@ pub(crate) unconstrained fn attempt_note_nonce_discovery<Env>(
9091
}
9192
});
9293

93-
debug_log_format(
94-
"Found valid nonces for a total of {0} notes",
95-
[discovered_notes.len() as Field],
96-
);
94+
aztecnr_debug_log_format!("Found valid nonces for a total of {0} notes")([discovered_notes.len() as Field]);
9795

9896
*discovered_notes
9997
}

noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ use crate::{
1212
utils::array,
1313
};
1414

15-
use crate::protocol::{
16-
address::AztecAddress,
17-
hash::sha256_to_field,
18-
logging::debug_log_format,
19-
traits::{Deserialize, Serialize},
20-
};
15+
use crate::logging::aztecnr_debug_log_format;
16+
use crate::protocol::{address::AztecAddress, hash::sha256_to_field, traits::{Deserialize, Serialize}};
2117

2218
/// The slot in the PXE capsules where we store a `CapsuleArray` of `DeliveredPendingPartialNote`.
2319
pub(crate) global DELIVERED_PENDING_PARTIAL_NOTE_ARRAY_LENGTH_CAPSULES_SLOT: Field = sha256_to_field(
@@ -76,10 +72,7 @@ pub(crate) unconstrained fn fetch_and_process_partial_note_completion_logs<Env>(
7672
DELIVERED_PENDING_PARTIAL_NOTE_ARRAY_LENGTH_CAPSULES_SLOT,
7773
);
7874

79-
debug_log_format(
80-
"{} pending partial notes",
81-
[pending_partial_notes.len() as Field],
82-
);
75+
aztecnr_debug_log_format!("{} pending partial notes")([pending_partial_notes.len() as Field]);
8376

8477
// Each of the pending partial notes might get completed by a log containing its public values. For performance
8578
// reasons, we fetch all of these logs concurrently and then process them one by one, minimizing the amount of time
@@ -99,19 +92,17 @@ pub(crate) unconstrained fn fetch_and_process_partial_note_completion_logs<Env>(
9992
let pending_partial_note = pending_partial_notes.get(i);
10093

10194
if maybe_log.is_none() {
102-
debug_log_format(
103-
"Found no completion logs for partial note with tag {}",
95+
aztecnr_debug_log_format!("Found no completion logs for partial note with tag {}")(
10496
[pending_partial_note.note_completion_log_tag],
10597
);
10698

10799
// Note that we're not removing the pending partial note from the capsule array, so we will continue
108100
// searching for this tagged log when performing message discovery in the future until we either find it or
109101
// the entry is somehow removed from the array.
110102
} else {
111-
debug_log_format(
112-
"Completion log found for partial note with tag {}",
113-
[pending_partial_note.note_completion_log_tag],
114-
);
103+
aztecnr_debug_log_format!("Completion log found for partial note with tag {}")([
104+
pending_partial_note.note_completion_log_tag,
105+
]);
115106
let log = maybe_log.unwrap();
116107

117108
// Public fields are assumed to all be placed at the end of the packed representation, so we combine the
@@ -142,10 +133,10 @@ pub(crate) unconstrained fn fetch_and_process_partial_note_completion_logs<Env>(
142133
);
143134
}
144135

145-
debug_log_format(
146-
"Discovered {0} notes for partial note with tag {1}",
147-
[discovered_notes.len() as Field, pending_partial_note.note_completion_log_tag],
148-
);
136+
aztecnr_debug_log_format!("Discovered {0} notes for partial note with tag {1}")([
137+
discovered_notes.len() as Field,
138+
pending_partial_note.note_completion_log_tag,
139+
]);
149140

150141
discovered_notes.for_each(|discovered_note| {
151142
enqueue_note_for_validation(

noir-projects/aztec-nr/aztec/src/messages/discovery/private_notes.nr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
use crate::logging::aztecnr_debug_log_format;
12
use crate::messages::{
23
discovery::{ComputeNoteHashAndNullifier, nonce_discovery::attempt_note_nonce_discovery},
34
encoding::MAX_MESSAGE_CONTENT_LEN,
45
logs::note::{decode_private_note_message, MAX_NOTE_PACKED_LEN},
56
processing::enqueue_note_for_validation,
67
};
7-
use crate::protocol::{address::AztecAddress, constants::MAX_NOTE_HASHES_PER_TX, logging::debug_log_format};
8+
use crate::protocol::{address::AztecAddress, constants::MAX_NOTE_HASHES_PER_TX};
89

910
pub(crate) unconstrained fn process_private_note_msg<Env>(
1011
contract_address: AztecAddress,
@@ -61,10 +62,7 @@ pub unconstrained fn attempt_note_discovery<Env>(
6162
packed_note,
6263
);
6364

64-
debug_log_format(
65-
"Discovered {0} notes from a private message",
66-
[discovered_notes.len() as Field],
67-
);
65+
aztecnr_debug_log_format!("Discovered {0} notes from a private message")([discovered_notes.len() as Field]);
6866

6967
discovered_notes.for_each(|discovered_note| {
7068
enqueue_note_for_validation(

noir-projects/aztec-nr/aztec/src/messages/discovery/process_message.nr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::messages::{
1111
processing::MessageContext,
1212
};
1313

14-
use crate::protocol::{address::AztecAddress, logging::{debug_log, warn_log_format}};
14+
use crate::logging::{aztecnr_debug_log, aztecnr_warn_log_format};
15+
use crate::protocol::address::AztecAddress;
1516

1617
/// Processes a message that can contain notes, partial notes, or events.
1718
///
@@ -43,10 +44,7 @@ pub unconstrained fn process_message_ciphertext<ComputeNoteHashAndNullifierEnv,
4344
message_context,
4445
);
4546
} else {
46-
warn_log_format(
47-
"Could not decrypt message ciphertext from tx {0}, ignoring",
48-
[message_context.tx_hash],
49-
);
47+
aztecnr_warn_log_format!("Could not decrypt message ciphertext from tx {0}, ignoring")([message_context.tx_hash]);
5048
}
5149
}
5250

@@ -64,7 +62,7 @@ pub(crate) unconstrained fn process_message_plaintext<ComputeNoteHashAndNullifie
6462
let (msg_type_id, msg_metadata, msg_content) = decode_message(message_plaintext);
6563

6664
if msg_type_id == PRIVATE_NOTE_MSG_TYPE_ID {
67-
debug_log("Processing private note msg");
65+
aztecnr_debug_log!("Processing private note msg");
6866

6967
process_private_note_msg(
7068
contract_address,
@@ -77,7 +75,7 @@ pub(crate) unconstrained fn process_message_plaintext<ComputeNoteHashAndNullifie
7775
msg_content,
7876
);
7977
} else if msg_type_id == PARTIAL_NOTE_PRIVATE_MSG_TYPE_ID {
80-
debug_log("Processing partial note private msg");
78+
aztecnr_debug_log!("Processing partial note private msg");
8179

8280
process_partial_note_private_msg(
8381
contract_address,
@@ -86,7 +84,7 @@ pub(crate) unconstrained fn process_message_plaintext<ComputeNoteHashAndNullifie
8684
msg_content,
8785
);
8886
} else if msg_type_id == PRIVATE_EVENT_MSG_TYPE_ID {
89-
debug_log("Processing private event msg");
87+
aztecnr_debug_log!("Processing private event msg");
9088

9189
process_private_event_msg(
9290
contract_address,
@@ -99,8 +97,9 @@ pub(crate) unconstrained fn process_message_plaintext<ComputeNoteHashAndNullifie
9997
// The message type ID falls in the range reserved for aztec.nr built-in types but wasn't matched above. This
10098
// most likely means the message is malformed or a custom message was incorrectly assigned a reserved ID.
10199
// Custom message types must use IDs allocated via `custom_msg_type_id`.
102-
warn_log_format(
100+
aztecnr_warn_log_format!(
103101
"Message type ID {0} is in the reserved range but is not recognized, ignoring. See https://docs.aztec.network/errors/3",
102+
)(
104103
[msg_type_id as Field],
105104
);
106105
} else if process_custom_message.is_some() {
@@ -114,8 +113,9 @@ pub(crate) unconstrained fn process_message_plaintext<ComputeNoteHashAndNullifie
114113
} else {
115114
// A custom message was received but no handler is configured. This likely means the contract emits custom
116115
// messages but forgot to register a handler via `AztecConfig::custom_message_handler`.
117-
warn_log_format(
116+
aztecnr_warn_log_format!(
118117
"Received custom message with type id {0} but no handler is configured, ignoring. See https://docs.aztec.network/errors/2",
118+
)(
119119
[msg_type_id as Field],
120120
);
121121
}

0 commit comments

Comments
 (0)