Skip to content

fix(aztec-nr): range-check auth witness fields before byte cast#22624

Merged
nchamo merged 4 commits intomerge-train/fairiesfrom
fix/auth-witness-byte-range-check
Apr 17, 2026
Merged

fix(aztec-nr): range-check auth witness fields before byte cast#22624
nchamo merged 4 commits intomerge-train/fairiesfrom
fix/auth-witness-byte-range-check

Conversation

@nchamo
Copy link
Copy Markdown
Contributor

@nchamo nchamo commented Apr 16, 2026

Problem

Account contracts cast auth witness fields from Field to u8 without range-checking. Since Field values can exceed 255, a value like b + 256 truncates to the same byte as b, producing a different witness encoding that passes signature verification identically to the original.

Fix

Adds auth_witness_to_byte_signature in aztec-nr/authwit, which asserts each field is in [0, 256) before casting. All four account contracts (ecdsa k1, ecdsa r1, schnorr, schnorr hardcoded) now use this function instead of inline cast loops. Includes a Noir unit test for the range check and an e2e test that verifies aliased witness fields are rejected.

Fixes https://github.com/AztecProtocol/aztec-claude/issues/461

@nchamo nchamo requested a review from nventuro as a code owner April 16, 2026 20:38
@nchamo nchamo self-assigned this Apr 16, 2026
@nchamo nchamo requested a review from benesjan April 16, 2026 22:21
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.

Henlo 👋

Currently auth_witness_to_byte_signature is executed as constrained code but there is no reason for this to be constrained since witness is only a magical value that needs to be provided from wherever that makes the signature verification pass - we are wasting constraints there on the assertions.

I think it makes sense to return the casted and range checked values directly from the get_auth_witness oracle wrapper function and nuke the signature_witness file.

Actually I would leave get_auth_witness as is as I think we might eventually genuinely have field based witnesses so would create a wrapper function in that file that would do what auth_witness_to_byte_signature does. get_auth_witness_bytes or smt.

@nchamo nchamo requested a review from benesjan April 17, 2026 02:55
Comment on lines +87 to +88
// Safety: the witness is only a magical value that makes signature verification pass.
// A fabricated or wrong-hash witness is rejected by the signature scheme below.
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.

Suggested change
// Safety: the witness is only a magical value that makes signature verification pass.
// A fabricated or wrong-hash witness is rejected by the signature scheme below.
// Safety: The witness is only used as a "magical value" that makes the signature verification below pass.
// Hence it's safe.

Did you do this change from the original intentionally? I like the original more

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.

The original felt unclear to me, but I can go back

@nchamo nchamo requested a review from benesjan April 17, 2026 10:50
Comment thread noir-projects/aztec-nr/aztec/src/oracle/auth_witness.nr
Comment thread yarn-project/end-to-end/src/e2e_account_contracts.test.ts Outdated
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.

Looks good 👍

@nchamo nchamo merged commit d94cd77 into merge-train/fairies Apr 17, 2026
12 checks passed
@nchamo nchamo deleted the fix/auth-witness-byte-range-check branch April 17, 2026 12:00
@AztecBot
Copy link
Copy Markdown
Collaborator

✅ Successfully backported to backport-to-v4-next-staging #22580.

github-merge-queue Bot pushed a commit that referenced this pull request Apr 17, 2026
BEGIN_COMMIT_OVERRIDE
fix(pxe): stop block synchronizer on PXE shutdown (#22604)
fix(aztec): respect TEST_ACCOUNTS env var in local network mode (#22600)
fix: check all aztec-nr dependency tags, not just aztec (#22483)
fix: reuse anchor block in kernel oracle (#22631)
refactor: unify contract compilation pipeline via bb aztec_process
(#22590)
fix(pxe): queue registerSender wipe to avoid racing with in-flight jobs
(#22623)
fix(pxe): bounds-check PropertySelector in pick_notes (#22614)
fix(pxe): guard private event store rollback against in-flight jobs
(#22615)
refactor(pxe): rename sideEffectCounter to initialSideEffectCounter
(#22599)
fix(pxe): correct stale authwitness comment and inverted tagging error
(#22537)
fix(aztec-nr): range-check auth witness fields before byte cast (#22624)
fix(pxe): serialize block stream event handling to prevent race
conditions (#22635)
fix(pxe): throw error on origin/contract address mismatch in simulation
(#22637)
END_COMMIT_OVERRIDE
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.

3 participants