Skip to content

fix(aztec-nr): return Option from decode functions and fix event commitment capacity#21264

Merged
nchamo merged 3 commits intomerge-train/fairiesfrom
fix/decode-message-option-return
Mar 11, 2026
Merged

fix(aztec-nr): return Option from decode functions and fix event commitment capacity#21264
nchamo merged 3 commits intomerge-train/fairiesfrom
fix/decode-message-option-return

Conversation

@nchamo
Copy link
Copy Markdown
Contributor

@nchamo nchamo commented Mar 9, 2026

Summary

  • Fix off-by-one capacity bug in compute_private_serialized_event_commitment (capacity 1 + MAX2 + MAX) that would panic on max-size events
  • Change all decode functions to return Option instead of panicking on malformed input
  • Add warning logs with tx_hash for all decode failure paths in message discovery

Closes F-357

@nchamo nchamo requested a review from nventuro as a code owner March 9, 2026 16:24
@nchamo nchamo self-assigned this Mar 9, 2026
) -> Field {
let mut commitment_preimage =
BoundedVec::<_, 1 + MAX_EVENT_SERIALIZED_LEN>::from_array([randomness, event_type_id]);
BoundedVec::<_, 2 + MAX_EVENT_SERIALIZED_LEN>::from_array([randomness, event_type_id]);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually a bug. We are adding two fields, so it should have been + 2 all along

The new test below would fail before this fix


(note_type_id, owner, storage_slot, randomness, packed_note)
) -> Option<(Field, AztecAddress, Field, Field, BoundedVec<Field, MAX_NOTE_PACKED_LEN>)> {
if msg_content.len() < PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to panic when msg_content.len() == PRIVATE_NOTE_MSG_PLAINTEXT_RESERVED_FIELDS_LEN. Now we allow it per @benesjan 's suggestion

We might want to have >= for notes and events as well as we might want to emit no-content note to represent e.g. an "is_registered" flag.

Copy link
Copy Markdown
Contributor

@benesjan benesjan Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add an empty note and empty event tests to verify this works.

That makes sense to do in a followup PR though. Any reason why this change needed to be here?

Would wait for Nico's opinion on if we want to support empty notes and events before investing more time in this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tests called decode_succeeds_with_only_reserved_fields (would be the same as empty) for this scenario. Did you mean e2e tests?

Anyways, I reverted the behavior back to how it worked, we can revisit if we want to change it later

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we already had this tested then there was no reason to revert this. I just thought the tests would increase the scope too much.


(event_type_id, randomness, serialized_event)
) -> Option<(EventSelector, Field, BoundedVec<Field, MAX_EVENT_SERIALIZED_LEN>)> {
if msg_content.len() < PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to panic when msg_content.len() == PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN. Now we allow it per @benesjan 's suggestion

We might want to have >= for notes and events as well as we might want to emit no-content note to represent e.g. an "is_registered" flag.

Copy link
Copy Markdown
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

# Conflicts:
#	noir-projects/aztec-nr/aztec/src/messages/discovery/partial_notes.nr
#	noir-projects/aztec-nr/aztec/src/messages/logs/partial_note.nr
@nchamo nchamo enabled auto-merge (squash) March 11, 2026 13:04
@nchamo nchamo merged commit 7a485d1 into merge-train/fairies Mar 11, 2026
10 checks passed
@nchamo nchamo deleted the fix/decode-message-option-return branch March 11, 2026 13:22
@AztecBot
Copy link
Copy Markdown
Collaborator

❌ Failed to cherry-pick to v4-next due to conflicts. (🤖) View backport run.

AztecBot pushed a commit that referenced this pull request Mar 11, 2026
…ix event commitment capacity (#21264)

Cherry-pick of 7a485d1 from next. Contains conflict markers.
AztecBot added a commit that referenced this pull request Mar 11, 2026
Adapted PR #21264 changes to v4-next:
- v4-next uses protocol logging (debug_log/warn_log_format) instead of aztecnr macros
- v4-next partial note decode has storage_slot (4 reserved fields vs 3)
- v4-next process_message.nr has no custom message handling
AztecBot pushed a commit that referenced this pull request Mar 11, 2026
…ix event commitment capacity (#21264)

Cherry-pick of 7a485d1 with conflicts preserved for review.
AztecBot added a commit that referenced this pull request Mar 11, 2026
Adapted PR #21264 changes for v4-next:
- Keep storage_slot in partial note decode (4 reserved fields vs 3 on next)
- Use debug_log_format instead of aztecnr_warn_log_format (not available on v4-next)
- Keep v4-next's simpler process_message without custom message handling
github-merge-queue Bot pushed a commit that referenced this pull request Mar 13, 2026
BEGIN_COMMIT_OVERRIDE
fix: skip oracle version check for pinned protocol contracts (#21349)
fix: not reusing tags of partially reverted txs (#20817)
feat: move storage_slot from partial commitment to completion hash
(#21351)
feat: offchain reception (#20893)
fix: handle workspace members in needsRecompile crate collection
(#21284)
fix(aztec-nr): return Option from decode functions and fix event
commitment capacity (#21264)
fix: handle bad note lengths on compute_note_hash_and_nullifier (#21271)
fix: address review feedback from PRs #21284 and #21237 (#21369)
fix: claim contract & improve nullif docs (#21234)
feat!: auto-enqueue public init nullifier for contracts with public
functions (#20775)
fix: search for all note nonces instead of just the one for the note
index (#21438)
fix: set anvilSlotsInAnEpoch in e2e_offchain_payment to prevent
finalization race (#21452)
fix: complete legacy oracle mappings for all pinned contracts (#21404)
fix: correct inverted constrained encryption check in message delivery
(#21399)
feat!: improve L2ToL1MessageWitness API (#21231)
END_COMMIT_OVERRIDE
AztecBot pushed a commit that referenced this pull request Mar 14, 2026
…ix event commitment capacity (#21264)

Cherry-pick of 7a485d1 with conflicts preserved for review.
AztecBot added a commit that referenced this pull request Mar 14, 2026
Adapted PR #21264 changes for backport-to-v4-staging:
- Keep storage_slot in partial note decode (4 reserved fields vs 3 on next)
- Use debug_log_format instead of aztecnr_warn_log_format (not available on v4)
- Keep v4's simpler process_message without custom message handling
- Fix private_events.nr auto-merged import of unavailable aztecnr_warn_log_format
nchamo pushed a commit that referenced this pull request Mar 14, 2026
alexghr pushed a commit that referenced this pull request Mar 17, 2026
BEGIN_COMMIT_OVERRIDE
fix(aztec-nr): return Option from decode functions and fix event
commitment capacity (backport #21264) (#21360)
fix: backport #21271 — handle bad note lengths on
compute_note_hash_and_nullifier (#21364)
fix: not reusing tags of partially reverted txs (#20817)
chore: revert accidental backport of #20817 (#21583)
feat: Implement commit all and revert all for world state checkpoints
(#21532)
cherry-pick: fix: dependabot alerts (#21531)
fix: dependabot alerts (backport #21531 to v4) (#21592)
fix: backport #21443 — Don't update state if we failed to execute
sufficient transactions (v4) (#21610)
chore: Fix msgpack serialisation (#21612)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
Co-authored-by: PhilWindle <60546371+PhilWindle@users.noreply.github.com>
Co-authored-by: Phil Windle <philip.windle@gmail.com>
Co-authored-by: Santiago Palladino <santiago@aztecprotocol.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: ludamad <adam.domurad@gmail.com>
alexghr added a commit that referenced this pull request Mar 17, 2026
BEGIN_COMMIT_OVERRIDE
fix(aztec-nr): return Option from decode functions and fix event
commitment capacity (backport #21264) (#21360)
fix: backport #21271 — handle bad note lengths on
compute_note_hash_and_nullifier (#21364)
fix: not reusing tags of partially reverted txs (#20817)
chore: revert accidental backport of #20817 (#21583)
feat: Implement commit all and revert all for world state checkpoints
(#21532)
cherry-pick: fix: dependabot alerts (#21531)
fix: dependabot alerts (backport #21531 to v4) (#21592)
fix: backport #21443 — Don't update state if we failed to execute
sufficient transactions (v4) (#21610)
chore: Fix msgpack serialisation (#21612)
fix(p2p): fall back to maxTxsPerCheckpoint for per-block tx validation
(#21605)
chore: merge v4 into backport-to-v4-staging (#21618)
fix(revert): avm sim uses event loop again (#21138) (#21630)
fix(e2e): remove historic/finalized block checks from epochs_multiple
test (#21642)
fix: clamp finalized block to oldest available in world-state (#21643)
fix: skip handleChainFinalized when block is behind oldest available
(#21656)
chore: demote finalized block skip log to trace (#21661)
fix: off-by-1 in getBlockHashMembershipWitness archive snapshot
(backport #21648) (#21663)
fix: capture txs not available error reason in proposal handler (#21670)
chore: add L1 inclusion time to stg public (#21665)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
Co-authored-by: PhilWindle <60546371+PhilWindle@users.noreply.github.com>
Co-authored-by: Phil Windle <philip.windle@gmail.com>
Co-authored-by: Santiago Palladino <santiago@aztecprotocol.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: ludamad <adam.domurad@gmail.com>
Co-authored-by: Alex Gherghisan <alexghr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants