feat(aztec-nr)!: embed BoundedVec max length in validation requests#23622
Conversation
| } | ||
|
|
||
| impl EventValidationRequest { | ||
| pub(crate) fn new( |
There was a problem hiding this comment.
Added a new constructor, because it didn't make much sense to expose max_event_serialized_len
| } | ||
|
|
||
| impl NoteValidationRequest { | ||
| pub fn new( |
There was a problem hiding this comment.
Added a new constructor, because it didn't make much sense to expose max_note_packed_len
| '0x0000000000000000000000000000000000000000000000000000000000000002', // storage slot | ||
| '0x000000000000000000000000000000000000000000000000000000000000002a', // randomness | ||
| '0x0000000000000000000000000000000000000000000000000000000000000003', // note nonce | ||
| '0x0000000000000000000000000000000000000000000000000000000000000008', // max_note_packed_len |
There was a problem hiding this comment.
BoundedVec serialization is already storage: [T; MaxLen] followed by len (looking at noir-projects/noir-protocol-circuits/crates/serde/src/type_impls.nr). Noir deserialization knows MaxLen from the type parameter and uses that layout to locate the trailing len, so the serialized value does not include the capacity (which is type information).
TS is working over raw fields and does not have the Noir type parameter MaxLen at runtime, but we should be able to infer it from the fields.length itself because the struct contains a single BoundedVec and it has known fixed fields before and after it.
We already have a shared type schema in the ABI. Longer term, this parser should use ABI type metadata for the struct layout when converting from fields.
For now, I do think we could get rid of this extra payload field. But ultimately, we should utilize the ABI here long-term.
There was a problem hiding this comment.
We discussed it offline, we will go with the approach in this PR for now
Problem
NoteValidationRequestandEventValidationRequestcontain aBoundedVecwhosemaxLenis needed for deserialization, but it was passed as a separate oracle parameter (maxNotePackedLen/maxEventSerializedLen). This meant that we can't build a self-containedTypeMappingfor it, and we wouldn't be able to build auto generated mappings in the futureFix
Each struct now includes its own max length field (
max_note_packed_len/max_event_serialized_len) that is populated automatically via anewconstructor from the compile-time constant. The TypeScriptfromFieldsmethods read the length from the field stream instead of taking it as a parameter, making them self-contained.