From bca563fd0f0c461d00e721c84ba958da1cb7c7d4 Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Wed, 15 Jun 2022 22:17:16 +0200 Subject: [PATCH] Fix genesis storage collision state tests (#4462) * Enable a couple of tests that work now * Fix genesis storage collision state tests * IncarnationMap in t8ntool MakePreState --- cmd/evm/internal/t8ntool/execution.go | 7 ++++++- core/genesis.go | 4 ++-- tests/state_test.go | 9 --------- tests/state_test_util.go | 10 +++++++++- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 06988c0ed..1ef1457c2 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -18,6 +18,7 @@ package t8ntool import ( "context" + "encoding/binary" "fmt" "math/big" @@ -297,7 +298,11 @@ func MakePreState(chainRules *params.Rules, tx kv.RwTx, accounts core.GenesisAll } if len(a.Code) > 0 || len(a.Storage) > 0 { - statedb.SetIncarnation(addr, 1) + statedb.SetIncarnation(addr, state.FirstContractIncarnation) + + var b [8]byte + binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation) + tx.Put(kv.IncarnationMap, addr[:], b[:]) } } // Commit and re-open to start with a clean state. diff --git a/core/genesis.go b/core/genesis.go index 6935bf9e4..89a3ca80e 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -338,7 +338,7 @@ func (g *Genesis) ToBlock() (*types.Block, *state.IntraBlockState, error) { } if len(account.Code) > 0 || len(account.Storage) > 0 { - statedb.SetIncarnation(addr, 1) + statedb.SetIncarnation(addr, state.FirstContractIncarnation) } } if err := statedb.FinalizeTx(¶ms.Rules{}, w); err != nil { @@ -401,7 +401,7 @@ func (g *Genesis) WriteGenesisState(tx kv.RwTx) (*types.Block, *state.IntraBlock return nil, nil, err } for addr, account := range g.Alloc { - if len(account.Code) == 0 && len(account.Storage) > 0 { + if len(account.Code) > 0 || len(account.Storage) > 0 { // Special case for weird tests - inaccessible storage var b [8]byte binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation) diff --git a/tests/state_test.go b/tests/state_test.go index 955f1714a..15766aa1b 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -46,15 +46,6 @@ func TestState(t *testing.T) { st.skipLoad(`^stTimeConsuming/`) st.skipLoad(`.*vmPerformance/loop.*`) - // Broken tests: - st.skipLoad(`^stCreate2/create2collisionStorage.json`) - st.skipLoad(`^stExtCodeHash/dynamicAccountOverwriteEmpty.json`) - st.skipLoad(`^stSStoreTest/InitCollision.json`) - st.skipLoad(`^stEIP1559/typeTwoBerlin.json`) - - // value exceeding 256 bit is not supported - st.skipLoad(`^stTransactionTest/ValueOverflow.json`) - st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) { db := memdb.NewTestDB(t) for _, subtest := range test.Subtests() { diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 0200753e5..4989ab2af 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -17,6 +17,7 @@ package tests import ( + "encoding/binary" "encoding/json" "fmt" "math/big" @@ -274,9 +275,16 @@ func MakePreState(rules *params.Rules, tx kv.RwTx, accounts core.GenesisAlloc, b } if len(a.Code) > 0 || len(a.Storage) > 0 { - statedb.SetIncarnation(addr, 1) + statedb.SetIncarnation(addr, state.FirstContractIncarnation) + + var b [8]byte + binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation) + if err := tx.Put(kv.IncarnationMap, addr[:], b[:]); err != nil { + return nil, err + } } } + // Commit and re-open to start with a clean state. if err := statedb.FinalizeTx(rules, state.NewPlainStateWriter(tx, nil, blockNr+1)); err != nil { return nil, err