Skip to content

fix: prevent uint64 underflow in ListFinalizedSlots on short-lived chains#241

Open
barnabasbusa wants to merge 1 commit intomasterfrom
bbusa/fix-list-finalized-slots-underflow
Open

fix: prevent uint64 underflow in ListFinalizedSlots on short-lived chains#241
barnabasbusa wants to merge 1 commit intomasterfrom
bbusa/fix-list-finalized-slots-underflow

Conversation

@barnabasbusa
Copy link
Copy Markdown
Contributor

Summary

  • ListFinalizedSlots (backing GET /checkpointz/v1/beacon/slots) computed its lower-bound slot as latestSlot - SlotsPerEpoch * HistoricalEpochCount in uint64. When the finalized epoch is smaller than historical_epoch_count — e.g. during the first ~2 minutes of a freshly started devnet or a kurtosis enclave — the subtraction underflows to ~2^64, so the i > val loop condition is immediately false and the function returns an empty slice. The UI's "historical finalized epoch boundaries" table then stays blank until the chain has produced HistoricalEpochCount (default 20) epochs.
  • Clamp the lower bound at 0 so every available finalized epoch-boundary slot is returned, regardless of chain age. No behavior change once finalizedEpoch >= HistoricalEpochCount.

Repro

Spin up a kurtosis enclave that produces epochs quickly (e.g. gloas devnet, SLOTS_PER_EPOCH=8) and hit /checkpointz/v1/beacon/slots while finalizedEpoch < 20:

$ curl .../checkpointz/v1/beacon/slots
{"data":{"slots":[]}}

Bundle fetching and /eth/v2/beacon/blocks/finalized work fine — only the UI's history list is affected.

Test plan

  • go build ./...
  • go vet ./...
  • golangci-lint run --new-from-rev=origin/master ./pkg/beacon/... → 0 issues
  • Rebuild image, rerun kurtosis enclave, verify /checkpointz/v1/beacon/slots returns non-empty list before epoch 20 and that the UI populates the historical-checkpoints table

…ains

When the finalized epoch is smaller than historical_epoch_count (e.g. on a
freshly started devnet or kurtosis enclave), the previous expression
`latestSlot - SlotsPerEpoch*HistoricalEpochCount` underflows uint64 and
produces a value near 2^64, so the loop never executes and the
/checkpointz/v1/beacon/slots endpoint returns an empty list — leaving the
UI's historical checkpoints table blank until the chain has produced
HistoricalEpochCount epochs.

Clamp the lower bound at 0 so we return every available finalized
epoch-boundary slot, regardless of chain age.
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.

1 participant