Skip to content
2 changes: 1 addition & 1 deletion .avalanche-golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ linters:
- errorlint
# - forbidigo
- goconst
# - gocritic
- gocritic
- goprintffuncname
# - gosec
- govet
Expand Down
5 changes: 3 additions & 2 deletions core/blockchain_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package core
import (
"fmt"
"math/big"
"slices"
"testing"

"github.com/ava-labs/libevm/common"
Expand Down Expand Up @@ -1694,7 +1695,7 @@ func ReexecBlocksTest(t *testing.T, create ReexecTestFunc) {

newChain, restartedChain := checkBlockChainState(t, blockchain, gspec, chainDB, checkCreate, checkState)

allTxs := append(foundTxs, missingTxs...)
allTxs := slices.Concat(foundTxs, missingTxs)
for _, bc := range []*BlockChain{newChain, restartedChain} {
// We should confirm that snapshots were properly initialized
if bc.snaps == nil && bc.cacheConfig.SnapshotLimit > 0 {
Expand Down Expand Up @@ -1826,7 +1827,7 @@ func ReexecMaxBlocksTest(t *testing.T, create ReexecTestFunc) {
}
newChain, restartedChain := checkBlockChainState(t, blockchain, gspec, chainDB, checkCreate, checkState)

allTxs := append(foundTxs, missingTxs...)
allTxs := slices.Concat(foundTxs, missingTxs)
for _, bc := range []*BlockChain{newChain, restartedChain} {
// We should confirm that snapshots were properly initialized
if bc.snaps == nil && bc.cacheConfig.SnapshotLimit > 0 {
Expand Down
6 changes: 3 additions & 3 deletions core/extstate/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (fs *fuzzState) updateAccount(addrIndex int) {
fs.require.NoError(err, "failed to get account %s for update in %s", addr.Hex(), tr.name)
fs.require.NotNil(acc, "account %s is nil for update in %s", addr.Hex(), tr.name)
acc.Nonce++
acc.CodeHash = crypto.Keccak256Hash(acc.CodeHash[:]).Bytes()
acc.CodeHash = crypto.Keccak256Hash(acc.CodeHash).Bytes()
acc.Balance.Add(acc.Balance, uint256.NewInt(3))
fs.require.NoError(tr.accountTrie.UpdateAccount(addr, acc), "failed to update account %s in %s", addr.Hex(), tr.name)
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func (fs *fuzzState) updateStorage(accountIndex int, storageIndexInput uint64) {
storageKeyHash := crypto.Keccak256Hash(storageKey[:])
fs.inputCounter++
updatedValInput := binary.BigEndian.AppendUint64(storageKeyHash[:], fs.inputCounter)
updatedVal := crypto.Keccak256Hash(updatedValInput[:])
updatedVal := crypto.Keccak256Hash(updatedValInput)

for _, tr := range fs.merkleTries {
str := fs.openStorageTrie(addr, tr)
Expand Down Expand Up @@ -324,7 +324,7 @@ func FuzzTree(f *testing.F) {
}

for _, step := range byteSteps {
step = step % maxStep
step %= maxStep
t.Log(stepMap[step])
switch step {
case commit:
Expand Down
7 changes: 4 additions & 3 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ func SetEthUpgrades(c *ChainConfig) error {
extra := GetExtra(c)
// Because Fuji and Mainnet have already accepted the Berlin and London
// blocks, it is assumed that they are scheduled for activation.
if c.ChainID != nil && AvalancheFujiChainID.Cmp(c.ChainID) == 0 {
switch {
case c.ChainID != nil && AvalancheFujiChainID.Cmp(c.ChainID) == 0:
c.BerlinBlock = big.NewInt(184985) // https://testnet.snowtrace.io/block/184985?chainid=43113, AP2 activation block
c.LondonBlock = big.NewInt(805078) // https://testnet.snowtrace.io/block/805078?chainid=43113, AP3 activation block
} else if c.ChainID != nil && AvalancheMainnetChainID.Cmp(c.ChainID) == 0 {
case c.ChainID != nil && AvalancheMainnetChainID.Cmp(c.ChainID) == 0:
c.BerlinBlock = big.NewInt(1640340) // https://snowtrace.io/block/1640340?chainid=43114, AP2 activation block
c.LondonBlock = big.NewInt(3308552) // https://snowtrace.io/block/3308552?chainid=43114, AP3 activation block
} else {
default:
// In testing or local networks, we only support enabling Berlin and
// London at the initially active time. This corresponds to an intended
// block number of 0.
Expand Down
12 changes: 5 additions & 7 deletions plugin/evm/atomic/vm/block_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,11 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error {
if headerExtra.ExtDataHash != hash {
return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, hash)
}
} else {
if headerExtra.ExtDataHash != (common.Hash{}) {
return fmt.Errorf(
"expected ExtDataHash to be empty but got %x",
headerExtra.ExtDataHash,
)
}
} else if headerExtra.ExtDataHash != (common.Hash{}) {
return fmt.Errorf(
"expected ExtDataHash to be empty but got %x",
headerExtra.ExtDataHash,
)
}

// Block must not be empty
Expand Down
3 changes: 1 addition & 2 deletions plugin/evm/atomic/vm/import_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1327,8 +1327,7 @@ func executeTxTest(t *testing.T, test atomicTxTest) {

var baseFee *big.Int
// If ApricotPhase3 is active, use the initial base fee for the atomic transaction
switch {
case rules.IsApricotPhase3:
if rules.IsApricotPhase3 {
baseFee = vmtest.InitialBaseFee
}

Expand Down
6 changes: 2 additions & 4 deletions plugin/evm/atomic/vm/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ func TestCalculateDynamicFee(t *testing.T) {
if cost != test.expectedValue {
t.Fatalf("Expected value: %d, found: %d", test.expectedValue, cost)
}
} else {
if err != test.expectedErr {
t.Fatalf("Expected error: %s, found error: %s", test.expectedErr, err)
}
} else if err != test.expectedErr {
t.Fatalf("Expected error: %s, found error: %s", test.expectedErr, err)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion plugin/evm/customrawdb/accessors_state_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package customrawdb

import (
"slices"
"testing"

"github.com/ava-labs/libevm/common"
Expand All @@ -18,7 +19,7 @@ func TestClearPrefix(t *testing.T) {
require.NoError(WriteSyncSegment(db, common.Hash{1}, common.Hash{}))

// add a key that should not be cleared
key := append(syncSegmentsPrefix, []byte("foo")...)
key := slices.Concat(syncSegmentsPrefix, []byte("foo"))
require.NoError(db.Put(key, []byte("bar")))

require.NoError(ClearAllSyncSegments(db))
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ func (vm *VM) startContinuousProfiler() {
return
}
vm.profiler = profiler.NewContinuous(
filepath.Join(vm.config.ContinuousProfilerDir),
filepath.Clean(vm.config.ContinuousProfilerDir),
vm.config.ContinuousProfilerFrequency.Duration,
vm.config.ContinuousProfilerMaxFiles,
)
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/vm_warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func testSendWarpMessage(t *testing.T, scheme string) {
// Verify the message signature after accepting the block.
rawSignatureBytes, err := vm.warpBackend.GetMessageSignature(context.TODO(), unsignedMessage)
require.NoError(err)
blsSignature, err := bls.SignatureFromBytes(rawSignatureBytes[:])
blsSignature, err := bls.SignatureFromBytes(rawSignatureBytes)
require.NoError(err)

select {
Expand All @@ -169,7 +169,7 @@ func testSendWarpMessage(t *testing.T, scheme string) {
// Verify the blockID will now be signed by the backend and produces a valid signature.
rawSignatureBytes, err = vm.warpBackend.GetBlockSignature(context.TODO(), blk.ID())
require.NoError(err)
blsSignature, err = bls.SignatureFromBytes(rawSignatureBytes[:])
blsSignature, err = bls.SignatureFromBytes(rawSignatureBytes)
require.NoError(err)

blockHashPayload, err := payload.NewHash(blk.ID())
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 @@ -358,8 +358,8 @@ func TestLeafsRequestHandler_OnLeafsRequest(t *testing.T) {
"partial mid range": {
prepareTestFn: func() (context.Context, message.LeafsRequest) {
startKey := largeTrieKeys[1_000]
startKey[31] = startKey[31] + 1 // exclude start key from response
endKey := largeTrieKeys[1_040] // include end key in response
startKey[31]++ // exclude start key from response
endKey := largeTrieKeys[1_040] // include end key in response
return context.Background(), message.LeafsRequest{
Root: largeTrieRoot,
Start: startKey,
Expand Down
4 changes: 1 addition & 3 deletions triedb/firewood/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,5 @@ func arrangeKeyValuePairs(nodes *trienode.MergedNodeSet) ([][]byte, [][]byte) {
}

// We need to do all storage operations first, so prefix-deletion works for accounts.
keys := append(storageKeys, acctKeys...)
values := append(storageValues, acctValues...)
return keys, values
return append(storageKeys, acctKeys...), append(storageValues, acctValues...)
}
8 changes: 4 additions & 4 deletions warp/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestAddAndGetValidMessage(t *testing.T) {

expectedSig, err := warpSigner.Sign(testUnsignedMessage)
require.NoError(t, err)
require.Equal(t, expectedSig, signature[:])
require.Equal(t, expectedSig, signature)
}

func TestAddAndGetUnknownMessage(t *testing.T) {
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestGetBlockSignature(t *testing.T) {

signature, err := backend.GetBlockSignature(context.TODO(), blkID)
require.NoError(err)
require.Equal(expectedSig, signature[:])
require.Equal(expectedSig, signature)

_, err = backend.GetBlockSignature(context.TODO(), ids.GenerateTestID())
require.Error(err)
Expand All @@ -127,7 +127,7 @@ func TestZeroSizedCache(t *testing.T) {

expectedSig, err := warpSigner.Sign(testUnsignedMessage)
require.NoError(t, err)
require.Equal(t, expectedSig, signature[:])
require.Equal(t, expectedSig, signature)
}

func TestOffChainMessages(t *testing.T) {
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestOffChainMessages(t *testing.T) {
require.NoError(err)
expectedSignatureBytes, err := warpSigner.Sign(msg)
require.NoError(err)
require.Equal(expectedSignatureBytes, signature[:])
require.Equal(expectedSignatureBytes, signature)
},
},
"unknown message": {
Expand Down
4 changes: 2 additions & 2 deletions warp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (a *API) GetMessageSignature(ctx context.Context, messageID ids.ID) (hexuti
if err != nil {
return nil, fmt.Errorf("failed to get signature for message %s with error %w", messageID, err)
}
return signature[:], nil
return signature, nil
}

// GetBlockSignature returns the BLS signature associated with a blockID.
Expand All @@ -67,7 +67,7 @@ func (a *API) GetBlockSignature(ctx context.Context, blockID ids.ID) (hexutil.By
if err != nil {
return nil, fmt.Errorf("failed to get signature for block %s with error %w", blockID, err)
}
return signature[:], nil
return signature, nil
}

// GetMessageAggregateSignature fetches the aggregate signature for the requested [messageID]
Expand Down
6 changes: 3 additions & 3 deletions warp/verifier_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestAddressedCallSignatures(t *testing.T) {
require.NoError(t, err)

backend.AddMessage(msg)
return msg.Bytes(), signature[:]
return msg.Bytes(), signature
},
verifyStats: func(t *testing.T, stats *verifierStats) {
require.EqualValues(t, 0, stats.messageParseFail.Snapshot().Count())
Expand All @@ -63,7 +63,7 @@ func TestAddressedCallSignatures(t *testing.T) {
},
"offchain message": {
setup: func(_ Backend) (request []byte, expectedResponse []byte) {
return offchainMessage.Bytes(), offchainSignature[:]
return offchainMessage.Bytes(), offchainSignature
},
verifyStats: func(t *testing.T, stats *verifierStats) {
require.EqualValues(t, 0, stats.messageParseFail.Snapshot().Count())
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestBlockSignatures(t *testing.T) {
require.NoError(t, err)
signature, err := snowCtx.WarpSigner.Sign(unsignedMessage)
require.NoError(t, err)
return toMessageBytes(knownBlkID), signature[:]
return toMessageBytes(knownBlkID), signature
},
verifyStats: func(t *testing.T, stats *verifierStats) {
require.EqualValues(t, 0, stats.blockValidationFail.Snapshot().Count())
Expand Down