@@ -152,7 +152,7 @@ func TestProcessVerkle(t *testing.T) {
152152 txCost1 * 2 + txCost2 ,
153153 txCost1 * 2 + txCost2 + contractCreationCost + codeWithExtCodeCopyGas ,
154154 }
155- _ , chain , _ , proofs , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
155+ _ , _ , chain , _ , proofs , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
156156 gen .SetPoS ()
157157
158158 // TODO need to check that the tx cost provided is the exact amount used (no remaining left-over)
@@ -219,44 +219,51 @@ func TestProcessParentBlockHash(t *testing.T) {
219219 // block 1 parent hash is 0x0100....
220220 // block 2 parent hash is 0x0200....
221221 // etc
222- checkBlockHashes := func (statedb * state.StateDB ) {
222+ checkBlockHashes := func (statedb * state.StateDB , isVerkle bool ) {
223223 statedb .SetNonce (params .HistoryStorageAddress , 1 )
224224 statedb .SetCode (params .HistoryStorageAddress , params .HistoryStorageCode )
225225 // Process n blocks, from 1 .. num
226226 var num = 2
227227 for i := 1 ; i <= num ; i ++ {
228228 header := & types.Header {ParentHash : common.Hash {byte (i )}, Number : big .NewInt (int64 (i )), Difficulty : new (big.Int )}
229229 vmContext := NewEVMBlockContext (header , nil , new (common.Address ))
230- evm := vm .NewEVM (vmContext , statedb , params .MergedTestChainConfig , vm.Config {})
230+ chainConfig := params .MergedTestChainConfig
231+ if isVerkle {
232+ chainConfig = testVerkleChainConfig
233+ }
234+ evm := vm .NewEVM (vmContext , statedb , chainConfig , vm.Config {})
231235 ProcessParentBlockHash (header .ParentHash , evm )
232236 }
233237 // Read block hashes for block 0 .. num-1
234238 for i := 0 ; i < num ; i ++ {
235- have , want := getContractStoredBlockHash (statedb , uint64 (i )), common.Hash {byte (i + 1 )}
239+ have , want := getContractStoredBlockHash (statedb , uint64 (i ), isVerkle ), common.Hash {byte (i + 1 )}
236240 if have != want {
237- t .Errorf ("block %d, have parent hash %v, want %v" , i , have , want )
241+ t .Errorf ("block %d, verkle=%v, have parent hash %v, want %v" , i , isVerkle , have , want )
238242 }
239243 }
240244 }
241245 t .Run ("MPT" , func (t * testing.T ) {
242246 statedb , _ := state .New (types .EmptyRootHash , state .NewDatabaseForTesting ())
243- checkBlockHashes (statedb )
247+ checkBlockHashes (statedb , false )
244248 })
245249 t .Run ("Verkle" , func (t * testing.T ) {
246250 db := rawdb .NewMemoryDatabase ()
247251 cacheConfig := DefaultCacheConfigWithScheme (rawdb .PathScheme )
248252 cacheConfig .SnapshotLimit = 0
249253 triedb := triedb .NewDatabase (db , cacheConfig .triedbConfig (true ))
250254 statedb , _ := state .New (types .EmptyVerkleHash , state .NewDatabase (triedb , nil ))
251- checkBlockHashes (statedb )
255+ checkBlockHashes (statedb , true )
252256 })
253257}
254258
255259// getContractStoredBlockHash is a utility method which reads the stored parent blockhash for block 'number'
256- func getContractStoredBlockHash (statedb * state.StateDB , number uint64 ) common.Hash {
260+ func getContractStoredBlockHash (statedb * state.StateDB , number uint64 , isVerkle bool ) common.Hash {
257261 ringIndex := number % params .HistoryServeWindow
258262 var key common.Hash
259263 binary .BigEndian .PutUint64 (key [24 :], ringIndex )
264+ if isVerkle {
265+ return statedb .GetState (params .HistoryStorageAddress , key )
266+ }
260267 return statedb .GetState (params .HistoryStorageAddress , key )
261268}
262269
@@ -279,7 +286,7 @@ func TestProcessVerkleInvalidContractCreation(t *testing.T) {
279286 //
280287 // - The second block contains a single failing contract creation transaction,
281288 // that fails right off the bat.
282- _ , chain , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
289+ genesisH , _ , chain , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
283290 gen .SetPoS ()
284291
285292 if i == 0 {
@@ -364,8 +371,8 @@ func TestProcessVerkleInvalidContractCreation(t *testing.T) {
364371 if stemStateDiff .SuffixDiffs [0 ].NewValue == nil {
365372 t .Fatalf ("nil new value in BLOCKHASH contract insert" )
366373 }
367- if * stemStateDiff .SuffixDiffs [0 ].NewValue != chain [ 0 ]. Hash () {
368- t .Fatalf ("invalid BLOCKHASH value: %x != %x" , * stemStateDiff .SuffixDiffs [0 ].NewValue , chain [ 0 ]. Hash () )
374+ if * stemStateDiff .SuffixDiffs [0 ].NewValue != genesisH {
375+ t .Fatalf ("invalid BLOCKHASH value: %x != %x" , * stemStateDiff .SuffixDiffs [0 ].NewValue , genesisH )
369376 }
370377 } else {
371378 // For all other entries present in the witness, check that nothing beyond
@@ -393,8 +400,8 @@ func TestProcessVerkleInvalidContractCreation(t *testing.T) {
393400 if stemStateDiff .SuffixDiffs [0 ].NewValue == nil {
394401 t .Fatalf ("missing post state value for BLOCKHASH contract at block #2" )
395402 }
396- if * stemStateDiff .SuffixDiffs [0 ].NewValue != common . HexToHash ( "0788c2c0f23aa07eb8bf76fe6c1ca9064a4821c1fd0af803913da488a58dba54" ) {
397- t .Fatalf ("invalid post state value for BLOCKHASH contract at block #2: 0788c2c0f23aa07eb8bf76fe6c1ca9064a4821c1fd0af803913da488a58dba54 != %x" , (* stemStateDiff .SuffixDiffs [0 ].NewValue )[:])
403+ if * stemStateDiff .SuffixDiffs [0 ].NewValue != chain [ 0 ]. Hash ( ) {
404+ t .Fatalf ("invalid post state value for BLOCKHASH contract at block #2: %x != %x" , chain [ 0 ]. Hash () , (* stemStateDiff .SuffixDiffs [0 ].NewValue )[:])
398405 }
399406 } else if suffixDiff .Suffix > 4 {
400407 t .Fatalf ("invalid suffix diff found for %x in block #2: %d\n " , stemStateDiff .Stem , suffixDiff .Suffix )
@@ -440,7 +447,7 @@ func TestProcessVerkleContractWithEmptyCode(t *testing.T) {
440447 config .ChainID .SetUint64 (69421 )
441448 gspec := verkleTestGenesis (& config )
442449
443- _ , chain , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
450+ genesisH , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
444451 gen .SetPoS ()
445452 var tx types.Transaction
446453 // a transaction that does some PUSH1n but returns a 0-sized contract
@@ -472,8 +479,8 @@ func TestProcessVerkleContractWithEmptyCode(t *testing.T) {
472479 if stemStateDiff .SuffixDiffs [0 ].NewValue == nil {
473480 t .Fatalf ("nil new value in BLOCKHASH contract insert" )
474481 }
475- if * stemStateDiff .SuffixDiffs [0 ].NewValue != chain [ 0 ]. Hash () {
476- t .Fatalf ("invalid BLOCKHASH value: %x != %x" , * stemStateDiff .SuffixDiffs [0 ].NewValue , chain [ 0 ]. Hash () )
482+ if * stemStateDiff .SuffixDiffs [0 ].NewValue != genesisH {
483+ t .Fatalf ("invalid BLOCKHASH value: %x != %x" , * stemStateDiff .SuffixDiffs [0 ].NewValue , genesisH )
477484 }
478485 } else {
479486 for _ , suffixDiff := range stemStateDiff .SuffixDiffs {
@@ -532,7 +539,7 @@ func TestProcessVerkleExtCodeHashOpcode(t *testing.T) {
532539 }
533540 extCodeHashContractAddr := crypto .CreateAddress (deployer , 1 )
534541
535- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
542+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
536543 gen .SetPoS ()
537544
538545 if i == 0 {
@@ -605,7 +612,7 @@ func TestProcessVerkleBalanceOpcode(t *testing.T) {
605612 account2 = common .HexToAddress ("0x6177843db3138ae69679A54b95cf345ED759450d" )
606613 gspec = verkleTestGenesis (& config )
607614 )
608- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
615+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
609616 gen .SetPoS ()
610617 txData := slices .Concat (
611618 []byte {byte (vm .PUSH20 )},
@@ -686,7 +693,7 @@ func TestProcessVerkleSelfDestructInSeparateTx(t *testing.T) {
686693 deployer := crypto .PubkeyToAddress (testKey .PublicKey )
687694 contract := crypto .CreateAddress (deployer , 0 )
688695
689- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
696+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
690697 gen .SetPoS ()
691698
692699 if i == 0 {
@@ -794,7 +801,7 @@ func TestProcessVerkleSelfDestructInSameTx(t *testing.T) {
794801 deployer := crypto .PubkeyToAddress (testKey .PublicKey )
795802 contract := crypto .CreateAddress (deployer , 0 )
796803
797- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
804+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
798805 gen .SetPoS ()
799806 tx , _ := types .SignNewTx (testKey , signer , & types.LegacyTx {Nonce : 0 ,
800807 Value : big .NewInt (42 ),
@@ -897,7 +904,7 @@ func TestProcessVerkleSelfDestructInSeparateTxWithSelfBeneficiary(t *testing.T)
897904 deployer := crypto .PubkeyToAddress (testKey .PublicKey )
898905 contract := crypto .CreateAddress (deployer , 0 )
899906
900- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
907+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
901908 gen .SetPoS ()
902909 if i == 0 {
903910 // Create self-destruct contract, sending 42 wei.
@@ -977,7 +984,7 @@ func TestProcessVerkleSelfDestructInSameTxWithSelfBeneficiary(t *testing.T) {
977984
978985 selfDestructContract := []byte {byte (vm .ADDRESS ), byte (vm .SELFDESTRUCT )}
979986
980- _ , _ , _ , _ , stateDiffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
987+ _ , _ , _ , _ , _ , stateDiffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
981988 gen .SetPoS ()
982989 tx , _ := types .SignNewTx (testKey , signer , & types.LegacyTx {Nonce : 0 ,
983990 Value : big .NewInt (42 ),
@@ -1043,7 +1050,7 @@ func TestProcessVerkleSelfDestructInSameTxWithSelfBeneficiaryAndPrefundedAccount
10431050
10441051 selfDestructContract := []byte {byte (vm .ADDRESS ), byte (vm .SELFDESTRUCT )}
10451052
1046- _ , _ , _ , _ , stateDiffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
1053+ _ , _ , _ , _ , _ , stateDiffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
10471054 gen .SetPoS ()
10481055 tx , _ := types .SignNewTx (testKey , signer , & types.LegacyTx {Nonce : 0 ,
10491056 Value : big .NewInt (42 ),
0 commit comments