Skip to content

Commit e775ffa

Browse files
committed
fix(lint): address gosec G115 integer overflow warnings
Add nolint directives for safe integer conversions where values are bounded by design (config limits, beacon chain constraints, blob indices). Add validation for negative slot values in NewSlotFromString.
1 parent 1cd542a commit e775ffa

6 files changed

Lines changed: 11 additions & 0 deletions

File tree

pkg/beacon/default.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ func (d *Default) ListFinalizedSlots(ctx context.Context) ([]phase0.Slot, error)
750750

751751
latestSlot := phase0.Slot(uint64(finality.Finalized.Epoch) * uint64(sp.SlotsPerEpoch))
752752

753+
//nolint:gosec // G115: HistoricalEpochCount is a small positive config value, safe to convert
753754
for i, val := uint64(latestSlot), uint64(latestSlot)-uint64(sp.SlotsPerEpoch)*uint64(d.config.HistoricalEpochCount); i > val; i -= uint64(sp.SlotsPerEpoch) {
754755
slots = append(slots, phase0.Slot(i))
755756
}

pkg/beacon/download.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ func (d *Default) fetchHistoricalCheckpoints(ctx context.Context, checkpoint *v1
173173
// We'll derive the current finalized slot and then work back in intervals of SLOTS_PER_EPOCH.
174174
currentSlot := uint64(checkpoint.Finalized.Epoch) * uint64(sp.SlotsPerEpoch)
175175
for i := 1; i < d.config.HistoricalEpochCount; i++ {
176+
//nolint:gosec // G115: i is a positive loop counter bounded by HistoricalEpochCount
176177
if uint64(i)*uint64(sp.SlotsPerEpoch) > currentSlot {
177178
break
178179
}
179180

181+
//nolint:gosec // G115: i is a positive loop counter bounded by HistoricalEpochCount
180182
slot := phase0.Slot(currentSlot - uint64(i)*uint64(sp.SlotsPerEpoch))
181183

182184
slotsInScope[slot] = struct{}{}

pkg/beacon/expire_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ var (
1313
)
1414

1515
func CalculateSlotExpiration(slot phase0.Slot, slotsOfHistory int) phase0.Slot {
16+
//nolint:gosec // G115: slotsOfHistory is a small positive test value
1617
return slot + phase0.Slot(slotsOfHistory)
1718
}
1819

1920
func GetSlotTime(slot phase0.Slot, secondsPerSlot time.Duration, genesis time.Time) time.Time {
21+
//nolint:gosec // G115: slot values are bounded by beacon chain limits, safe for duration
2022
return genesis.Add(time.Duration(slot) * secondsPerSlot)
2123
}
2224

pkg/eth/slot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type SlotTime struct {
1414
}
1515

1616
func CalculateSlotTime(slot phase0.Slot, genesisTime time.Time, durationPerSlot time.Duration) SlotTime {
17+
//nolint:gosec // G115: slot values are bounded by beacon chain limits, safe for duration
1718
slotStartTime := genesisTime.Add(time.Duration(slot) * durationPerSlot).UTC()
1819

1920
return SlotTime{

pkg/service/eth/block_id.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func NewSlotFromString(id string) (phase0.Slot, error) {
8888
return 0, err
8989
}
9090

91+
if slot < 0 {
92+
return 0, errors.New("slot cannot be negative")
93+
}
94+
9195
return phase0.Slot(slot), nil
9296
}
9397

pkg/service/eth/eth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ func (h *Handler) BlobSidecars(ctx context.Context, blockID BlockIdentifier, ind
572572

573573
// Find the sidecar with the given index
574574
for i, sidecar := range sidecars {
575+
//nolint:gosec // G115: blob indices are small values (max 6), safe to convert
575576
if index == int(sidecar.Index) {
576577
filtered = append(filtered, sidecars[i])
577578

0 commit comments

Comments
 (0)