Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum ProposerPreferencesErrorCode {
INVALID_EPOCH = "PROPOSER_PREFERENCES_ERROR_INVALID_EPOCH",
PROPOSAL_SLOT_PASSED = "PROPOSER_PREFERENCES_ERROR_PROPOSAL_SLOT_PASSED",
UNKNOWN_DEPENDENT_ROOT = "PROPOSER_PREFERENCES_ERROR_UNKNOWN_DEPENDENT_ROOT",
INVALID_DEPENDENT_ROOT = "PROPOSER_PREFERENCES_ERROR_INVALID_DEPENDENT_ROOT",
INVALID_PROPOSER = "PROPOSER_PREFERENCES_ERROR_INVALID_PROPOSER",
ALREADY_KNOWN = "PROPOSER_PREFERENCES_ERROR_ALREADY_KNOWN",
INVALID_SIGNATURE = "PROPOSER_PREFERENCES_ERROR_INVALID_SIGNATURE",
Expand All @@ -26,6 +27,11 @@ export type ProposerPreferencesErrorType =
proposalSlot: Slot;
dependentRoot: RootHex;
}
| {
code: ProposerPreferencesErrorCode.INVALID_DEPENDENT_ROOT;
proposalSlot: Slot;
dependentRoot: RootHex;
}
| {
code: ProposerPreferencesErrorCode.INVALID_PROPOSER;
proposalSlot: Slot;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {SLOTS_PER_EPOCH} from "@lodestar/params";
import {GENESIS_SLOT, MIN_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params";
import {
computeEpochAtSlot,
computeStartSlotAtEpoch,
createSingleSignatureSetFromComponents,
getProposerPreferencesSigningRoot,
} from "@lodestar/state-transition";
Expand Down Expand Up @@ -70,6 +71,24 @@ export async function validateGossipProposerPreferences(
});
}

// [REJECT] A dependent block after the lookahead decision slot cannot be the block the proposer
// lookahead was derived from. `get_proposer_dependent_root` is `block_root_at_slot(
// start_slot(proposal_epoch - MIN_SEED_LOOKAHEAD) - 1)` clamped to `GENESIS_SLOT`, so a valid
// dependent block is at or before that (clamped) decision slot. Clamping keeps genesis-epoch
// dependents (`proposalEpoch <= MIN_SEED_LOOKAHEAD` → the genesis block) valid instead of
// underflowing to a negative slot and rejecting every early-epoch preference. Kept after the
// proposer-resolution IGNORE so a dependent root whose state is unavailable stays IGNORE (per the
// `ignore_dependent_root_state_unavailable` spec fixture), not REJECT.
const decisionSlot = Math.max(GENESIS_SLOT, computeStartSlotAtEpoch(proposalEpoch - MIN_SEED_LOOKAHEAD) - 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we make the comment less verbose please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Trimmed to 2 lines in bd6b61ac72 (kept the GENESIS_SLOT clamp + the after-IGNORE ordering note).

const dependentBlock = chain.forkChoice.getBlockHexDefaultStatus(dependentRootHex);
if (dependentBlock !== null && dependentBlock.slot > decisionSlot) {
throw new ProposerPreferencesError(GossipAction.REJECT, {
code: ProposerPreferencesErrorCode.INVALID_DEPENDENT_ROOT,
proposalSlot,
dependentRoot: dependentRootHex,
});
}

// [REJECT] `is_valid_proposal_slot(state, preferences)` returns True.
if (proposers[proposalSlot % SLOTS_PER_EPOCH] !== validatorIndex) {
throw new ProposerPreferencesError(GossipAction.REJECT, {
Expand Down
Loading