diff --git a/beacon-chain/rpc/eth/validator/handlers.go b/beacon-chain/rpc/eth/validator/handlers.go index a44a2c3d0b..7be36698d7 100644 --- a/beacon-chain/rpc/eth/validator/handlers.go +++ b/beacon-chain/rpc/eth/validator/handlers.go @@ -690,6 +690,10 @@ func (s *Server) ProduceSyncCommitteeContribution(w http.ResponseWriter, r *http if !ok { return } + if index >= params.BeaconConfig().SyncCommitteeSubnetCount { + httputil.HandleError(w, fmt.Sprintf("Subcommittee index needs to be between 0 and %d, %d is outside of this range.", params.BeaconConfig().SyncCommitteeSubnetCount-1, index), http.StatusBadRequest) + return + } _, slot, ok := shared.UintFromQuery(w, r, "slot", true) if !ok { return diff --git a/beacon-chain/rpc/eth/validator/handlers_test.go b/beacon-chain/rpc/eth/validator/handlers_test.go index 490d4ae66d..3baba284b8 100644 --- a/beacon-chain/rpc/eth/validator/handlers_test.go +++ b/beacon-chain/rpc/eth/validator/handlers_test.go @@ -2117,6 +2117,27 @@ func TestProduceSyncCommitteeContribution(t *testing.T) { server.ProduceSyncCommitteeContribution(writer, request) assert.Equal(t, http.StatusServiceUnavailable, writer.Code) }) + t.Run("invalid subcommittee_index", func(t *testing.T) { + url := "http://example.com?slot=1&subcommittee_index=10&beacon_block_root=0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2" + request := httptest.NewRequest(http.MethodGet, url, nil) + writer := httptest.NewRecorder() + writer.Body = &bytes.Buffer{} + + // Use non-optimistic server for this test + server := Server{ + CoreService: &core.Service{ + HeadFetcher: &mockChain.ChainService{ + SyncCommitteeIndices: []primitives.CommitteeIndex{0}, + }, + }, + SyncCommitteePool: syncCommitteePool, + OptimisticModeFetcher: &mockChain.ChainService{}, // Optimistic: false by default + } + + server.ProduceSyncCommitteeContribution(writer, request) + assert.Equal(t, http.StatusBadRequest, writer.Code) + require.ErrorContains(t, "Subcommittee index needs to be between 0 and 3, 10 is outside of this range.", errors.New(writer.Body.String())) + }) } func TestServer_RegisterValidator(t *testing.T) { diff --git a/changelog/muzry_fix_produce_sync_committee.md b/changelog/muzry_fix_produce_sync_committee.md new file mode 100644 index 0000000000..e6ff7c707d --- /dev/null +++ b/changelog/muzry_fix_produce_sync_committee.md @@ -0,0 +1,4 @@ +### Fixed + +- Fix ProduceSyncCommitteeContribution not returning error when committee index is out of range +