1717package core
1818
1919import (
20+ "encoding/json"
2021 "errors"
2122 "fmt"
2223 "math/big"
@@ -39,7 +40,9 @@ import (
3940 "github.com/ethereum/go-ethereum/eth/tracers/logger"
4041 "github.com/ethereum/go-ethereum/ethdb"
4142 "github.com/ethereum/go-ethereum/params"
43+ "github.com/ethereum/go-ethereum/rollup/rcfg"
4244 "github.com/ethereum/go-ethereum/trie"
45+ "github.com/stretchr/testify/assert"
4346)
4447
4548// So we can deterministically seed different blockchains
@@ -4716,3 +4719,78 @@ func TestEIP3651(t *testing.T) {
47164719 t .Fatalf ("sender balance incorrect: expected %d, got %d" , expected , actual )
47174720 }
47184721}
4722+
4723+ func TestCurieTransition (t * testing.T ) {
4724+ // Set fork blocks in config
4725+ // (we make a deep copy to avoid interference with other tests)
4726+ var config * params.ChainConfig
4727+ b , _ := json .Marshal (params .AllEthashProtocolChanges )
4728+ json .Unmarshal (b , & config )
4729+ config .CurieBlock = big .NewInt (2 )
4730+ config .DescartesBlock = nil
4731+
4732+ var (
4733+ db = rawdb .NewMemoryDatabase ()
4734+ gspec = & Genesis {Config : config }
4735+ genesis = gspec .MustCommit (db , trie .NewDatabase (db , trie .HashDefaults ))
4736+ )
4737+
4738+ blockchain , _ := NewBlockChain (db , nil , gspec , nil , ethash .NewFaker (), vm.Config {}, nil , nil )
4739+ defer blockchain .Stop ()
4740+ blocks , _ := GenerateChain (gspec .Config , genesis , ethash .NewFaker (), db , 4 , nil )
4741+
4742+ if _ , err := blockchain .InsertChain (blocks ); err != nil {
4743+ t .Fatal (err )
4744+ }
4745+
4746+ latestBlock := uint64 (4 )
4747+ assert .Equal (t , latestBlock , blockchain .CurrentHeader ().Number .Uint64 ())
4748+
4749+ for ii := uint64 (0 ); ii <= latestBlock ; ii ++ {
4750+ block := blockchain .GetBlockByNumber (ii )
4751+
4752+ number := block .Number ().Uint64 ()
4753+ baseFee := block .BaseFee ()
4754+
4755+ statedb , _ := state .New (block .Root (), state .NewDatabase (db ), nil )
4756+
4757+ code := statedb .GetCode (rcfg .L1GasPriceOracleAddress )
4758+ codeSize := statedb .GetCodeSize (rcfg .L1GasPriceOracleAddress )
4759+ keccakCodeHash := statedb .GetKeccakCodeHash (rcfg .L1GasPriceOracleAddress )
4760+ poseidonCodeHash := statedb .GetPoseidonCodeHash (rcfg .L1GasPriceOracleAddress )
4761+
4762+ l1BlobBaseFee := statedb .GetState (rcfg .L1GasPriceOracleAddress , rcfg .L1BlobBaseFeeSlot )
4763+ commitScalar := statedb .GetState (rcfg .L1GasPriceOracleAddress , rcfg .CommitScalarSlot )
4764+ blobScalar := statedb .GetState (rcfg .L1GasPriceOracleAddress , rcfg .BlobScalarSlot )
4765+ isCurie := statedb .GetState (rcfg .L1GasPriceOracleAddress , rcfg .IsCurieSlot )
4766+
4767+ if number < config .CurieBlock .Uint64 () {
4768+ assert .Nil (t , baseFee , "Expected zero base fee before Curie" )
4769+
4770+ // we don't have predeploys configured in this test,
4771+ // so there is no gas oracle deployed before Curie
4772+ assert .Nil (t , code )
4773+ assert .Equal (t , uint64 (0 ), codeSize )
4774+ assert .Equal (t , common.Hash {}, keccakCodeHash )
4775+ assert .Equal (t , common.Hash {}, poseidonCodeHash )
4776+
4777+ assert .Equal (t , common.Hash {}, l1BlobBaseFee )
4778+ assert .Equal (t , common.Hash {}, commitScalar )
4779+ assert .Equal (t , common.Hash {}, blobScalar )
4780+ assert .Equal (t , common.Hash {}, isCurie )
4781+ } else {
4782+ assert .NotNil (t , baseFee , "Expected nonzero base fee after Curie" )
4783+
4784+ // all gas oracle entries updated
4785+ assert .NotNil (t , code )
4786+ assert .NotEqual (t , uint64 (0 ), codeSize )
4787+ assert .NotEqual (t , common.Hash {}, keccakCodeHash )
4788+ assert .NotEqual (t , common.Hash {}, poseidonCodeHash )
4789+
4790+ assert .NotEqual (t , common.Hash {}, l1BlobBaseFee )
4791+ assert .NotEqual (t , common.Hash {}, commitScalar )
4792+ assert .NotEqual (t , common.Hash {}, blobScalar )
4793+ assert .NotEqual (t , common.Hash {}, isCurie )
4794+ }
4795+ }
4796+ }
0 commit comments