@@ -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,9 @@ 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+ // je sais pas pourquoi, le hash storé est faux. On dirait le empty code hash mais c'est un hasard
376+ t .Fatalf ("invalid BLOCKHASH value: %x != %x" , * stemStateDiff .SuffixDiffs [0 ].NewValue , genesisH )
369377 }
370378 } else {
371379 // For all other entries present in the witness, check that nothing beyond
@@ -393,8 +401,8 @@ func TestProcessVerkleInvalidContractCreation(t *testing.T) {
393401 if stemStateDiff .SuffixDiffs [0 ].NewValue == nil {
394402 t .Fatalf ("missing post state value for BLOCKHASH contract at block #2" )
395403 }
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 )[:])
404+ if * stemStateDiff .SuffixDiffs [0 ].NewValue != chain [ 0 ]. Hash ( ) {
405+ t .Fatalf ("invalid post state value for BLOCKHASH contract at block #2: %x != %x" , chain [ 0 ]. Hash () , (* stemStateDiff .SuffixDiffs [0 ].NewValue )[:])
398406 }
399407 } else if suffixDiff .Suffix > 4 {
400408 t .Fatalf ("invalid suffix diff found for %x in block #2: %d\n " , stemStateDiff .Stem , suffixDiff .Suffix )
@@ -440,7 +448,7 @@ func TestProcessVerkleContractWithEmptyCode(t *testing.T) {
440448 config .ChainID .SetUint64 (69421 )
441449 gspec := verkleTestGenesis (& config )
442450
443- _ , chain , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
451+ genesisH , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
444452 gen .SetPoS ()
445453 var tx types.Transaction
446454 // a transaction that does some PUSH1n but returns a 0-sized contract
@@ -472,8 +480,8 @@ func TestProcessVerkleContractWithEmptyCode(t *testing.T) {
472480 if stemStateDiff .SuffixDiffs [0 ].NewValue == nil {
473481 t .Fatalf ("nil new value in BLOCKHASH contract insert" )
474482 }
475- if * stemStateDiff .SuffixDiffs [0 ].NewValue != chain [ 0 ]. Hash () {
476- t .Fatalf ("invalid BLOCKHASH value: %x != %x" , * stemStateDiff .SuffixDiffs [0 ].NewValue , chain [ 0 ]. Hash () )
483+ if * stemStateDiff .SuffixDiffs [0 ].NewValue != genesisH {
484+ t .Fatalf ("invalid BLOCKHASH value: %x != %x" , * stemStateDiff .SuffixDiffs [0 ].NewValue , genesisH )
477485 }
478486 } else {
479487 for _ , suffixDiff := range stemStateDiff .SuffixDiffs {
@@ -532,7 +540,7 @@ func TestProcessVerkleExtCodeHashOpcode(t *testing.T) {
532540 }
533541 extCodeHashContractAddr := crypto .CreateAddress (deployer , 1 )
534542
535- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
543+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
536544 gen .SetPoS ()
537545
538546 if i == 0 {
@@ -605,7 +613,7 @@ func TestProcessVerkleBalanceOpcode(t *testing.T) {
605613 account2 = common .HexToAddress ("0x6177843db3138ae69679A54b95cf345ED759450d" )
606614 gspec = verkleTestGenesis (& config )
607615 )
608- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
616+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
609617 gen .SetPoS ()
610618 txData := slices .Concat (
611619 []byte {byte (vm .PUSH20 )},
@@ -686,7 +694,7 @@ func TestProcessVerkleSelfDestructInSeparateTx(t *testing.T) {
686694 deployer := crypto .PubkeyToAddress (testKey .PublicKey )
687695 contract := crypto .CreateAddress (deployer , 0 )
688696
689- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
697+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
690698 gen .SetPoS ()
691699
692700 if i == 0 {
@@ -794,7 +802,7 @@ func TestProcessVerkleSelfDestructInSameTx(t *testing.T) {
794802 deployer := crypto .PubkeyToAddress (testKey .PublicKey )
795803 contract := crypto .CreateAddress (deployer , 0 )
796804
797- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
805+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
798806 gen .SetPoS ()
799807 tx , _ := types .SignNewTx (testKey , signer , & types.LegacyTx {Nonce : 0 ,
800808 Value : big .NewInt (42 ),
@@ -897,7 +905,7 @@ func TestProcessVerkleSelfDestructInSeparateTxWithSelfBeneficiary(t *testing.T)
897905 deployer := crypto .PubkeyToAddress (testKey .PublicKey )
898906 contract := crypto .CreateAddress (deployer , 0 )
899907
900- _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
908+ _ , _ , _ , _ , _ , statediffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 2 , func (i int , gen * BlockGen ) {
901909 gen .SetPoS ()
902910 if i == 0 {
903911 // Create self-destruct contract, sending 42 wei.
@@ -977,7 +985,7 @@ func TestProcessVerkleSelfDestructInSameTxWithSelfBeneficiary(t *testing.T) {
977985
978986 selfDestructContract := []byte {byte (vm .ADDRESS ), byte (vm .SELFDESTRUCT )}
979987
980- _ , _ , _ , _ , stateDiffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
988+ _ , _ , _ , _ , _ , stateDiffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
981989 gen .SetPoS ()
982990 tx , _ := types .SignNewTx (testKey , signer , & types.LegacyTx {Nonce : 0 ,
983991 Value : big .NewInt (42 ),
@@ -1043,7 +1051,7 @@ func TestProcessVerkleSelfDestructInSameTxWithSelfBeneficiaryAndPrefundedAccount
10431051
10441052 selfDestructContract := []byte {byte (vm .ADDRESS ), byte (vm .SELFDESTRUCT )}
10451053
1046- _ , _ , _ , _ , stateDiffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
1054+ _ , _ , _ , _ , _ , stateDiffs := GenerateVerkleChainWithGenesis (gspec , beacon .New (ethash .NewFaker ()), 1 , func (i int , gen * BlockGen ) {
10471055 gen .SetPoS ()
10481056 tx , _ := types .SignNewTx (testKey , signer , & types.LegacyTx {Nonce : 0 ,
10491057 Value : big .NewInt (42 ),
0 commit comments