Skip to content

Coreth merge #1562

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 4 additions & 3 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ package backends
import (
"context"

ethereum "github.com/ava-labs/libevm"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/ethclient/simulated"
"github.com/ava-labs/subnet-evm/interfaces"

ethereum "github.com/ava-labs/libevm"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/types"
)

// Verify that SimulatedBackend implements required interfaces
Expand Down
7 changes: 4 additions & 3 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ import (
"strings"
"sync"

"github.com/ava-labs/libevm/event"
"github.com/ava-labs/subnet-evm/accounts/abi"
"github.com/ava-labs/subnet-evm/rpc"

ethereum "github.com/ava-labs/libevm"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/crypto"
"github.com/ava-labs/libevm/event"
"github.com/ava-labs/subnet-evm/accounts/abi"
"github.com/ava-labs/subnet-evm/rpc"
)

const basefeeWiggleMultiplier = 2
Expand Down
6 changes: 4 additions & 2 deletions accounts/abi/bind/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ import (
"strings"
"testing"

"github.com/ava-labs/subnet-evm/accounts/abi"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"

ethereum "github.com/ava-labs/libevm"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/common/hexutil"
"github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/crypto"
"github.com/ava-labs/libevm/rlp"
"github.com/ava-labs/subnet-evm/accounts/abi"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"

"github.com/stretchr/testify/assert"
)

Expand Down
20 changes: 11 additions & 9 deletions accounts/abi/bind/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import (
"testing"
"time"

"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/crypto"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/ethclient/simulated"
"github.com/ava-labs/subnet-evm/params"

"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/crypto"

"github.com/stretchr/testify/require"
)

var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
Expand Down Expand Up @@ -77,11 +80,11 @@ func TestWaitDeployed(t *testing.T) {
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei))

tx := types.NewContractCreation(0, big.NewInt(0), test.gas, gasPrice, common.FromHex(test.code))
tx, _ = types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
tx, err := types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
require.NoError(t, err, "types.SignTx")

// Wait for it to get mined in the background.
var (
err error
address common.Address
mined = make(chan struct{})
ctx = context.Background()
Expand Down Expand Up @@ -126,9 +129,7 @@ func TestWaitDeployedCornerCases(t *testing.T) {
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)
}
require.NoError(t, err, "types.SignTx")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
Expand All @@ -142,7 +143,8 @@ func TestWaitDeployedCornerCases(t *testing.T) {

// Create a transaction that is not mined.
tx = types.NewContractCreation(1, big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
tx, _ = types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
tx, err = types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
require.NoError(t, err, "types.SignTx")

go func() {
contextCanceled := errors.New("context canceled")
Expand Down
8 changes: 5 additions & 3 deletions cmd/abigen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ import (
"regexp"
"strings"

"github.com/ava-labs/libevm/common/compiler"
"github.com/ava-labs/libevm/crypto"
"github.com/ava-labs/libevm/log"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/cmd/utils"
"github.com/ava-labs/subnet-evm/internal/flags"

"github.com/ava-labs/libevm/common/compiler"
"github.com/ava-labs/libevm/crypto"
"github.com/ava-labs/libevm/log"

"github.com/urfave/cli/v2"
)

Expand Down
7 changes: 4 additions & 3 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/ava-labs/subnet-evm/core/state"
"github.com/ava-labs/subnet-evm/eth/tracers"
"github.com/ava-labs/subnet-evm/params"
extraparams "github.com/ava-labs/subnet-evm/params/extras"
customheader "github.com/ava-labs/subnet-evm/plugin/evm/header"
"github.com/ava-labs/subnet-evm/plugin/evm/upgrade/subnetevm"
"github.com/ava-labs/subnet-evm/tests"
Expand Down Expand Up @@ -91,7 +92,7 @@ type input struct {
}

func Transition(ctx *cli.Context) error {
var getTracer = func(txIndex int, txHash common.Hash) (vm.EVMLogger, error) { return nil, nil }
getTracer := func(txIndex int, txHash common.Hash) (vm.EVMLogger, error) { return nil, nil }

baseDir, err := createBasedir(ctx)
if err != nil {
Expand Down Expand Up @@ -224,7 +225,7 @@ func applyLondonChecks(env *stEnv, chainConfig *params.ChainConfig) error {
GasLimit: env.ParentGasLimit,
Extra: make([]byte, subnetevm.WindowSize), // TODO: consider passing extra through env
}
feeConfig := params.DefaultFeeConfig
feeConfig := extraparams.DefaultFeeConfig
if env.MinBaseFee != nil {
// Override the default min base fee if it's set in the env
feeConfig.MinBaseFee = env.MinBaseFee
Expand Down Expand Up @@ -283,7 +284,7 @@ func saveFile(baseDir, filename string, data interface{}) error {
return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err))
}
location := path.Join(baseDir, filename)
if err = os.WriteFile(location, b, 0644); err != nil {
if err = os.WriteFile(location, b, 0o644); err != nil {
return NewError(ErrorIO, fmt.Errorf("failed writing output: %v", err))
}
log.Info("Wrote file", "file", location)
Expand Down
6 changes: 3 additions & 3 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var runCommand = &cli.Command{
// the initialized Genesis structure
func readGenesis(genesisPath string) *core.Genesis {
// Make sure we have a valid genesis JSON
//genesisPath := ctx.Args().First()
// genesisPath := ctx.Args().First()
if len(genesisPath) == 0 {
utils.Fatalf("Must supply path to genesis JSON file")
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func runCmd(ctx *cli.Context) error {
initialGas = genesisConfig.GasLimit
}
} else {
genesisConfig.Config = params.TestSubnetEVMChainConfig
genesisConfig.Config = params.TestChainConfig
}

db := rawdb.NewMemoryDatabase()
Expand Down Expand Up @@ -188,7 +188,7 @@ func runCmd(ctx *cli.Context) error {
var err error
// If - is specified, it means that code comes from stdin
if codeFileFlag == "-" {
//Try reading from stdin
// Try reading from stdin
if hexcode, err = io.ReadAll(os.Stdin); err != nil {
fmt.Printf("Could not load code from stdin: %v\n", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/ExampleWarp.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;

import "./interfaces/IWarpMessenger.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/interfaces/IWarpMessenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;
pragma solidity ^0.8.0;

struct WarpMessage {
bytes32 sourceChainID;
Expand Down
3 changes: 2 additions & 1 deletion core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/ava-labs/subnet-evm/core/state"
"github.com/ava-labs/subnet-evm/core/state/snapshot"
"github.com/ava-labs/subnet-evm/params"
extraparams "github.com/ava-labs/subnet-evm/params/extras"
"github.com/ava-labs/subnet-evm/precompile/contracts/feemanager"
"github.com/ava-labs/subnet-evm/precompile/contracts/rewardmanager"
)
Expand Down Expand Up @@ -368,7 +369,7 @@ func (bc *BlockChain) SubscribeAcceptedTransactionEvent(ch chan<- NewTxsEvent) e
func (bc *BlockChain) GetFeeConfigAt(parent *types.Header) (commontype.FeeConfig, *big.Int, error) {
config := params.GetExtra(bc.Config())
if !config.IsSubnetEVM(parent.Time) {
return params.DefaultFeeConfig, nil, nil
return extraparams.DefaultFeeConfig, nil, nil
}
if !config.IsPrecompileEnabled(feemanager.ContractAddress, parent.Time) {
return config.FeeConfig, common.Big0, nil
Expand Down
21 changes: 12 additions & 9 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/ava-labs/subnet-evm/core/state"
"github.com/ava-labs/subnet-evm/core/state/pruner"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/params/extras"
extraparams "github.com/ava-labs/subnet-evm/params/extras"
"github.com/ava-labs/subnet-evm/plugin/evm/customrawdb"
"github.com/ava-labs/subnet-evm/plugin/evm/upgrade/legacy"
"github.com/holiman/uint256"
Expand Down Expand Up @@ -317,7 +317,7 @@ func testRepopulateMissingTriesParallel(t *testing.T, parallelism int) {
gspec := &Genesis{
Config: params.WithExtra(
&params.ChainConfig{HomesteadBlock: new(big.Int)},
&extras.ChainConfig{FeeConfig: params.DefaultFeeConfig},
&extraparams.ChainConfig{FeeConfig: extraparams.DefaultFeeConfig},
),
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
}
Expand Down Expand Up @@ -433,7 +433,7 @@ func TestUngracefulAsyncShutdown(t *testing.T) {
gspec := &Genesis{
Config: params.WithExtra(
&params.ChainConfig{HomesteadBlock: new(big.Int)},
&extras.ChainConfig{FeeConfig: params.DefaultFeeConfig},
&extraparams.ChainConfig{FeeConfig: extraparams.DefaultFeeConfig},
),
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
}
Expand Down Expand Up @@ -555,7 +555,7 @@ func TestCanonicalHashMarker(t *testing.T) {
}

func testCanonicalHashMarker(t *testing.T, scheme string) {
var cases = []struct {
cases := []struct {
forkA int
forkB int
}{
Expand Down Expand Up @@ -713,7 +713,7 @@ func TestTxLookupSkipIndexingBlockChain(t *testing.T) {
func TestCreateThenDeletePreByzantium(t *testing.T) {
// We want to use pre-byzantium rules where we have intermediate state roots
// between transactions.
config := *params.TestPreSubnetEVMChainConfig
config := *params.TestCChainLaunchConfig
config.ByzantiumBlock = nil
config.ConstantinopleBlock = nil
config.PetersburgBlock = nil
Expand All @@ -724,6 +724,7 @@ func TestCreateThenDeletePreByzantium(t *testing.T) {

testCreateThenDelete(t, &config)
}

func TestCreateThenDeletePostByzantium(t *testing.T) {
testCreateThenDelete(t, params.TestChainConfig)
}
Expand All @@ -748,7 +749,8 @@ func testCreateThenDelete(t *testing.T, config *params.ChainConfig) {
byte(vm.PUSH1), 0x1,
byte(vm.SSTORE),
// Get the runtime-code on the stack
byte(vm.PUSH32)}
byte(vm.PUSH32),
}
initCode = append(initCode, code...)
initCode = append(initCode, []byte{
byte(vm.PUSH1), 0x0, // offset
Expand Down Expand Up @@ -790,8 +792,8 @@ func testCreateThenDelete(t *testing.T, config *params.ChainConfig) {
})
// Import the canonical chain
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfig, gspec, engine, vm.Config{
//Debug: true,
//Tracer: logger.NewJSONLogger(nil, os.Stdout),
// Debug: true,
// Tracer: logger.NewJSONLogger(nil, os.Stdout),
}, common.Hash{}, false)
if err != nil {
t.Fatalf("failed to create tester chain: %v", err)
Expand Down Expand Up @@ -950,7 +952,8 @@ func TestTransientStorageReset(t *testing.T) {
byte(vm.TSTORE),

// Get the runtime-code on the stack
byte(vm.PUSH32)}
byte(vm.PUSH32),
}
initCode = append(initCode, code...)
initCode = append(initCode, []byte{
byte(vm.PUSH1), 0x0, // offset
Expand Down
6 changes: 5 additions & 1 deletion core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/ava-labs/subnet-evm/consensus/misc/eip4844"
"github.com/ava-labs/subnet-evm/core/extstate"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/params/extras"
customheader "github.com/ava-labs/subnet-evm/plugin/evm/header"
"github.com/ava-labs/subnet-evm/predicate"
"github.com/holiman/uint256"
Expand Down Expand Up @@ -91,7 +92,8 @@ type ChainContext interface {

// NewEVMBlockContext creates a new context for use in the EVM.
func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common.Address) vm.BlockContext {
predicateBytes := customheader.PredicateBytesFromExtra(header.Extra)
// TODO: fix this
predicateBytes := customheader.PredicateBytesFromExtra(extras.AvalancheRules{}, header.Extra)
if len(predicateBytes) == 0 {
return newEVMBlockContext(header, chain, author, nil)
}
Expand All @@ -118,6 +120,8 @@ func NewEVMBlockContextWithPredicateResults(header *types.Header, chain ChainCon
// Note this only sets the block context, which is the hand-off point for
// the EVM. The actual header is not modified.
blockCtx.Header.Extra = customheader.SetPredicateBytesInExtra(
// TODO: fix this
extras.AvalancheRules{},
bytes.Clone(header.Extra),
predicateBytes,
)
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func SetupGenesisBlock(
// have the Berlin or London forks initialized by block number on disk.
// See https://github.com/ava-labs/coreth/pull/667/files
// - this is not needed in subnet-evm but it does not impact it either
params.SetEthUpgrades(storedcfg, params.GetExtra(storedcfg).NetworkUpgrades)
params.SetEthUpgrades(storedcfg)
// Check config compatibility and write the config. Compatibility errors
// are returned to the caller unless we're already at block zero.
// we use last accepted block for cfg compatibility check. Note this allows
Expand Down
22 changes: 5 additions & 17 deletions core/genesis_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@ import (
"testing"
"time"

"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/rawdb"
"github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/triedb"
"github.com/ava-labs/subnet-evm/commontype"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/params/extras"
"github.com/ava-labs/subnet-evm/utils"
"github.com/stretchr/testify/require"
)

func TestGenesisEthUpgrades(t *testing.T) {
db := rawdb.NewMemoryDatabase()
preEthUpgrades := params.WithExtra(
&params.ChainConfig{
ChainID: big.NewInt(43114), // Specifically refers to mainnet for this UT
HomesteadBlock: big.NewInt(0),
// For this test to be a proper regression test, DAOForkBlock and
// DAOForkSupport should be set to match the values in
// [params.SetEthUpgrades]. Otherwise, in case of a regression, the test
// would pass as there would be a mismatch at genesis, which is
// incorrectly considered a success.
ChainID: big.NewInt(43114), // Specifically refers to mainnet for this UT
HomesteadBlock: big.NewInt(0),
DAOForkBlock: big.NewInt(0),
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
Expand All @@ -42,12 +36,7 @@ func TestGenesisEthUpgrades(t *testing.T) {
MuirGlacierBlock: big.NewInt(0),
},
&extras.ChainConfig{
FeeConfig: commontype.FeeConfig{
MinBaseFee: big.NewInt(1),
},
NetworkUpgrades: extras.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
},
NetworkUpgrades: extras.CorethDefaultNetworkUpgrades(upgrade.Default),
},
)
tdb := triedb.NewDatabase(db, triedb.HashDefaults)
Expand All @@ -70,8 +59,7 @@ func TestGenesisEthUpgrades(t *testing.T) {
rawdb.WriteBlock(db, block)
// We should still be able to re-initialize
config = *preEthUpgrades
avalancheUpgrades := extras.NetworkUpgrades{}
params.SetEthUpgrades(&config, avalancheUpgrades) // New versions will set additional fields eg, LondonBlock
params.SetEthUpgrades(&config) // New versions will set additional fields eg, LondonBlock
_, _, err = SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, block.Hash(), false)
require.NoError(t, err)
}
Loading
Loading