Skip to content

fix(stdlib): accept null return_type for void Noir functions#21647

Merged
Thunkar merged 1 commit intomerge-train/fairiesfrom
jan/fix-noir-void-return-type
Mar 17, 2026
Merged

fix(stdlib): accept null return_type for void Noir functions#21647
Thunkar merged 1 commit intomerge-train/fairiesfrom
jan/fix-noir-void-return-type

Conversation

@benesjan
Copy link
Contributor

@benesjan benesjan commented Mar 17, 2026

Fixing issue reproted by @just-mitch on slack.

AI Summary

Fixes a TypeScript compilation error when running aztec-builder codegen on contracts where every function is void (most notably, a blank #[aztec] contract Main {}).

The #[aztec] macro injects lifecycle functions like process_message and sync_state into every contract. These are void, so the Noir compiler outputs "return_type": null for them. Our NoirFunctionAbi type only accepted a non-null object for return_type, which caused a type error on the as NoirCompiledContract cast in the generated TS.

For contracts with at least one non-void function, TypeScript infers the JSON array element type as a union (null | { abi_type, visibility }), which has enough overlap with the expected type for the as cast to succeed. But when every function is void, the inferred type is just null — zero overlap — so the cast fails.

The runtime code in contract_artifact.ts already handled the null case correctly. Only the type definition was out of sync with the compiler's actual output.

Repro: https://github.com/just-mitch/mytoken

Test plan

  • Verified yarn build passes with no new type errors
  • Cloned the repro, confirmed the TS error, patched node_modules/@aztec/stdlib with the fix, confirmed clean compilation

🤖 Generated with Claude Code

@benesjan benesjan marked this pull request as draft March 17, 2026 07:03
@benesjan benesjan changed the base branch from next to merge-train/fairies March 17, 2026 07:08
@benesjan benesjan changed the base branch from merge-train/fairies to graphite-base/21647 March 17, 2026 07:10
@benesjan benesjan force-pushed the graphite-base/21647 branch from cc08554 to 478515c Compare March 17, 2026 07:10
@benesjan benesjan changed the base branch from graphite-base/21647 to next March 17, 2026 07:10
Copy link
Contributor Author

benesjan commented Mar 17, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@benesjan benesjan changed the base branch from next to graphite-base/21647 March 17, 2026 07:11
@benesjan benesjan force-pushed the graphite-base/21647 branch from cc08554 to 478515c Compare March 17, 2026 07:11
@benesjan benesjan changed the base branch from graphite-base/21647 to merge-train/fairies March 17, 2026 07:11
…tions

The Noir compiler outputs `"return_type": null` for void functions, but our
NoirFunctionAbi type only accepted a non-null object. This caused a TypeScript
error when using `aztec-builder codegen` on contracts whose only functions are
the macro-injected void lifecycle functions (e.g. a blank `#[aztec] contract`).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@benesjan benesjan force-pushed the jan/fix-noir-void-return-type branch from a8098fc to 477572e Compare March 17, 2026 07:13
@benesjan benesjan marked this pull request as ready for review March 17, 2026 07:16
@benesjan benesjan requested a review from Thunkar March 17, 2026 09:40
@Thunkar Thunkar enabled auto-merge (squash) March 17, 2026 15:51
@Thunkar Thunkar disabled auto-merge March 17, 2026 16:17
@Thunkar Thunkar merged commit 325a7a7 into merge-train/fairies Mar 17, 2026
19 checks passed
@Thunkar Thunkar deleted the jan/fix-noir-void-return-type branch March 17, 2026 16:17
github-merge-queue bot pushed a commit that referenced this pull request Mar 18, 2026
BEGIN_COMMIT_OVERRIDE
fix(stdlib): accept null return_type for void Noir functions (#21647)
feat!: make AES128 decrypt oracle return Option (#21696)
fix(aztec-nr): fix OOB index with nonzero offset (#21613)
feat!: include init_hash in private initialization nullifier to prevent
privacy leak (#21427)
END_COMMIT_OVERRIDE
AztecBot pushed a commit that referenced this pull request Mar 18, 2026
Fixing issue reproted by @just-mitch on
[slack](https://aztecprotocol.slack.com/archives/C04PUD9AA4W/p1773715408859609).

## AI Summary

Fixes a TypeScript compilation error when running `aztec-builder
codegen` on contracts where every function is void (most notably, a
blank `#[aztec] contract Main {}`).

The `#[aztec]` macro injects lifecycle functions like `process_message`
and `sync_state` into every contract. These are void, so the Noir
compiler outputs `"return_type": null` for them. Our `NoirFunctionAbi`
type only accepted a non-null object for `return_type`, which caused a
type error on the `as NoirCompiledContract` cast in the generated TS.

For contracts with at least one non-void function, TypeScript infers the
JSON array element type as a union (`null | { abi_type, visibility }`),
which has enough overlap with the expected type for the `as` cast to
succeed. But when *every* function is void, the inferred type is just
`null` — zero overlap — so the cast fails.

The runtime code in `contract_artifact.ts` already handled the `null`
case correctly. Only the type definition was out of sync with the
compiler's actual output.

Repro: https://github.com/just-mitch/mytoken

## Test plan

- Verified `yarn build` passes with no new type errors
- Cloned the repro, confirmed the TS error, patched
`node_modules/@aztec/stdlib` with the fix, confirmed clean compilation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AztecBot
Copy link
Collaborator

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

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