Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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 @@ -17,7 +17,7 @@ import {toRootHex} from "@lodestar/utils";
export class ProposerPreferencesPool {
private readonly bySlot = new Map<Slot, Map<RootHex, gloas.SignedProposerPreferences>>();

/** Lookup for bid validation: matches `(bid.slot, get_proposer_dependent_root(parent_state, ...))`. */
/** Lookup for bid validation: matches `(bid.slot, get_shuffling_dependent_root(store, bid.parent_block_root, epoch))`. */
get(slot: Slot, dependentRootHex: RootHex): gloas.SignedProposerPreferences | null {
return this.bySlot.get(slot)?.get(dependentRootHex) ?? null;
}
Expand Down
15 changes: 11 additions & 4 deletions packages/beacon-node/src/chain/validation/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,17 @@ async function validateAttestationNoSignatureCheck(
// [REJECT] If `attestation.data.index == 1` (payload present for a past
// block), the execution payload for `block` passes validation.
// [IGNORE] When `attestation.data.index == 1` (payload present for a past block),
// the corresponding execution payload for `block` has been seen (a client MAY queue
// attestations for processing once the payload is retrieved and SHOULD request the
// payload envelope via `ExecutionPayloadEnvelopesByRoot`).
if (block !== null && attData.index === 1 && !chain.seenPayloadEnvelope(toRootHex(attData.beaconBlockRoot))) {
// the corresponding execution payload for `block` has been fully imported, including its
// data -- i.e. `is_payload_verified(store, beacon_block_root)` returns True (consensus-specs
// #5355). `forkChoice.hasPayloadHexUnsafe` is the equivalent of `root in store.payloads`:
// it is true only once the SignedExecutionPayloadEnvelope has been imported and verified,
// not merely seen on gossip. A client MAY queue attestations until the payload is imported
// and SHOULD request the payload envelope via `ExecutionPayloadEnvelopesByRoot`.
if (
block !== null &&
attData.index === 1 &&
!chain.forkChoice.hasPayloadHexUnsafe(toRootHex(attData.beaconBlockRoot))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Mirror imported-payload gating for aggregates

This updates the unaggregated attestation path to require forkChoice.hasPayloadHexUnsafe, but the aggregate path still uses chain.seenPayloadEnvelope in packages/beacon-node/src/chain/validation/aggregateAndProof.ts:99. In Gloas, an index == 1 aggregate submitted through publishAggregateAndProofsV2 can therefore be accepted and published while the envelope is only in seenPayloadEnvelopeInputCache and not fully imported with data, even though the alpha.12 gossip rule requires is_payload_verified for beacon_aggregate_and_proof too. Please apply the same fork-choice payload check there.

Useful? React with 👍 / 👎.

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.

yes this is valid

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Addressed as of c00a00bc8c ("fix: require imported payload for index==1 aggregate gossip"): the index == 1 aggregate path in aggregateAndProof.ts now gates on !chain.forkChoice.hasPayloadHexUnsafe(toRootHex(attData.beaconBlockRoot)) → IGNORE EXECUTION_PAYLOAD_NOT_SEEN, structurally identical to the unaggregated path in attestation.ts:330. No seenPayloadEnvelope reference remains in the file, so publishAggregateAndProofsV2 now enforces the same is_payload_verified gossip rule. Good catch by the bot.

) {
throw new AttestationError(GossipAction.IGNORE, {
code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
beaconBlockRoot: toRootHex(attData.beaconBlockRoot),
Expand Down
3 changes: 0 additions & 3 deletions packages/beacon-node/src/chain/validation/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD,
MAX_BUILDER_EXIT_REQUESTS_PER_PAYLOAD,
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD,
MAX_DEPOSIT_REQUESTS_PER_PAYLOAD,
MAX_PAYLOAD_ATTESTATIONS,
MAX_PROPOSER_SLASHINGS,
MAX_VOLUNTARY_EXITS,
Expand Down Expand Up @@ -182,7 +181,6 @@ export async function validateGossipBlock(

// [REJECT] The counts of `block.body.parent_execution_requests` are within
// their respective limits -- i.e. validate that
// `len(block.body.parent_execution_requests.deposits) <= MAX_DEPOSIT_REQUESTS_PER_PAYLOAD`,
// `len(block.body.parent_execution_requests.withdrawals) <= MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD`,
// `len(block.body.parent_execution_requests.consolidations) <= MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD`,
// `len(block.body.parent_execution_requests.builder_deposits) <= MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD`,
Expand All @@ -200,7 +198,6 @@ export async function validateGossipBlock(
const body = (block as gloas.BeaconBlock).body;
const requests = body.parentExecutionRequests;
const countLimits: [string, number, number][] = [
["parentExecutionRequests.deposits", requests.deposits.length, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD],
["parentExecutionRequests.withdrawals", requests.withdrawals.length, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD],
[
"parentExecutionRequests.consolidations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ async function validateExecutionPayloadBid(
});
}

// [REJECT] `bid.fee_recipient == proposer_preferences.fee_recipient`.
// [IGNORE] `bid.fee_recipient == proposer_preferences.fee_recipient`.
if (!byteArrayEquals(bid.feeRecipient, proposerPreferences.message.feeRecipient)) {
throw new ExecutionPayloadBidError(GossipAction.REJECT, {
throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_FEE_RECIPIENT_MISMATCH,
builderIndex: bid.builderIndex,
bidFeeRecipient: toHex(bid.feeRecipient),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD,
MAX_BUILDER_EXIT_REQUESTS_PER_PAYLOAD,
MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD,
MAX_DEPOSIT_REQUESTS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD,
} from "@lodestar/params";
Expand Down Expand Up @@ -128,7 +127,6 @@ async function validateExecutionPayloadEnvelope(
// are enforced here in gossip validation.
const {executionRequests} = envelope;
const requestCountLimits: [string, number, number][] = [
["deposits", executionRequests.deposits.length, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD],
["withdrawals", executionRequests.withdrawals.length, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD],
["consolidations", executionRequests.consolidations.length, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD],
["builderDeposits", executionRequests.builderDeposits.length, MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD],
Expand Down
3 changes: 1 addition & 2 deletions packages/beacon-node/src/network/gossip/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
MAX_ATTESTER_SLASHING_SIZE,
MAX_DATA_COLUMN_SIDECAR_SIZE,
MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE,
MAX_SIGNED_BEACON_BLOCK_SIZE,
MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE,
SYNC_COMMITTEE_SUBNET_COUNT,
isForkPostAltair,
Expand Down Expand Up @@ -145,7 +144,7 @@ export function getGossipSSZMaxSize(topic: GossipTopic, maxPayloadSize: number,
// Gloas progressive containers have broad theoretical SSZ max sizes; use the preset p2p bounds instead.
switch (topic.type) {
case GossipType.beacon_block:
return isForkPostGloas(fork) ? MAX_SIGNED_BEACON_BLOCK_SIZE : maxPayloadSize;
return maxPayloadSize;
case GossipType.beacon_aggregate_and_proof:
return isForkPostGloas(fork) ? MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE : (sszType ?? getGossipSSZType(topic)).maxSize;
case GossipType.attester_slashing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ export function validateExecutionPayloadEnvelopesByRangeRequest(
// The gloas req/resp spec uses MIN_EPOCHS_FOR_BLOCK_REQUESTS to define the minimum range peers MUST serve.
// Archival nodes may still serve older retained payloads to allow genesis sync.

if (count > config.MAX_REQUEST_BLOCKS_DENEB) {
count = config.MAX_REQUEST_BLOCKS_DENEB;
// Spec: EnvelopesByRange response is bounded by MAX_REQUEST_PAYLOADS (consensus-specs #5383),
// distinct from the MAX_REQUEST_BLOCKS_DENEB cap used for block-by-range.
if (count > config.MAX_REQUEST_PAYLOADS) {
count = config.MAX_REQUEST_PAYLOADS;
}

return {startSlot, count};
Expand Down
19 changes: 0 additions & 19 deletions packages/beacon-node/test/spec/utils/specTestIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,10 @@ export const defaultSkipOpts: SkipOpts = {
// New test suite added in v1.7.0-alpha.8 (consensus-specs #5206); gloas PTC fork choice
// handling is not yet implemented in Lodestar.
/^gloas\/fork_choice\/on_payload_attestation_message\/.*$/,
// TODO GLOAS: Unskip in #9606
/^gloas\/operations\/builder_deposit_request\/.*$/,
],
skippedTests: [
// TODO-GLOAS: re-enable after gloas light client is implemented
/\/gloas_fork$/,
// TODO GLOAS: Unskip in #9606

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.

it's great to see we removed a lot of skipped tests in this PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks 🙏 — most of the gloas handlers that were stubbed through the earlier alphas are implemented now, so the skips could go. A few remain with TODOs for follow-up (the on_payload_attestation_message fork-choice handler, the gloas light-client path, and the networking runner that's been skipped since alpha.5).

/^gloas\/operations\/builder_deposit_request\/.*$/,
/\/fork_builder_deposit_followed_by_non_builder_credentials$/,
/\/fork_builder_deposit_uses_deposit_slot_epoch$/,
/\/fork_builder_deposit_version$/,
/\/fork_invalid_builder_deposit_followed_by_valid_builder_deposit$/,
/\/fork_invalid_validator_deposit_followed_by_builder_credentials$/,
/\/fork_mixed_pending_deposits$/,
/\/fork_multiple_builder_deposits$/,
/\/fork_multiple_deposits_same_builder$/,
/\/fork_single_builder_deposit$/,
/\/fork_valid_builder_deposit_followed_by_invalid_builder_deposit$/,
/\/deposit_requests_greater_than_electra_max$/,
/\/process_parent_execution_payload__new_builder_does_not_reuse_topped_up_builder_slot$/,
/\/process_builder_exit_request__success$/,
/\/process_parent_execution_payload__builder_exit_request$/,
/\/switch_to_compounding_with_pending_consolidations_at_limit$/,
],
// TODO GLOAS: Investigate why networking tests are failing since alpha.5
skippedRunners: ["networking"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
MAX_ATTESTER_SLASHING_SIZE,
MAX_DATA_COLUMN_SIDECAR_SIZE,
MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE,
MAX_SIGNED_BEACON_BLOCK_SIZE,
MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE,
ZERO_HASH,
} from "@lodestar/params";
Expand Down Expand Up @@ -274,7 +273,7 @@ describe("network / gossip / topic", () => {
config.MAX_PAYLOAD_SIZE
),
}).toEqual({
[GossipType.beacon_block]: MAX_SIGNED_BEACON_BLOCK_SIZE,
[GossipType.beacon_block]: config.MAX_PAYLOAD_SIZE,
[GossipType.data_column_sidecar]: MAX_DATA_COLUMN_SIDECAR_SIZE,
[GossipType.beacon_aggregate_and_proof]: MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE,
[GossipType.attester_slashing]: MAX_ATTESTER_SLASHING_SIZE,
Expand Down
8 changes: 4 additions & 4 deletions packages/config/src/chainConfig/configs/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const chainConfig: ChainConfig = {
SECONDS_PER_ETH1_BLOCK: 14,
// 2**8 (= 256) epochs ~27 hours
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256,
// 2**13 (= 8,192) epochs ~36 days
MIN_BUILDER_WITHDRAWABILITY_DELAY: 8192,
// 2**6 (= 64) epochs ~6.8 hours
MIN_BUILDER_WITHDRAWABILITY_DELAY: 64,
// 2**8 (= 256) epochs ~27 hours
SHARD_COMMITTEE_PERIOD: 256,
// 2**11 (= 2,048) Eth1 blocks ~8 hours
Expand Down Expand Up @@ -99,8 +99,8 @@ export const chainConfig: ChainConfig = {
CONTRIBUTION_DUE_BPS_GLOAS: 5000,
// 75% of SLOT_DURATION_MS
PAYLOAD_ATTESTATION_DUE_BPS: 7500,
// 75% of SLOT_DURATION_MS
PAYLOAD_DUE_BPS: 7500,
// 50% of SLOT_DURATION_MS
PAYLOAD_DUE_BPS: 5000,

// Validator cycle
// ---------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/chainConfig/configs/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export const chainConfig: ChainConfig = {
CONTRIBUTION_DUE_BPS_GLOAS: 5000,
// 75% of SLOT_DURATION_MS
PAYLOAD_ATTESTATION_DUE_BPS: 7500,
// 75% of SLOT_DURATION_MS
PAYLOAD_DUE_BPS: 7500,
// 50% of SLOT_DURATION_MS
PAYLOAD_DUE_BPS: 5000,

// Validator cycle
// ---------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions packages/config/test/e2e/ensure-config-is-synced.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ const ignoredRemoteConfigFields: (keyof ChainConfig)[] = [
// These are preset values, not config values - they're tested separately
"PRESET_BASE",
"CONFIG_NAME",
// TODO GLOAS: Unskip in #9606
"PAYLOAD_DUE_BPS" as keyof ChainConfig,
"MIN_BUILDER_WITHDRAWABILITY_DELAY" as keyof ChainConfig,
];

/**
Expand Down
5 changes: 1 addition & 4 deletions packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,12 @@ export const {
MAX_PAYLOAD_ATTESTATIONS,
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD,
MAX_BUILDER_EXIT_REQUESTS_PER_PAYLOAD,
BUILDER_REGISTRY_LIMIT,
BUILDER_PENDING_WITHDRAWALS_LIMIT,
MAX_BUILDERS_PER_WITHDRAWALS_SWEEP,
MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE,
MAX_ATTESTER_SLASHING_SIZE,
MAX_DATA_COLUMN_SIDECAR_SIZE,
MAX_PARTIAL_DATA_COLUMN_SIDECAR_SIZE,
MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE,
MAX_SIGNED_BEACON_BLOCK_SIZE,
} = activePreset;

////////////
Expand All @@ -152,7 +149,7 @@ export const ZERO_HASH_HEX = "0x" + "00".repeat(32);
export const BLS_WITHDRAWAL_PREFIX = 0x00;
export const ETH1_ADDRESS_WITHDRAWAL_PREFIX = 0x01;
export const COMPOUNDING_WITHDRAWAL_PREFIX = 0x02;
export const BUILDER_WITHDRAWAL_PREFIX = 0x03;
export const BUILDER_WITHDRAWAL_PREFIX = 0xb0;

// Builder version
export const PAYLOAD_BUILDER_VERSION = 0;
Expand Down
5 changes: 1 addition & 4 deletions packages/params/src/presets/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ export const mainnetPreset: BeaconPreset = {
// GLOAS
PTC_SIZE: 512,
MAX_PAYLOAD_ATTESTATIONS: 4,
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD: 256, // 2**8
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD: 64, // 2**6
MAX_BUILDER_EXIT_REQUESTS_PER_PAYLOAD: 16, // 2**4
BUILDER_REGISTRY_LIMIT: 1099511627776, // 2**40
BUILDER_PENDING_WITHDRAWALS_LIMIT: 1048576, // 2**20
MAX_BUILDERS_PER_WITHDRAWALS_SWEEP: 16384, // 2**14

// Type-specific SSZ bounds
Expand All @@ -158,5 +156,4 @@ export const mainnetPreset: BeaconPreset = {
MAX_DATA_COLUMN_SIDECAR_SIZE: 8585272,
MAX_PARTIAL_DATA_COLUMN_SIDECAR_SIZE: 8585741,
MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE: 196932,
MAX_SIGNED_BEACON_BLOCK_SIZE: 4027336,
};
5 changes: 1 addition & 4 deletions packages/params/src/presets/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ export const minimalPreset: BeaconPreset = {
// GLOAS
PTC_SIZE: 16,
MAX_PAYLOAD_ATTESTATIONS: 4,
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD: 256, // 2**8
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD: 64, // 2**6
MAX_BUILDER_EXIT_REQUESTS_PER_PAYLOAD: 16, // 2**4
BUILDER_REGISTRY_LIMIT: 1099511627776, // 2**40
BUILDER_PENDING_WITHDRAWALS_LIMIT: 1048576, // 2**20
MAX_BUILDERS_PER_WITHDRAWALS_SWEEP: 16, // 2**4

// Type-specific SSZ bounds
Expand All @@ -159,5 +157,4 @@ export const minimalPreset: BeaconPreset = {
MAX_DATA_COLUMN_SIDECAR_SIZE: 8585272,
MAX_PARTIAL_DATA_COLUMN_SIDECAR_SIZE: 8585741,
MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE: 196932,
MAX_SIGNED_BEACON_BLOCK_SIZE: 1938012,
};
6 changes: 0 additions & 6 deletions packages/params/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,12 @@ export type BeaconPreset = {
MAX_PAYLOAD_ATTESTATIONS: number;
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD: number;
MAX_BUILDER_EXIT_REQUESTS_PER_PAYLOAD: number;
BUILDER_REGISTRY_LIMIT: number;
BUILDER_PENDING_WITHDRAWALS_LIMIT: number;
MAX_BUILDERS_PER_WITHDRAWALS_SWEEP: number;
MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE: number;
MAX_ATTESTER_SLASHING_SIZE: number;
MAX_DATA_COLUMN_SIDECAR_SIZE: number;
MAX_PARTIAL_DATA_COLUMN_SIDECAR_SIZE: number;
MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE: number;
MAX_SIGNED_BEACON_BLOCK_SIZE: number;
};

/**
Expand Down Expand Up @@ -232,15 +229,12 @@ export const beaconPresetTypes: BeaconPresetTypes = {
MAX_PAYLOAD_ATTESTATIONS: "number",
MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD: "number",
MAX_BUILDER_EXIT_REQUESTS_PER_PAYLOAD: "number",
BUILDER_REGISTRY_LIMIT: "number",
BUILDER_PENDING_WITHDRAWALS_LIMIT: "number",
MAX_BUILDERS_PER_WITHDRAWALS_SWEEP: "number",
MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE: "number",
MAX_ATTESTER_SLASHING_SIZE: "number",
MAX_DATA_COLUMN_SIDECAR_SIZE: "number",
MAX_PARTIAL_DATA_COLUMN_SIDECAR_SIZE: "number",
MAX_SIGNED_EXECUTION_PAYLOAD_BID_SIZE: "number",
MAX_SIGNED_BEACON_BLOCK_SIZE: "number",
};

type BeaconPresetTypes = {
Expand Down
13 changes: 3 additions & 10 deletions packages/params/test/e2e/ensure-config-is-synced.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ import {loadConfigYaml} from "../yaml.js";
* Fields that we filter from local config when doing comparison.
* Ideally this should be empty as it is not spec compliant
*/
// TODO GLOAS: Remove in #9606
const ignoredLocalPresetFields: (keyof BeaconPreset)[] = [
"BUILDER_REGISTRY_LIMIT",
"BUILDER_PENDING_WITHDRAWALS_LIMIT",
"MAX_SIGNED_BEACON_BLOCK_SIZE",
"MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD",
];

// TODO GLOAS: Remove in #9606
const ignoredRemotePresetFields: string[] = ["MAX_BUILDER_DEPOSIT_REQUESTS_PER_PAYLOAD"];
const ignoredLocalPresetFields: (keyof BeaconPreset)[] = [];

const ignoredRemotePresetFields: string[] = [];

describe("Ensure config is synced", () => {
vi.setConfig({testTimeout: 60 * 1000});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {FAR_FUTURE_EPOCH} from "@lodestar/params";
import {FAR_FUTURE_EPOCH, PAYLOAD_BUILDER_VERSION} from "@lodestar/params";
import {gloas} from "@lodestar/types";
import {CachedBeaconStateGloas} from "../types.js";
import {computeEpochAtSlot} from "../util/epoch.js";
import {addBuilderToRegistry, findBuilderIndexByPubkey, isValidBuilderDepositSignature} from "../util/gloas.js";
import {
addBuilderToRegistry,
findBuilderIndexByPubkey,
isBuilderWithdrawalCredential,
isValidBuilderDepositSignature,
} from "../util/gloas.js";

/**
* Process a builder deposit request from the execution layer: register a new builder
Expand All @@ -15,14 +20,20 @@ export function processBuilderDepositRequest(
request: gloas.BuilderDepositRequest
): void {
const {pubkey, withdrawalCredentials, amount, signature} = request;

// Ignore deposits with unexpected withdrawal credential prefixes.
if (!isBuilderWithdrawalCredential(withdrawalCredentials)) {
return;
}

const builderIndex = findBuilderIndexByPubkey(state, pubkey);

if (builderIndex === null) {
if (isValidBuilderDepositSignature(state.config, pubkey, withdrawalCredentials, amount, signature)) {
addBuilderToRegistry(
state,
pubkey,
withdrawalCredentials[0],
PAYLOAD_BUILDER_VERSION,
withdrawalCredentials.subarray(12),
amount,
state.slot
Expand All @@ -33,11 +44,13 @@ export function processBuilderDepositRequest(

const builder = state.builders.get(builderIndex);

// Increase balance by deposit amount
builder.balance += amount;

// If exited, reset the withdrawable epoch
if (builder.withdrawableEpoch !== FAR_FUTURE_EPOCH) {
// If the builder has exited and been fully swept (balance drained to 0), reset the
// withdrawable epoch so this top-up becomes withdrawable again. Must run before the
// balance increase, since the reset is gated on the current balance being 0.
if (builder.withdrawableEpoch !== FAR_FUTURE_EPOCH && builder.balance === 0) {
builder.withdrawableEpoch = computeEpochAtSlot(state.slot) + state.config.MIN_BUILDER_WITHDRAWABILITY_DELAY;
}

// Increase balance by deposit amount
builder.balance += amount;
}
10 changes: 6 additions & 4 deletions packages/state-transition/src/util/gloas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export function isBuilderWithdrawalCredential(withdrawalCredentials: Uint8Array)
}

export function getBuilderPaymentQuorumThreshold(state: CachedBeaconStateGloas): number {
const quorum =
Math.floor((state.epochCtx.totalActiveBalanceIncrements * EFFECTIVE_BALANCE_INCREMENT) / SLOTS_PER_EPOCH) *
BUILDER_PAYMENT_THRESHOLD_NUMERATOR;
// total active balance exceeds Number.MAX_SAFE_INTEGER at mainnet scale, keep the intermediate math in bigint
const perSlotBalance =
Comment on lines +34 to +35

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.

is this true? how was this caught, seems like a new spec test?

@ensi321 ensi321 Jul 23, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think so.

Total active EB is like 34M ETH on mainnet, multiply by EFFECTIVE_BALANCE_INCREMENT = 34M * 10^9 = 3.4 * 10^16 Gwei. Which is greater than MAX_SAFE_INTEGER.

No spec test for this. Just caught this when reviewing with claude.

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.

@lodekeeper can you confirm this math, I assumed Number was safe to use for anything that is accounted for in gwei due to max eth supply cap

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed — ensi321 is right, it does overflow, and the current bigint version (from c7663acefa) handles it correctly.

The overflow is on the intermediate totalActiveBalanceIncrements * EFFECTIVE_BALANCE_INCREMENT, which reconstructs total active balance in gwei:

  • totalActiveBalanceIncrements is tracked in ETH units (epochCache.ts:370 keeps it that way precisely to fit total network balance in a JS number), so ~34M at today's mainnet.
  • × EFFECTIVE_BALANCE_INCREMENT (1e9) → total active balance in gwei ≈ 3.4e16, vs MAX_SAFE_INTEGER ≈ 9.007e15 → ~3.8× over. At ensi321's 41M ETH it's 4.1e16 (~4.6×). Conclusion holds regardless of the exact staking figure.

On your assumption — that's the part that doesn't hold. The safe ceiling for a gwei value in a JS number is MAX_SAFE_INTEGER / 1e9 ≈ 9.01M ETH:

  • A single validator balance is always fine — even MAX_EFFECTIVE_BALANCE_ELECTRA (2048 ETH = 2.048e12 gwei) is ~4000× under the limit.
  • Any sum across the validator set is not: total active balance (~34M ETH) already passes ~9M ETH, and the supply cap makes it worse, not safer — ~120M ETH in gwei is 1.2e17, ~13× MAX_SAFE_INTEGER. So "accounted for in gwei ⇒ safe in Number" is true per-validator, not for aggregates.

The function itself is fine: all intermediate math stays in bigint and only the final result is cast back — and that result is small (perSlot × 6/10 ≈ 6.4e14 at 34M ETH, ≤ ~2.25e15 even if the entire supply were staked), comfortably under MAX_SAFE_INTEGER. So no further change needed here; epochCache.ts:392 (throw if totalActiveBalanceIncrements itself ≥ MAX_SAFE_INTEGER) is the backstop on the input side.

And yeah — no spec test would catch this as-is: it's silent precision loss, not a throw, so a unit test would need a state built at realistic mainnet-scale total balance to surface it.

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.

realized we also use bigint for the ssz type

export type Gwei = UintBn64;

so this change is needed, that's a good catch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah — and it's worth pinning down why that's consistent, because the two Gwei representations are used deliberately here.

Gwei = UintBn64 (bigint) is the right type for full-total balances that can exceed 2^53 — e.g. depositBalanceToConsume/exitBalanceToConsume (sszTypes.ts:522-523). But the field this threshold actually feeds — BuilderPendingPayment.weight (sszTypes.ts:239) — is intentionally UintNum64 (number), and that's correct rather than an oversight: weight accumulates only the same-slot attesting balance for one payment (processAttestationsAltair.ts:153, existingWeight + paymentWeightToAdd * EFFECTIVE_BALANCE_INCREMENT), so it's bounded by ~one slot's committee ≈ total_active_balance / 32. That's ~1.06e15 gwei at 34M ETH staked, and still only ~3.75e15 even if the entire supply were staked — comfortably under MAX_SAFE_INTEGER (it wouldn't reach it until ~288M ETH active, well past the supply cap).

So the overflow was specifically the intermediate full-total reconstruction inside the threshold fn (totalActiveBalanceIncrements × EFFECTIVE_BALANCE_INCREMENT ≈ 3.4e16, before the ÷32) — which is why the bigint-intermediate / small-Number-result shape is the right fix, and why the number-typed weight on the other side of the >= compare is fine as-is. Same reason the accumulation at :153 can stay in plain number: it's per-slot-scoped and never materializes the full total in one value.

tl;dr the split is intentional — full-total balances → Gwei/UintBn64; per-slot / bounded sums → UintNum64. weight is correctly the latter, so c7663acefa (bigint intermediates) is the whole of it, no further change needed.

(BigInt(state.epochCtx.totalActiveBalanceIncrements) * BigInt(EFFECTIVE_BALANCE_INCREMENT)) /
BigInt(SLOTS_PER_EPOCH);
const quorum = perSlotBalance * BigInt(BUILDER_PAYMENT_THRESHOLD_NUMERATOR);

return Math.floor(quorum / BUILDER_PAYMENT_THRESHOLD_DENOMINATOR);
return Number(quorum / BigInt(BUILDER_PAYMENT_THRESHOLD_DENOMINATOR));
}

function hasBuilderIndexFlag(index: number): boolean {
Expand Down
Loading
Loading