fix: prevent uint64 underflow in ListFinalizedSlots on short-lived chains#241
Open
barnabasbusa wants to merge 1 commit intomasterfrom
Open
fix: prevent uint64 underflow in ListFinalizedSlots on short-lived chains#241barnabasbusa wants to merge 1 commit intomasterfrom
barnabasbusa wants to merge 1 commit intomasterfrom
Conversation
…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.
This was referenced Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ListFinalizedSlots(backingGET /checkpointz/v1/beacon/slots) computed its lower-bound slot aslatestSlot - SlotsPerEpoch * HistoricalEpochCountinuint64. When the finalized epoch is smaller thanhistorical_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 thei > valloop 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 producedHistoricalEpochCount(default 20) epochs.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/slotswhilefinalizedEpoch < 20:Bundle fetching and
/eth/v2/beacon/blocks/finalizedwork 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/checkpointz/v1/beacon/slotsreturns non-empty list before epoch 20 and that the UI populates the historical-checkpoints table