Handle addition overflow in /eth/v1/beacon/rewards/attestations/{epoch} (#15970)

* Handle addition overflow in `/eth/v1/beacon/rewards/attestations/{epoch}`

* Changelog
This commit is contained in:
Jun Song
2025-11-04 16:14:47 +00:00
committed by GitHub
parent d0f5253b8d
commit 165c4b0af1
3 changed files with 22 additions and 2 deletions

View File

@@ -209,8 +209,13 @@ func (s *Server) attRewardsState(w http.ResponseWriter, r *http.Request) (state.
httputil.HandleError(w, "Attestation rewards are not supported for Phase 0", http.StatusNotFound)
return nil, false
}
currentEpoch := uint64(slots.ToEpoch(s.TimeFetcher.CurrentSlot()))
if requestedEpoch+1 >= currentEpoch {
currentEpoch := slots.ToEpoch(s.TimeFetcher.CurrentSlot())
bufferedEpoch, err := primitives.Epoch(requestedEpoch).SafeAdd(1)
if err != nil {
httputil.HandleError(w, "Could not increment epoch: "+err.Error(), http.StatusNotFound)
return nil, false
}
if bufferedEpoch >= currentEpoch {
httputil.HandleError(w,
"Attestation rewards are available after two epoch transitions to ensure all attestations have a chance of inclusion",
http.StatusNotFound)

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"math"
"net/http"
"net/http/httptest"
"strconv"
@@ -747,6 +748,18 @@ func TestAttestationRewards(t *testing.T) {
assert.Equal(t, http.StatusNotFound, e.Code)
assert.Equal(t, "Attestation rewards are available after two epoch transitions to ensure all attestations have a chance of inclusion", e.Message)
})
t.Run("epoch overflow", func(t *testing.T) {
url := "http://only.the.epoch.number.at.the.end.is.important/" + strconv.FormatUint(math.MaxUint64, 10)
request := httptest.NewRequest("POST", url, nil)
writer := httptest.NewRecorder()
writer.Body = &bytes.Buffer{}
s.AttestationRewards(writer, request)
assert.Equal(t, http.StatusNotFound, writer.Code)
e := &httputil.DefaultJsonError{}
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), e))
assert.Equal(t, http.StatusNotFound, e.Code)
})
}
func TestSyncCommiteeRewards(t *testing.T) {

View File

@@ -0,0 +1,2 @@
### Fixed
- Fix #15969: Handle addition overflow in `/eth/v1/beacon/rewards/attestations/{epoch}`.