From 0dc09da7db47de4a9a9eb6ea335e2e367fae6015 Mon Sep 17 00:00:00 2001 From: imalasong <55082705+imalasong@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:29:49 +0800 Subject: [PATCH 1/6] all: replace path.Join with filepath.Join (#29479) * core/rawdb: replace file.Join with filepath.Join Signed-off-by: xiaochangbai <704566072@qq.com> * internal/build: replace file.Join with filepath.Join Signed-off-by: xiaochangbai <704566072@qq.com> --------- Signed-off-by: xiaochangbai <704566072@qq.com> --- core/blockchain_sethead_test.go | 4 ++-- core/rawdb/database.go | 3 +-- core/rawdb/freezer_test.go | 13 ++++++------- internal/build/util.go | 2 +- node/node_auth_test.go | 4 ++-- signer/core/signed_data_test.go | 3 ++- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/blockchain_sethead_test.go b/core/blockchain_sethead_test.go index b96ee12c9952..8b77f9f8b20c 100644 --- a/core/blockchain_sethead_test.go +++ b/core/blockchain_sethead_test.go @@ -22,7 +22,7 @@ package core import ( "fmt" "math/big" - "path" + "path/filepath" "strings" "testing" "time" @@ -1966,7 +1966,7 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme // Create a temporary persistent database datadir := t.TempDir() - ancient := path.Join(datadir, "ancient") + ancient := filepath.Join(datadir, "ancient") db, err := rawdb.Open(rawdb.OpenOptions{ Directory: datadir, diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 9cab30bfcd1f..7b2c0415cbbf 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "os" - "path" "path/filepath" "strings" "time" @@ -172,7 +171,7 @@ func resolveChainFreezerDir(ancient string) string { // sub folder, if not then two possibilities: // - chain freezer is not initialized // - chain freezer exists in legacy location (root ancient folder) - freezer := path.Join(ancient, ChainFreezerName) + freezer := filepath.Join(ancient, ChainFreezerName) if !common.FileExist(freezer) { if !common.FileExist(ancient) { // The entire ancient store is not initialized, still use the sub diff --git a/core/rawdb/freezer_test.go b/core/rawdb/freezer_test.go index b92cd7b734f9..93bc2c225442 100644 --- a/core/rawdb/freezer_test.go +++ b/core/rawdb/freezer_test.go @@ -23,7 +23,6 @@ import ( "math/big" "math/rand" "os" - "path" "path/filepath" "sync" "testing" @@ -398,11 +397,11 @@ func TestRenameWindows(t *testing.T) { if err != nil { t.Fatal(err) } - f2, err := os.Create(path.Join(dir1, fname2)) + f2, err := os.Create(filepath.Join(dir1, fname2)) if err != nil { t.Fatal(err) } - f3, err := os.Create(path.Join(dir2, fname2)) + f3, err := os.Create(filepath.Join(dir2, fname2)) if err != nil { t.Fatal(err) } @@ -424,15 +423,15 @@ func TestRenameWindows(t *testing.T) { if err := f3.Close(); err != nil { t.Fatal(err) } - if err := os.Rename(f.Name(), path.Join(dir2, fname)); err != nil { + if err := os.Rename(f.Name(), filepath.Join(dir2, fname)); err != nil { t.Fatal(err) } - if err := os.Rename(f2.Name(), path.Join(dir2, fname2)); err != nil { + if err := os.Rename(f2.Name(), filepath.Join(dir2, fname2)); err != nil { t.Fatal(err) } // Check file contents - f, err = os.Open(path.Join(dir2, fname)) + f, err = os.Open(filepath.Join(dir2, fname)) if err != nil { t.Fatal(err) } @@ -446,7 +445,7 @@ func TestRenameWindows(t *testing.T) { t.Errorf("unexpected file contents. Got %v\n", buf) } - f, err = os.Open(path.Join(dir2, fname2)) + f, err = os.Open(filepath.Join(dir2, fname2)) if err != nil { t.Fatal(err) } diff --git a/internal/build/util.go b/internal/build/util.go index b41014a16f0d..e57a4e3a9a04 100644 --- a/internal/build/util.go +++ b/internal/build/util.go @@ -175,7 +175,7 @@ func UploadSFTP(identityFile, host, dir string, files []string) error { } in := io.MultiWriter(stdin, os.Stdout) for _, f := range files { - fmt.Fprintln(in, "put", f, path.Join(dir, filepath.Base(f))) + fmt.Fprintln(in, "put", f, filepath.Join(dir, filepath.Base(f))) } fmt.Fprintln(in, "exit") // Some issue with the PPA sftp server makes it so the server does not diff --git a/node/node_auth_test.go b/node/node_auth_test.go index 597cd8531f79..900f53440cb9 100644 --- a/node/node_auth_test.go +++ b/node/node_auth_test.go @@ -22,7 +22,7 @@ import ( "fmt" "net/http" "os" - "path" + "path/filepath" "testing" "time" @@ -98,7 +98,7 @@ func TestAuthEndpoints(t *testing.T) { t.Fatalf("failed to create jwt secret: %v", err) } // Geth must read it from a file, and does not support in-memory JWT secrets, so we create a temporary file. - jwtPath := path.Join(t.TempDir(), "jwt_secret") + jwtPath := filepath.Join(t.TempDir(), "jwt_secret") if err := os.WriteFile(jwtPath, []byte(hexutil.Encode(secret[:])), 0600); err != nil { t.Fatalf("failed to prepare jwt secret file: %v", err) } diff --git a/signer/core/signed_data_test.go b/signer/core/signed_data_test.go index bb21525507cb..a4fe7a22dd0f 100644 --- a/signer/core/signed_data_test.go +++ b/signer/core/signed_data_test.go @@ -24,6 +24,7 @@ import ( "math/big" "os" "path" + "path/filepath" "strings" "testing" @@ -411,7 +412,7 @@ func TestJsonFiles(t *testing.T) { // crashes or hangs. func TestFuzzerFiles(t *testing.T) { t.Parallel() - corpusdir := path.Join("testdata", "fuzzing") + corpusdir := filepath.Join("testdata", "fuzzing") testfiles, err := os.ReadDir(corpusdir) if err != nil { t.Fatalf("failed reading files: %v", err) From cfc7d06cc91122f44d09592ddc616fb189bc4ca4 Mon Sep 17 00:00:00 2001 From: Aaron Chen Date: Mon, 8 Apr 2024 18:58:37 +0800 Subject: [PATCH 2/6] signer/core/apitypes: use slices.Contains (#29474) --- log/handler.go | 2 +- signer/core/apitypes/types.go | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/log/handler.go b/log/handler.go index 290e38150956..c604a6230188 100644 --- a/log/handler.go +++ b/log/handler.go @@ -118,7 +118,7 @@ func JSONHandler(wr io.Writer) slog.Handler { return JSONHandlerWithLevel(wr, levelMaxVerbosity) } -// JSONHandler returns a handler which prints records in JSON format that are less than or equal to +// JSONHandlerWithLevel returns a handler which prints records in JSON format that are less than or equal to // the specified verbosity level. func JSONHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler { return slog.NewJSONHandler(wr, &slog.HandlerOptions{ diff --git a/signer/core/apitypes/types.go b/signer/core/apitypes/types.go index eba9d7768f99..9113c091c5c7 100644 --- a/signer/core/apitypes/types.go +++ b/signer/core/apitypes/types.go @@ -25,6 +25,7 @@ import ( "math/big" "reflect" "regexp" + "slices" "sort" "strconv" "strings" @@ -386,16 +387,8 @@ func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage // Dependencies returns an array of custom types ordered by their hierarchical reference tree func (typedData *TypedData) Dependencies(primaryType string, found []string) []string { primaryType = strings.TrimSuffix(primaryType, "[]") - includes := func(arr []string, str string) bool { - for _, obj := range arr { - if obj == str { - return true - } - } - return false - } - if includes(found, primaryType) { + if slices.Contains(found, primaryType) { return found } if typedData.Types[primaryType] == nil { @@ -404,7 +397,7 @@ func (typedData *TypedData) Dependencies(primaryType string, found []string) []s found = append(found, primaryType) for _, field := range typedData.Types[primaryType] { for _, dep := range typedData.Dependencies(field.Type, found) { - if !includes(found, dep) { + if !slices.Contains(found, dep) { found = append(found, dep) } } From ed4bc7f27ba071403484240fa71b4878c4ca9756 Mon Sep 17 00:00:00 2001 From: Aaron Chen Date: Mon, 8 Apr 2024 18:59:17 +0800 Subject: [PATCH 3/6] all: replace fmt.Errorf() with errors.New() if no param required (#29472) --- accounts/external/backend.go | 2 +- cmd/devp2p/internal/ethtest/transaction.go | 2 +- core/blockchain.go | 2 +- internal/era/iterator.go | 3 +-- miner/worker.go | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/accounts/external/backend.go b/accounts/external/backend.go index 0b336448fc17..62322753daa8 100644 --- a/accounts/external/backend.go +++ b/accounts/external/backend.go @@ -239,7 +239,7 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio args.BlobHashes = tx.BlobHashes() sidecar := tx.BlobTxSidecar() if sidecar == nil { - return nil, fmt.Errorf("blobs must be present for signing") + return nil, errors.New("blobs must be present for signing") } args.Blobs = sidecar.Blobs args.Commitments = sidecar.Commitments diff --git a/cmd/devp2p/internal/ethtest/transaction.go b/cmd/devp2p/internal/ethtest/transaction.go index 80b5d80745ec..cbbbbce8d94b 100644 --- a/cmd/devp2p/internal/ethtest/transaction.go +++ b/cmd/devp2p/internal/ethtest/transaction.go @@ -102,7 +102,7 @@ func (s *Suite) sendTxs(t *utesting.T, txs []*types.Transaction) error { } } - return fmt.Errorf("timed out waiting for txs") + return errors.New("timed out waiting for txs") } func (s *Suite) sendInvalidTxs(t *utesting.T, txs []*types.Transaction) error { diff --git a/core/blockchain.go b/core/blockchain.go index 680875373454..fa112c25039e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -439,7 +439,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis } if alloc == nil { - return nil, fmt.Errorf("live blockchain tracer requires genesis alloc to be set") + return nil, errors.New("live blockchain tracer requires genesis alloc to be set") } bc.logger.OnGenesisBlock(bc.genesisBlock, alloc) diff --git a/internal/era/iterator.go b/internal/era/iterator.go index d90e9586a4e6..cc4f27c20190 100644 --- a/internal/era/iterator.go +++ b/internal/era/iterator.go @@ -18,7 +18,6 @@ package era import ( "errors" - "fmt" "io" "math/big" @@ -80,7 +79,7 @@ func (it *Iterator) Block() (*types.Block, error) { // Receipts returns the receipts for the iterator's current position. func (it *Iterator) Receipts() (types.Receipts, error) { if it.inner.Receipts == nil { - return nil, fmt.Errorf("receipts must be non-nil") + return nil, errors.New("receipts must be non-nil") } var receipts types.Receipts err := rlp.Decode(it.inner.Receipts, &receipts) diff --git a/miner/worker.go b/miner/worker.go index 9f8d9f663f86..4924952478e5 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -75,7 +75,7 @@ type newPayloadResult struct { receipts []*types.Receipt // Receipts collected during construction } -// generateParams wraps various of settings for generating sealing task. +// generateParams wraps various settings for generating sealing task. type generateParams struct { timestamp uint64 // The timestamp for sealing task forceTime bool // Flag whether the given timestamp is immutable or not @@ -131,7 +131,7 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error) if genParams.parentHash != (common.Hash{}) { block := miner.chain.GetBlockByHash(genParams.parentHash) if block == nil { - return nil, fmt.Errorf("missing parent") + return nil, errors.New("missing parent") } parent = block.Header() } From c3465cb5ba94e8ee4153319416db9484406084ee Mon Sep 17 00:00:00 2001 From: Sina M <1591639+s1na@users.noreply.github.com> Date: Mon, 8 Apr 2024 13:01:22 +0200 Subject: [PATCH 4/6] core: fix dev mode genesis difficulty (#29469) The dev mode is nowadays in Merge-mode from genesis, hence the difficulty of the first block should be zero. --- core/genesis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/genesis.go b/core/genesis.go index ee0e322f8013..f05e84199ae4 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -582,7 +582,7 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis { Config: &config, GasLimit: gasLimit, BaseFee: big.NewInt(params.InitialBaseFee), - Difficulty: big.NewInt(1), + Difficulty: big.NewInt(0), Alloc: map[common.Address]types.Account{ common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256 From 3c75c64e6bbf64f842c6f725a595713262c2f8fe Mon Sep 17 00:00:00 2001 From: seayyyy <163325936+seay404@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:02:56 +0800 Subject: [PATCH 5/6] core: fix typo (#29438) --- core/block_validator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/block_validator.go b/core/block_validator.go index f3d65cea25ff..3d49f4e6a3df 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -132,7 +132,7 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD if rbloom != header.Bloom { return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom) } - // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]])) + // The receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]])) receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil)) if receiptSha != header.ReceiptHash { return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha) From c170cc0ab0a1f60adcde80d0af8e3050ee19da93 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Mon, 8 Apr 2024 21:48:37 +0800 Subject: [PATCH 6/6] core/vm: reject contract creation if the storage is non-empty (#28912) This change implements EIP-7610, which rejects the contract deployment if the destination has non-empty storage. --- core/vm/evm.go | 12 +++++++++--- core/vm/interface.go | 1 + tests/block_test.go | 8 ++++++++ tests/state_test.go | 13 +++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index 25b5bc84e8bd..36bbf0d3da67 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -439,13 +439,19 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, if evm.chainRules.IsBerlin { evm.StateDB.AddAddressToAccessList(address) } - // Ensure there's no existing contract already at the designated address + // Ensure there's no existing contract already at the designated address. + // Account is regarded as existent if any of these three conditions is met: + // - the nonce is nonzero + // - the code is non-empty + // - the storage is non-empty contractHash := evm.StateDB.GetCodeHash(address) - if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) { + storageRoot := evm.StateDB.GetStorageRoot(address) + if evm.StateDB.GetNonce(address) != 0 || + (contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) || // non-empty code + (storageRoot != (common.Hash{}) && storageRoot != types.EmptyRootHash) { // non-empty storage if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil { evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution) } - return nil, common.Address{}, 0, ErrContractAddressCollision } // Create a new account on the state diff --git a/core/vm/interface.go b/core/vm/interface.go index d7028cc7c7e3..30742e96de2b 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -49,6 +49,7 @@ type StateDB interface { GetCommittedState(common.Address, common.Hash) common.Hash GetState(common.Address, common.Hash) common.Hash SetState(common.Address, common.Hash, common.Hash) + GetStorageRoot(addr common.Address) common.Hash GetTransientState(addr common.Address, key common.Hash) common.Hash SetTransientState(addr common.Address, key, value common.Hash) diff --git a/tests/block_test.go b/tests/block_test.go index 1ba84f5f24b6..43e3d99b3e8c 100644 --- a/tests/block_test.go +++ b/tests/block_test.go @@ -64,6 +64,14 @@ func TestExecutionSpecBlocktests(t *testing.T) { } bt := new(testMatcher) + // These tests fail as of https://github.com/ethereum/go-ethereum/pull/28666, since we + // no longer delete "leftover storage" when deploying a contract. + bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/self_destructing_initcode_create_tx.json`) + bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/self_destructing_initcode.json`) + bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/recreate_self_destructed_contract_different_txs.json`) + bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/delegatecall_from_new_contract_to_pre_existing_contract.json`) + bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/create_selfdestruct_same_tx.json`) + bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) { execBlockTest(t, bt, test) }) diff --git a/tests/state_test.go b/tests/state_test.go index 6ec5c9d857bc..6f53b88722d6 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -54,9 +54,22 @@ func initMatcher(st *testMatcher) { // Uses 1GB RAM per tested fork st.skipLoad(`^stStaticCall/static_Call1MB`) + // These tests fail as of https://github.com/ethereum/go-ethereum/pull/28666, since we + // no longer delete "leftover storage" when deploying a contract. + st.skipLoad(`^stSStoreTest/InitCollision\.json`) + st.skipLoad(`^stRevertTest/RevertInCreateInInit\.json`) + st.skipLoad(`^stExtCodeHash/dynamicAccountOverwriteEmpty\.json`) + st.skipLoad(`^stCreate2/create2collisionStorage\.json`) + st.skipLoad(`^stCreate2/RevertInCreateInInitCreate2\.json`) + // Broken tests: // EOF is not part of cancun st.skipLoad(`^stEOF/`) + + // The tests under Pyspecs are the ones that are published as execution-spec tests. + // We run these tests separately, no need to _also_ run them as part of the + // reference tests. + st.skipLoad(`^Pyspecs/`) } func TestState(t *testing.T) {