From c23058e3fd48114138c2750791797b128e1df98a Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Mon, 8 Apr 2024 16:00:56 -0300 Subject: [PATCH] core: change block hash history scope (#411) Signed-off-by: Ignacio Hagopian --- core/state_processor.go | 4 ++-- core/vm/instructions.go | 2 +- params/protocol_params.go | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index d28df7aac1d0..6961a873602e 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -371,14 +371,14 @@ func (kvm *keyValueMigrator) migrateCollectedKeyValues(tree *trie.VerkleTrie) er func InsertBlockHashHistoryAtEip2935Fork(statedb *state.StateDB, prevNumber uint64, prevHash common.Hash, chain consensus.ChainHeaderReader) { ancestor := chain.GetHeader(prevHash, prevNumber) - for i := prevNumber; i > 0 && i >= prevNumber-256; i-- { + for i := prevNumber; i > 0 && i >= prevNumber-params.Eip2935BlockHashHistorySize; i-- { ProcessParentBlockHash(statedb, i, ancestor.Hash()) ancestor = chain.GetHeader(ancestor.ParentHash, ancestor.Number.Uint64()-1) } } func ProcessParentBlockHash(statedb *state.StateDB, prevNumber uint64, prevHash common.Hash) { - ringIndex := prevNumber % 256 + ringIndex := prevNumber % params.Eip2935BlockHashHistorySize var key common.Hash binary.BigEndian.PutUint64(key[24:], ringIndex) statedb.SetState(params.HistoryStorageAddress, key, prevHash) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 14b5704c5b87..7073f2d7c297 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -517,7 +517,7 @@ func opGasprice(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([ } func getBlockHashFromContract(number uint64, statedb StateDB, witness *state.AccessWitness) common.Hash { - ringIndex := number % 256 + ringIndex := number % params.Eip2935BlockHashHistorySize var pnum common.Hash binary.BigEndian.PutUint64(pnum[24:], ringIndex) treeIndex, suffix := utils.GetTreeKeyStorageSlotTreeIndexes(pnum.Bytes()) diff --git a/params/protocol_params.go b/params/protocol_params.go index 6d91ee48a85f..8aad52103979 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -173,6 +173,9 @@ const ( BlobTxMinBlobGasprice = 1 // Minimum gas price for data blobs BlobTxBlobGaspriceUpdateFraction = 2225652 // Controls the maximum rate of change for blob gas price BlobTxPointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile. + + // Block hash history parameters + Eip2935BlockHashHistorySize = 8192 ) // Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations