Skip to content

chore(aztec-nr): Public self constructor function to prevent static byte code size blow up#23062

Merged
vezenovm merged 12 commits into
merge-train/fairiesfrom
mv/f-637-public-self-creator
May 11, 2026
Merged

chore(aztec-nr): Public self constructor function to prevent static byte code size blow up#23062
vezenovm merged 12 commits into
merge-train/fairiesfrom
mv/f-637-public-self-creator

Conversation

@vezenovm
Copy link
Copy Markdown
Contributor

@vezenovm vezenovm commented May 7, 2026

Resolves F-637

Stacks on #23061

  • New generate_public_self_creator emits a per-contract __aztec_nr_internals__create_public_self<let N: u32>() helper
  • generate_public_external now emits a single call to it instead of inlining the preamble. This can be seen in the snapshots.
  • Helper is emitted from process_functions and gated on public_functions.len() > 0

Improvements tested locally:

I need to test further. Either way this is cleaner macro code.

@vezenovm vezenovm requested a review from nventuro as a code owner May 7, 2026 19:47
@vezenovm vezenovm changed the title chore(aztec-nr): Public self creator function to prevent static byte code size blow up chore(aztec-nr): Public self constructor function to prevent static byte code size blow up May 7, 2026
@vezenovm vezenovm requested review from benesjan and nchamo May 7, 2026 20:13
@nchamo nchamo added the ci-full Run all master checks. label May 8, 2026
@nchamo
Copy link
Copy Markdown
Contributor

nchamo commented May 8, 2026

I added the ci-full label so that we can be 100% sure we don't break something

vezenovm added a commit that referenced this pull request May 8, 2026
…rgo expand (#23061)

Resolves
[F-607](https://linear.app/aztec-labs/issue/F-607/adopt-cargo-insta-for-noir-contract-snapshot-testing)

Don't be scared by the diff size, the majority of the diff is new
snapshots.

- Deleted `noir-projects/noir-contracts-comp-failures/` crate. We now
have `noir-projects/contract-snapshots/`
- `nargo expand` tests cover Token, AMM, StorageProofTest, AvmTest,
AvmGadgetsTest to match the CI benchmarks
- `compile_failure` snapshots are now full stderr (not just `error: `
headlines)

Asserting the full stderr and `expand` output provide us a strong test
invariant on the current compiler behavior. Some of the expanded
snapshots are quite large, and that is why I ultimately chose to only
have snapshots for the benchmark contracts. For compilation failures, I
felt it would be better to have the full snapshot in all cases. We then
assert against the actual compiler behavior rather than some stripped
version of the stderr.

A great example of how these snapshots are useful can be seen in the
child PR #23062.
Base automatically changed from mv/cargo-insta-snaps to merge-train/fairies May 8, 2026 14:56
…37-public-self-creator

# Conflicts:
#	noir-projects/contract-snapshots/.gitignore
#	noir-projects/contract-snapshots/tests/snapshots/compile_failure/authorize_once_from_wrong_type/snapshots__stderr.snap
#	noir-projects/contract-snapshots/tests/snapshots/compile_failure/authorize_once_missing_from_param/snapshots__stderr.snap
#	noir-projects/contract-snapshots/tests/snapshots/compile_failure/authorize_once_missing_nonce_param/snapshots__stderr.snap
#	noir-projects/contract-snapshots/tests/snapshots/compile_failure/authorize_once_nonce_wrong_type/snapshots__stderr.snap
#	noir-projects/contract-snapshots/tests/snapshots/expand/amm_contract/snapshots__expanded.snap
#	noir-projects/contract-snapshots/tests/snapshots/expand/avm_gadgets_test_contract/snapshots__expanded.snap
#	noir-projects/contract-snapshots/tests/snapshots/expand/avm_test_contract/snapshots__expanded.snap
#	noir-projects/contract-snapshots/tests/snapshots/expand/storage_proof_test_contract/snapshots__expanded.snap
#	noir-projects/contract-snapshots/tests/snapshots/expand/token_contract/snapshots__expanded.snap
Copy link
Copy Markdown
Contributor

@nchamo nchamo left a comment

Choose a reason for hiding this comment

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

Great work!

Small suggestions about the docs/comments

@vezenovm vezenovm requested a review from nchamo May 11, 2026 15:58
Copy link
Copy Markdown
Contributor

@nchamo nchamo left a comment

Choose a reason for hiding this comment

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

Great work!

@vezenovm vezenovm enabled auto-merge (squash) May 11, 2026 16:22
@vezenovm vezenovm merged commit b6adc6b into merge-train/fairies May 11, 2026
14 checks passed
@vezenovm vezenovm deleted the mv/f-637-public-self-creator branch May 11, 2026 16:32
@AztecBot
Copy link
Copy Markdown
Collaborator

❌ Failed to cherry-pick to v4-next due to conflicts. (🤖) View backport run.

vezenovm added a commit that referenced this pull request May 11, 2026
…yte code size blow up (#23062)

Resolves
[F-637](https://linear.app/aztec-labs/issue/F-637/aztec-nr-macros-contain-self-construction-to-a-function-to-prevent)

Stacks on #23061

- New `generate_public_self_creator` emits a per-contract
`__aztec_nr_internals__create_public_self<let N: u32>()` helper
- `generate_public_external` now emits a single call to it instead of
inlining the preamble. This can be seen in the snapshots.
- Helper is emitted from `process_functions` and gated on
`public_functions.len() > 0`

~~Improvements tested locally:~~

I need to test further. Either way this is cleaner macro code.
vezenovm added a commit that referenced this pull request May 11, 2026
…23156)

## Summary
Backport of #23062
to `v4-next`.

Cherry-pick of merge commit `b6adc6b20fa79f4b55a73517a7ba8e2444716387`.

### Conflict resolved
-
`noir-projects/contract-snapshots/tests/snapshots/expand/avm_gadgets_test_contract/snapshots__expanded.snap`
— the upstream PR's snapshot included a
`__aztec_nr_internals__keccak_hash_300` function (added in a separate
upstream commit), but the v4-next source contract
(`avm_gadgets_test_contract/src/main.nr`) does not contain a
`keccak_hash_300` test function. The conflict was resolved by dropping
the `keccak_hash_300` block from the snapshot so it matches the v4-next
source contract. All other public-function helpers in the snapshot were
updated to call the new
`__aztec_nr_internals__create_public_self::<N>()` helper.

### What this PR does
- Adds `generate_public_self_creator` which emits a per-contract
`__aztec_nr_internals__create_public_self<let N: u32>()` helper.
- `generate_public_external` now emits a single call to the helper
instead of inlining the preamble, shrinking generated bytecode.
- Helper emission is gated on `public_functions.len() > 0` in
`process_functions`.

### Files changed
-
`noir-projects/aztec-nr/aztec/src/macros/internals_functions_generation/external/public.nr`
-
`noir-projects/aztec-nr/aztec/src/macros/internals_functions_generation/mod.nr`
- 4 `compile_failure` `snapshots__stderr.snap` files
- 6 `expand` `snapshots__expanded.snap` files

12 files changed, 302 insertions(+), 1817 deletions(-).

🤖 Generated automatically by the backport workflow.

ClaudeBox log: https://claudebox.work/s/b8ac01ace45bf87e?run=1
benesjan added a commit that referenced this pull request May 12, 2026
BEGIN_COMMIT_OVERRIDE
fix(sequencer): bounded sweep instead of event scan for governance
proposal check (#22989)
fix(sequencer): bounded sweep instead of event scan for governance
proposal check (#22989) (#23001)
chore: route backport CI failure notifications to #backports channel
(#21779)
fix: (A-589) epochs l1 reorgs test (#20999)
chore: Accumulated backports to v4 (#23065)
fix(bb-prover): use temp directory for avm_verify (#23138)
chore: notify on v4-next sync (#23139)
refactor(pxe): use findLeavesIndexes for read request verification
(#23123)
refactor(pxe): skip storage reads for never-updated contracts (#23131)
fix(pxe): skip registerContractFunctionSignatures when no public fns
(#23134)
chore: Update Noir to nightly-2026-04-15 (#22572)
chore: Update Noir to nightly-2026-04-16 (#22594)
chore: Update Noir to nightly-2026-04-17 (#22633)
chore: Update Noir to nightly-2026-04-23 (#22653)
chore: Update Noir to nightly-2026-04-28 (#22755)
chore: Update Noir to nightly-2026-05-01 (#22836)
chore: Update Noir to nightly-2026-05-05 (#22911)
chore: Update Noir to nightly-2026-05-11 (#23023)
chore: backport noir sync PRs to backport-to-v4-next-staging (#23148)
refactor(pxe): prefetch updated class id hints per unique contract
(#23130)
chore(aztec-nr): Public self constructor function to prevent static byte
code size blow up (#23062)
chore: merge v4 into backport-to-v4-next-staging (#23140)
chore(aztec-nr): Public self constructor function (backport #23062)
(#23156)
refactor(pxe): avoid expensive toTx() call when computing tx hash
(#23136)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v4-next ci-full Run all master checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants