Skip to content

Commit

Permalink
update common tests to 14.0 (#11000)
Browse files Browse the repository at this point in the history
- [issue link](#10928)
  • Loading branch information
sudeepdino008 authored Aug 2, 2024
1 parent 3604490 commit d3112dc
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 42 deletions.
5 changes: 5 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ func BlockPostValidation(gasUsed, blobGasUsed uint64, checkReceipts bool, receip
return fmt.Errorf("receiptHash mismatch: %x != %x, headerNum=%d, %x",
receiptHash, h.ReceiptHash, h.Number.Uint64(), h.Hash())
}

lbloom := types.CreateBloom(receipts)
if lbloom != h.Bloom {
return fmt.Errorf("invalid bloom (remote: %x local: %x)", h.Bloom, lbloom)
}
}
return nil
}
9 changes: 4 additions & 5 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ import (
"github.com/erigontech/erigon/core/vm/evmtypes"
"github.com/erigontech/erigon/crypto"
"github.com/erigontech/erigon/params"
"github.com/erigontech/erigon/turbo/trie"
)

// emptyCodeHash is used by create to ensure deployment is disallowed to already
// deployed contract addresses (relevant after the account abstraction).
var emptyCodeHash = crypto.Keccak256Hash(nil)
var emptyHash = libcommon.Hash{}

func (evm *EVM) precompile(addr libcommon.Address) (PrecompiledContract, bool) {
var precompiles map[libcommon.Address]PrecompiledContract
Expand Down Expand Up @@ -343,7 +342,7 @@ func NewCodeAndHash(code []byte) *codeAndHash {
}

func (c *codeAndHash) Hash() libcommon.Hash {
if c.hash == (libcommon.Hash{}) {
if c.hash == emptyHash {
c.hash = crypto.Keccak256Hash(c.code)
}
return c.hash
Expand Down Expand Up @@ -401,7 +400,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gasRemainin
}
// Ensure there's no existing contract already at the designated address
contractHash := evm.intraBlockState.GetCodeHash(address)
if evm.intraBlockState.GetNonce(address) != 0 || (contractHash != (libcommon.Hash{}) && contractHash != emptyCodeHash) {
if evm.intraBlockState.GetNonce(address) != 0 || (contractHash != (libcommon.Hash{}) && contractHash != trie.EmptyCodeHash) {
err = ErrContractAddressCollision
return nil, libcommon.Address{}, 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions eth/stagedsync/stages/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var (
BlockHashes SyncStage = "BlockHashes" // Headers Number are written, fills blockHash => number bucket
Bodies SyncStage = "Bodies" // Block bodies are downloaded, TxHash and UncleHash are getting verified
Senders SyncStage = "Senders" // "From" recovered from signatures, bodies re-written
Execution SyncStage = "Execution" // Executing each block w/o buildinf a trie
CustomTrace SyncStage = "CustomTrace" // Executing each block w/o buildinf a trie
Execution SyncStage = "Execution" // Executing each block w/o building a trie
CustomTrace SyncStage = "CustomTrace" // Executing each block w/o building a trie
Translation SyncStage = "Translation" // Translation each marked for translation contract (from EVM to TEVM)
VerkleTrie SyncStage = "VerkleTrie"
TxLookup SyncStage = "TxLookup" // Generating transactions lookup index
Expand Down
3 changes: 2 additions & 1 deletion tests/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestBlockchain(t *testing.T) {

// Currently it fails because SpawnStageHeaders doesn't accept any PoW blocks after PoS transition
// TODO(yperbasis): make it work
bt.skipLoad(`^TransitionTests/bcArrowGlacierToMerge/powToPosBlockRejection\.json`)
bt.skipLoad(`^TransitionTests/bcArrowGlacierToParis/powToPosBlockRejection\.json`)
bt.skipLoad(`^TransitionTests/bcFrontierToHomestead/blockChainFrontierWithLargerTDvsHomesteadBlockchain\.json`)

// TODO: HistoryV3: doesn't produce receipts on execution by design. But maybe we can Generate them on-the fly (on history) and enable this tests
Expand All @@ -68,6 +68,7 @@ func TestBlockchainEIP(t *testing.T) {

// EOF is not supported yet
bt.skipLoad(`^StateTests/stEOF/`)
bt.skipLoad(`^StateTests/stEIP2537/`)

checkStateRoot := true

Expand Down
1 change: 1 addition & 0 deletions tests/block_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func (bt *BlockTest) genesis(config *chain.Config) *types.Genesis {
BlobGasUsed: bt.json.Genesis.BlobGasUsed,
ExcessBlobGas: bt.json.Genesis.ExcessBlobGas,
ParentBeaconBlockRoot: bt.json.Genesis.ParentBeaconBlockRoot,
RequestsRoot: bt.json.Genesis.RequestsRoot,
}
}

Expand Down
34 changes: 20 additions & 14 deletions tests/gen_stenv.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func TestState(t *testing.T) {
st.skipLoad(`.*vmPerformance/loop.*`)
//if ethconfig.EnableHistoryV3InTest {
//}
// these need to implement eip-7610
st.skipLoad(`InitCollisionParis.json`)
st.skipLoad(`RevertInCreateInInit_Paris.json`)
st.skipLoad(`RevertInCreateInInitCreate2Paris.json`)
st.skipLoad(`create2collisionStorageParis.json`)
st.skipLoad(`dynamicAccountOverwriteEmpty_Paris.json`)

dirs := datadir.New(t.TempDir())
db, _ := temporaltest.NewTestDB(t, dirs)
st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) {
Expand Down
52 changes: 34 additions & 18 deletions tests/state_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/common/math"
"github.com/erigontech/erigon/consensus/misc"
"github.com/erigontech/erigon/core"
"github.com/erigontech/erigon/core/state"
"github.com/erigontech/erigon/core/tracing"
Expand Down Expand Up @@ -109,23 +110,25 @@ type stTransaction struct {
//go:generate gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go

type stEnv struct {
Coinbase libcommon.Address `json:"currentCoinbase" gencodec:"required"`
Difficulty *big.Int `json:"currentDifficulty" gencodec:"required"`
Random *big.Int `json:"currentRandom" gencodec:"optional"`
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
Number uint64 `json:"currentNumber" gencodec:"required"`
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
BaseFee *big.Int `json:"currentBaseFee" gencodec:"optional"`
Coinbase libcommon.Address `json:"currentCoinbase" gencodec:"required"`
Difficulty *big.Int `json:"currentDifficulty" gencodec:"required"`
Random *big.Int `json:"currentRandom" gencodec:"optional"`
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
Number uint64 `json:"currentNumber" gencodec:"required"`
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
BaseFee *big.Int `json:"currentBaseFee" gencodec:"optional"`
ExcessBlobGas *uint64 `json:"currentExcessBlobGas" gencodec:"optional"`
}

type stEnvMarshaling struct {
Coinbase common.UnprefixedAddress
Difficulty *math.HexOrDecimal256
Random *math.HexOrDecimal256
GasLimit math.HexOrDecimal64
Number math.HexOrDecimal64
Timestamp math.HexOrDecimal64
BaseFee *math.HexOrDecimal256
Coinbase common.UnprefixedAddress
Difficulty *math.HexOrDecimal256
Random *math.HexOrDecimal256
GasLimit math.HexOrDecimal64
Number math.HexOrDecimal64
Timestamp math.HexOrDecimal64
BaseFee *math.HexOrDecimal256
ExcessBlobGas *math.HexOrDecimal64
}

// GetChainConfig takes a fork definition and returns a chain config.
Expand Down Expand Up @@ -249,9 +252,19 @@ func (t *StateTest) RunNoVerify(tx kv.RwTx, subtest StateSubtest, vmconfig vm.Co
context.BaseFee = new(uint256.Int)
context.BaseFee.SetFromBig(baseFee)
}
if t.json.Env.Random != nil {
if t.json.Env.Difficulty != nil {
context.Difficulty = new(big.Int).Set(t.json.Env.Difficulty)
}
if config.IsLondon(0) && t.json.Env.Random != nil {
rnd := libcommon.BigToHash(t.json.Env.Random)
context.PrevRanDao = &rnd
context.Difficulty = big.NewInt(0)
}
if config.IsCancun(block.Time()) && t.json.Env.ExcessBlobGas != nil {
context.BlobBaseFee, err = misc.GetBlobGasPrice(config, *t.json.Env.ExcessBlobGas)
if err != nil {
return nil, libcommon.Hash{}, err
}
}
evm := vm.NewEVM(context, txContext, statedb, config, vmconfig)

Expand Down Expand Up @@ -424,10 +437,13 @@ func toMessage(tx stTransaction, ps stPostState, baseFee *big.Int) (core.Message
tx.MaxPriorityFeePerGas = tx.MaxFeePerGas
}

feeCap = big.Int(*tx.MaxPriorityFeePerGas)
tipCap = big.Int(*tx.MaxFeePerGas)
//feeCap = big.Int(*tx.MaxPriorityFeePerGas)
//tipCap = big.Int(*tx.MaxFeePerGas)

tipCap = big.Int(*tx.MaxPriorityFeePerGas)
feeCap = big.Int(*tx.MaxFeePerGas)

gp := math.BigMin(new(big.Int).Add(&feeCap, baseFee), &tipCap)
gp := math.BigMin(new(big.Int).Add(&tipCap, baseFee), &feeCap)
gasPrice = math.NewHexOrDecimal256(gp.Int64())
}
if gasPrice == nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata
2 changes: 1 addition & 1 deletion turbo/trie/hashbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (

const hashStackStride = length2.Hash + 1 // + 1 byte for RLP encoding

var EmptyCodeHash = crypto.Keccak256Hash(nil)
var EmptyCodeHash = crypto.Keccak256Hash(nil) //c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

// HashBuilder implements the interface `structInfoReceiver` and opcodes that the structural information of the trie
// is comprised of
Expand Down

0 comments on commit d3112dc

Please sign in to comment.