Repository navigation
perf(beacon): verify attestations against committee key sums - #742
MegaRedHand wants to merge 79 commits into
Conversation
… addition A committee's key sum is the largest cost left in verifying an attestation once its keys are cached. Folding the keys one by one through AggregatePublicKey::aggregate pays a projective addition per key; blst_p1s_add (reached through the safe MultiPoint::add) shares one field inversion across the batch and runs 1.6-2.3x faster in a single-threaded measurement. From 384 points up blst also spreads the work over its own thread pool. fast_aggregate_verify and eth_aggregate_pubkeys now sum through one private helper, sum_validated_points, which guards the empty slice (MultiPoint::add indexes the first element). The helper returns the same group element as the sequential sum, including for repeated keys (sync committees are drawn with replacement, so P + P occurs), which the new tests check at sizes around the 384-point threshold. Accepted and rejected inputs are unchanged.
An attestation aggregate usually covers most of its committee, so its verification key is cheaper to derive as the committee's key sum minus the non-attesters than as the sum of the attesters. The result is the same group element, so the pairing check is unchanged; only the number of point additions drops. Each resident shuffling in the committee cache gets a second slot for its committee key sums, so eviction and head pinning stay in one place. Block import only looks the sums up: building them costs a pass over the whole active set, which is more than they save for committees attested once. The epoch precompute worker builds them instead, after it has handed the advanced state to the actor, so the epoch's first block never waits. Sums are keyed by the shuffling key. That is sound because the registry is append-only, a pubkey is never reassigned, and a validator active at epoch E was activated at least MAX_SEED_LOOKAHEAD + 1 epochs earlier, so it is already in the history the decision root commits to. Nothing in block processing calls the new key builder yet.
Block import paid one pairing per signature: the proposer's, the RANDAO reveal, every attestation, the sync aggregate and each slashing, exit and BLS change. A pairing is dominated by its final exponentiation, which a batch pays once, so a block with a dozen signature sets checks in a fraction of the time. ethlambda-crypto gains SignatureSet and verify_signature_sets: resolved checks combined with unpredictable non-zero 64-bit weights from the OS-seeded CSPRNG (without them two invalid signatures can cancel). The state transition builds each set where the specification verifies it and pushes it into a SignatureBatch that the block driver verifies once processing ends. A failing batch re-checks sets one by one so the error still names the first bad signature with its usual label. Signatures whose failure rejects the block are deferred; deposit signatures, whose failure only skips the deposit, stay immediate, as does epoch processing. process_block keeps its meaning and signature, apply_block adds the proposer's signature to the same batch. The operation packer in block production uses an immediate batch so a rejected candidate still writes nothing. The attestation validity helpers are split into a set builder plus the existing bool function, so gossip and fork choice are untouched.
SignatureSet::fast_aggregate now sums its keys with part a's batched sum_validated_points instead of a sequential AggregatePublicKey::aggregate, and the identity-key check in verify_signature_sets documents that blst rejects the same input.
Brings in the per-block signature batch and the batched key sums. The two parts each added a point-sum helper. The batched one now lives in bls.rs as a single projective sum, with sum_validated_points a thin wrapper that converts to affine once, so committee key sums (which add and subtract projective points) do not pay a field inversion per conversion. The committee-sum module uses that helper instead of its own, and AggregatePubkey::verify shares its pairing path with the new SignatureSet::from_aggregate.
Electra, fulu and gloas process_attestation now build the attestation's signature set from attesters_aggregate_pubkey, which derives the key as the warmed committee sum minus the non-attesters when most of the committee attested, and sums the attesters otherwise. The key is the same group element either way, so the verdict is unchanged; only the point additions differ. Import still never builds the sums: with them cold, the builder sums the attesters directly. The indexed attestation is still built for the participation flags, and the structural checks on it (non-empty, sorted and unique, gloas's length bound) and the push label are the ones the indexed path made. The spec runners use a fresh committee cache, which only ever runs the cold branch, so electra-and-later attestation cases and every block run now run a second time with the sums warmed. Both runs must reach the same verdict and post-state.
The replay drives import_block directly with no tick loop, so the epoch precompute worker never runs and committee key sums stay cold; the committee-sum saving is invisible in a replay although a live node gets it. The flag warms each epoch's sums before its first block, outside every measured span, so the warm-up is in no phase and no wall_seconds. It is recorded in the report params and the human header.
perf(beacon): committee key sums, warmed off the import path An attestation aggregate usually covers most of its committee, so its verification key is cheaper to derive as the committee's key sum minus the non-attesters than as the sum of the attesters. The result is the same group element, so the pairing check is unchanged; only the number of point additions drops. Each resident shuffling in the committee cache gets a second slot for its committee key sums, so eviction and head pinning stay in one place. Block import only looks the sums up: building them costs a pass over the whole active set, which is more than they save for committees attested once. The epoch precompute worker builds them instead, after it has handed the advanced state to the actor, so the epoch's first block never waits. Sums are keyed by the shuffling key. That is sound because the registry is append-only, a pubkey is never reassigned, and a validator active at epoch E was activated at least MAX_SEED_LOOKAHEAD + 1 epochs earlier, so it is already in the history the decision root commits to. Nothing in block processing calls the new key builder yet. perf(beacon): verify attestations against committee key sums Electra, fulu and gloas process_attestation now build the attestation's signature set from attesters_aggregate_pubkey, which derives the key as the warmed committee sum minus the non-attesters when most of the committee attested, and sums the attesters otherwise. The key is the same group element either way, so the verdict is unchanged; only the point additions differ. Import still never builds the sums: with them cold, the builder sums the attesters directly. The indexed attestation is still built for the participation flags, and the structural checks on it (non-empty, sorted and unique, gloas's length bound) and the push label are the ones the indexed path made. The spec runners use a fresh committee cache, which only ever runs the cold branch, so electra-and-later attestation cases and every block run now run a second time with the sums warmed. Both runs must reach the same verdict and post-state. feat(benchmark): add --warm-committee-sums to the import replay The replay drives import_block directly with no tick loop, so the epoch precompute worker never runs and committee key sums stay cold; the committee-sum saving is invisible in a replay although a live node gets it. The flag warms each epoch's sums before its first block, outside every measured span, so the warm-up is in no phase and no wall_seconds. It is recorded in the report params and the human header. Cherry-picked from perf/committee-key-sums at 508c43e.
A key and its negation are both valid, so a registry can hold both and an aggregate can name both. Pin that the batched sum still matches the sequential one when keys cancel, that such a pair aggregates to the identity, and that the identity never verifies. Also state the CPU-count condition on blst's pool.
…tch unverified A block fetched by request reaches the state transition without gossip's precheck, and with the proposer's signature in the body's batch a block its proposer never signed was only rejected after the whole body ran. Check that one signature on its own again, before the body, as before the batch existed. A deferring SignatureBatch could also be built and dropped without its sets ever being checked, turning any function that takes one into "valid except for its signatures". Outside the crate, a deferring batch now only comes from SignatureBatch::deferred, which verifies once its closure returns. Also cover an infinity signature inside a batch and keys that cancel.
# Conflicts: # crates/blockchain/state_transition/tests/beacon_spec/operations.rs
…arm missed epochs With the sums cold, every committee was summed on its own, and each sum of a few hundred keys paid blst's pool dispatch separately where the plain path made one sum over all attesters: a cold multi-committee aggregate got slower than before this change. Every directly summed committee now goes into one sum, so the cold path is that plain sum again. Warming only ran for the epoch a precompute worker advanced into. The worker now also warms the previous epoch (after a restart mid-epoch, or a boundary whose worker did not run), and a boundary state someone else already cached (a gloas bid for the epoch's first slot) gets a warm-only task instead of no warm-up at all. Pre-electra states skip it, since nothing reads the sums there, and the warm-up histogram now times the sums alone, only when they are built.
🤖 Claude Code ReviewReview of PR 742: warm committee key sums and use them in electra and gloas attestation verificationI read the diff but did not build it or run the tests, so everything below comes from reading the code. Overall: the design is sound and carefully argued. Warming happens off the import path. The cold path stays a single flat sum. The sum-minus-absentees result is the same group element as summing the attesters, so the pairing check can't tell them apart. The correctness argument for sharing sums on the Checked and fine
Minor points
Approve, with point 1 worth confirming before merge. Automated review by Claude (Anthropic) · sonnet · custom prompt |
🤖 Codex Code ReviewOverall this looks solid. I didn’t spot a consensus/safety bug in the changed logic, and the fallback behavior is conservative: when precomputed sums are missing or unusable, the code falls back to direct key summation rather than accepting anything it shouldn’t.
Looks good to me aside from the small blocking-pool/perf concern in Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
🤖 Kimi Code ReviewI'll review this PR which introduces committee key sum caching to optimize attestation verification in Electra and later forks. Let me analyze the changes systematically. Overall AssessmentThis is a well-structured optimization PR that caches BLS public key sums per committee to speed up attestation verification. The core insight is sound: for committees with high attestation rates, subtracting absentee keys from a precomputed sum is cheaper than summing all attesters from scratch. Critical Issues1. Potential Race Condition in
|
| Priority | Item | File | Line |
|---|---|---|---|
| Critical | Wrong parameter type in warm_committee_sums calls |
replay.rs |
133, 150 |
| High | Overflow risk in majority check | electra.rs |
600 |
| Medium | Typo in comment | epoch_precompute.rs |
200 |
| Low | Metrics bucket upper bound | metrics.rs |
151 |
| Low | decide re-evaluation clarity |
epoch_precompute.rs |
198-210 |
The core cryptography and consensus logic is well-designed and correct. The main blocker is the compilation error in replay.rs.
Automated review by Kimi (Moonshot AI) · kimi-k2.6 · custom prompt
…review fixes perf(beacon): keep cold committee sums at the plain path's cost and warm missed epochs With the sums cold, every committee was summed on its own, and each sum of a few hundred keys paid blst's pool dispatch separately where the plain path made one sum over all attesters: a cold multi-committee aggregate got slower than before this change. Every directly summed committee now goes into one sum, so the cold path is that plain sum again. Warming only ran for the epoch a precompute worker advanced into. The worker now also warms the previous epoch (after a restart mid-epoch, or a boundary whose worker did not run), and a boundary state someone else already cached (a gloas bid for the epoch's first slot) gets a warm-only task instead of no warm-up at all. Pre-electra states skip it, since nothing reads the sums there, and the warm-up histogram now times the sums alone, only when they are built. Updates nightly's #742 from perf/committee-key-sums at 508c43e to 562b369.
Block import benchmark (offline replay of mainnet blocks, steady state)
Open question: is the cold path expected to be slower than #738's direct sum? If #742 merges together with #743 the gap does not show; if #742 lands alone, it is worth a look. Method
|
🤖 Gemini Code ReviewOverall, this is a very well-designed and thoroughly tested PR. The invariant justifying why committee key sums can share A couple of minor observations:
Automated review by Gemini · gemini-4-argon · custom prompt |
🤖 Kimi Code ReviewNo blocking correctness or security issues found. The cold/warm paths preserve attestation semantics, including invalid-key fallback, empty and identity aggregate rejection, sorted/unique index checks, and the gloas length bound. Key sums are also correctly tied to shuffling-cache eviction, and the warm/cold spec-test runs provide strong consensus-equivalence coverage. Non-blocking performance note:
Automated review by Kimi (Moonshot AI) · kimi-k3.1-pro · custom prompt |
🤖 Grok Code ReviewThe warm-sum design is sound: sums stay off the import path, a miss falls back to the spec sum, and the electra/gloas spec runners comparing cold vs warm post-states are the right check. A few places can still reject a valid attestation or miss the warm-up the benchmark claims to measure.
The shuffling-key write-up (append-only registry, activation lookahead, immutable pubkeys) is the consensus-critical claim, and it is argued carefully. Subtraction matches the attester sum only while a validator cannot appear twice in one slot’s committees: the warm path is a multiset of bit positions, the indexed path is a set. Worth a debug assert if that assignment rule is ever relaxed. Crypto tests for Automated review by Grok (xAI) · grok-4.7 · custom prompt |
🤖 DeepSeek Code ReviewAutomated review by DeepSeek |
… addition A committee's key sum is the largest cost left in verifying an attestation once its keys are cached. Folding the keys one by one through AggregatePublicKey::aggregate pays a projective addition per key; blst_p1s_add (reached through the safe MultiPoint::add) shares one field inversion across the batch and runs 1.6-2.3x faster in a single-threaded measurement. From 384 points up blst also spreads the work over its own thread pool. fast_aggregate_verify and eth_aggregate_pubkeys now sum through one private helper, sum_validated_points, which guards the empty slice (MultiPoint::add indexes the first element). The helper returns the same group element as the sequential sum, including for repeated keys (sync committees are drawn with replacement, so P + P occurs), which the new tests check at sizes around the 384-point threshold. Accepted and rejected inputs are unchanged.
A key and its negation are both valid, so a registry can hold both and an aggregate can name both. Pin that the batched sum still matches the sequential one when keys cancel, that such a pair aggregates to the identity, and that the identity never verifies. Also state the CPU-count condition on blst's pool.
…mes from The comment credited the sum's existence to `pubkeys` being non-empty without saying what guarantees it. It is the early return at the top of the function, not `validated_pubkeys`, which maps an empty input to an empty `Some`.
Nothing pinned the early return that keeps an empty list away from the batched sum. The identity signature is used because it is the one input `eth_fast_aggregate_verify` accepts for an empty list, so the test also shows the two functions part ways there.
From the second automated review round: - sum_validated_points returns a one-key slice's key as is, skipping blst_p1s_add and its conversion back to affine coordinates for an aggregate with one signer. - MultiPoint::add is called by its trait name, so it does not read like std::ops::Add. - The thread-pool paragraph is tied to blst 0.3.16 and shortened, since its 384-point threshold is that version's. - The size test's comment says plainly which paths a host exercises: one CPU stays on the calling thread and takes two 1024-point scratch passes at 2000 points; two or more split the work into chunks of about 256.
…e RANDAO mix changes A deferred signature let its operation write before the signature was known to be good, and every later operation ran on that write. That is now confined to votes: 1. Proposer and attester slashings, voluntary exits and BLS-to-execution changes call SignatureBatch::verify_pending before they write, so their own sets and every set still pending are checked first. No operation that slashes, exits or redirects a validator writes on a forged signature or runs on a state an earlier forged signature wrote to. A forged one is refused at its own operation. 2. The RANDAO reveal is checked the same way before it is mixed in, the specification's order. In gloas the builder's bid, pushed just before it, is checked in the same batch. 3. A failed batch is bisected to its first failing set instead of re-checking every set on its own: fewer set checks than the batch had, at one final exponentiation per halving, rather than a full pairing per set on top of the batch. Attestations, the sync aggregate and gloas's payload attestations still go into one batch, checked at the next of those points or at the end.
transition_block returned the partly applied copy alongside the error, so nothing but convention kept a caller from reading a state that a rejected block had written to. It now returns Result<BeaconState>, and SpeculativeTransition holds that Result, so a failed transition has no state to read.
Its one caller was verify_block_signature, and as public API it invited batching the proposer's signature again, which would undo the one-pairing rejection of an unsigned block apply_block relies on. verify_block_signature now calls verify_proposer_signature directly.
…ecks Phase0, electra and gloas each had four functions for one check: is_valid_indexed_attestation, its _with_domain variant, and the two matching signature-set builders, with the structural rules copied into each fork's file. The rules now live once, in attestation::attesters_signature_set, which takes the attester list, data and signature of any fork's container and an optional domain. Each fork keeps is_valid_indexed_attestation and indexed_attestation_signature_set, both thin over it: six functions where there were twelve. The _with_domain pair is gone; gossip's aggregate validation, its only caller, calls attesters_signature_set with the schedule's domain. The shared check includes gloas's MAX_VALIDATORS_PER_SLOT bound. Every earlier fork's attester list is bounded at or below it by its own type, so the check changes no earlier fork's answer.
key_is_identity changed no behavior, by its own documentation: blst refuses an infinite public key wherever it adds one to a pairing (BLST_PK_IS_INFINITY in blst/src/aggregate.c), on the batch path and the single path alike, and the single-set arm returned before the check anyway. The tests that pin it stay: [P, -P] fails alone and inside a batch, with the identity signature and with a real one. Also states what the random weights' soundness rests on. rand::rng() is a ChaCha12 generator seeded from the operating system; rand 0.10.1, the locked version, still reseeds it every 64 KiB, but the argument does not need that.
bls::verify and bls::fast_aggregate_verify each repeated the validate, sum and pair sequence SignatureSet holds, so only tests kept gossip and fork choice deciding a signature the way block import does. They are now SignatureSet::single and SignatureSet::fast_aggregate followed by its verify. eth_fast_aggregate_verify's empty-participants rule (valid exactly with G2_POINT_AT_INFINITY) was written twice: in bls, which block production's sync-aggregate check calls, and inline in altair's process_sync_aggregate. It now lives in SignatureSet::eth_fast_aggregate, which answers Valid, Invalid, or the set whose pairing decides. bls::eth_fast_aggregate_verify is that answer checked now, and the sync aggregate pushes the set or rejects from it.
…t module scope The state transition's metrics are module-scoped LazyLock statics, as CLAUDE.md prefers; this was the one function-scoped. Its help text and docs/metrics.md now say what it counts since the failing set is found by bisection: a failed batch whose narrowed-to set verifies alone.
… writes Pins the ordering for one of the operations that change a validator's record: through a batch that defers, a forged BLS-to-execution change is refused by the operation itself, and a genuine one is refused under the earlier set's label while a forged set is pending, with the credentials untouched both times. With the signature deferred to the end of the block, the first call returned Ok and rewrote them.
…check The signatures module doc said deferral was confined to votes, but process_execution_payload_bid records the builder's payment and the bid before its signature is checked. It is checked right after, with the RANDAO reveal, before any operation runs, whenever the reveal is verified (always on import; block production skips it for its own block). The doc now says so. Also corrects the cost wording: a bisection costs about what the batch did, not less, and a lone check is a pairing with a Miller loop of its own for the signature, which is what a batch saves along with the final exponentiation.
Stack 3/4 of the BLS verification work: (a) batched key sums -> (b) per-block signature batch -> (c) committee key sums -> (d) index-keyed pubkey cache. Based on (b).
An attestation aggregate usually covers most of its committee, and its verification key is the sum of the attesters' keys. This PR precomputes each committee's key sum once per shuffling, off the import path, and derives an attestation's key as
committee_sum - sum(non-attesters)when more than half the committee attested, and assum(attesters)otherwise. The group element is the same either way, so the pairing check is unchanged; only the number of point additions differs (absentees instead of attesters).What it changes on top of the signature batch
ethlambda-cryptobls/committee_sums.rs:AggregatePubkey(sum,minus,plus,verify) andCommitteeKeySums. Negation uses blst's safesub_aggregate, so there is nounsafe.SignatureSet::from_aggregate(key, message, signature): builds a set from an already-summed key (Nonewhen the signature failssig_validate; one affine conversion of the key).AggregatePubkey::verifydelegates to it, so both checks share one path, and the batch's identity-key guard covers it.bls.rs(sum_validated_projective); the batched-key-sum PR'ssum_validated_pointsis now a thin wrapper that converts to affine once. Committee sums add and subtract projective points, so building them on the affine helper would cost an extra field inversion per committee, about 512 per block.ethlambda-storage: each resident shuffling gets a secondOnceLock<Arc<CommitteeKeySums>>beside its committees, so eviction and head pinning stay in one place and the sums die with their shuffling.resident_key_sumsis lookup only;get_or_init_key_sumsbuilds into a resident entry and never holds the entry-list lock while building.ethlambda-state-transitionCommitteeCacheExt::key_sums(lookup only: import never builds) andwarm_key_sums(oneiter_validators()pass, then rayon across committees). A committee with an invalid member key gets no sum and falls back to the direct path.attesters_aggregate_pubkey(helpers/electra.rs), with the majority rule, usable by gloas through the sameis_setclosure asattesting_indices_from_committee_bits. Committees derived from their sums are added one by one; the attesters of every committee summed directly go into one sum. With cold sums that is the single sum over every attester that perf(beacon): verify a block's signatures in one random-weight batch #738 makes, at its cost: one sum per committee would pay blst's pool dispatch once per committee for a few hundred keys each, which made the cold path slower than perf(beacon): verify a block's signatures in one random-weight batch #738's.process_attestationbuild theirSignatureSetfrom it (electra_attestation_signature_set,gloas_attestation_signature_set). The indexed attestation is still built, for the participation flags, and the same structural checks are made on it (non-empty, sorted and unique; gloas'sMAX_VALIDATORS_PER_SLOTbound). Same signing root, same push label. Phase0 through deneb are unchanged.ethlambda-blockchain(epoch_precompute.rs): the precomputed state is sent to the actor first, then the sums are warmed in the same blocking task, so the epoch's first block never waits for them. The task warms the epoch's sums and the previous epoch's (for the attestations its blocks carry from it), so a restart mid-epoch or a boundary whose worker did not run is covered at the next one. When the boundary state is already cached (a gloas bid for the epoch's first slot advances it), no worker runs, so a warm-only task runs from that state instead. Warming is skipped before electra, whose attestations never read the sums. New histogramlean_beacon_committee_key_sums_warm_seconds(indocs/metrics.md), recorded only when sums are actually built and covering the sums alone.Soundness of keying sums by
ShufflingKeyThe sums are filed under (epoch, decision root), so two states with one key must agree on each member's public key as well as on who the members are. Checked against this repo's spec code:
process_deposit, electra's pending-deposit path); a validator's index and pubkey are fixed at append and no code assignspubkeyafterwards.activation_epoch = FAR_FUTURE_EPOCH. Onlyprocess_registry_updates(epoch processing at epoch N) assigns one,compute_activation_exit_epoch(N) = N + 1 + MAX_SEED_LOOKAHEAD.The argument is in the
CommitteeCacheExt::key_sumsdoc comment.Measured
On a heavily loaded M3, blst 0.3.16, single-threaded, block shape of 11 signature sets and 33k signers:
The single-threaded ratio overstates the wall-time gain on a multi-core host, where #738's one large sum already runs on blst's pool. In CPU time, profiling a Hoodi block replay on a Ryzen 9700X (the whole stack, warm sums) puts key summation at 12.3 ms CPU per block before the stack and 1.5 ms after.
Behavior notes
current_sync_committee.pubkeys, which has no committee sums.Tests
New tests:
sum/minus/plusagainst blst's direct sum (including duplicate keys, andminusover 40 random masks of a 64-key committee);verifyagainstbls::fast_aggregate_verifywith real signatures; the identity aggregate rejected; the empty and invalid-key cases.key_sumsnever builds or inserts; sums are built once into a resident shuffling only; sums are evicted with their shuffling.operations/*/attestationcase and every block run (sanity,finality,random) now runs twice, cold and afterwarm_key_sums(previous, current and next epoch of the state each block applies to); both runs must reach the same verdict and post-state.Run (
--profile release-fast):cargo test -p ethlambda-crypto --lib: 35 passed, 14 ignoredcargo test -p ethlambda-storage --lib: 213 passed, 1 ignoredcargo test -p ethlambda-state-transition --lib --features beacon-spec-tests: 658 passedbeacon_spec_tests -- /attestation/: 356 passed;-- sanity/: 595 passed;-- random/: 1969 passed, 175 ignoredbeacon_spec_tests: 7493 passed, 977 ignoredcargo fmt --all; clippy-D warnings --all-targetson crypto, storage, state-transition, blockchain: cleanethlambda-blockchain --lib(before the merge): 291 passed, 43 ignoredOn this branch after its review fixes: crypto
--lib40 passed; storage 213; state-transition--lib658; blockchain 291;beacon_spec_testsoperations/2141,sanity/595,finality/41,fork_choice/206,random/1969 (175 ignored),transition/172,sync/6 passed.Rerun after the review fixes, on the stack's tip (all four PRs,
--profile release-fast):ethlambda-crypto --lib47 passed, 14 ignored;ethlambda-state-transition --lib --features beacon-spec-tests(with the BLS fixture vectors) 658 passed; storage 213, blockchain 291, p2p 362, rpc 335 passed; fullbeacon_spec_tests7493 passed, 977 ignored, 0 failed;make lintclean, also on a trial merge of currentmain.