refactor(stdlib)!: rename unsafe AztecAddress constructors to *Unsafe - #24230
Merged
benesjan merged 3 commits intoJun 23, 2026
Merged
Conversation
…amo/rename-unsafe-aztec-address
nchamo
marked this pull request as ready for review
June 22, 2026 23:19
nchamo
requested review from
a team,
IlyasRidhuan,
MirandaWood and
jeanmon
as code owners
June 22, 2026 23:19
nchamo
commented
Jun 22, 2026
|
|
||
| ## TBD | ||
|
|
||
| ### [Aztec.js] Unchecked `AztecAddress` constructors renamed with an `Unsafe` suffix |
Contributor
Author
There was a problem hiding this comment.
Relevant changes here
nchamo
commented
Jun 22, 2026
| } | ||
|
|
||
| static fromField(fr: Fr) { | ||
| /** |
Contributor
Author
There was a problem hiding this comment.
Relevant changes here
benesjan
approved these changes
Jun 23, 2026
benesjan
left a comment
Contributor
There was a problem hiding this comment.
Perfect. Thanks for tackling this Chamo!
Will just merge it as it's conflict prone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why we are doing this
The synchronous
AztecAddressconstructors that build an address from a raw value (fromField,fromBigInt,fromNumber,fromString) do not check that the value is a valid address: the x-coordinate of a point on the Grumpkin curve. An invalid value is accepted silently and only fails much later, when a transaction is sent. This recently sent an AI agent down a long debugging detour after it usedfromBigIntin a test.Validating requires curve math that is only available asynchronously today, so making the constructors validate would force them to become async. Instead we make the missing validation explicit at the call site.
Our fix
Rename the four unchecked constructors with an
Unsafesuffix and document them:fromField→fromFieldUnsafefromBigInt→fromBigIntUnsafefromNumber→fromNumberUnsafefromString→fromStringUnsafeEach now carries JSDoc that it does not check Grumpkin-curve validity, pointing to
isValid()to validate andrandom()for valid test addresses. The serialization constructorsfromBuffer/fromFieldskeep their names: they are the structural (de)serialization interface (BufferReader/FieldReader.readObject, the Zod schema) and read addresses from already-validated protocol data, but their docs now note they perform no validation either. No constructor was made async and no curve check was reimplemented in TypeScript.Migration
Use
AztecAddress.random()for valid test addresses andaddress.isValid()to check an untrusted value. Amigration_notes.mdentry documents this.Fixes F-754