Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static analysis for unsafe uint casting #10318

Merged
merged 37 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d92031f
Add static analysis for unsafe uint casting
prestonvanloon Mar 7, 2022
133de3e
Fix violations of uintcast
prestonvanloon Mar 7, 2022
3070974
Merge branch 'develop' into uintcast-sa
prestonvanloon Mar 7, 2022
907acc0
go mod tidy
prestonvanloon Mar 7, 2022
cf72314
Add exclusion to nogo for darwin build
prestonvanloon Mar 7, 2022
9f2f5b5
Add test for math.Int
prestonvanloon Mar 7, 2022
9c6c96a
Move some things to const so they are assured not to exceed int64
prestonvanloon Mar 7, 2022
5363873
Self review
prestonvanloon Mar 7, 2022
e139cf0
lint
prestonvanloon Mar 7, 2022
0c4149b
fix tests
prestonvanloon Mar 7, 2022
c9fb2d8
fix test
prestonvanloon Mar 7, 2022
c256d4e
Merge branch 'develop' of github.com:prysmaticlabs/prysm into uintcas…
prestonvanloon Mar 7, 2022
5416ae2
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 8, 2022
279ab22
Add init check for non 64 bit OS
prestonvanloon Mar 8, 2022
13c37a9
Move new deps from WORKSPACE to deps.bzl
prestonvanloon Mar 8, 2022
d2dbc2a
fix bazel build for go analysis runs
prestonvanloon Mar 8, 2022
eddedd3
Update BUILD.bazel
prestonvanloon Mar 8, 2022
b7288a4
add math.AddInt method
prestonvanloon Mar 8, 2022
41385a3
Add new test casts
prestonvanloon Mar 9, 2022
aae7d32
Add case where builtin functions and declared functions are covered
prestonvanloon Mar 9, 2022
083dc61
Fix new findings
prestonvanloon Mar 9, 2022
c41d455
Merge branch 'develop' of github.com:prysmaticlabs/prysm into uintcas…
prestonvanloon Mar 9, 2022
f60c8d5
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 9, 2022
677bb93
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 9, 2022
ccce09a
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 9, 2022
9bb6be1
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 9, 2022
b0a7059
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 9, 2022
6c55ae9
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 9, 2022
4d19385
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 10, 2022
483a093
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 10, 2022
f1f1689
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 10, 2022
731a687
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 10, 2022
108cbae
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 10, 2022
5c709ff
Merge branch 'develop' into uintcast-sa
nisdas Mar 11, 2022
c6f3d53
cleanup
nisdas Mar 11, 2022
22205fd
Merge branch 'develop' into uintcast-sa
nisdas Mar 11, 2022
0c23e3b
Merge refs/heads/develop into uintcast-sa
prylabs-bulldozer[bot] Mar 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ nogo(
"//tools/analyzers/ineffassign:go_default_library",
"//tools/analyzers/properpermissions:go_default_library",
"//tools/analyzers/recursivelock:go_default_library",
"//tools/analyzers/uintcast:go_default_library",
] + select({
# nogo checks that fail with coverage enabled.
":coverage_enabled": [],
Expand Down
51 changes: 50 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,56 @@ load("@com_github_atlassian_bazel_tools//gometalinter:deps.bzl", "gometalinter_d

gometalinter_dependencies()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

go_repository(
prestonvanloon marked this conversation as resolved.
Show resolved Hide resolved
name = "com_github_gostaticanalysis_comment",
importpath = "github.com/gostaticanalysis/comment",
sum = "h1:hlnx5+S2fY9Zo9ePo4AhgYsYHbM2+eAv8m/s1JiCd6Q=",
version = "v1.4.2",
)

go_repository(
name = "com_github_gostaticanalysis_testutil",
importpath = "github.com/gostaticanalysis/testutil",
sum = "h1:d2/eIbH9XjD1fFwD5SHv8x168fjbQ9PB8hvs8DSEC08=",
version = "v0.3.1-0.20210208050101-bfb5c8eec0e4",
)

go_repository(
name = "com_github_otiai10_copy",
importpath = "github.com/otiai10/copy",
sum = "h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=",
version = "v1.2.0",
)

go_repository(
name = "com_github_otiai10_curr",
importpath = "github.com/otiai10/curr",
sum = "h1:TJIWdbX0B+kpNagQrjgq8bCMrbhiuX73M2XwgtDMoOI=",
version = "v1.0.0",
)

go_repository(
name = "com_github_otiai10_mint",
importpath = "github.com/otiai10/mint",
sum = "h1:BCmzIS3n71sGfHB5NMNDB3lHYPz8fWSkCAErHed//qc=",
version = "v1.3.1",
)

go_repository(
name = "com_github_tenntenn_modver",
importpath = "github.com/tenntenn/modver",
sum = "h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA=",
version = "v1.0.1",
)

go_repository(
name = "com_github_tenntenn_text_transform",
importpath = "github.com/tenntenn/text/transform",
sum = "h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag=",
version = "v0.0.0-20200319021203-7eef512accb3",
)

gazelle_dependencies()

Expand Down
5 changes: 3 additions & 2 deletions beacon-chain/cache/active_balance.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !fuzz
// +build !fuzz

package cache
Expand All @@ -19,7 +20,7 @@ import (

var (
// maxBalanceCacheSize defines the max number of active balances can cache.
maxBalanceCacheSize = uint64(4)
maxBalanceCacheSize = int(4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was brought up offline cc @uncdr , but is there any reason we have cache sizes as a signed integer here ? It can't be negative in any case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah k, I see it is due to the lruwrpr, maybe we can change the method signature to take a uint64. And it does the safe casting internally in the lru constructor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah exactly, I moved these to const so that we are assured it can never change. I thought this was the easier route vs changing 3rd party API

Copy link
Member

@nisdas nisdas Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not 3rd party though, this lruwrpr package is under prysm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! OK, I'll take a look!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we even have lruwrpr? It's a flow through to github.com/hashicorp/golang-lru with panics. I'm going to leave it out of scope for this PR. It seems strange to have this package when we could use lru directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we wanted the lru package to not return an error mostly. The package returns an error if the cache size is negative.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, it might be best to handle this in a follow up PR. The LRU cache is used across prysm and changing the api of it, will require changes across prysm


// BalanceCacheMiss tracks the number of balance requests that aren't present in the cache.
balanceCacheMiss = promauto.NewCounter(prometheus.CounterOpts{
Expand All @@ -42,7 +43,7 @@ type BalanceCache struct {
// NewEffectiveBalanceCache creates a new effective balance cache for storing/accessing total balance by epoch.
func NewEffectiveBalanceCache() *BalanceCache {
return &BalanceCache{
cache: lruwrpr.New(int(maxBalanceCacheSize)),
cache: lruwrpr.New(maxBalanceCacheSize),
}
}

Expand Down
5 changes: 3 additions & 2 deletions beacon-chain/cache/committee.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !fuzz
// +build !fuzz

package cache
Expand All @@ -22,7 +23,7 @@ import (
var (
// maxCommitteesCacheSize defines the max number of shuffled committees on per randao basis can cache.
// Due to reorgs and long finality, it's good to keep the old cache around for quickly switch over.
maxCommitteesCacheSize = uint64(32)
maxCommitteesCacheSize = int(32)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as in another thread, why signed int?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the 3rd party API. I'm not sure. This is a constant now so it can't overflow/underflow. I think we can address cache API in another PR or issue.


// CommitteeCacheMiss tracks the number of committee requests that aren't present in the cache.
CommitteeCacheMiss = promauto.NewCounter(prometheus.CounterOpts{
Expand Down Expand Up @@ -55,7 +56,7 @@ func committeeKeyFn(obj interface{}) (string, error) {
// NewCommitteesCache creates a new committee cache for storing/accessing shuffled indices of a committee.
func NewCommitteesCache() *CommitteeCache {
return &CommitteeCache{
CommitteeCache: lruwrpr.New(int(maxCommitteesCacheSize)),
CommitteeCache: lruwrpr.New(maxCommitteesCacheSize),
inProgress: make(map[string]bool),
}
}
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/forkchoice/protoarray/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_library(
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//encoding/bytesutil:go_default_library",
"//math:go_default_library",
"//time/slots:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
Expand Down
17 changes: 13 additions & 4 deletions beacon-chain/forkchoice/protoarray/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/prysmaticlabs/prysm/config/params"
pmath "github.com/prysmaticlabs/prysm/math"
"go.opencensus.io/trace"
)

Expand Down Expand Up @@ -46,19 +47,27 @@ func computeDeltas(
if ok {
// Protection against out of bound, the `nextDeltaIndex` which defines
// the block location in the dag can not exceed the total `delta` length.
if int(nextDeltaIndex) >= len(deltas) {
if nextDeltaIndex >= uint64(len(deltas)) {
return nil, nil, errInvalidNodeDelta
}
deltas[nextDeltaIndex] += int(newBalance)
delta, err := pmath.Int(newBalance)
if err != nil {
return nil, nil, err
}
deltas[nextDeltaIndex] += delta
}

currentDeltaIndex, ok := blockIndices[vote.currentRoot]
if ok {
// Protection against out of bound (same as above)
if int(currentDeltaIndex) >= len(deltas) {
if currentDeltaIndex >= uint64(len(deltas)) {
return nil, nil, errInvalidNodeDelta
}
deltas[currentDeltaIndex] -= int(oldBalance)
delta, err := pmath.Int(oldBalance)
prestonvanloon marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, nil, err
}
deltas[currentDeltaIndex] -= delta
}
}

Expand Down
7 changes: 6 additions & 1 deletion beacon-chain/forkchoice/protoarray/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
"github.com/prysmaticlabs/prysm/config/params"
pmath "github.com/prysmaticlabs/prysm/math"
"go.opencensus.io/trace"
)

Expand Down Expand Up @@ -472,7 +473,11 @@ func (s *Store) applyWeightChanges(
s.proposerBoostLock.Unlock()
return err
}
nodeDelta = nodeDelta + int(proposerScore)
iProposerScore, err := pmath.Int(proposerScore)
if err != nil {
return err
}
nodeDelta = nodeDelta + iProposerScore
}
s.proposerBoostLock.Unlock()

Expand Down
12 changes: 7 additions & 5 deletions beacon-chain/p2p/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func (s *Service) broadcastAttestation(ctx context.Context, subnet uint64, att *

span.AddAttributes(
trace.BoolAttribute("hasPeer", hasPeer),
trace.Int64Attribute("slot", int64(att.Data.Slot)),
trace.Int64Attribute("subnet", int64(subnet)),
trace.Int64Attribute("slot", int64(att.Data.Slot)), // lint:ignore uintcast -- It's safe to do this for tracing.
trace.Int64Attribute("subnet", int64(subnet)), // lint:ignore uintcast -- It's safe to do this for tracing.
)

if !hasPeer {
Expand Down Expand Up @@ -160,8 +160,8 @@ func (s *Service) broadcastSyncCommittee(ctx context.Context, subnet uint64, sMs

span.AddAttributes(
trace.BoolAttribute("hasPeer", hasPeer),
trace.Int64Attribute("slot", int64(sMsg.Slot)),
trace.Int64Attribute("subnet", int64(subnet)),
trace.Int64Attribute("slot", int64(sMsg.Slot)), // lint:ignore uintcast -- It's safe to do this for tracing.
trace.Int64Attribute("subnet", int64(subnet)), // lint:ignore uintcast -- It's safe to do this for tracing.
)

if !hasPeer {
Expand Down Expand Up @@ -213,7 +213,9 @@ func (s *Service) broadcastObject(ctx context.Context, obj ssz.Marshaler, topic
if span.IsRecordingEvents() {
id := hash.FastSum64(buf.Bytes())
messageLen := int64(buf.Len())
span.AddMessageSendEvent(int64(id), messageLen /*uncompressed*/, messageLen /*compressed*/)
// lint:ignore uintcast -- It's safe to do this for tracing.
iid := int64(id)
span.AddMessageSendEvent(iid, messageLen /*uncompressed*/, messageLen /*compressed*/)
}
if err := s.PublishToTopic(ctx, topic+s.Encoding().ProtocolSuffix(), buf.Bytes()); err != nil {
err := errors.Wrap(err, "could not publish message")
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/p2p/encoder/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
],
deps = [
"//config/params:go_default_library",
"//math:go_default_library",
"@com_github_ferranbt_fastssz//:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_snappy//:go_default_library",
Expand Down
10 changes: 5 additions & 5 deletions beacon-chain/p2p/encoder/ssz.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package encoder
import (
"fmt"
"io"
"math"
"sync"

fastssz "github.com/ferranbt/fastssz"
"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/math"
)

var _ NetworkEncoding = (*SszNetworkEncoder)(nil)
Expand Down Expand Up @@ -145,11 +145,11 @@ func (_ SszNetworkEncoder) ProtocolSuffix() string {
// MaxLength specifies the maximum possible length of an encoded
// chunk of data.
func (_ SszNetworkEncoder) MaxLength(length uint64) (int, error) {
// Defensive check to prevent potential issues when casting to int64.
if length > math.MaxInt64 {
return 0, errors.Errorf("invalid length provided: %d", length)
il, err := math.Int(length)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validation has moved to math.Int

if err != nil {
return 0, err
}
maxLen := snappy.MaxEncodedLen(int(length))
maxLen := snappy.MaxEncodedLen(il)
if maxLen < 0 {
return 0, errors.Errorf("max encoded length is negative: %d", maxLen)
}
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/p2p/message_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func postAltairMsgID(pmsg *pubsub_pb.Message, fEpoch types.Epoch) string {

decodedData, err := encoder.DecodeSnappy(pmsg.Data, gossipPubSubSize)
if err != nil {
totalLength := len(params.BeaconNetworkConfig().MessageDomainInvalidSnappy) + len(topicLenBytes) + int(topicLen) + len(pmsg.Data)
totalLength := len(params.BeaconNetworkConfig().MessageDomainInvalidSnappy) + len(topicLenBytes) + int(topicLen) + len(pmsg.Data) // lint:ignore uintcast -- Message length cannot exceed int64
combinedData := make([]byte, 0, totalLength)
combinedData = append(combinedData, params.BeaconNetworkConfig().MessageDomainInvalidSnappy[:]...)
combinedData = append(combinedData, topicLenBytes...)
Expand All @@ -92,7 +92,7 @@ func postAltairMsgID(pmsg *pubsub_pb.Message, fEpoch types.Epoch) string {
h := hash.Hash(combinedData)
return string(h[:20])
}
totalLength := len(params.BeaconNetworkConfig().MessageDomainValidSnappy) + len(topicLenBytes) + int(topicLen) + len(decodedData)
totalLength := len(params.BeaconNetworkConfig().MessageDomainValidSnappy) + len(topicLenBytes) + int(topicLen) + len(decodedData) // lint:ignore uintcast -- Message length cannot exceed int64
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if totalLength exceeds int64? overflow and a negative value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a SafeAddInt64 method for this

combinedData := make([]byte, 0, totalLength)
combinedData = append(combinedData, params.BeaconNetworkConfig().MessageDomainValidSnappy[:]...)
combinedData = append(combinedData, topicLenBytes...)
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/p2p/peers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
"//config/features:go_default_library",
"//config/params:go_default_library",
"//crypto/rand:go_default_library",
"//math:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/metadata:go_default_library",
"//time:go_default_library",
Expand Down
31 changes: 20 additions & 11 deletions beacon-chain/p2p/peers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/prysmaticlabs/prysm/config/features"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/crypto/rand"
pmath "github.com/prysmaticlabs/prysm/math"
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/metadata"
prysmTime "github.com/prysmaticlabs/prysm/time"
Expand Down Expand Up @@ -749,12 +750,12 @@ func (p *Status) PeersToPrune() []peer.ID {
return p.deprecatedPeersToPrune()
}
connLimit := p.ConnectedPeerLimit()
inBoundLimit := p.InboundLimit()
inBoundLimit := uint64(p.InboundLimit())
activePeers := p.Active()
numInboundPeers := len(p.InboundConnected())
numInboundPeers := uint64(len(p.InboundConnected()))
// Exit early if we are still below our max
// limit.
if len(activePeers) <= int(connLimit) {
if uint64(len(activePeers)) <= connLimit {
return []peer.ID{}
}
p.store.Lock()
Expand Down Expand Up @@ -784,10 +785,14 @@ func (p *Status) PeersToPrune() []peer.ID {

// Determine amount of peers to prune using our
// max connection limit.
amountToPrune := len(activePeers) - int(connLimit)
amountToPrune, err := pmath.Sub64(uint64(len(activePeers)), connLimit)
if err != nil {
// This should never happen.
return []peer.ID{}
}

// Also check for inbound peers above our limit.
excessInbound := 0
excessInbound := uint64(0)
if numInboundPeers > inBoundLimit {
excessInbound = numInboundPeers - inBoundLimit
}
Expand All @@ -796,7 +801,7 @@ func (p *Status) PeersToPrune() []peer.ID {
if excessInbound > amountToPrune {
amountToPrune = excessInbound
}
if amountToPrune < len(peersToPrune) {
if amountToPrune < uint64(len(peersToPrune)) {
peersToPrune = peersToPrune[:amountToPrune]
}
ids := make([]peer.ID, 0, len(peersToPrune))
Expand All @@ -815,7 +820,7 @@ func (p *Status) deprecatedPeersToPrune() []peer.ID {
numInboundPeers := len(p.InboundConnected())
// Exit early if we are still below our max
// limit.
if len(activePeers) <= int(connLimit) {
if uint64(len(activePeers)) <= connLimit {
return []peer.ID{}
}
p.store.Lock()
Expand Down Expand Up @@ -845,18 +850,22 @@ func (p *Status) deprecatedPeersToPrune() []peer.ID {

// Determine amount of peers to prune using our
// max connection limit.
amountToPrune := len(activePeers) - int(connLimit)
amountToPrune, err := pmath.Sub64(uint64(len(activePeers)), connLimit)
if err != nil {
// This should never happen
return []peer.ID{}
}
// Also check for inbound peers above our limit.
excessInbound := 0
excessInbound := uint64(0)
if numInboundPeers > inBoundLimit {
excessInbound = numInboundPeers - inBoundLimit
excessInbound = uint64(numInboundPeers - inBoundLimit)
}
// Prune the largest amount between excess peers and
// excess inbound peers.
if excessInbound > amountToPrune {
amountToPrune = excessInbound
}
if amountToPrune < len(peersToPrune) {
if amountToPrune < uint64(len(peersToPrune)) {
peersToPrune = peersToPrune[:amountToPrune]
}
ids := make([]peer.ID, 0, len(peersToPrune))
Expand Down
6 changes: 4 additions & 2 deletions beacon-chain/p2p/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *Service) FindPeersWithSubnet(ctx context.Context, topic string,
ctx, span := trace.StartSpan(ctx, "p2p.FindPeersWithSubnet")
defer span.End()

span.AddAttributes(trace.Int64Attribute("index", int64(index)))
span.AddAttributes(trace.Int64Attribute("index", int64(index))) // lint:ignore uintcast -- It's safe to do this for tracing.

if s.dv5Listener == nil {
// return if discovery isn't set
Expand Down Expand Up @@ -138,7 +138,7 @@ func (s *Service) hasPeerWithSubnet(topic string) bool {
// In the event peer threshold is lower, we will choose the lower
// threshold.
minPeers := mathutil.Min(1, uint64(flags.Get().MinimumPeersPerSubnet))
return len(s.pubsub.ListPeers(topic+s.Encoding().ProtocolSuffix())) >= int(minPeers)
return len(s.pubsub.ListPeers(topic+s.Encoding().ProtocolSuffix())) >= int(minPeers) // lint:ignore uintcast -- Min peers can be safely cast to int.
}

// Updates the service's discv5 listener record's attestation subnet
Expand Down Expand Up @@ -195,6 +195,7 @@ func attSubnets(record *enr.Record) ([]uint64, error) {
if err != nil {
return nil, err
}
// lint:ignore uintcast -- subnet count can be safely cast to int.
if len(bitV) != byteCount(int(attestationSubnetCount)) {
return []uint64{}, errors.Errorf("invalid bitvector provided, it has a size of %d", len(bitV))
}
Expand All @@ -214,6 +215,7 @@ func syncSubnets(record *enr.Record) ([]uint64, error) {
if err != nil {
return nil, err
}
// lint:ignore uintcast -- subnet count can be safely cast to int.
if len(bitV) != byteCount(int(syncCommsSubnetCount)) {
return []uint64{}, errors.Errorf("invalid bitvector provided, it has a size of %d", len(bitV))
}
Expand Down
Loading