Skip to content

refactor(stdlib)!: rename unsafe AztecAddress constructors to *Unsafe - #24230

Merged
benesjan merged 3 commits into
merge-train/fairies-v5from
nchamo/rename-unsafe-aztec-address
Jun 23, 2026
Merged

benesjan merged 3 commits into
merge-train/fairies-v5from
nchamo/rename-unsafe-aztec-address

Conversation

@nchamo

@nchamo nchamo commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Why we are doing this

The synchronous AztecAddress constructors 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 used fromBigInt in 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 Unsafe suffix and document them:

  • fromFieldfromFieldUnsafe
  • fromBigIntfromBigIntUnsafe
  • fromNumberfromNumberUnsafe
  • fromStringfromStringUnsafe

Each now carries JSDoc that it does not check Grumpkin-curve validity, pointing to isValid() to validate and random() for valid test addresses. The serialization constructors fromBuffer/fromFields keep 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

- const address = AztecAddress.fromBigInt(123n);
+ const address = AztecAddress.fromBigIntUnsafe(123n);

Use AztecAddress.random() for valid test addresses and address.isValid() to check an untrusted value. A migration_notes.md entry documents this.

Fixes F-754

@nchamo nchamo added the ci-draft Run CI on draft PRs. label Jun 22, 2026
@nchamo nchamo self-assigned this Jun 22, 2026
@nchamo nchamo added the ci-full Run all master checks. label Jun 22, 2026
@nchamo nchamo removed the ci-full Run all master checks. label Jun 22, 2026
@nchamo
nchamo marked this pull request as ready for review June 22, 2026 23:19
@nchamo
nchamo requested review from a team, IlyasRidhuan, MirandaWood and jeanmon as code owners June 22, 2026 23:19
@nchamo
nchamo requested a review from benesjan June 22, 2026 23:20

## TBD

### [Aztec.js] Unchecked `AztecAddress` constructors renamed with an `Unsafe` suffix

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.

Relevant changes here

}

static fromField(fr: Fr) {
/**

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.

Relevant changes here

@benesjan benesjan left a comment

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.

Perfect. Thanks for tackling this Chamo!

Will just merge it as it's conflict prone

@benesjan
benesjan merged commit 1657cd6 into merge-train/fairies-v5 Jun 23, 2026
18 checks passed
@benesjan
benesjan deleted the nchamo/rename-unsafe-aztec-address branch June 23, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants