Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 1 addition & 4 deletions accounts/abi/bind/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ func TestWaitDeployedCornerCases(t *testing.T) {
// Create a transaction to an account.
code := "6060604052600a8060106000396000f360606040526008565b00"
tx := types.NewTransaction(0, common.HexToAddress("0x01"), big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
tx, err := types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
if err != nil {
t.Fatalf("Failed to sign transaction: %s", err)
}
tx, _ = types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import (
"fmt"

"github.com/ava-labs/libevm/core/types"
ethparams "github.com/ava-labs/libevm/params"
"github.com/ava-labs/libevm/trie"
"github.com/ava-labs/subnet-evm/consensus"
"github.com/ava-labs/subnet-evm/core/state"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/params/extras"
)

// BlockValidator is responsible for validating block headers, uncles and
Expand Down Expand Up @@ -148,10 +148,10 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
// the gas allowance.
func CalcGasLimit(parentGasUsed, parentGasLimit, gasFloor, gasCeil uint64) uint64 {
// contrib = (parentGasUsed * 3 / 2) / 1024
contrib := (parentGasUsed + parentGasUsed/2) / extras.GasLimitBoundDivisor
contrib := (parentGasUsed + parentGasUsed/2) / ethparams.GasLimitBoundDivisor

// decay = parentGasLimit / 1024 -1
decay := parentGasLimit/extras.GasLimitBoundDivisor - 1
decay := parentGasLimit/ethparams.GasLimitBoundDivisor - 1

/*
strategy: gasLimit of block-to-mine is set based on parent's
Expand All @@ -161,8 +161,8 @@ func CalcGasLimit(parentGasUsed, parentGasLimit, gasFloor, gasCeil uint64) uint6
from parentGasLimit * (2/3) parentGasUsed is.
*/
limit := parentGasLimit - decay + contrib
if limit < extras.MinGasLimit {
limit = extras.MinGasLimit
if limit < ethparams.MinGasLimit {
limit = ethparams.MinGasLimit
}
// If we're outside our allowed gas range, we try to hone towards them
if limit < gasFloor {
Expand Down
8 changes: 8 additions & 0 deletions core/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ package core

import (
"testing"

ethparams "github.com/ava-labs/libevm/params"
"github.com/stretchr/testify/assert"
)

// TODO: Add TestHeaderVerification
Expand Down Expand Up @@ -63,3 +66,8 @@ func TestCalcGasLimit(t *testing.T) {
}
}
}

func TestUpstreamParamsValues(t *testing.T) {
assert.Equal(t, uint64(1024), ethparams.GasLimitBoundDivisor, "gas limit bound divisor")
assert.Equal(t, uint64(5000), ethparams.MinGasLimit, "min gas limit")
}
2 changes: 1 addition & 1 deletion core/extstate/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *StateDB) GetLogData() (topics [][]common.Hash, data [][]byte) {
// GetPredicateStorageSlots(AddrA, 0) -> Predicate1
// GetPredicateStorageSlots(AddrB, 0) -> Predicate2
// GetPredicateStorageSlots(AddrA, 1) -> Predicate3
func (s *StateDB) GetPredicateStorageSlots(address common.Address, index int) ([]byte, bool) {
func (s *StateDB) GetPredicateStorageSlots(address common.Address, index int) (predicate []byte, exists bool) {
predicates, exists := s.predicateStorageSlots[address]
if !exists || index >= len(predicates) {
return nil, false
Expand Down
16 changes: 0 additions & 16 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,3 @@ func (s *StateDB) Copy() *StateDB {
txIndex: s.txIndex,
}
}

// NormalizeCoinID ORs the 0th bit of the first byte in
// `coinID`, which ensures this bit will be 1 and all other
// bits are left the same.
// This partitions multicoin storage from normal state storage.
func NormalizeCoinID(coinID *common.Hash) {
coinID[0] |= 0x01
}

// NormalizeStateKey ANDs the 0th bit of the first byte in
// `key`, which ensures this bit will be 0 and all other bits
// are left the same.
// This partitions normal state storage from multicoin storage.
func NormalizeStateKey(key *common.Hash) {
key[0] &= 0xfe
}
4 changes: 2 additions & 2 deletions utils/key.go → internal/testutils/key.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) 2024, Ava Labs, Inc. All rights reserved.
// (c) 2024-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package utils
package testutils

import (
"crypto/ecdsa"
Expand Down
6 changes: 3 additions & 3 deletions params/extras/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ type ChainConfig struct {
UpgradeConfig `json:"-"` // Config specified in upgradeBytes (avalanche network upgrades or enable/disabling precompiles). Not serialized.
}

func (c *ChainConfig) CheckConfigCompatible(newcfg_ *ethparams.ChainConfig, headNumber *big.Int, headTimestamp uint64) *ethparams.ConfigCompatError {
func (c *ChainConfig) CheckConfigCompatible(newConfig *ethparams.ChainConfig, headNumber *big.Int, headTimestamp uint64) *ethparams.ConfigCompatError {
if c == nil {
return nil
}
newcfg, ok := newcfg_.Hooks().(*ChainConfig)
newcfg, ok := newConfig.Hooks().(*ChainConfig)
if !ok {
// Proper registration of the extras on the libevm side should prevent this from happening.
// Return an error to prevent the chain from starting, just in case.
return ethparams.NewTimestampCompatError(
fmt.Sprintf("ChainConfig.Hooks() is not of the expected type *extras.ChainConfig, got %T", newcfg_.Hooks()),
fmt.Sprintf("ChainConfig.Hooks() is not of the expected type *extras.ChainConfig, got %T", newConfig.Hooks()),
utils.NewUint64(0),
nil,
)
Expand Down
11 changes: 0 additions & 11 deletions params/extras/protocol_params.go

This file was deleted.

8 changes: 6 additions & 2 deletions plugin/evm/header/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
"github.com/ava-labs/subnet-evm/plugin/evm/upgrade/subnetevm"
)

const (
maximumExtraDataSize = 64 // Maximum size extra data may be after Genesis.
)

var (
errInvalidExtraPrefix = errors.New("invalid header.Extra prefix")
errInvalidExtraLength = errors.New("invalid header.Extra length")
Expand Down Expand Up @@ -89,11 +93,11 @@ func VerifyExtra(rules extras.AvalancheRules, extra []byte) error {
)
}
default:
if uint64(extraLen) > extras.MaximumExtraDataSize {
if uint64(extraLen) > maximumExtraDataSize {
return fmt.Errorf(
"%w: expected <= %d but got %d",
errInvalidExtraLength,
extras.MaximumExtraDataSize,
maximumExtraDataSize,
extraLen,
)
}
Expand Down
12 changes: 10 additions & 2 deletions plugin/evm/header/extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"testing"

"github.com/ava-labs/libevm/core/types"
ethparams "github.com/ava-labs/libevm/params"
"github.com/ava-labs/subnet-evm/params/extras"
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
"github.com/ava-labs/subnet-evm/plugin/evm/upgrade/subnetevm"
"github.com/ava-labs/subnet-evm/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -187,13 +189,13 @@ func TestVerifyExtra(t *testing.T) {
{
name: "initial_valid",
rules: extras.AvalancheRules{},
extra: make([]byte, extras.MaximumExtraDataSize),
extra: make([]byte, maximumExtraDataSize),
expected: nil,
},
{
name: "initial_invalid",
rules: extras.AvalancheRules{},
extra: make([]byte, extras.MaximumExtraDataSize+1),
extra: make([]byte, maximumExtraDataSize+1),
expected: errInvalidExtraLength,
},
{
Expand Down Expand Up @@ -367,3 +369,9 @@ func TestPredicateBytesExtra(t *testing.T) {
})
}
}

func TestUpstreamParamsValues(t *testing.T) {
assert.Equal(t, uint64(1024), ethparams.GasLimitBoundDivisor, "gas limit bound divisor")
assert.Equal(t, uint64(5000), ethparams.MinGasLimit, "min gas limit")
assert.Equal(t, uint64(0x7fffffffffffffff), ethparams.MaxGasLimit, "max gas limit")
}
9 changes: 5 additions & 4 deletions plugin/evm/header/gas_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/libevm/core/types"
ethparams "github.com/ava-labs/libevm/params"
"github.com/ava-labs/subnet-evm/commontype"
"github.com/ava-labs/subnet-evm/params/extras"
)
Expand Down Expand Up @@ -81,18 +82,18 @@ func VerifyGasLimit(
)
}
default:
if header.GasLimit < extras.MinGasLimit || header.GasLimit > extras.MaxGasLimit {
if header.GasLimit < ethparams.MinGasLimit || header.GasLimit > ethparams.MaxGasLimit {
return fmt.Errorf("%w: %d not in range [%d, %d]",
errInvalidGasLimit,
header.GasLimit,
extras.MinGasLimit,
extras.MaxGasLimit,
ethparams.MinGasLimit,
ethparams.MaxGasLimit,
)
}

// Verify that the gas limit remains within allowed bounds
diff := math.AbsDiff(parent.GasLimit, header.GasLimit)
limit := parent.GasLimit / extras.GasLimitBoundDivisor
limit := parent.GasLimit / ethparams.GasLimitBoundDivisor
if diff >= limit {
return fmt.Errorf("%w: have %d, want %d += %d",
errInvalidGasLimit,
Expand Down
13 changes: 7 additions & 6 deletions plugin/evm/header/gas_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/ava-labs/libevm/core/types"
ethparams "github.com/ava-labs/libevm/params"
"github.com/ava-labs/subnet-evm/commontype"
"github.com/ava-labs/subnet-evm/params/extras"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -104,32 +105,32 @@ func VerifyGasLimitTest(t *testing.T, feeConfig commontype.FeeConfig) {
name: "pre_subnet_evm_too_low",
upgrades: extras.TestPreSubnetEVMChainConfig.NetworkUpgrades,
parent: &types.Header{
GasLimit: extras.MinGasLimit,
GasLimit: ethparams.MinGasLimit,
},
header: &types.Header{
GasLimit: extras.MinGasLimit - 1,
GasLimit: ethparams.MinGasLimit - 1,
},
want: errInvalidGasLimit,
},
{
name: "pre_subnet_evm_too_high",
upgrades: extras.TestPreSubnetEVMChainConfig.NetworkUpgrades,
parent: &types.Header{
GasLimit: extras.MaxGasLimit,
GasLimit: ethparams.MaxGasLimit,
},
header: &types.Header{
GasLimit: extras.MaxGasLimit + 1,
GasLimit: ethparams.MaxGasLimit + 1,
},
want: errInvalidGasLimit,
},
{
name: "pre_subnet_evm_too_large",
upgrades: extras.TestPreSubnetEVMChainConfig.NetworkUpgrades,
parent: &types.Header{
GasLimit: extras.MinGasLimit,
GasLimit: ethparams.MinGasLimit,
},
header: &types.Header{
GasLimit: extras.MaxGasLimit,
GasLimit: ethparams.MaxGasLimit,
},
want: errInvalidGasLimit,
},
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ import (
"github.com/ava-labs/subnet-evm/consensus/dummy"
"github.com/ava-labs/subnet-evm/constants"
"github.com/ava-labs/subnet-evm/core"
"github.com/ava-labs/subnet-evm/internal/testutils"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/plugin/evm/customrawdb"
"github.com/ava-labs/subnet-evm/plugin/evm/database"
"github.com/ava-labs/subnet-evm/predicate"
statesyncclient "github.com/ava-labs/subnet-evm/sync/client"
"github.com/ava-labs/subnet-evm/sync/statesync"
"github.com/ava-labs/subnet-evm/utils"
)

func TestSkipStateSync(t *testing.T) {
Expand Down Expand Up @@ -369,7 +369,7 @@ type syncVMSetup struct {
serverVM *VM
serverAppSender *enginetest.Sender

fundedAccounts map[*utils.Key]*types.StateAccount
fundedAccounts map[*testutils.Key]*types.StateAccount

syncerVM *VM
syncerDB avalanchedatabase.Database
Expand Down
5 changes: 3 additions & 2 deletions plugin/evm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/ava-labs/subnet-evm/core"
"github.com/ava-labs/subnet-evm/core/txpool"
"github.com/ava-labs/subnet-evm/eth"
"github.com/ava-labs/subnet-evm/internal/testutils"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/params/extras"
"github.com/ava-labs/subnet-evm/plugin/evm/config"
Expand Down Expand Up @@ -361,7 +362,7 @@ func TestBuildEthTxBlock(t *testing.T) {
newTxPoolHeadChan := make(chan core.NewTxPoolReorgEvent, 1)
vm.txPool.SubscribeNewReorgEvent(newTxPoolHeadChan)

key := utils.NewKey(t)
key := testutils.NewKey(t)

tx := types.NewTransaction(uint64(0), key.Address, firstTxAmount, 21000, big.NewInt(testMinGasPrice), nil)
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(vm.chainConfig.ChainID), testKeys[0])
Expand Down Expand Up @@ -2947,7 +2948,7 @@ func TestSkipChainConfigCheckCompatible(t *testing.T) {
newTxPoolHeadChan := make(chan core.NewTxPoolReorgEvent, 1)
vm.txPool.SubscribeNewReorgEvent(newTxPoolHeadChan)

key := utils.NewKey(t)
key := testutils.NewKey(t)

tx := types.NewTransaction(uint64(0), key.Address, firstTxAmount, 21000, big.NewInt(testMinGasPrice), nil)
signedTx, err := types.SignTx(tx, types.NewEIP155Signer(vm.chainConfig.ChainID), testKeys[0])
Expand Down
2 changes: 1 addition & 1 deletion precompile/contract/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type StateDB interface {

AddLog(*ethtypes.Log)
GetLogData() (topics [][]common.Hash, data [][]byte)
GetPredicateStorageSlots(address common.Address, index int) ([]byte, bool)
GetPredicateStorageSlots(address common.Address, index int) (predicate []byte, exists bool)
SetPredicateStorageSlots(address common.Address, predicates [][]byte)

GetTxHash() common.Hash
Expand Down
4 changes: 2 additions & 2 deletions sync/statesync/test_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"github.com/ava-labs/libevm/ethdb"
"github.com/ava-labs/libevm/rlp"
"github.com/ava-labs/libevm/triedb"
"github.com/ava-labs/subnet-evm/internal/testutils"
"github.com/ava-labs/subnet-evm/plugin/evm/customrawdb"
"github.com/ava-labs/subnet-evm/sync/syncutils"
"github.com/ava-labs/subnet-evm/utils"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -117,7 +117,7 @@ func fillAccountsWithStorage(t *testing.T, serverDB ethdb.Database, serverTrieDB
// returns the new trie root and a map of funded keys to StateAccount structs.
func FillAccountsWithOverlappingStorage(
t *testing.T, trieDB *triedb.Database, root common.Hash, numAccounts int, numOverlappingStorageRoots int,
) (common.Hash, map[*utils.Key]*types.StateAccount) {
) (common.Hash, map[*testutils.Key]*types.StateAccount) {
storageRoots := make([]common.Hash, 0, numOverlappingStorageRoots)
for i := 0; i < numOverlappingStorageRoots; i++ {
storageRoot, _, _ := syncutils.GenerateTrie(t, trieDB, 16, common.HashLength)
Expand Down
8 changes: 4 additions & 4 deletions sync/syncutils/test_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ava-labs/libevm/trie"
"github.com/ava-labs/libevm/trie/trienode"
"github.com/ava-labs/libevm/triedb"
"github.com/ava-labs/subnet-evm/utils"
"github.com/ava-labs/subnet-evm/internal/testutils"
"github.com/holiman/uint256"

"github.com/ava-labs/libevm/common"
Expand Down Expand Up @@ -146,12 +146,12 @@ func CorruptTrie(t *testing.T, diskdb ethdb.Batcher, tr *trie.Trie, n int) {
func FillAccounts(
t *testing.T, trieDB *triedb.Database, root common.Hash, numAccounts int,
onAccount func(*testing.T, int, types.StateAccount) types.StateAccount,
) (common.Hash, map[*utils.Key]*types.StateAccount) {
) (common.Hash, map[*testutils.Key]*types.StateAccount) {
var (
minBalance = uint256.NewInt(3000000000000000000)
randBalance = uint256.NewInt(1000000000000000000)
maxNonce = 10
accounts = make(map[*utils.Key]*types.StateAccount, numAccounts)
accounts = make(map[*testutils.Key]*types.StateAccount, numAccounts)
)

tr, err := trie.NewStateTrie(trie.TrieID(root), trieDB)
Expand All @@ -175,7 +175,7 @@ func FillAccounts(
t.Fatalf("failed to rlp encode account: %v", err)
}

key := utils.NewKey(t)
key := testutils.NewKey(t)
tr.MustUpdate(key.Address[:], accBytes)
accounts[key] = &acc
}
Expand Down
Loading