fix: add proposer index bounds check before signature verification - #9194
Conversation
Without this check, a block with proposer_index >= len(state.validators)
causes a raw Error ("Missing pubkey for validator index N") in the pubkey
cache during signature verification, instead of a clean REJECT with
UNKNOWN_PROPOSER error code.
Spec: [REJECT] The proposer_index is valid -- i.e.
block.proposer_index < len(state.validators)
🤖 Generated with AI assistance
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| } | ||
| } | ||
|
|
||
| // [REJECT] The proposer_index is valid -- i.e. block.proposer_index < len(state.validators) |
There was a problem hiding this comment.
that condition doesn't exist in the spec??
There was a problem hiding this comment.
It's in the executable spec from PR #5047 (bellatrix gossip validation):
# [REJECT] The proposer index is a valid validator index
if block.proposer_index >= len(state.validators):
raise GossipReject("proposer index out of range")The prose spec doesn't have it explicitly — it's implied by the signature check (no valid pubkey for an out-of-range index). But without this guard, the pubkey cache throws a raw Error before the signature verification runs, which bypasses the GossipActionError path entirely.
The test vectors also expect REJECT for reject_invalid_proposer_index. If you'd prefer a different approach (e.g., wrapping the signature path to catch the pubkey lookup error), happy to change it.
There was a problem hiding this comment.
ok please align the comment with whats' in 5047
There was a problem hiding this comment.
Updated the comment to match the spec wording from #5047.
There was a problem hiding this comment.
Code Review
This pull request introduces a validation check in validateGossipBlock to ensure the proposer_index is within the valid range of the state's validator count. If the index is invalid, the block is rejected with an UNKNOWN_PROPOSER error. I have no feedback to provide.
🤖 Generated with AI assistance Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
06a0c33
into
ChainSafe:nflaig/bellatrix-capella-gossip-tests-2
Summary
proposer_index < len(state.validators)bounds check before signature verification in gossip block validationMissing pubkey for validator indexcrash in the pubkey cache instead of a clean REJECTBlockErrorCode.UNKNOWN_PROPOSERerror codeSpec reference:
[REJECT] The proposer_index is valid -- i.e. block.proposer_index < len(state.validators)Test plan
gossip_beacon_block__reject_invalid_proposer_indexnow passes for both phase0 and bellatrix (was crashing before)🤖 Generated with AI assistance