Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d24bd6a
lint enable gosec
JonathanOppenheimer Sep 10, 2025
b465187
make tests deterministic
JonathanOppenheimer Sep 10, 2025
969b51e
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 11, 2025
01395ef
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 12, 2025
3b51256
Update plugin/evm/message/helpers_test.go
JonathanOppenheimer Sep 12, 2025
fb0a1c6
first round stephen reviews
JonathanOppenheimer Sep 12, 2025
6021c88
redo rand implementation
JonathanOppenheimer Sep 12, 2025
e2dd1c0
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 12, 2025
eab8c81
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 17, 2025
e9e136d
austin suggestion
JonathanOppenheimer Sep 17, 2025
66e1c6f
lol what
JonathanOppenheimer Sep 17, 2025
7cbf4c8
lint
JonathanOppenheimer Sep 17, 2025
f92fa5a
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 17, 2025
37f65a0
revert balance
JonathanOppenheimer Sep 18, 2025
57ec43b
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 18, 2025
5fd167c
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 22, 2025
b050e4f
Austin suggestions
JonathanOppenheimer Sep 22, 2025
d960769
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 23, 2025
c121ab6
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 24, 2025
eaf433d
Austin suggestions
JonathanOppenheimer Sep 24, 2025
341e908
clean-up
JonathanOppenheimer Sep 24, 2025
7172e4f
update request strings
JonathanOppenheimer Sep 24, 2025
40ebd2b
this too
JonathanOppenheimer Sep 24, 2025
80c06b8
use correct rand
JonathanOppenheimer Sep 24, 2025
603dd3b
crypto rand
JonathanOppenheimer Sep 24, 2025
57989a3
more aggressive corruption
JonathanOppenheimer Sep 24, 2025
b244df3
fix seeding here too
JonathanOppenheimer Sep 24, 2025
62ec0ca
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 24, 2025
8e657bf
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 25, 2025
e02b224
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 29, 2025
8d0388a
fix imports
JonathanOppenheimer Sep 29, 2025
62612f3
lint
JonathanOppenheimer Sep 29, 2025
1f1bb2a
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Sep 30, 2025
6786d70
Merge branch 'master' into lint-enable-gosec
JonathanOppenheimer Oct 2, 2025
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 .avalanche-golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ linters:
- goconst
- gocritic
- goprintffuncname
# - gosec
- gosec
- govet
- importas
- ineffassign
Expand Down
5 changes: 4 additions & 1 deletion cmd/simulator/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/ava-labs/libevm/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/ava-labs/coreth/rpc"
)

type Metrics struct {
Expand Down Expand Up @@ -66,7 +68,8 @@ func (m *Metrics) Serve(ctx context.Context, metricsPort string, metricsEndpoint
ctx, cancel := context.WithCancel(ctx)
// Create a prometheus server to expose individual tx metrics
server := &http.Server{
Addr: ":" + metricsPort,
Addr: ":" + metricsPort,
ReadHeaderTimeout: rpc.DefaultHTTPTimeouts.ReadHeaderTimeout,
}

// Start up go routine to listen for SIGINT notifications to gracefully shut down server
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ func ReexecCorruptedStateTest(t *testing.T, create ReexecTestFunc) {
require.NoError(t, blockchain.Accept(chain[0]))

// Simulate a crash by updating the acceptor tip
blockchain.writeBlockAcceptedIndices(chain[1])
require.NoError(t, blockchain.writeBlockAcceptedIndices(chain[1]))
blockchain.Stop()

// Restart blockchain with existing state
Expand Down
2 changes: 1 addition & 1 deletion core/extstate/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (fs *fuzzState) deleteStorage(accountIndex int, storageIndexInput uint64) {
func FuzzTree(f *testing.F) {
f.Fuzz(func(t *testing.T, randSeed int64, byteSteps []byte) {
fuzzState := newFuzzState(t)
rand := rand.New(rand.NewSource(randSeed))
rand := rand.New(rand.NewSource(randSeed)) //nolint:gosec // this isn't a good fuzz test, but it is reproducible.

for range 10 {
fuzzState.createAccount()
Expand Down
7 changes: 4 additions & 3 deletions network/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package network

import (
"math"
"math/rand"
"time"

"github.com/ava-labs/avalanchego/ids"
Expand All @@ -14,6 +13,8 @@ import (
"github.com/ava-labs/libevm/log"
"github.com/ava-labs/libevm/metrics"

"github.com/ava-labs/coreth/utils/rand"

safemath "github.com/ava-labs/avalanchego/utils/math"
)

Expand Down Expand Up @@ -76,7 +77,7 @@ func (p *peerTracker) shouldTrackNewPeer() bool {
return false
}
newPeerProbability := math.Exp(-float64(numResponsivePeers) * newPeerConnectFactor)
return rand.Float64() < newPeerProbability
return rand.SecureFloat64() < newPeerProbability
}

// getResponsivePeer returns a random [ids.NodeID] of a peer that has responded
Expand Down Expand Up @@ -115,7 +116,7 @@ func (p *peerTracker) GetAnyPeer(minVersion *version.Application) (ids.NodeID, b
random bool
averager safemath.Averager
)
if rand.Float64() < randomPeerProbability {
if rand.SecureFloat64() < randomPeerProbability {
random = true
nodeID, averager, ok = p.getResponsivePeer()
} else {
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/atomic/atomictest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func GenerateTestExportTx() *atomic.Tx {
}

func NewTestTx() *atomic.Tx {
txType := rand.Intn(2)
txType := rand.Intn(2) //nolint:gosec
switch txType {
case 0:
return GenerateTestImportTx()
Expand Down
8 changes: 4 additions & 4 deletions plugin/evm/atomic/sync/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestSyncerScenarios(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
targetHeight := 10 * uint64(testCommitInterval)
serverTrieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
root, _, _ := statesynctest.GenerateTrie(t, r, serverTrieDB, int(targetHeight), state.TrieKeyLength)
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestSyncerResumeScenarios(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
targetHeight := 10 * uint64(testCommitInterval)
serverTrieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
numTrieKeys := int(targetHeight) - 1 // no atomic ops for genesis
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestSyncerResumeNewRootCheckpointScenarios(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
targetHeight1 := 10 * uint64(testCommitInterval)
serverTrieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
numTrieKeys1 := int(targetHeight1) - 1 // no atomic ops for genesis
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestSyncerContextCancellation(t *testing.T) {
// It returns the context, mock client, atomic backend, client DB, and root hash for testing.
func setupParallelizationTest(t *testing.T, targetHeight uint64) (context.Context, *syncclient.TestClient, *state.AtomicBackend, *versiondb.Database, common.Hash) {
// Create a simple test trie with some data.
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
serverTrieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
root, _, _ := statesynctest.GenerateTrie(t, r, serverTrieDB, int(targetHeight), state.TrieKeyLength)

Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/customtypes/header_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func allFieldsSet[T interface {
if fieldValue.Kind() == reflect.Ptr {
require.Falsef(t, fieldValue.IsNil(), "field %q is nil", field.Name)
}
fieldValue = reflect.NewAt(fieldValue.Type(), unsafe.Pointer(fieldValue.UnsafeAddr())).Elem() //nolint:gosec
fieldValue = reflect.NewAt(fieldValue.Type(), unsafe.Pointer(fieldValue.UnsafeAddr())).Elem()
}

switch f := fieldValue.Interface().(type) {
Expand Down
5 changes: 1 addition & 4 deletions plugin/evm/message/block_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,17 @@ func TestMarshalBlockRequest(t *testing.T) {
func TestMarshalBlockResponse(t *testing.T) {
// create some random bytes
// set seed to ensure deterministic random behaviour
rand := rand.New(rand.NewSource(1))
rand := rand.New(rand.NewSource(1)) //nolint:gosec
blocksBytes := make([][]byte, 32)
for i := range blocksBytes {
blocksBytes[i] = make([]byte, rand.Intn(32)+32) // min 32 length, max 64
_, err := rand.Read(blocksBytes[i])
require.NoError(t, err)
}

blockResponse := BlockResponse{
Blocks: blocksBytes,
}

base64BlockResponse := "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"

blockResponseBytes, err := Codec.Marshal(Version, blockResponse)
require.NoError(t, err)
require.Equal(t, base64BlockResponse, base64.StdEncoding.EncodeToString(blockResponseBytes))
Expand Down
6 changes: 2 additions & 4 deletions plugin/evm/message/code_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ func TestMarshalCodeRequest(t *testing.T) {
// TestMarshalCodeResponse requires that the structure or serialization logic hasn't changed, primarily to
// ensure compatibility with the network.
func TestMarshalCodeResponse(t *testing.T) {
// generate some random code data
// set random seed for deterministic random
rand := rand.New(rand.NewSource(1))
rand := rand.New(rand.NewSource(1)) //nolint:gosec

codeData := make([]byte, 50)
_, err := rand.Read(codeData)
require.NoError(t, err)
Expand All @@ -46,7 +45,6 @@ func TestMarshalCodeResponse(t *testing.T) {
}

base64CodeResponse := "AAAAAAABAAAAMlL9/AchgmVPFj9fD5piHXKVZsdNEAN8TXu7BAfR4sZJgYVa2GgdDYbR6R4AFnk5y2aU"

codeResponseBytes, err := Codec.Marshal(Version, codeResponse)
require.NoError(t, err)
require.Equal(t, base64CodeResponse, base64.StdEncoding.EncodeToString(codeResponseBytes))
Expand Down
8 changes: 2 additions & 6 deletions plugin/evm/message/leafs_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (
// TestMarshalLeafsRequest requires that the structure or serialization logic hasn't changed, primarily to
// ensure compatibility with the network.
func TestMarshalLeafsRequest(t *testing.T) {
// generate some random code data
// set random seed for deterministic random
rand := rand.New(rand.NewSource(1))
rand := rand.New(rand.NewSource(1)) //nolint:gosec

startBytes := make([]byte, common.HashLength)
endBytes := make([]byte, common.HashLength)
Expand Down Expand Up @@ -55,9 +53,7 @@ func TestMarshalLeafsRequest(t *testing.T) {
// TestMarshalLeafsResponse requires that the structure or serialization logic hasn't changed, primarily to
// ensure compatibility with the network.
func TestMarshalLeafsResponse(t *testing.T) {
// generate some random code data
// set random seed for deterministic random
rand := rand.New(rand.NewSource(1))
rand := rand.New(rand.NewSource(1)) //nolint:gosec

keysBytes := make([][]byte, 16)
valsBytes := make([][]byte, 16)
Expand Down
16 changes: 8 additions & 8 deletions plugin/evm/vmtest/test_syncervm.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ func StateSyncToggleEnabledToDisabledTest(t *testing.T, testSetup *SyncTestSetup
require := require.New(t)
reqCount := 0
test := SyncTestParams{
SyncableInterval: 256,
SyncableInterval: vmsync.BlocksToFetch,
StateSyncMinBlocks: 50, // must be less than [syncableInterval] to perform sync
SyncMode: block.StateSyncStatic,
responseIntercept: func(syncerVM extension.InnerVM, nodeID ids.NodeID, requestID uint32, response []byte) {
lock.Lock()
defer lock.Unlock()

reqCount++
// Fail all requests after number 50 to interrupt the sync
if reqCount > 50 {
// Fail all requests after number 5 to interrupt the sync
if reqCount > 5 {
if err := syncerVM.AppRequestFailed(context.Background(), nodeID, requestID, commonEng.ErrTimeout); err != nil {
panic(err)
}
Expand Down Expand Up @@ -251,19 +251,19 @@ func VMShutdownWhileSyncingTest(t *testing.T, testSetup *SyncTestSetup) {
)
reqCount := 0
test := SyncTestParams{
SyncableInterval: 256,
SyncableInterval: vmsync.BlocksToFetch,
StateSyncMinBlocks: 50, // must be less than [syncableInterval] to perform sync
SyncMode: block.StateSyncStatic,
responseIntercept: func(syncerVM extension.InnerVM, nodeID ids.NodeID, requestID uint32, response []byte) {
lock.Lock()
defer lock.Unlock()

reqCount++
// Shutdown the VM after 50 requests to interrupt the sync
if reqCount == 50 {
// Shutdown the VM after 5 requests to interrupt the sync
if reqCount == 5 {
// Note this verifies the VM shutdown does not time out while syncing.
require.NoError(t, testSyncVMSetup.syncerVM.shutdownOnceSyncerVM.Shutdown(context.Background()))
} else if reqCount < 50 {
} else if reqCount < 5 {
require.NoError(t, syncerVM.AppResponse(context.Background(), nodeID, requestID, response))
}
},
Expand Down Expand Up @@ -312,7 +312,7 @@ func initSyncServerAndClientVMs(t *testing.T, test SyncTestParams, numBlocks int
generateAndAcceptBlocks(t, serverVM, numBlocks, testSetup.GenFn, nil, cb)

// make some accounts
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
root, accounts := statesynctest.FillAccountsWithOverlappingStorage(t, r, serverVM.Ethereum().BlockChain().TrieDB(), types.EmptyRootHash, 1000, 16)

// patch serverVM's lastAcceptedBlock to have the new root
Expand Down
4 changes: 2 additions & 2 deletions sync/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func buildGetter(blocks []*types.Block) handlers.BlockProvider {

func TestGetLeafs(t *testing.T) {
const leafsLimit = 1024
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec

trieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
largeTrieRoot, largeTrieKeys, _ := statesynctest.GenerateTrie(t, r, trieDB, 100_000, common.HashLength)
Expand Down Expand Up @@ -677,7 +677,7 @@ func TestGetLeafs(t *testing.T) {
}

func TestGetLeafsRetries(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
trieDB := triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)
root, _, _ := statesynctest.GenerateTrie(t, r, trieDB, 100_000, common.HashLength)

Expand Down
4 changes: 2 additions & 2 deletions sync/handlers/leafs_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func TestLeafsRequestHandler_OnLeafsRequest(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
testHandlerStats := &statstest.TestHandlerStats{}
memdb := rawdb.NewMemoryDatabase()
trieDB := triedb.NewDatabase(memdb, nil)
Expand All @@ -35,7 +35,7 @@ func TestLeafsRequestHandler_OnLeafsRequest(t *testing.T) {
tr, err := trie.New(trie.TrieID(corruptedTrieRoot), trieDB)
require.NoError(t, err)
// Corrupt [corruptedTrieRoot]
statesynctest.CorruptTrie(t, memdb, tr, 5)
statesynctest.CorruptTrie(t, memdb, tr, 2)

largeTrieRoot, largeTrieKeys, _ := statesynctest.GenerateTrie(t, r, trieDB, 10_000, common.HashLength)
smallTrieRoot, _, _ := statesynctest.GenerateTrie(t, r, trieDB, 500, common.HashLength)
Expand Down
16 changes: 8 additions & 8 deletions sync/statesync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func testSync(t *testing.T, test syncTest) {
if test.ctx != nil {
ctx = test.ctx
}
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
clientDB, serverDB, serverTrieDB, root := test.prepareForTest(t, r)
leafsRequestHandler := handlers.NewLeafsRequestHandler(serverTrieDB, message.StateTrieKeyLength, nil, message.Codec, handlerstats.NewNoopHandlerStats())
codeRequestHandler := handlers.NewCodeRequestHandler(serverDB, message.Codec, handlerstats.NewNoopHandlerStats())
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestSimpleSyncCases(t *testing.T) {
}

func TestCancelSync(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
serverDB := rawdb.NewMemoryDatabase()
serverTrieDB := triedb.NewDatabase(serverDB, nil)
// Create trie with 2000 accounts (more than one leaf request)
Expand Down Expand Up @@ -241,7 +241,7 @@ func (i *interruptLeafsIntercept) getLeafsIntercept(request message.LeafsRequest
}

func TestResumeSyncAccountsTrieInterrupted(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
serverDB := rawdb.NewMemoryDatabase()
serverTrieDB := triedb.NewDatabase(serverDB, nil)
root, _ := statesynctest.FillAccountsWithOverlappingStorage(t, r, serverTrieDB, common.Hash{}, 2000, 3)
Expand All @@ -268,7 +268,7 @@ func TestResumeSyncAccountsTrieInterrupted(t *testing.T) {
}

func TestResumeSyncLargeStorageTrieInterrupted(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
serverDB := rawdb.NewMemoryDatabase()
serverTrieDB := triedb.NewDatabase(serverDB, nil)

Expand Down Expand Up @@ -301,7 +301,7 @@ func TestResumeSyncLargeStorageTrieInterrupted(t *testing.T) {
}

func TestResumeSyncToNewRootAfterLargeStorageTrieInterrupted(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
serverDB := rawdb.NewMemoryDatabase()
serverTrieDB := triedb.NewDatabase(serverDB, nil)

Expand Down Expand Up @@ -343,7 +343,7 @@ func TestResumeSyncToNewRootAfterLargeStorageTrieInterrupted(t *testing.T) {
}

func TestResumeSyncLargeStorageTrieWithConsecutiveDuplicatesInterrupted(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
serverDB := rawdb.NewMemoryDatabase()
serverTrieDB := triedb.NewDatabase(serverDB, nil)

Expand Down Expand Up @@ -376,7 +376,7 @@ func TestResumeSyncLargeStorageTrieWithConsecutiveDuplicatesInterrupted(t *testi
}

func TestResumeSyncLargeStorageTrieWithSpreadOutDuplicatesInterrupted(t *testing.T) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
serverDB := rawdb.NewMemoryDatabase()
serverTrieDB := triedb.NewDatabase(serverDB, nil)

Expand Down Expand Up @@ -477,7 +477,7 @@ func TestResyncNewRootAfterDeletes(t *testing.T) {
}

func testSyncerSyncsToNewRoot(t *testing.T, deleteBetweenSyncs func(*testing.T, common.Hash, ethdb.Database)) {
r := rand.New(rand.NewSource(1))
r := rand.New(rand.NewSource(1)) //nolint:gosec
clientDB := rawdb.NewMemoryDatabase()
serverDB := rawdb.NewMemoryDatabase()
serverTrieDB := triedb.NewDatabase(serverDB, nil)
Expand Down
20 changes: 20 additions & 0 deletions utils/rand/rand.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package rand

import (
"crypto/rand"
"encoding/binary"
"math"
)

func SecureFloat64() float64 {
var b [8]byte
if _, err := rand.Read(b[:]); err != nil {
panic("crypto/rand failed: " + err.Error())
}
bits := binary.BigEndian.Uint64(b[:])
bits = (bits >> 12) | (1023 << 52) // 52-bit mantissa, exponent=1023 -> [1,2)
return math.Float64frombits(bits) - 1.0
}
Loading