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

Fix a bunch of deepsource warnings #11814

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/execution_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ func Test_UpdateLastValidatedCheckpoint(t *testing.T) {
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
genesisStateRoot := [32]byte{}
var genesisStateRoot [32]byte
genesisBlk := blocks.NewGenesisBlock(genesisStateRoot[:])
util.SaveBlock(t, ctx, beaconDB, genesisBlk)
genesisRoot, err := genesisBlk.Block.HashTreeRoot()
Expand Down
10 changes: 5 additions & 5 deletions beacon-chain/blockchain/process_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestStore_OnBlock(t *testing.T) {

service, err := NewService(ctx, opts...)
require.NoError(t, err)
genesisStateRoot := [32]byte{}
var genesisStateRoot [32]byte
genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
util.SaveBlock(t, ctx, beaconDB, genesis)
validGenesisRoot, err := genesis.Block.HashTreeRoot()
Expand Down Expand Up @@ -362,7 +362,7 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized(t *testing.T) {
require.NoError(t, err)
service.cfg.ForkChoiceStore = doublylinkedtree.New()

genesisStateRoot := [32]byte{}
var genesisStateRoot [32]byte
genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
util.SaveBlock(t, ctx, beaconDB, genesis)
validGenesisRoot, err := genesis.Block.HashTreeRoot()
Expand Down Expand Up @@ -421,7 +421,7 @@ func TestFillForkChoiceMissingBlocks_FinalizedSibling(t *testing.T) {
require.NoError(t, err)
service.cfg.ForkChoiceStore = doublylinkedtree.New()

genesisStateRoot := [32]byte{}
var genesisStateRoot [32]byte
genesis := blocks.NewGenesisBlock(genesisStateRoot[:])
util.SaveBlock(t, ctx, beaconDB, genesis)
validGenesisRoot, err := genesis.Block.HashTreeRoot()
Expand Down Expand Up @@ -1004,7 +1004,7 @@ func TestInsertFinalizedDeposits(t *testing.T) {
assert.NoError(t, gs.SetEth1Data(&ethpb.Eth1Data{DepositCount: 10}))
assert.NoError(t, gs.SetEth1DepositIndex(8))
assert.NoError(t, service.cfg.StateGen.SaveState(ctx, [32]byte{'m', 'o', 'c', 'k'}, gs))
zeroSig := [96]byte{}
var zeroSig [96]byte
for i := uint64(0); i < uint64(4*params.BeaconConfig().SlotsPerEpoch); i++ {
root := []byte(strconv.Itoa(int(i)))
assert.NoError(t, depositCache.InsertDeposit(ctx, &ethpb.Deposit{Data: &ethpb.Deposit_Data{
Expand Down Expand Up @@ -1042,7 +1042,7 @@ func TestInsertFinalizedDeposits_MultipleFinalizedRoutines(t *testing.T) {
assert.NoError(t, gs2.SetEth1Data(&ethpb.Eth1Data{DepositCount: 15}))
assert.NoError(t, gs2.SetEth1DepositIndex(13))
assert.NoError(t, service.cfg.StateGen.SaveState(ctx, [32]byte{'m', 'o', 'c', 'k', '2'}, gs2))
zeroSig := [96]byte{}
var zeroSig [96]byte
for i := uint64(0); i < uint64(4*params.BeaconConfig().SlotsPerEpoch); i++ {
root := []byte(strconv.Itoa(int(i)))
assert.NoError(t, depositCache.InsertDeposit(ctx, &ethpb.Deposit{Data: &ethpb.Deposit_Data{
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/cache/payload_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (f *ProposerPayloadIDsCache) SetProposerAndPayloadIDs(slot types.Slot, vId
ids, ok := f.slotToProposerAndPayloadIDs[k]
// Ok to overwrite if the slot is already set but the cached payload ID is not set.
// This combats the re-org case where payload assignment could change at the start of the epoch.
byte8 := [vIdLength]byte{}
var byte8 [vIdLength]byte
if !ok || (ok && bytes.Equal(ids[vIdLength:], byte8[:])) {
f.slotToProposerAndPayloadIDs[k] = bs
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/cache/payload_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestValidatorPayloadIDsCache_GetAndSaveValidatorPayloadIDs(t *testing.T) {
cache := NewProposerPayloadIDsCache()
r := [32]byte{}
var r [32]byte
i, p, ok := cache.GetProposerPayloadIDs(0, r)
require.Equal(t, false, ok)
require.Equal(t, types.ValidatorIndex(0), i)
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/altair/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestProcessAttestationNoVerify_SourceTargetHead(t *testing.T) {
},
AggregationBits: aggBits,
}
zeroSig := [96]byte{}
var zeroSig [96]byte
att.Signature = zeroSig[:]

ckp := beaconState.CurrentJustifiedCheckpoint()
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/attestation_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestVerifyAttestationNoVerifySignature_IncorrectSourceEpoch(t *testing.T) {
AggregationBits: aggBits,
}

zeroSig := [96]byte{}
var zeroSig [96]byte
att.Signature = zeroSig[:]

err := beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/core/blocks/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestProcessAttestationsNoVerify_OK(t *testing.T) {
AggregationBits: aggBits,
}

zeroSig := [fieldparams.BLSSignatureLength]byte{}
var zeroSig [fieldparams.BLSSignatureLength]byte
att.Signature = zeroSig[:]

err := beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestVerifyAttestationNoVerifySignature_OK(t *testing.T) {
AggregationBits: aggBits,
}

zeroSig := [fieldparams.BLSSignatureLength]byte{}
var zeroSig [fieldparams.BLSSignatureLength]byte
att.Signature = zeroSig[:]

err := beaconState.SetSlot(beaconState.Slot() + params.BeaconConfig().MinAttestationInclusionDelay)
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestVerifyAttestationNoVerifySignature_BadAttIdx(t *testing.T) {
},
AggregationBits: aggBits,
}
zeroSig := [fieldparams.BLSSignatureLength]byte{}
var zeroSig [fieldparams.BLSSignatureLength]byte
att.Signature = zeroSig[:]
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+params.BeaconConfig().MinAttestationInclusionDelay))
ckp := beaconState.CurrentJustifiedCheckpoint()
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/core/blocks/block_operations_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func TestFuzzProcessBlockHeader_10000(t *testing.T) {
func TestFuzzverifyDepositDataSigningRoot_10000(_ *testing.T) {
fuzzer := fuzz.NewWithSeed(0)
var ba []byte
pubkey := [fieldparams.BLSPubkeyLength]byte{}
sig := [96]byte{}
domain := [4]byte{}
var pubkey [fieldparams.BLSPubkeyLength]byte
var sig [96]byte
var domain [4]byte
var p []byte
var s []byte
var d []byte
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func ProcessPayloadHeader(st state.BeaconState, header interfaces.ExecutionData)

// GetBlockPayloadHash returns the hash of the execution payload of the block
func GetBlockPayloadHash(blk interfaces.BeaconBlock) ([32]byte, error) {
payloadHash := [32]byte{}
var payloadHash [32]byte
if IsPreBellatrixVersion(blk.Version()) {
return payloadHash, nil
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/signing/signing_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func ComputeDomain(domainType [DomainByteLength]byte, forkVersion, genesisValida
if genesisValidatorsRoot == nil {
genesisValidatorsRoot = params.BeaconConfig().ZeroHash[:]
}
forkBytes := [ForkVersionByteLength]byte{}
var forkBytes [ForkVersionByteLength]byte
copy(forkBytes[:], forkVersion)

forkDataRoot, err := computeForkDataRoot(forkBytes[:], genesisValidatorsRoot)
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/core/signing/signing_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ func TestSigningRoot_ComputeForkDigest(t *testing.T) {
func TestFuzzverifySigningRoot_10000(_ *testing.T) {
fuzzer := fuzz.NewWithSeed(0)
st := &ethpb.BeaconState{}
pubkey := [fieldparams.BLSPubkeyLength]byte{}
sig := [96]byte{}
domain := [4]byte{}
var pubkey [fieldparams.BLSPubkeyLength]byte
var sig [96]byte
var domain [4]byte
var p []byte
var s []byte
var d []byte
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/transition/transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func createFullBlockWithOperations(t *testing.T) (state.BeaconState,
err = beaconState.SetSlashings(make([]uint64, params.BeaconConfig().EpochsPerSlashingsVector))
require.NoError(t, err)
cp := beaconState.CurrentJustifiedCheckpoint()
mockRoot := [32]byte{}
var mockRoot [32]byte
copy(mockRoot[:], "hello-world")
cp.Root = mockRoot[:]
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cp))
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/db/kv/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestStore_SaveBackfillBlockRoot(t *testing.T) {
_, err := db.BackfillBlockRoot(ctx)
require.ErrorIs(t, err, ErrNotFoundBackfillBlockRoot)

expected := [32]byte{}
var expected [32]byte
copy(expected[:], []byte{0x23})
err = db.SaveBackfillBlockRoot(ctx, expected)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (f *ForkChoice) InsertNode(ctx context.Context, state state.BeaconState, ro
return errNilBlockHeader
}
parentRoot := bytesutil.ToBytes32(bh.ParentRoot)
payloadHash := [32]byte{}
var payloadHash [32]byte
if state.Version() >= version.Bellatrix {
ph, err := state.LatestExecutionPayloadHeader()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func TestStore_InsertOptimisticChain(t *testing.T) {
blks := make([]*forkchoicetypes.BlockAndCheckpoints, 0)
blk := util.NewBeaconBlock()
blk.Block.Slot = 1
pr := [32]byte{}
var pr [32]byte
blk.Block.ParentRoot = pr[:]
root, err := blk.Block.HashTreeRoot()
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func TestForkChoice_BoostProposerRoot_PreventsExAnteAttack(t *testing.T) {
func TestForkChoice_BoostProposerRoot(t *testing.T) {
ctx := context.Background()
root := [32]byte{'A'}
zeroHash := [32]byte{}
var zeroHash [32]byte

t.Run("does not boost block from different slot", func(t *testing.T) {
f := setup(0, 0)
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/forkchoice/doubly-linked-tree/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestForkChoice_HighestReceivedBlockSlotRoot(t *testing.T) {
func TestForkChoice_ReceivedBlocksLastEpoch(t *testing.T) {
f := setup(1, 1)
s := f.store
b := [32]byte{}
var b [32]byte

// Make sure it doesn't underflow
s.genesisTime = uint64(time.Now().Add(time.Duration(-1*int64(params.BeaconConfig().SecondsPerSlot)) * time.Second).Unix())
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/monitor/process_attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestProcessUnaggregatedAttestationStateCached(t *testing.T) {
participation := []byte{0xff, 0xff, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
require.NoError(t, state.SetCurrentParticipationBits(participation))

root := [32]byte{}
var root [32]byte
copy(root[:], "hello-world")

att := &ethpb.Attestation{
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestProcessAggregatedAttestationStateCached(t *testing.T) {
participation := []byte{0xff, 0xff, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
require.NoError(t, state.SetCurrentParticipationBits(participation))

root := [32]byte{}
var root [32]byte
copy(root[:], "hello-world")

att := &ethpb.AggregateAttestationAndProof{
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/monitor/process_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestProcessProposedBlock(t *testing.T) {
hook := logTest.NewGlobal()
s := setupService(t)
beaconState, _ := util.DeterministicGenesisState(t, 256)
root := [32]byte{}
var root [32]byte
copy(root[:], "hello-world")
wb, err := blocks.NewBeaconBlock(tt.block)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func TestNodeStart_Ok_registerDeterministicGenesisService(t *testing.T) {
genesisState, _, err := interop.GenerateGenesisState(context.Background(), 0, numValidators)
require.NoError(t, err, "Could not generate genesis beacon state")
for i := uint64(1); i < 2; i++ {
someRoot := [32]byte{}
someKey := [fieldparams.BLSPubkeyLength]byte{}
var someRoot [32]byte
var someKey [fieldparams.BLSPubkeyLength]byte
copy(someRoot[:], strconv.Itoa(int(i)))
copy(someKey[:], strconv.Itoa(int(i)))
genesisState.Validators = append(genesisState.Validators, &ethpb.Validator{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestBatchAttestations_Single(t *testing.T) {
priv, err := bls.RandKey()
require.NoError(t, err)
sig := priv.Sign([]byte("dummy_test_data"))
mockRoot := [32]byte{}
var mockRoot [32]byte
d := &ethpb.AttestationData{
BeaconBlockRoot: mockRoot[:],
Source: &ethpb.Checkpoint{Root: mockRoot[:]},
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestAggregateAndSaveForkChoiceAtts_Single(t *testing.T) {
priv, err := bls.RandKey()
require.NoError(t, err)
sig := priv.Sign([]byte("dummy_test_data"))
mockRoot := [32]byte{}
var mockRoot [32]byte
d := &ethpb.AttestationData{
BeaconBlockRoot: mockRoot[:],
Source: &ethpb.Checkpoint{Root: mockRoot[:]},
Expand All @@ -186,7 +186,7 @@ func TestAggregateAndSaveForkChoiceAtts_Multiple(t *testing.T) {
priv, err := bls.RandKey()
require.NoError(t, err)
sig := priv.Sign([]byte("dummy_test_data"))
mockRoot := [32]byte{}
var mockRoot [32]byte
d := &ethpb.AttestationData{
BeaconBlockRoot: mockRoot[:],
Source: &ethpb.Checkpoint{Root: mockRoot[:]},
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/p2p/peers/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,10 @@ func TestTrimmedOrderedPeers(t *testing.T) {

expectedTarget := types.Epoch(2)
maxPeers := 3
mockroot2 := [32]byte{}
mockroot3 := [32]byte{}
mockroot4 := [32]byte{}
mockroot5 := [32]byte{}
var mockroot2 [32]byte
var mockroot3 [32]byte
var mockroot4 [32]byte
var mockroot5 [32]byte
copy(mockroot2[:], "two")
copy(mockroot3[:], "three")
copy(mockroot4[:], "four")
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/p2p/pubsub_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestService_CanSubscribe(t *testing.T) {
currentFork := [4]byte{0x01, 0x02, 0x03, 0x04}
validProtocolSuffix := "/" + encoder.ProtocolSuffixSSZSnappy
genesisTime := time.Now()
valRoot := [32]byte{}
var valRoot [32]byte
digest, err := forks.CreateForkDigest(genesisTime, valRoot[:])
assert.NoError(t, err)
type test struct {
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestService_FilterIncomingSubscriptions(t *testing.T) {
params.SetupTestConfigCleanup(t)
validProtocolSuffix := "/" + encoder.ProtocolSuffixSSZSnappy
genesisTime := time.Now()
valRoot := [32]byte{}
var valRoot [32]byte
digest, err := forks.CreateForkDigest(genesisTime, valRoot[:])
assert.NoError(t, err)
type args struct {
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/rpc/eth/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (vs *Server) GetAttesterDuties(ctx context.Context, req *ethpbv1.AttesterDu
duties := make([]*ethpbv1.AttesterDuty, 0, len(req.Index))
for _, index := range req.Index {
pubkey := s.PubkeyAtIndex(index)
zeroPubkey := [fieldparams.BLSPubkeyLength]byte{}
var zeroPubkey [fieldparams.BLSPubkeyLength]byte
if bytes.Equal(pubkey[:], zeroPubkey[:]) {
return nil, status.Errorf(codes.InvalidArgument, "Invalid validator index")
}
Expand Down Expand Up @@ -1118,7 +1118,7 @@ func syncCommitteeDuties(
ValidatorIndex: index,
}
valPubkey48 := st.PubkeyAtIndex(index)
zeroPubkey := [fieldparams.BLSPubkeyLength]byte{}
var zeroPubkey [fieldparams.BLSPubkeyLength]byte
if bytes.Equal(valPubkey48[:], zeroPubkey[:]) {
return nil, errInvalidValIndex
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func generateAtt(state state.ReadOnlyBeaconState, index uint64, privKeys []bls.S
}

sigs := make([]bls.Signature, len(attestingIndices))
zeroSig := [96]byte{}
var zeroSig [96]byte
att.Signature = zeroSig[:]

for i, indice := range attestingIndices {
Expand Down Expand Up @@ -274,7 +274,7 @@ func generateUnaggregatedAtt(state state.ReadOnlyBeaconState, index uint64, priv
}

sigs := make([]bls.Signature, len(attestingIndices))
zeroSig := [96]byte{}
var zeroSig [96]byte
att.Signature = zeroSig[:]

for i, indice := range attestingIndices {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ func TestProposer_FilterAttestation(t *testing.T) {
domain, err := signing.Domain(st.Fork(), 0, params.BeaconConfig().DomainBeaconAttester, params.BeaconConfig().ZeroHash[:])
require.NoError(t, err)
sigs := make([]bls.Signature, len(attestingIndices))
zeroSig := [96]byte{}
var zeroSig [96]byte
atts[i].Signature = zeroSig[:]

for i, indice := range attestingIndices {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestGetSyncSubcommitteeIndex_Ok(t *testing.T) {
SyncCommitteeIndices: []types.CommitteeIndex{0},
},
}
pubKey := [fieldparams.BLSPubkeyLength]byte{}
var pubKey [fieldparams.BLSPubkeyLength]byte
// Request slot 0, should get the index 0 for validator 0.
res, err := server.GetSyncSubcommitteeIndex(context.Background(), &ethpb.SyncSubcommitteeIndexRequest{
PublicKey: pubKey[:], Slot: types.Slot(0),
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/slasher/detect_attestations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ func runAttestationsBenchmark(b *testing.B, s *Service, numAtts, numValidators u
for i := uint64(0); i < numAtts; i++ {
source := types.Epoch(i)
target := types.Epoch(i + 1)
signingRoot := [32]byte{}
var signingRoot [32]byte
copy(signingRoot[:], fmt.Sprintf("%d", i))
atts[i] = createAttestationWrapper(
b,
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/state/fieldtrie/field_trie_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func handleBalanceSlice(val, indices []uint64, convertAll bool) ([][32]byte, err
// are compressed according to 4 values -> 1 chunk.
startIdx := idx / numOfElems
startGroup := startIdx * numOfElems
chunk := [32]byte{}
var chunk [32]byte
sizeOfElem := len(chunk) / iNumOfElems
for i, j := 0, startGroup; j < startGroup+numOfElems; i, j = i+sizeOfElem, j+1 {
wantedVal := uint64(0)
Expand Down
Loading