@@ -517,8 +517,9 @@ func opGasprice(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
517517}
518518
519519func getBlockHashFromContract (number uint64 , statedb StateDB , witness * state.AccessWitness ) common.Hash {
520+ ringIndex := number % 256
520521 var pnum common.Hash
521- binary .BigEndian .PutUint64 (pnum [24 :], number )
522+ binary .BigEndian .PutUint64 (pnum [24 :], ringIndex )
522523 treeIndex , suffix := utils .GetTreeKeyStorageSlotTreeIndexes (pnum .Bytes ())
523524 witness .TouchAddressOnReadAndComputeGas (params .HistoryStorageAddress [:], * treeIndex , suffix )
524525 return statedb .GetState (params .HistoryStorageAddress , pnum )
@@ -533,11 +534,6 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
533534 }
534535
535536 evm := interpreter .evm
536- // if Prague is active, read it from the history contract (EIP 2935).
537- if evm .chainRules .IsPrague {
538- num .SetBytes (getBlockHashFromContract (num64 , evm .StateDB , evm .Accesses ).Bytes ())
539- return nil , nil
540- }
541537
542538 var upper , lower uint64
543539 upper = interpreter .evm .Context .BlockNumber .Uint64 ()
@@ -547,7 +543,12 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) (
547543 lower = upper - 256
548544 }
549545 if num64 >= lower && num64 < upper {
550- num .SetBytes (interpreter .evm .Context .GetHash (num64 ).Bytes ())
546+ // if Prague is active, read it from the history contract (EIP 2935).
547+ if evm .chainRules .IsPrague {
548+ num .SetBytes (getBlockHashFromContract (num64 , evm .StateDB , evm .Accesses ).Bytes ())
549+ } else {
550+ num .SetBytes (interpreter .evm .Context .GetHash (num64 ).Bytes ())
551+ }
551552 } else {
552553 num .Clear ()
553554 }
0 commit comments