Skip to content

Commit 5b6966e

Browse files
authored
feat: merge-train/fairies (#21022)
BEGIN_COMMIT_OVERRIDE feat: allow custom addresses to be prefunded with fee juice in local network (#21000) docs(claude): add Noir early return idiom to CLAUDE.md (#21021) feat: add compile-time size check for events and error code links (#21024) feat: use warn_log_format for discarded messages (#21053) END_COMMIT_OVERRIDE
2 parents f15d59d + b56485d commit 5b6966e

15 files changed

Lines changed: 117 additions & 15 deletions

File tree

docs/netlify.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,8 +774,13 @@
774774
from = "/errors/3"
775775
to = "/aztec-nr-api/nightly/noir_aztec/messages/msg_type/index.html"
776776

777-
# Example (uncomment and modify when adding error codes):
778-
# [[redirects]]
779-
# from = "/errors/4"
780-
# to = "/developers/docs/aztec-nr/framework-description/functions/how_to_define_functions"
777+
[[redirects]]
778+
# Aztec-nr: note packed length exceeds MAX_NOTE_PACKED_LEN
779+
from = "/errors/4"
780+
to = "/aztec-nr-api/nightly/noir_aztec/macros/notes/fn.note.html"
781+
782+
[[redirects]]
783+
# Aztec-nr: event serialized length exceeds MAX_EVENT_SERIALIZED_LEN
784+
from = "/errors/5"
785+
to = "/aztec-nr-api/nightly/noir_aztec/macros/events/fn.event.html"
781786

noir-projects/aztec-nr/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## Noir Idioms
88

99
- Use `panic("message")` instead of `assert(false, "message")` for unconditional failures. `panic` returns the parent function's return type, making it usable in expression position (e.g. in if/else branches). Even when the return type doesn't matter, `panic` is the idiomatic choice.
10+
- **Early `return` is not supported in Noir.** You cannot use `return` or `return value` to exit a function early. Instead, restructure the code using `if/else` branches so that all paths lead to the end of the function with a single return expression. For example, instead of `if cond { return None; } ... Some(result)`, write `if cond { Option::none() } else { ... Option::some(result) }`.
1011

1112
## Doc Comments
1213

noir-projects/aztec-nr/aztec/src/macros/events.nr

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ pub comptime mut global EVENT_SELECTORS: CHashMap<Field, Quoted> = CHashMap::new
1010

1111
comptime fn generate_event_interface_and_get_selector(s: TypeDefinition) -> (Quoted, Field) {
1212
let name = s.name();
13+
let typ = s.as_type();
14+
let event_type_name: str<_> = f"{name}".as_quoted_str!();
15+
let max_event_serialized_len = crate::messages::logs::event::MAX_EVENT_SERIALIZED_LEN;
1316

1417
let event_selector = compute_struct_selector(s, quote { crate::event::EventSelector::from_signature });
1518

@@ -23,6 +26,18 @@ comptime fn generate_event_interface_and_get_selector(s: TypeDefinition) -> (Quo
2326
quote {
2427
impl aztec::event::event_interface::EventInterface for $name {
2528
fn get_event_type_id() -> aztec::event::EventSelector {
29+
// This static assertion ensures the event's serialized length doesn't exceed the maximum
30+
// allowed size. While this check would ideally live in the Serialize trait implementation, we
31+
// place it here since this function is always generated by our macros and the Serialize trait
32+
// implementation is not.
33+
//
34+
// Note: We set the event type name and max serialized length as local variables because
35+
// injecting them directly into the error message doesn't work.
36+
let event_type_name = $event_type_name;
37+
let max_event_serialized_len: u32 = $max_event_serialized_len;
38+
let event_serialized_len = <$typ as aztec::protocol::traits::Serialize>::N;
39+
std::static_assert(event_serialized_len <= $max_event_serialized_len, f"{event_type_name} has a serialized length of {event_serialized_len} fields, which exceeds the maximum allowed length of {max_event_serialized_len} fields. See https://docs.aztec.network/errors/5");
40+
2641
$from_field($event_selector)
2742
}
2843
}
@@ -42,6 +57,14 @@ comptime fn register_event_selector(event_selector: Field, event_name: Quoted) {
4257
EVENT_SELECTORS.insert(event_selector, event_name);
4358
}
4459

60+
/// Generates the core event functionality for a struct, including the
61+
/// [`EventInterface`](crate::event::event_interface::EventInterface) implementation (which provides the event type
62+
/// id) and a [`Serialize`](crate::protocol::traits::Serialize) implementation if one is not already provided.
63+
///
64+
/// ## Requirements
65+
///
66+
/// The event struct must not exceed
67+
/// [`MAX_EVENT_SERIALIZED_LEN`](crate::messages::logs::event::MAX_EVENT_SERIALIZED_LEN) when serialized.
4568
pub comptime fn event(s: TypeDefinition) -> Quoted {
4669
let (event_interface_impl, event_selector) = generate_event_interface_and_get_selector(s);
4770
register_event_selector(event_selector, s.name());

noir-projects/aztec-nr/aztec/src/macros/notes.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ comptime fn generate_note_type_impl(s: TypeDefinition, note_type_id: Field) -> Q
4848
// directly into the error message doesn't work.
4949
let note_type_name = $note_type_name;
5050
let max_note_packed_len: u32 = $max_note_packed_len; // Casting to u32 to avoid the value to be printed in hex.
51-
let note_packed_len = <$typ as Packable>::N;
52-
std::static_assert(note_packed_len <= $max_note_packed_len, f"{note_type_name} has a packed length of {note_packed_len} fields, which exceeds the maximum allowed length of {max_note_packed_len} fields");
51+
let note_packed_len = <$typ as aztec::protocol::traits::Packable>::N;
52+
std::static_assert(note_packed_len <= $max_note_packed_len, f"{note_type_name} has a packed length of {note_packed_len} fields, which exceeds the maximum allowed length of {max_note_packed_len} fields. See https://docs.aztec.network/errors/4");
5353

5454
$note_type_id
5555
}

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

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

14-
use crate::protocol::{address::AztecAddress, logging::{debug_log, debug_log_format}};
14+
use crate::protocol::{address::AztecAddress, logging::{debug_log, warn_log_format}};
1515

1616
/// Processes a message that can contain notes, partial notes, or events.
1717
///
@@ -43,7 +43,7 @@ pub unconstrained fn process_message_ciphertext<ComputeNoteHashAndNullifierEnv,
4343
message_context,
4444
);
4545
} else {
46-
debug_log_format(
46+
warn_log_format(
4747
"Could not decrypt message ciphertext from tx {0}, ignoring",
4848
[message_context.tx_hash],
4949
);
@@ -99,7 +99,7 @@ pub(crate) unconstrained fn process_message_plaintext<ComputeNoteHashAndNullifie
9999
// The message type ID falls in the range reserved for aztec.nr built-in types but wasn't matched above. This
100100
// most likely means the message is malformed or a custom message was incorrectly assigned a reserved ID.
101101
// Custom message types must use IDs allocated via `custom_msg_type_id`.
102-
debug_log_format(
102+
warn_log_format(
103103
"Message type ID {0} is in the reserved range but is not recognized, ignoring. See https://docs.aztec.network/errors/3",
104104
[msg_type_id as Field],
105105
);
@@ -114,7 +114,7 @@ pub(crate) unconstrained fn process_message_plaintext<ComputeNoteHashAndNullifie
114114
} else {
115115
// A custom message was received but no handler is configured. This likely means the contract emits custom
116116
// messages but forgot to register a handler via `AztecConfig::custom_message_handler`.
117-
debug_log_format(
117+
warn_log_format(
118118
"Received custom message with type id {0} but no handler is configured, ignoring. See https://docs.aztec.network/errors/2",
119119
[msg_type_id as Field],
120120
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "invalid_event"
3+
authors = [""]
4+
compiler_version = ">=0.25.0"
5+
type = "contract"
6+
7+
[dependencies]
8+
aztec = { path = "../../../aztec-nr/aztec" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
InvalidEvent has a serialized length of 11 fields, which exceeds the maximum allowed length of 10 fields. See https://docs.aztec.network/errors/5
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use aztec::{
2+
macros::events::event,
3+
messages::logs::event::MAX_EVENT_SERIALIZED_LEN,
4+
protocol::{traits::Serialize, utils::writer::Writer},
5+
};
6+
7+
#[event]
8+
pub struct InvalidEvent {}
9+
10+
impl Serialize for InvalidEvent {
11+
let N: u32 = MAX_EVENT_SERIALIZED_LEN + 1;
12+
13+
fn serialize(self) -> [Field; Self::N] {
14+
std::mem::zeroed()
15+
}
16+
17+
fn stream_serialize<let K: u32>(self, _writer: &mut Writer<K>) {}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use aztec::macros::aztec;
2+
3+
mod invalid_event;
4+
5+
#[aztec]
6+
pub contract InvalidEventContract {
7+
use crate::invalid_event::InvalidEvent;
8+
use aztec::{event::event_interface::EventInterface, macros::functions::external};
9+
10+
// We have here this function in order for the static_assert in `get_event_type_id` to get triggered.
11+
#[external("private")]
12+
fn trigger_event_check() {
13+
let _ = InvalidEvent::get_event_type_id();
14+
}
15+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
InvalidNote has a packed length of 9 fields, which exceeds the maximum allowed length of 8 fields
1+
InvalidNote has a packed length of 9 fields, which exceeds the maximum allowed length of 8 fields. See https://docs.aztec.network/errors/4

0 commit comments

Comments
 (0)