chore: add a regeneration flow for the genesis constants - #25503
Merged
spalladino merged 1 commit intoSep 18, 2026
Merged
spalladino merged 1 commit into
spalladino merged 1 commit into
Conversation
spalladino
marked this pull request as ready for review
September 17, 2026 17:44
spalladino
requested review from
IlyasRidhuan,
LeilaWang,
iAmMichaelConnor,
iakovenkos,
ledwards2225 and
ludamad
as code owners
September 17, 2026 17:44
spalladino
added this pull request to stack #25505
September 17, 2026 17:47
Rotating a protocol contract class id moves the genesis roots, and until now the only way to find out was a late CI failure, with no documented way to fix it beyond re-deriving the numbers by hand. Reduce the pins before automating them. The genesis nullifier-tree root was repeated as a literal in the Noir block-header test, the C++ world-state test and the TypeScript l2_block test, and the six seeded nullifiers were duplicated between the generated protocol contract data and the C++ test. GENESIS_NULLIFIER_TREE_ROOT now lives in constants.nr, which the existing codegen projects into aztec_constants.hpp, ConstantsGen.sol and constants.gen.ts, and all three tests read it; the C++ seed vector moves into a generated header. That leaves two hand-pinned locations rather than five, and none inside the labs patch series, so regenerating no longer means editing a patch. `noir-projects/fnd/scripts/regenerate_genesis_constants.sh` is then the single source of truth: it measures the canonical genesis from a real ephemeral world state, rewrites the constants and the C++ seed vector, re-runs the generators, verifies they picked up the new values, and with --fixtures regenerates the six L1 checkpoint fixtures. --check reports staleness without writing. Bash orchestrates; a small node helper does the JSON validation and the constants.nr rewrite, since both need real parsing and must fail loudly rather than silently no-op. Unlike the Noir bump script it is fail-fast rather than best-effort: a missing dependency, a failed measurement or a replacement that did not match aborts, because a half-applied regeneration leaves constants that disagree with each other. It also rebuilds constants-codegen before the remake scripts, which otherwise reproduce the previous values from the inputs embedded at build time. Two things only an end-to-end run surfaced. The build-freshness preflight warns rather than aborts: the fnd precommit hook rewrites every protocol contract .nr through `nargo fmt` on any commit that stages one, so their mtimes move without their content changing and a hard check fires on a perfectly fresh tree. And the checkpoint fixture producer picks a wall-clock timestamp and a random coinbase and fee recipient per run, so --fixtures rewrites all six whether or not the genesis moved; only lastArchiveRoot is stable, which is what --check keys on. A precommit reminder fires when staged changes can rotate a class id. It is explicitly a reminder and not evidence of freshness: deciding whether an id actually moved means compiling the contracts, which is far too slow for a hook, so its path predicate is a cheap and incomplete proxy.
spalladino
force-pushed
the
spl/a-1264-genesis-constants-regen
branch
from
September 17, 2026 18:34
65ffb86 to
064e570
Compare
iAmMichaelConnor
approved these changes
Sep 18, 2026
charlielye
added a commit
that referenced
this pull request
Sep 18, 2026
Moves the world-state DB service (world_state engine, persistent content-addressed merkle storage, lmdb tree store, IPC server) out of barretenberg into native-packages/wsdb, compiling with zero barretenberg headers: bb is linked only as a prebuilt archive for the poseidon2 c_bind and for the new bb_wsref_* C ABI over the in-memory reference world state (world_state_reference), against which this package's conformance test drives its WorldState and asserts agreement on roots, sibling paths, low-leaf lookups, preimages and checkpointing. Constants stay in lockstep via a wsdb-local remake-constants hook on the protocol constants-codegen (generated header, no longer checked in). Rebased onto next after the @aztec-foundation scope rename (#25328). wsdb keeps the name next gave it; the new kvdb package follows the same scope rather than introducing an @aztec-scoped foundation package. The labs series is re-exported against the current pin: the wsdb/kvdb consumption patch is rewritten for the new scope, and the indexed/nullifier tree reference update is dropped because upstream removed that references frontmatter, leaving only its cspell additions. Rebased onto next: the labs patch series is re-derived against the current pin (42d7d24b) and renumbered -- next's own scope patch has been absorbed upstream and dropped out. scripts/labs_fnd_hashes.sh keeps next's acvm -> noir-execute rename alongside the native-packages/{wsdb,kvdb} component entries. A test pins the on-disk lmdb key bytes, which nothing covered: the bb-linked parity target compiles only field_element.test.cpp, so it checks fr's hash, msgpack and ordering but not how a key reaches disk -- and lmdblib's concrete serialise_key(const uint256_t&) became a generic template that memcpys from &key rather than uint256_t::data, which agree only while data[4] is the sole member at offset 0. Rebased onto next: the labs series is re-derived against the current pin and our three patches renumbered to 0016-0018, since next's own series has grown into 0002-0015 and the old numbering collided. The barretenberg-side wsdb bootstrap and CMakeLists carry #25403's flag removal into their native-packages homes, which next applied to the paths this moves. The NAPI scaffolding moves rather than being copied. lmdb_store_wrapper was its only consumer -- msgpack_client includes just ipc_client.hpp and napi.h, and nothing outside the module referenced barretenberg/messaging -- so extracting the store orphaned util/{promise,async_op,message_processor} and messaging/{dispatcher, header} on the bb side. Deleting them there leaves nodejs_module as init_module.cpp plus msgpack_client (still needed until #25362 removes it), and lets the diff read as renames instead of ~450 lines of apparently new code. stream_parser.hpp goes with them: it was already unreferenced and only header.hpp kept it compiling. The five bin32 wire aliases (Fr, Nullifier, PublicDataSlot, PublicDataValue, BlockHeaderHash) are the same 32 canonical bytes as FieldElement under a nominal tag, so FieldElement now converts to and from any of them implicitly, detected by the marker typedef codegen stamps on ipc::Bin32Alias (no generated header reaches field_element.hpp). That removes the ten per-alias converter functions and the fr-vector helpers from the wsdb converter; the composite converters reduce to aggregate init. bb's copy gets the equivalent for bb::fr without touching field.hpp: a to_wire proxy convertible to whichever alias the call site expects, and one from_wire template. Rebased onto next: the genesis seeding (#25497, #25503) landed in bb's world_state, so its generated seed header moves with the rest of world_state into native-packages/wsdb in wsdb's own types, regenerate_genesis_constants.sh and the genesis-constants skill point at the new path, GENESIS_NULLIFIER_TREE_ROOT joins wsdb's constants selection, and the three labs patches renumber to 0021-0023 behind next's grown series. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012EUKia6wteDk9kZZuT2Gju
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.
Stacked on #25497 — review that one first; this PR's diff is only the two commits on top.
Answers the review comment on #25497: "Is there a signposted automated regeneration flow that a person/ai can do to easily update them? I wonder if a git commit hook might be useful to warn people about this."
The problem
The genesis nullifier tree is seeded with the protocol contracts' registration nullifiers, which derive from their class ids. Anything that rotates a class id — a protocol contract change, a compiler bump, a transpiler change — moves the genesis roots, and several tracked files record them. Before this PR that was five hand-pinned locations, one of them inside the labs patch series, discoverable only via a late CI failure.
Reduce the pins first, then automate
Rather than automate the rewriting of five duplicated literals, most of them are removed:
GENESIS_NULLIFIER_TREE_ROOTinconstants.nr. The existing codegen already projects it intoaztec_constants.hpp,ConstantsGen.solandconstants.gen.ts, so the Noir, C++ and TypeScript genesis tests now all read one constant instead of repeating the literal.world_state.test.cppinto a generatedgenesis_protocol_nullifiers.hpp.Two hand-pinned locations remain (
constants.nrand that header), and none insidelabs/— which matters, because a file inside the patch series cannot be rewritten by a script that "never commits": persisting a labs edit requires a commit plusbootstrap.sh export.The regeneration flow
Single source of truth, modelled on
noir/scripts/bump_noir_compiler.sh. Phases: preflight → measure → validate → update → regenerate consumers → verify → stage. It does not commit.--fixtures--checkThree deliberate design points, all from review:
constants-codegenbefore the remake scripts. Those read the inputs embedded when the package was built, so running them against an editedconstants.nrwithout rebuilding will cheerfully reproduce the previous values and report success. This bit me during development.aztec compute-genesis-valuesnow also reports the canonical measurement, through the same sharedmeasureCanonicalGenesishelper the script reads, so there is one computation rather than two that can drift.Precommit reminder
Fires when staged changes touch the protocol contract sources, the Noir submodule pin or the transpiler. It names the regeneration command and never blocks.
It is explicitly a reminder, not evidence of freshness — deciding whether a class id actually moved means compiling the contracts and computing the ids, far too slow for a hook, so the path predicate is a cheap and deliberately incomplete proxy (a shared library the contracts pull in can move an id without tripping it). It also does not go quiet merely because
constants.nris staged: only a staged edit to theGENESIS_declarations themselves counts as handled.What it deliberately does not touch
mainnet_compatibility.test.tsandtestnet_compatibility.test.tspin what a live network was actually deployed with. A class id rotation fails those too, and that is correct — they change only at a governance upgrade. The script never rewrites them, and both the skill and theCLAUDE.mdblock say so explicitly, because the tempting "fix" is to paste in the new values, which silently claims the deployed network moved.Signposting
.claude/skills/genesis-constants/plus a<genesis_constants>block in the rootCLAUDE.md, mirroring howbump_noir_compiler.shis surfaced throughnoir-sync-update.Validation
--checkagainst the current tree: measures independently and confirms all three constants, the seed header and the fixtures agree.GENESIS_ARCHIVE_ROOT→--checkexits 1 naming the stale constant → a plain run restores it and regenerates the derived outputs. The verify phase caught a real bug in its own Solidity check (grouped digits) during that run.GENESIS_constants are staged too.nargo test --package types hash_of_genesis— 1 passed.world_state_tests --gtest_filter='*GetInitialTreeInfo*'— 3 passed.stdlib/src/block/l2_block.test.ts(3),world-state/src/testing.test.ts(7),protocol-contracts/src/genesis_data.test.ts(2) — passed.labs-patches/bootstrap.sh check— clean. Patch0009is unchanged; the labs changes here are a new0010.Relates to A-1264.