Skip to content

fix: handle bad note lengths on compute_note_hash_and_nullifier#21271

Merged
nchamo merged 10 commits intomerge-train/fairiesfrom
fix/handle-bad-note-lengths-compute-note-hash-and-nullifier
Mar 11, 2026
Merged

fix: handle bad note lengths on compute_note_hash_and_nullifier#21271
nchamo merged 10 commits intomerge-train/fairiesfrom
fix/handle-bad-note-lengths-compute-note-hash-and-nullifier

Conversation

@nchamo
Copy link
Contributor

@nchamo nchamo commented Mar 9, 2026

Summary

We are now being safe on _compute_note_hash_and_nullifier by returning Option::none() instead of panicking when the length doesn't match the expected value

Fixes F-362

@nchamo nchamo requested a review from nventuro as a code owner March 9, 2026 19:57
@nchamo nchamo self-assigned this Mar 9, 2026
/// let note = MyNoteType::unpack(aztec::utils::array::subarray(packed_note.storage(), 0));
/// let note_hash = note.compute_note_hash(owner, storage_slot, randomness);
/// let note_hash_for_nullification = aztec::note::utils::compute_note_hash_for_nullification(
/// HintedNote {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the comment since now storage_slot goes inside HintedNote

@@ -298,7 +314,7 @@ comptime fn generate_contract_library_method_compute_note_hash_and_nullifier() -
///
/// This function is automatically injected by the `#[aztec]` macro.
#[contract_library_method]
unconstrained fn _compute_note_hash_and_nullifier(
pub(crate) unconstrained fn _compute_note_hash_and_nullifier(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made pub(crate) so we could test it

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the tests are already in a contract crate this can be avoided by just having a simple wrapper function in the test contract that is exposed and just calls this.

Would say that is preferrable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, that would be much better 🫡

@nchamo nchamo requested a review from benesjan March 9, 2026 20:48
Copy link
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.

@nchamo are you aware that we would still error out during actually note processing in case of a mismatch here?

Given that I expect the change there to not be big think it makes sense to tackle that as part of this PR as well even though the original issue does not explicitly mention it.

@@ -298,7 +314,7 @@ comptime fn generate_contract_library_method_compute_note_hash_and_nullifier() -
///
/// This function is automatically injected by the `#[aztec]` macro.
#[contract_library_method]
unconstrained fn _compute_note_hash_and_nullifier(
pub(crate) unconstrained fn _compute_note_hash_and_nullifier(
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the tests are already in a contract crate this can be avoided by just having a simple wrapper function in the test contract that is exposed and just calls this.

Would say that is preferrable.

@@ -0,0 +1,48 @@
use crate::{Test, test_note::TestNote};
Copy link
Contributor

Choose a reason for hiding this comment

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

Test contract is an old pile of mess so ideally would not add to that and just create a new test contract for this.

@nchamo
Copy link
Contributor Author

nchamo commented Mar 10, 2026

@benesjan , I'm aware we still need to handle that scenario, but we already have F-344 for that. I just wanted to make each PR as small as possible, specially if we already had another task for it

@nchamo nchamo requested a review from benesjan March 10, 2026 16:03
Copy link
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


// TestNote::compute_nullifier_unconstrained returns a hardcoded Some(2) so we can verify the
// macro-generated function propagates the inner nullifier correctly.
assert_eq(note_hash_and_nullifier.inner_nullifier.unwrap(), 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though you have it explained here anyway think it would be better to define a TEST_NOTE_NULLIFIER in test_note.nr and use it here. Then you can easily navigate with LSP to where the value originates.

#[test]
unconstrained fn returns_none_for_bad_note_length() {
// TestNote has Packable N=1, but we provide 2 fields
let packed_note = BoundedVec::from_array([42, 99]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would also add a test case for empty BVec.

@nchamo nchamo enabled auto-merge (squash) March 11, 2026 13:19
@nchamo nchamo merged commit 20d6c29 into merge-train/fairies Mar 11, 2026
16 of 20 checks passed
@nchamo nchamo deleted the fix/handle-bad-note-lengths-compute-note-hash-and-nullifier branch March 11, 2026 13:35
@AztecBot
Copy link
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
…llifier (#21271)

Cherry-pick of 20d6c29 with conflicts preserved for review.
AztecBot pushed a commit that referenced this pull request Mar 11, 2026
…llifier (#21271)

Cherry-pick of 20d6c29 with conflicts preserved for review.
AztecBot pushed a commit that referenced this pull request Mar 11, 2026
AztecBot pushed a commit that referenced this pull request Mar 11, 2026
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
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