@@ -18,6 +18,7 @@ package core
1818
1919import (
2020 "crypto/ecdsa"
21+ "encoding/binary"
2122 "math/big"
2223 "testing"
2324
@@ -31,9 +32,11 @@ import (
3132 "github.com/scroll-tech/go-ethereum/consensus/ethash"
3233 "github.com/scroll-tech/go-ethereum/consensus/misc"
3334 "github.com/scroll-tech/go-ethereum/core/rawdb"
35+ "github.com/scroll-tech/go-ethereum/core/state"
3436 "github.com/scroll-tech/go-ethereum/core/types"
3537 "github.com/scroll-tech/go-ethereum/core/vm"
3638 "github.com/scroll-tech/go-ethereum/crypto"
39+ "github.com/scroll-tech/go-ethereum/ethdb/memorydb"
3740 "github.com/scroll-tech/go-ethereum/params"
3841 "github.com/scroll-tech/go-ethereum/trie"
3942)
@@ -64,6 +67,7 @@ func TestStateProcessorErrors(t *testing.T) {
6467 DarwinV2Time : new (uint64 ),
6568 EuclidTime : new (uint64 ),
6669 EuclidV2Time : new (uint64 ),
70+ FeynmanTime : new (uint64 ),
6771 Ethash : new (params.EthashConfig ),
6872 }
6973 signer = types .LatestSigner (config )
@@ -387,9 +391,9 @@ func TestStateProcessorErrors(t *testing.T) {
387391 }{
388392 { // ErrMaxInitCodeSizeExceeded
389393 txs : []* types.Transaction {
390- mkDynamicCreationTx (0 , 500000 , common .Big0 , misc .CalcBaseFee (config , genesis .Header (), parentL1BaseFee ), tooBigInitCode [:]),
394+ mkDynamicCreationTx (0 , 520000 , common .Big0 , misc .CalcBaseFee (config , genesis .Header (), parentL1BaseFee ), tooBigInitCode [:]),
391395 },
392- want : "could not apply tx 0 [0x7b33776d375660694a23ef992c090265682f3687607e0099b14503fdb65d73e3 ]: max initcode size exceeded: code size 49153 limit 49152" ,
396+ want : "could not apply tx 0 [0xe0d03426cecc04467410064cb4de02012fc069d2462282735d7dfcb9dea9f63b ]: max initcode size exceeded: code size 49153 limit 49152" ,
393397 },
394398 { // ErrIntrinsicGas: Not enough gas to cover init code
395399 txs : []* types.Transaction {
@@ -453,3 +457,68 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
453457 // Assemble and return the final block for sealing
454458 return types .NewBlock (header , txs , nil , receipts , trie .NewStackTrie (nil ))
455459}
460+
461+ func TestProcessParentBlockHash (t * testing.T ) {
462+ var (
463+ chainConfig = & params.ChainConfig {
464+ ChainID : big .NewInt (1 ),
465+ HomesteadBlock : big .NewInt (0 ),
466+ EIP150Block : big .NewInt (0 ),
467+ EIP155Block : big .NewInt (0 ),
468+ EIP158Block : big .NewInt (0 ),
469+ ByzantiumBlock : big .NewInt (0 ),
470+ ConstantinopleBlock : big .NewInt (0 ),
471+ PetersburgBlock : big .NewInt (0 ),
472+ IstanbulBlock : big .NewInt (0 ),
473+ MuirGlacierBlock : big .NewInt (0 ),
474+ BerlinBlock : big .NewInt (0 ),
475+ LondonBlock : big .NewInt (0 ),
476+ ShanghaiBlock : big .NewInt (0 ),
477+ BernoulliBlock : big .NewInt (0 ),
478+ CurieBlock : big .NewInt (0 ),
479+ DarwinTime : new (uint64 ),
480+ DarwinV2Time : new (uint64 ),
481+ EuclidTime : new (uint64 ),
482+ EuclidV2Time : new (uint64 ),
483+ FeynmanTime : new (uint64 ),
484+ Ethash : new (params.EthashConfig ),
485+ }
486+ hashA = common.Hash {0x01 }
487+ hashB = common.Hash {0x02 }
488+ header = & types.Header {ParentHash : hashA , Number : big .NewInt (2 ), Difficulty : big .NewInt (0 )}
489+ parent = & types.Header {ParentHash : hashB , Number : big .NewInt (1 ), Difficulty : big .NewInt (0 )}
490+ coinbase = common.Address {}
491+ )
492+ test := func (statedb * state.StateDB ) {
493+ statedb .SetNonce (params .HistoryStorageAddress , 1 )
494+ statedb .SetCode (params .HistoryStorageAddress , params .HistoryStorageCode )
495+ statedb .IntermediateRoot (true )
496+
497+ vmContext := NewEVMBlockContext (header , nil , chainConfig , & coinbase )
498+ evm := vm .NewEVM (vmContext , vm.TxContext {}, statedb , chainConfig , vm.Config {})
499+ ProcessParentBlockHash (header .ParentHash , evm , statedb )
500+
501+ vmContext = NewEVMBlockContext (parent , nil , chainConfig , & coinbase )
502+ evm = vm .NewEVM (vmContext , vm.TxContext {}, statedb , chainConfig , vm.Config {})
503+ ProcessParentBlockHash (parent .ParentHash , evm , statedb )
504+
505+ // make sure that the state is correct
506+ if have := getParentBlockHash (statedb , 1 ); have != hashA {
507+ t .Errorf ("want parent hash %v, have %v" , hashA , have )
508+ }
509+ if have := getParentBlockHash (statedb , 0 ); have != hashB {
510+ t .Errorf ("want parent hash %v, have %v" , hashB , have )
511+ }
512+ }
513+ t .Run ("MPT" , func (t * testing.T ) {
514+ statedb , _ := state .New (types .EmptyRootHash , state .NewDatabase (rawdb .NewDatabase (memorydb .New ())), nil )
515+ test (statedb )
516+ })
517+ }
518+
519+ func getParentBlockHash (statedb * state.StateDB , number uint64 ) common.Hash {
520+ ringIndex := number % params .HistoryServeWindow
521+ var key common.Hash
522+ binary .BigEndian .PutUint64 (key [24 :], ringIndex )
523+ return statedb .GetState (params .HistoryStorageAddress , key )
524+ }
0 commit comments