Skip to content

feat(pq): pq-devnet-1 — leanVM bindings v0.19.0 in process, consensus-specs pq at 4c296784 - #896

Draft
pablodeymo wants to merge 27 commits into
pq-devnet-0from
pq-devnet-1
Draft

pablodeymo wants to merge 27 commits into
pq-devnet-0from
pq-devnet-1

Conversation

@pablodeymo

@pablodeymo pablodeymo commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

🗒️ Description / Motivation

Everything ethlambda needs for pq-devnet-1 (notes.ethereum.org/@ethpandaops/pq-devnet-1, target launch 27.11.2026). It relaunches pq-devnet-0 with two changes:

  1. One leanVM release for every client, in-process, no sidecar. The devnet first pinned bindings v0.17.0 and moved to v0.19.0 (leanEthereum/leanVM@351f7ae4) on Nov 26; this branch is on v0.19.0 (commit 15). Proofs from any other revision are not accepted. v0.17.0 is the release that removed the leanvm-sidecar in favour of in-process proving (setup(threads), aggregate, from_bytes).
  2. Staggered attestation aggregators (consensus-specs pq 4595f0fc, "Stagger aggregators and skip redundant aggregates"). The spec pin is "TBD, at or after 4595f0fc".

Spec pin: consensus-specs pq head, 4c296784. Every commit after 4595f0fc changes consensus, so the pin is a real choice. Head is the most likely landing point, and any later pin includes all of these anyway:

commit change where
4595f0fc staggered aggregators, skip covered aggregates f8f43ace
b5d422b2 VRF leaves commit to a revealed per-slot secret e03f4185
af898d07 X_MAX_COMMITTEE_COUNT_PER_SLOT caps PQ committees 09990972
9bd63ad0, 32919f0f xmss_* / stark_* wrappers, reformatting (no behaviour change) —
4c296784 legacy XMSS keys and VRF roots are keccak256, not sha256 9fa5f2a1

Builds on #891 (the #880 port: attest on the block, PTC on the payload, parallel PQ attestation checks), already squash-merged into pq-devnet-0, so pq-devnet-1 also gets the attestation-latency fixes. This branch was cut before that squash and has since merged pq-devnet-0 back in (8391a4d0). #891's content is identical to the squash, so this PR's diff is only the devnet-1 work below.

The PR is three passes. Commits 1–6 are the devnet-1 work itself. Commits 14–16 are launch prep from the devops checklist of Nov 26 (leanVM v0.19.0, publish-on-sign). Commits 7–13 are a review pass over the first six: hardening that matters now that the prover runs inside the node, two fixes to my own first version of the committee cap, less wasted proving, and the image built to run the prover as fast as the host allows.

What Changed

First pass: pq-devnet-1

1. 40193875 feat(pq): prove in process with leanVM bindings v0.17.0, drop the sidecar

(The pin is v0.19.0 since commit 15; everything else here stands.)

  • Dependencies (Cargo.toml, Cargo.lock, leanvm-revision):
    • claims and lean_xmss move to 1e997c99. Their wire formats did not change: claims bytes and leanXMSS key, signature and cache sizes are all the same.
    • leanvm_sidecar is replaced by leanvm_prover = lean_vm with experimental_prover, the prover pq-devnet-0's sidecar was built with. It makes the same proofs as the stable prover.
    • leanVM's cpu_tiers was off in this commit. Commit 12 turns it on for the image.
    • The lockfile resolves cleanly: no jemalloc links conflict, and leanVM's allocator crate is not pulled in.
  • crates/common/crypto/src/stark/sidecar.rs → stark/leanvm.rs:
    • Same Lighthouse claim mapping as before: sorted, deduplicated (pubkey, message) pairs, the empty proof for no claims, and a refusal of signatures made at another leaf.
    • Merges fold MAX_RECURSIONS (16) children at a time.
    • Proving goes through lean_vm::aggregate, and verifying through AggregateProof::from_bytes(..).verify(..).
    • LeanVmConfig { threads, log_inv_rate: 2 } (Lighthouse's default rate), with the rate checked against leanVM's bounds.
  • stark.rs: install_leanvm replaces install_sidecar. With nothing left that can be unreachable, try_verify_aggregates, SidecarUnreachable, the gossip IgnoreReason::ProverUnreachable and its prover_unreachable label are removed. A bad proof is now always REJECT.
  • bin/ethlambda:
    • The node installs leanVM itself, right after --network resolves to a network that schedules PQ, and before anything can verify a proof.
    • --pq-prover-socket is replaced by --pq-prover-threads (default 0, one thread per core).
  • Image and CI:
    • The Dockerfile drops the sidecar build stage. The image records leanvm-revision at /usr/local/share/ethlambda/leanvm-revision.
    • bin/ethlambda/pq/ethlambda-pq becomes a shim that execs ethlambda and maps LEANVM_THREADS to --pq-prover-threads. ethereum-package's pq branch launches ethlambda-pq beacon …, so it keeps working unchanged.
    • The publish workflow's leanvm_rev input goes.

2. f8f43ace feat(pq): staggered aggregators again (4595f0fc)

This reverts e033029d, the revert that took pq-devnet-0 back to 2f43bc0f, and merges it with what landed since:

  • Config and duties:
    • AGGREGATION_CUTOFF_BPS / AGGREGATE_DUE_BPS_PQ / AGGREGATOR_DELAY_BPS come back (4000 / 6000 / 500, checked against the spec's configs/mainnet.yaml), along with get_aggregation_cutoff_ms / get_pq_aggregate_due_ms.
    • Attester duties carry aggregator_position again.
    • aggregate_attestation answers 404 for an aggregate already covered (should_broadcast_aggregate).
    • The validator client publishes seat by seat.
  • The node's prover (rpc/src/beacon/pq_aggregation.rs, merged by hand):
    • It proves per seat, at each seat's cutoff (4.8 / 5.4 / 6.0 / 6.6 s on a 12 s slot), before that seat's broadcast time (7.2 / 7.8 / 8.4 / 9.0 s).
    • It keeps b28ae833's genesis fix, rebased on the last seat's cutoff, so a node started before genesis still proves slot 0. It also keeps the guard against resealing a slot.
    • The cd849e37 cost line is now per seat.
  • Validator client: each seat signs in parallel off the duty task, as 908e88df does.
  • DB_VERSION → 10, not back to 8. Config's layout is 8's again, but a number stands for one history, and a pq-devnet-0 (v9) directory is refused rather than misread.

3. e03f4185 feat(pq): VRF leaves commit to revealed secrets (b5d422b2)

  • This reverts beb567c9:
    • secret = keccak256("VRF_SECRET" ‖ seed ‖ le64(i))
    • leaf = keccak256("VRF_LEAF" ‖ secret ‖ le64(i))
    • the proof reveals the secret.
  • Checked line by line against the spec at head. leanVM v0.17.0's own lean_vrf uses the same rule.
  • A VRF tree a pq-devnet-0 validator client stored is refused at load (WrongSeed: both stored formats are re-derived from the seed) and hashed again, so an upgraded directory never proves with an old-rule tree.
  • tooling/pq-devnet/ stays deleted (5c2fab24).

4. 09990972 feat(pq): X_MAX_COMMITTEE_COUNT_PER_SLOT (af898d07)

  • The key: a new Config field, mainnet 16 and minimal 4, each equal to its preset's MAX_COMMITTEES_PER_SLOT_PQ. It replaces that preset value in PQ's get_committee_count_per_slot.
  • Why it is process-wide: the state transition counts committees from a state alone, and threading a config through would touch every fork's process_attestation. So the cap is selected once per process from the network's config.yaml, next to the preset (network::select_committee_cap, right after select_preset / check_constants, on both the built-in and the directory paths), and read through config::x_max_committee_count_per_slot().
  • When unset (spec tests, lean), the cap is the preset value, which the spec's configs set equal to it.
  • Out of range or absent: this commit clamped with a warning. Commit 9 replaces that: an absent key takes the preset's value, and a value above the preset's is refused.
  • Caching: the committee cache's ShufflingKey already carries the cap, so cached shufflings stay correct.
  • Resume: a resume refuses a changed cap (first_config_difference), since a new cap reshuffles every PQ committee.

5. 9fa5f2a1 feat(pq): keccak256 legacy keys (4c296784)

  • compute_legacy_xmss_pubkey and compute_legacy_vrf_root now hash pubkey ‖ domain with keccak256. The RANDAO mix and the aggregation committee seeds stay on SHA-256, as the spec says.
  • New ethlambda_crypto::keccak256 (sha3's Keccak256).

6. b8d430bc docs(pq): pq-devnet-1 pin and docs (+ 8391a4d0, the merge of pq-devnet-0)

  • The spec pin b5d422b2… becomes 4c296784bb6ff54cbdcf72ebdda2a1057cce8893 in every module doc and in the preset test. No preset file changed between the two.
  • docs/beacon_pq.md:
    • rewritten Proofs section;
    • the committee cap;
    • legacy keys;
    • "Running a devnet" for pq-devnet-1, with cl_extra_params: [--pq-prover-threads=2] replacing LEANVM_THREADS;
    • What remains.
  • docs/cli.md, docs/metrics.md, docs/spec_deviations.md and CLAUDE.md follow.
  • The merge keeps pq-devnet-0's new "published files in use" notes and adds that VRF states published for pq-devnet-0's rule show as loaded=0 hashed=N.

Second pass: review of the above

7. 7a9d4318 fix(pq): catch leanVM panics, check the prover at startup, test it in CI

  • Panics stay inside leanVM. In pq-devnet-0 an input that crashed the prover cost the sidecar a restart. In process, the caller is the thread importing a block or judging gossip, and proof bytes come from peers. Every call into leanVM now goes through leanvm::guarded (catch_unwind): a panic in the verifier reads as a proof that does not verify, one in the prover as a proof that was not made, and both log leanVM panicked. leanVM's proving lock tolerates poisoning; verification takes no lock, so it keeps working whatever a panic left behind.
  • Startup self-check. LeanVmBackend::setup ends by proving and verifying one throwaway signature, and checks the proof does not verify against another claim. A prover that cannot run on the host stops the node at startup instead of silently missing every aggregation duty. Costs about 60 ms here.
  • Thread count. More --pq-prover-threads than cores is lowered to the cores with a warning (leanVM would oversubscribe; its own bindings refuse it).
  • CI coverage. The end-to-end prover test stays #[ignore] for a plain cargo test, which takes 160 s on it unoptimized, and make test-consensus (so CI) now runs it by name under release-fast, where it takes about 1.4 s. It also checks that garbage, truncated and bit-flipped bytes in a proof's place verify against nothing, and that a signature at another leaf than its statement's is refused.
  • Pin consistency. A test holds LEANVM_REV, the three revs in the workspace manifest and the root leanvm-revision file equal.

8. 16a19515 feat(pq): ethlambda pq-prover-check

  • A seat has from its cutoff to its broadcast to prove: 2.4 s of a 12 s slot, and leanVM makes one proof at a time. Nothing showed whether a host keeps up before a devnet's first aggregation duty.
  • The command starts the prover as the node does, proves and verifies an aggregate of --signatures claims (default 128) --rounds times, and reports each round against that window. No network, no data directory.
  • Measured on 14 cores of an Apple M4 Max, release-fast: 128 signatures in about 0.28 s, 512 in about 0.86 s, verification about 6 ms, proofs 160–200 KB.

9. dd187f98 fix(pq): the committee cap's absent and too-large cases

Two things commit 4 got wrong:

  • Absent key. It parsed as mainnet's 16, like every absent key, and was then lowered to the preset's value with a warning. A minimal network whose config.yaml predates the key (every pq-devnet-0 one) would warn at each start about a value its file never set. An absent key now takes the preset's MAX_COMMITTEES_PER_SLOT_PQ, which the spec's configs equal, and the value is written into the config, so the data directory and /eth/v1/config/spec hold what the node runs on.
  • Too large. A value above the preset's was lowered with a warning. The spec says it must not exceed it, and a node quietly running another cap than the file's would shuffle different committees than its peers. It is now a startup error naming both values. A zero still means one committee, as get_committee_count_per_slot has it.
  • Also restores the doc comment of Config's Default impl, which commit 4 had accidentally attached to the cap's static.

10. 3e56b1d5 perf(pq): a later seat does not re-prove what an earlier one proved

  • One node can hold several seats of a committee, 0.6 s apart. Unless a vote arrived between two cutoffs, the later seat collected exactly what the earlier one proved, and proving it again occupied the single prover for as long again, for an aggregate insert_proven would not keep and should_broadcast_aggregate rules out anyway.
  • PqSignaturePool::is_proven detects it; the seat's cost line gains already_proven. The held aggregate still answers the later seat's request.

11. ffbfc20a fix(validator): PQ seats publish side by side

  • The node holds an aggregate request for up to 3 s while the proof asked for is still being made. The validator client served its seats one after another, so a held request for the seat due at 7.2 s kept the seats due at 7.8, 8.4 and 9.0 s from even asking until 10.2 s. Each seat now waits for its own time and runs on its own.

12. 3d6d0f1d perf(pq): the image's prover is built with leanVM's CPU tiers

  • Without tiers, leanVM proves on the build's portable baseline (x86-64-v3 + PCLMULQDQ), and on a host with AVX-512, GFNI or VPCLMULQDQ it prints a banner at the first proof saying it is slower than the CPU allows. The other clients' leanVM builds pick a tier at run time, which is what the devnet notes mean by "CPU features selected at runtime".
  • New cargo feature leanvm-cpu-tiers (off by default, so an ordinary build does not compile the extra copies). A tier only gets its instructions under leanVM's scripts/tier-rustc as RUSTC_WRAPPER; the Dockerfile fetches it at the pinned revision and sets it before cargo chef cook. Every other crate keeps the baseline in .cargo/config.toml.
  • The Dockerfile's default FEATURES is now leanvm-cpu-tiers. The shadow variant passes its own FEATURES, so it is unaffected.
  • Cargo.lock gains the 42 tier crates.

13. 22d16f45 docs

  • docs/beacon_pq.md, docs/cli.md (new pq-prover-check section) and CLAUDE.md follow.
  • Corrects a wrong claim from commit 6: I had written that leanVM's jemalloc keeps a proof's pages resident for the life of the process. That is true of leanVM's own builds (dirty_decay_ms:-1), not of the node, whose jemalloc returns them like any freed memory. The note now says so, and that MALLOC_CONF=dirty_decay_ms:-1 makes the same trade for the whole node. Not measured.

Third pass: launch prep (Nov 26)

14. 787d5aa8 merge of pq-devnet-0

  • ba522d44 (start the gloas and PQ payload build a third of a slot ahead): taken as is.
  • a3732f4b (a pool of verifying connections to the sidecar, so gossip validation and block production's proof check stop waiting for each other): there is no sidecar here. In process, leanVM verifies on the calling thread under no lock, which is that change's whole effect already. Its file stays deleted.

15. 6039075e chore(pq): leanVM bindings v0.19.0 (351f7ae4)

  • The three revs, leanvm-revision and LEANVM_REV move together (the pin-consistency test holds them equal).
  • What changed upstream between v0.17.0 and v0.19.0, and what it means here:
    • setup now picks the prover's CPU tier, so a build that leaves some of the CPU unused says so at startup, not at the first proof.
    • MAX_CACHED_BOTTOM_TREES is renamed DEFAULT_BOTTOM_TREE_CACHE_SIZE and is 8, not 4. Only a comment named it here.
    • Faster leanXMSS key generation and signing.
    • PROTOCOL_VERSION (1), bumped on every STARK-breaking change. The prover's startup line and pq-prover-check now report it.
  • No wire or file format change: the proved program, the verifier's tag, the claim encoding and the key cache layout are identical, so xmss_cache_url's 14696-byte records still load. scripts/tier-rustc is unchanged and exists at the new pin.

16. 065f80e5 feat(validator): publish each PQ attestation as soon as it is signed

  • The devnet-1 requirement: sign in parallel on every core and publish each attestation as it is signed, not once the batch is done.
  • ethlambda already signed a duty's keys in parallel, then published the batch in one request. Normally that is a few signatures' time, but a key that has to build a bottom tree at signing time takes seconds, and every other key's vote waited for it.
  • pq::sign_each hands each signature over the moment it exists (still one leaf-record flush for the batch). AttestationService::publish_pq_as_signed publishes it with whatever else was signed by then, each request on its own, so none waits for a slower key or for an earlier request's answer.
  • Failing every request is the error the single request used to be; failing some is logged and the rest count as published.
  • Other forks, and PQ's PTC votes and aggregates, publish as before.

Correctness / Behavior Guarantees

  • Proof compatibility: every pq-devnet-1 client must be on leanVM bindings v0.19.0, which this branch is. The claim encoding is unchanged since pq-devnet-0, so the Lighthouse-compatible mapping carries over.
  • Mainnet and other non-PQ networks are untouched:
    • leanVM is installed only when the network schedules PQ.
    • The committee cap only applies to ForkName::Pq.
    • Built-in networks omit the key and so default to the preset value.
  • Gossip: an aggregate whose proof fails is now always REJECT. The IGNORE for "prover unreachable" existed only because a separate process could be down.
  • Legacy-key hash differs between clients today. This branch and Teku's pq-devnet-1 use keccak256 (spec head, 4c296784); Lodestar's and Grandine's pq-devnet-1 still use sha256. The devnet's spec commit is "TBD". It only matters when a BLS-keyed deposit is processed after genesis, but then the two groups would disagree on the new validator's key. If the devnet pins before 4c296784, commit 5 is the one to revert.
  • Publish-on-sign (commit 16): each attestation is still published exactly once; only when it goes out changes.
  • A leanVM panic no longer reaches the chain actor (commit 7). It fails the one proof.
  • Committee cap: absent means the preset's value; above the preset is a startup error (commit 9). This supersedes the clamp described under commit 4.
  • Skipping a seat's proof is equivalent (commit 10): the endpoint already kept only the larger aggregate, and answered 404 for one a broadcast covers. Only the proving time changes.
  • CPU tiers are additive (commit 12): a build without the feature, or without the wrapper, behaves as before. Not yet exercised on x86-64, see below.
  • Data directories: DB_VERSION 10. pq-devnet-0 directories (v9) are refused, so pq-devnet-1 starts fresh, which a relaunch does anyway.
  • Genesis interop risk: pq-devnet-1's "Genesis / key derivation" is still TBD in the notes. ethereum-package's VRF states and genesis keys must follow b5d422b2's VRF rule and 4c296784's keccak legacy keys.
    • States published for pq-devnet-0's rule are detected and ignored, and the validator client hashes the tree itself, which takes minutes per key.
    • If the devnet settles on an earlier pin, commits 3 and 5 are the ones to revert.

Tests Added / Run

  • New tests:
    • stark::leanvm::tests::leanvm_proofs_merge_and_verify (ignored by default, real leanVM): two committee proofs made in process and merged; the merged proof verifies against the concatenated statements and fails against a subset, the wrong order, or a truncated proof. Run and passing.
    • Claim encoding tests, and a test that refuses a rate outside leanVM's bounds.
    • Next-slot-to-seal tests on the last seat's cutoff, and a per-seat timing test.
    • Committee cap: parsing (mainnet 16, minimal 4, an absent key defaults), and clamping within CommitteeBits.
    • Keccak: the empty-input known answer, and the VRF single-block Keccak agreeing with the streaming hasher for 0–135 bytes.
    • Legacy keys equal keccak256(pubkey ‖ domain) and no longer equal the SHA-256 ones.
  • Run per commit:
    • cargo fmt --all --check
    • cargo clippy --workspace --all-targets -- -D warnings
    • tests for crypto, types, storage, state-transition --lib, rpc, validator, p2p, and the ethlambda binary: all passing
  • Second pass, new tests:
    • leanVM backend: a panic becomes an error; thread clamp; pin consistency; malformed proof bytes and wrong-leaf signatures (inside the end-to-end test).
    • Committee cap: absent key takes the preset's value; a value above it is refused, naming both.
    • PqSignaturePool::is_proven: proven once the held aggregate has every signer, not after a new vote, not for another vote's group.
    • Validator client: with the node holding each request 3 s, the second seat still asks 0.6 s after the first (paused tokio time).
    • pq-prover-check: the 2.4 s window from mainnet's timing.
  • Third pass, new tests:
    • pq::sign_each answers every request once, at its position, with the bytes the batch signer makes; an unsignable request is an error at its own position only.
    • A PQ attestation duty with three validators, one without a leanXMSS key: the two signed votes are each published once with leanXMSS signatures under the pq version, and the third costs only itself.
  • Run on the final tree (065f80e5):
    • make lint: pass.
    • make test (test-consensus + test-node): pass, 4,171 tests, none failing. It includes the end-to-end leanVM prover test on v0.19.0.
    • ethlambda pq-prover-check --signatures 128 on v0.19.0: 270–276 ms per round, protocol_version=1.
  • Published image (ethpandaops/ethlambda:pq-devnet-1-065f80e, built by ethPandaOps from this branch's head):
    • Reports ethlambda/v1.0.0-pq-devnet-1-065f80e and carries leanVM 351f7ae4.
    • pq-prover-check inside it on arm64: self-check passes, 128 signatures prove in 0.7–1.0 s with every core busy elsewhere (window 2.4 s), protocol_version=1.
    • LEANVM_TIER=armsha3 forced: proves fine, so the CPU-tier build (wrapper + leanvm-cpu-tiers, with fat LTO) is in the image and runs.
  • ethlambda-only devnet on that image (Nov 26, local kurtosis, ethereum-package pq branch):
    • Setup: two nodes (geth + ethlambda beacon node + ethlambda validator client), 16 validators each, mainnet preset, PQ at genesis. Genesis keys and VRF states generated with ethlambda pq-keys for the new VRF rule and served to the genesis generator and the validator clients, since the package's published files are still pq-devnet-0's.
    • Genesis: leanXMSS keys: 0 from cache, 32 fetched, 0 derived. Validator clients: leanXMSS cached=16 built=0 refused=0 from ethPandaOps' published cache (so that file loads under v0.19.0), VRF loaded=16 hashed=0.
    • Finalized: at slot 128 both nodes had justified epoch 3 and finalized epoch 2, same roots. 128 of 128 slots had a block.
    • Gossip verdicts on both nodes: accept only, for blocks, payload envelopes, aggregates (leanVM proofs checked by the other node), attestations, PTC votes and proposer preferences.
    • 0 errors, 0 panics; the only warnings are three expected startup ones.
    • Timings into the slot, medians over 131 slots: block 150 ms, envelope 233 ms, attestation 266 ms, PTC vote 317 ms; aggregate proved at 4.88 s (the 4.8 s cutoff plus a 75 ms proof) and published at 7.30 s (seat 0's 7.2 s). 132 leanVM proofs, none late, none failed.
    • What it does not show: with 32 validators a committee is one attester, so only seat 0 exists and proofs are tiny; everything ran on one arm64 machine; no other client was present.
  • Not run yet:
    • Interop with other clients (ethereum-package's .github/tests/pq-devnet-1.yaml). It cannot pass for any new-rule client until ethPandaOps publishes genesis VRF roots and .vrf files for b5d422b2; the published ones were checked to be the old rule's.
    • pq-prover-check on an x86-64 host, where the AVX-512 / GFNI tiers would be used.
    • The PQ spec fixtures (no release ships them).

Related Issues / PRs

✅ Verification Checklist

  • cargo fmt --all --check: clean
  • make lint on the final tree (065f80e5): clean
  • make test on the final tree: passing
  • The image builds on amd64 and arm64 (ethPandaOps' builder, from 065f80e5)
  • pq-prover-check inside the published image (arm64)
  • ethlambda-only devnet on the published image: finalized, no missed slots
  • Interop with other clients (waiting on new-rule genesis VRF files)
  • pq-prover-check on an x86-64 host

pablodeymo and others added 14 commits November 25, 2026 11:35
…e deadline

The duty loop slept until ATTESTATION_DUE_BPS(_GLOAS) every slot, so every
vote went out after the deadline, behind every client that votes on the
block. Follow the first beacon node's head events and cut the wait short
once a head at the slot is reported, as the honest-validator guide asks.
The deadline stays the fallback.
…e executor

post_pq_attestations ran one leanXMSS verification after another on the
async handler, so the last vote of a validator client's batch waited for
every other one's and the worker thread was held throughout. Run it on
spawn_blocking, check the batch with rayon, and publish in submission order.
…its payload does

The validator client signed attestations, sync committee messages and PTC
votes at their clock offsets only. The specification asks for whichever
comes first: the slot's block (its payload and blob data, for the PTC
vote) or the offset. Every other validator client the issue surveys
attests on the block by default.

beacon_node/events.rs reads GET /eth/v1/events with Response::chunk and a
small SSE parser (reqwest's stream feature would change Cargo.lock), on a
client of its own with a connect timeout and a 60 s idle timeout.

head_monitor.rs reads every configured node's stream, one connection per
topic (head, plus execution_payload_available when gloas is scheduled),
reconnecting with backoff, and wakes each duty on the earlier of its event
and its clock offset. The early attempt signs only when the node's answer
names the event's block (and, for the PTC vote, says payload_present and
blob_data_available); otherwise nothing is recorded, and the duty asks
again on the next report about the slot it has not tried (the answering
node's own, typically) or runs at its deadline, so each duty is still
signed at most once a slot. The services gained a fetch half and a sign
half for that check. A stream that idles out (quiet by design before
gloas, on a node with no keep-alives) reopens with debug logging only.

The duty loop's sleep to the first duty now ends on the block too, and
the PTC vote runs beside attest+aggregate rather than after the
aggregation. --disable-event-stream turns it all off.
ethlambda_validator_duty_triggers_total{duty,trigger} counts what started
each duty.

Closes #829.
…treams that end at once

The open-stream gauge was incremented when a stream opened and decremented
after it ended, so a reader aborted mid-stream (HeadMonitor's drop) left
its stream counted. It is now a guard dropped with the reader's future.

A node that keeps handing out streams that break or close before
delivering any event logged a warning and an info line on every reconnect,
forever. The first such end still warns; later ones, and the reopens
between them, log at debug until a stream delivers an event or goes quiet,
as repeated refused subscriptions already did.

Docs: CLAUDE.md's gloas validator-client sentence and the comment above
the proposer preparations still described the offsets as start times.
…pre-duty wait on a payload too

An early attempt's request (attestation data, head root, payload
attestation data) was awaited past the deadline: one still out then, and
answering a mismatch, started the deadline attempt late. Each is now
bounded by the deadline and dropped there, counted as a mismatch, so from
the deadline on a duty runs exactly as it would with no event.

The duty loop's wait before the slot's duties watched head reports only,
so with a node's head stream down and its payload stream up the committee
vote waited for the first duty's offset. `report_within` (was
`head_within`) ends on either topic's report for the slot.

A refused subscription's body excerpt bounded each piece's read rather
than the whole read, so a body trickled a byte at a time could hold the
reconnect for many minutes. One timeout now covers the whole read.

Docs: the PTC deadline's doc in slot_clock.rs, the sync committee module
doc, and spec_deviations.md, whose "signs a sync committee message at the
deadline only" entry is no longer a deviation and is removed.
…ecar

pq-devnet-1 runs one leanVM release for signer, prover and verifier:
bindings v0.17.0 (1e997c99), which removed leanvm-sidecar and its client
API in favour of lean_vm's in-process setup/aggregate/from_bytes. A proof
from another revision does not verify.

- claims and lean_xmss move to 1e997c99 (no wire change); leanvm_sidecar
  becomes lean_vm with the experimental prover, the one the pq-devnet-0
  sidecar ran. cpu_tiers stays off: it needs leanVM's tier-rustc wrapper,
  and the node's own CPU baseline already gives the prover its clmul.
- stark::sidecar becomes stark::leanvm: same Lighthouse claim mapping,
  merges folded MAX_RECURSIONS at a time, verification in process. With
  nothing to be unreachable, try_verify_aggregates, SidecarUnreachable and
  the prover_unreachable IGNORE go.
- The node installs the backend itself once --network says PQ is
  scheduled; --pq-prover-socket becomes --pq-prover-threads.
- The image no longer builds a sidecar. ethlambda-pq stays as a shim that
  execs ethlambda (LEANVM_THREADS -> --pq-prover-threads), so pq-devnet-0
  launchers keep working; the publish workflow's leanvm_rev input goes.
… has them

Reverts e033029 (the move back to pq-devnet-0's unstaggered aggregators):
pq-devnet-1 runs consensus-specs pq at or after 4595f0fc, which staggers a
committee's aggregators by their seat in its aggregation committee
(AGGREGATION_CUTOFF_BPS, AGGREGATE_DUE_BPS_PQ, AGGREGATOR_DELAY_BPS) and has
one skip an aggregate a received one already covers.

Merged with what landed since the revert:
- The node's prover proves per seat, with the per-pass cost line of
  cd849e3 (now per seat) and b28ae83's genesis rule: the first slot to
  seal is the wall clock's until its last seat's cutoff, so a node started
  before genesis still proves slot 0.
- The validator client's seats sign in parallel off the duty task, as
  908e88d has them.
- Tests on the runtime preset accessors; aggregator_position in the test
  duty helpers #880 brought.

Config's layout is 8's again; DB_VERSION goes to 10 rather than back to 8,
so a pq-devnet-0 (version 9) directory is refused rather than misread.
…q b5d422b2 has them

Reverts beb567c (the move back to pq-devnet-0's revealed leaves): from
b5d422b2 a VRF leaf is keccak256("VRF_LEAF" || secret || le64(slot)) over
the slot's secret keccak256("VRF_SECRET" || seed || le64(slot)), and the
proof reveals the secret, not the leaf. leanVM bindings v0.17.0's lean_vrf,
pq-devnet-1's release, follows the same rule.

A VRF tree a pq-devnet-0 validator client stored is refused at load
(WrongSeed: both stored formats are re-derived from the seed) and hashed
again under the new rule, so an upgraded directory never proves with one.

tooling/pq-devnet stays deleted (5c2fab2: ethereum-package's pq branch
runs ethlambda); CLAUDE.md keeps the current text until the docs pass.
…nsus-specs pq af898d07 has it

A temporary, testing-only config key that replaces MAX_COMMITTEES_PER_SLOT_PQ
in PQ's get_committee_count_per_slot, so a small devnet can put its
validators into fewer, larger committees. Mainnet 16 and minimal 4, each
equal to its preset's MAX_COMMITTEES_PER_SLOT_PQ, which it may not exceed.

The state transition counts committees from a state alone, so the cap is
selected once per process from the network's config.yaml, beside the
preset (network::select_committee_cap, after select_preset), and read
through config::x_max_committee_count_per_slot(). Unset, as in the spec
tests, it is the preset's value, which the specification's configs equal.
A value outside 1..=MAX_COMMITTEES_PER_SLOT_PQ is moved into range with a
warning. A resume refuses a changed cap, since it reshuffles every PQ
committee. The field rides on DB_VERSION 10 (still unreleased).
…specs pq 4c296784 has them

compute_legacy_xmss_pubkey and compute_legacy_vrf_root hash the BLS key and
domain byte with keccak256, the VRF tree's hash, rather than sha256; the
RANDAO mix and aggregation committee seeds stay on sha256. The fork upgrade
gives these to every validator and builder that registered no PQ key, and
a deposit for a new one looks its key up by them.

ethlambda_crypto::keccak256 wraps sha3's Keccak256; a test checks it
against the VRF tree's single-block permutation and the empty-input digest,
and another that the legacy keys are no longer the sha256 ones.
…ings v0.17.0

The spec pin moves from b5d422b2 to 4c296784 in every module doc, the
preset test and the docs (no preset changed in between; 9bd63ad0 and
32919f0f only wrap and reformat the xmss/stark calls). docs/beacon_pq.md
describes in-process proving and what became of the sidecar and its
supervisor, the committee cap, the keccak256 legacy keys, and running
pq-devnet-1; cli.md swaps --pq-prover-socket for --pq-prover-threads;
metrics.md loses prover_unreachable; CLAUDE.md follows, DB_VERSION 10
included.
# Conflicts:
#	crates/validator/src/head_monitor.rs
@MegaRedHand
MegaRedHand marked this pull request as draft November 25, 2026 19:31
leanVM now runs in the node's own process, on the threads that import
blocks and judge gossip, where pq-devnet-0's sidecar could crash on an
input and be restarted. Every call into it goes through guarded(), which
turns a panic into a proof that does not verify, or one that was not
made, instead of an unwind through the chain actor.

LeanVmBackend::setup now ends with a self-check: one throwaway signature
proved and verified, and checked not to verify against another claim. A
prover that cannot run on the machine is reported at startup, not at the
first aggregation duty. measure() proves the same input several rounds
over, for pq-prover-check. More prover threads than cores are lowered to
the cores with a warning rather than oversubscribed.

Tests: garbage and truncated bytes in a proof's place verify against
nothing; a signature at another leaf than its statement's is refused;
the leanVM pin is the same in the constant, the manifest and
leanvm-revision. The end-to-end prover test stays ignored for a plain
cargo test (minutes unoptimized) and make test-consensus, so CI, runs it
by name.
…s host

A seat has the window from its cutoff to its broadcast to prove in, 2.4 s
of a 12-second slot, and leanVM makes one proof at a time. Whether a host
keeps up depends on its cores and on which CPU instructions the build
uses, which nothing showed before a devnet's first aggregation duty.

The command starts the prover as the node does, proves and verifies an
aggregate of --signatures claims --rounds times, and reports each round
against that window. No network, no data directory.
…e above it is refused

Two things the first version of the cap got wrong:

- An absent key parsed as mainnet's 16, like every key, and was then
  lowered to the preset's value with a warning. A minimal network whose
  config.yaml predates the key (every pq-devnet-0 one) warned at each
  start about a value its file never set. An absent key now takes the
  preset's MAX_COMMITTEES_PER_SLOT_PQ, which the specification's configs
  equal, and the config says so afterwards, so the data directory and
  /eth/v1/config/spec hold what the node runs on.
- A value above the preset's was lowered with a warning. The
  specification says it must not exceed it, and a node that quietly ran
  another cap than the file's would shuffle other committees than peers
  that refused or ran it. It is now a startup error naming both values.

Also restores the doc comment of Config's Default impl, which the cap's
statics had been inserted under.
A committee's seats are staggered 0.6 s apart and one node can hold
several. Unless a vote arrived between two cutoffs, the later seat
collected exactly what the earlier one proved, and proving it again took
the prover, which makes one proof at a time, as long again for an
aggregate insert_proven would not keep and should_broadcast_aggregate
rules out once the earlier seat has broadcast. The held aggregate still
answers the later seat's request.

PqSignaturePool::is_proven says so, and the seat's cost line counts
already_proven.
The node holds an aggregate request for up to three seconds while the
proof asked for is still being made. Seats were served one after
another, so a held request for the seat due at 7.2 s kept the seats due
at 7.8, 8.4 and 9.0 s from even asking until 10.2 s. Each seat now waits
for its own time and runs on its own.

The mock can hold pq_aggregate requests and records when each arrived.
Without them leanVM's prover runs on the build's portable baseline
(x86-64-v3 with PCLMULQDQ), and on a host with AVX-512, GFNI or
VPCLMULQDQ says so on stderr at the first proof: slower than the CPU
allows, and slower than the other clients' leanVM builds, which pick a
tier at run time.

The leanvm-cpu-tiers feature compiles the prover once more per tier.
A tier only gets its instructions under leanVM's scripts/tier-rustc as
RUSTC_WRAPPER, which the Dockerfile fetches at the pinned revision and
sets before cargo chef cook; every other crate is compiled as before.
Off by default, so an ordinary build does not compile the copies; the
image builds with it. Cargo.lock gains the tier crates.
…ules; seats

Also corrects the memory note: the node's jemalloc returns a proof's
buffers like any freed memory. It is leanVM's own builds that keep them
(dirty_decay_ms:-1), which MALLOC_CONF can ask of the node too.
MegaRedHand added a commit that referenced this pull request Nov 26, 2026
#896 adds the same helper at the same place; identical lines merge
cleanly when pq-devnet-0 is merged into pq-devnet-1.
Two commits since the last merge:

- ba522d4 starts the gloas and PQ payload build a third of a slot ahead.
  Taken as is.
- a3732f4 gave the sidecar client a pool of verifying connections, so
  gossip validation and block production's check of a merged proof stopped
  waiting for each other. There is no sidecar here: leanVM verifies in
  process, on the calling thread, under no lock, which is that change's
  whole effect already. Its file stays deleted.

pq_proposal.rs: two comments still spoke of the proving sidecar.
…1 launches on

pq-devnet-1 moved from v0.17.0 to v0.19.0 for every client, and takes no
other revision. Between the two:

- v0.18.0: setup picks the experimental prover's CPU tier (so a build
  that leaves some of the CPU unused says so at startup, not at the first
  proof), and faster leanXMSS key generation and signing.
- v0.19.0: lean_xmss::MAX_CACHED_BOTTOM_TREES is renamed
  DEFAULT_BOTTOM_TREE_CACHE_SIZE and is 8, not 4 (only a comment named it
  here); signing hashes chain steps in batches; PROTOCOL_VERSION, bumped
  on every STARK-breaking change, which the prover's startup line and
  pq-prover-check now report (1).

No wire or file format changes: the proved program, the verifier's tag,
the claim encoding and the key cache layout are the same, and a cache
file with two bottom trees (xmss_cache_url's 14696-byte records) still
loads. scripts/tier-rustc is unchanged.

Also corrects the manifest comment that still said cpu_tiers was not
enabled.
pq-devnet-1 asks clients to sign in parallel on every core and publish
each attestation as it is signed, not once the whole batch is done:
pq-devnet-0's attestations went out five to ten seconds into the slot
that way and missed the aggregation cutoff.

ethlambda already signed a duty's keys in parallel, and then published
the batch in one request. Normally that is a few signatures' time, but a
key that has to build a bottom tree at signing time takes seconds, and
every other key's vote waited for it.

pq::sign_each hands each signature over the moment it exists (one leaf
record flush for the batch, as before). AttestationService publishes it
with whatever else was signed by then, each request on its own, so none
waits for a slower key or for an earlier request's answer. Failing every
request is the error the single request used to be; failing some is
logged and the rest count as published.

Other forks, and PQ's PTC votes and aggregates, publish as before.
@pablodeymo pablodeymo changed the title feat(pq): pq-devnet-1 — leanVM bindings v0.17.0 in process, consensus-specs pq at 4c296784 feat(pq): pq-devnet-1 — leanVM bindings v0.19.0 in process, consensus-specs pq at 4c296784 Nov 26, 2026
Brings pq-devnet-0's improvements of 2026-11-26 to pq-devnet-1:
- #906: publish each attestation as soon as it is signed;
- #907: sign the payload committee's votes after the slot's attestations;
- #908: fetch the next epoch's payload committee after the slot's duties;
- #909: sign a proposal's envelope alongside its block;
- #899: park votes for a block still importing, and check them again once it lands;
- #914: merge a block's attestation proofs ahead of its slot.

Resolution:
- #906 and 065f80e are two implementations of the same change. pq-devnet-1's
  is kept (pq::sign_each returning a receiver, concurrent submissions in
  publish_pq_as_signed). #906's callback sign_each, sign_streamed and their
  tests are dropped, and its per-vote delay metric
  (ethlambda_validator_attestation_vote_delay_seconds) is recorded on each
  accepted submission of pq-devnet-1's loop.
- #914's packing code moves unchanged into the blockchain crate. It merges
  through PqPacked::merge, which on this branch proves in process. Its docs
  say leanVM instead of the sidecar, and why a packing a third of a slot
  ahead comes after the node's own aggregator seats' proofs.
- docs/beacon_pq.md: the Proposing paragraph describes packing ahead with
  leanVM in process; the known gaps drop the merge-ahead item and keep
  pq-devnet-1's interop one.
…Q self-build target) (#953)

## Problem

pq-devnet-1's `config.yaml` schedules a gas limit of 200M from epoch 0
through `GAS_LIMIT_SCHEDULE`
([EIP-8261](https://eips.ethereum.org/EIPS/eip-8261)). Devops reported
that ethlambda votes the gas limit down. The chain shows something more
specific: **ethlambda never moves it.**

Over slots 20213–23212, each canonical block's gas limit compared with
its parent's (Dora's slots API):

| Client | Raises | Lowers | Keeps |
|---|---|---|---|
| lighthouse | 444 | 0 | 0 |
| teku | 437 | 0 | 0 |
| lodestar | 405 | 0 | 0 |
| grandine | 281 | 0 | 0 |
| **ethlambda** | 0 | 0 | **272** |
| prysm | 0 | 0 | 472 |
| nimbus | 0 | 273 | 0 |
| silver | 0 | 267 | 0 |
| unlabelled proposer | 0 | 102 | 0 |

Two things in this branch cause it:

1. **The validator client never reads the schedule.** Its default target
gas limit is a fixed 60M, and the ansible deployment doesn't pass
`--gas-limit`. It signs 60M into every PQ proposer preference.
2. **The beacon node's PQ self-build ignores the preferences anyway.**
`prepare_pq_proposal` builds every PQ payload toward
`parent_bid.gas_limit`, so whatever a preference says, ethlambda's own
blocks keep the parent's limit. Gloas's self-build does read the
preferences (`prepare_gloas_proposal_on`); the PQ one never did.

## What this does

### 1. `GAS_LIMIT_SCHEDULE` (port of #873)

**Beacon node:**
- Parses `GAS_LIMIT_SCHEDULE` into `Config` and serves it on
`/eth/v1/config/spec`.
- Stores it in a `Metadata` row of its own, so the `config` row's
encoding and `DB_VERSION` (10) don't change.
- A directory written before this change resumes and gains the row.

**Validator client:**
- `--gas-limit` no longer has a default.
- Each validator's gas limit resolves in this order: its own override,
then `--gas-limit`, then the schedule's value for the duty's epoch, then
60M.
- The epoch is the proposal's for preferences, BLS and PQ alike.
`publish_pq_epoch` is a call site #873 never saw.

**Differences from #873:**
- **No chain check:** this branch doesn't have it (#854). The schedule
is followed by a small module of its own instead; see part 3.
- **Test helper:** `gas_limit_schedule_text` moved from `chain_check` to
`proposer_settings`.
- **`dto` tests:** they use a local `spec_with` in place of main's
`complete_spec`, since this branch's spec parser accepts absent keys.
- **Docs:** comments that said `DB_VERSION` 7 now say 10.

### 2. PQ payloads follow the proposer's preferences (new)

- **The rule:** `prepare_pq_proposal` takes the PQ builder market. When
it holds the proposer's own signed preferences for the slot, under the
slot's dependent root, it builds toward their `target_gas_limit`, as
gloas's self-build does. Otherwise it keeps the parent's limit, as
before.
- **Callers:** both pass the node's one PQ market: the `pq_blocks`
endpoint, and the chain actor's payload preparation ahead of the slot
(`PayloadPreparation::pq_builder_market`, wired in `main.rs`).
- **Prepared builds:** the actor's `AttributesKey` now includes the PQ
preferences, so a build prepared before they arrived is redone.
Production and preparation still ask for the same attributes.
- **Fee recipient:** unchanged, still `prepare_beacon_proposer`'s.

### 3. The schedule is read off every beacon node, every epoch (review
fix)

Before this change, the schedule came from whichever node answered the
startup `/eth/v1/config/spec`. If that node served no
`GAS_LIMIT_SCHEDULE`, or one `check_rules` refuses, every preference
targeted 60M until a restart, even with another node serving the right
schedule. Nothing was logged.

`crates/validator/src/gas_limit_schedule.rs` now:
- **Asks every node:** all `--beacon-nodes` at once, taking the first
non-empty schedule in that order.
- **Repeats every epoch:** it reads at startup and again each epoch on
its own task, aborted when the client stops. A node that comes up, or
starts serving the key, later is followed without a restart.
- **Keeps a held schedule** while no node serves one. A node restarted
on an old build is likelier than the network dropping its schedule.
- **Warns** when no node serves a schedule while gloas is scheduled and
`--gas-limit` is unset, once per run of empty reads.

### Not done

EIP-8261 says a client SHOULD warn when an operator's gas limit is above
the scheduled value. #873 doesn't, and neither does this.

## Checked

- **Real config:** the beacon node from this branch, started on
`ethpandaops/pq-devnets`' `network-configs/devnet-1/metadata`, serves
`"GAS_LIMIT_SCHEDULE": [{"EPOCH": "0", "GAS_LIMIT": "200000000"}]`, no
longer among its ignored keys.
- **New tests:**
  - `a_pq_preference_carries_the_scheduled_gas_limit` (validator).
- `a_pq_proposal_takes_the_gas_target_of_its_proposers_own_preferences`
(blockchain): the proposer's own preference is used; none held, another
validator's, or another dependent root fall back to the parent's limit.
- **Reviewer's scenario, real binaries:** a beacon node on pq-devnet-1's
config, behind a proxy that strips `GAS_LIMIT_SCHEDULE`, is listed
first, then the node itself. The previous build started with
`gas_limit_schedule=[]`, silently. This one logs `Took the gas limit
schedule a beacon node serves … node=1 schedule=[0: 200000000]`. With
only the stripped node it warns `No beacon node serves a usable
GAS_LIMIT_SCHEDULE while gloas is scheduled …`.
- **`gas_limit_schedule` unit tests:**
  - the first serving node wins over an empty or down one;
  - order decides between two serving nodes;
- a schedule is followed when it appears, kept when it disappears, and
replaced by another;
  - no answer changes nothing;
  - the warning is given once per run, and only when it matters.
- **Suites:** `cargo test` for `ethlambda-validator`, `ethlambda-types`,
`ethlambda-storage` (with `rocksdb`), `ethlambda-rpc`,
`ethlambda-blockchain --lib` and the `ethlambda` binary all pass. That
includes #873's tests. `make fmt` and `make lint` are clean.
- **Not yet run on a devnet.** The expected result is that ethlambda's
blocks join the "raises" column, at the usual ~1/1024 per block, toward
200M.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants