Implement EIP-2935: Serve historical block hashes from state (#2606)
* Implement EIP-2935: Serve historical block hashes from state * Fix EIP-2935 in t8n
This commit is contained in:
parent
5464f8e5f1
commit
38c58c4feb
|
@ -107,4 +107,5 @@ const
|
|||
result[19] = x.byte
|
||||
initAddress(3)
|
||||
|
||||
HISTORY_STORAGE_ADDRESS* = hexToByteArray[20]("0x0aae40965e6800cd9b1f4b05ff21581047e3f91e")
|
||||
# End
|
||||
|
|
|
@ -66,6 +66,9 @@ proc procBlkPreamble(
|
|||
if blk.transactions.calcTxRoot != header.txRoot:
|
||||
return err("Mismatched txRoot")
|
||||
|
||||
if com.isPragueOrLater(header.timestamp):
|
||||
?vmState.processParentBlockHash(header.parentHash)
|
||||
|
||||
if com.isCancunOrLater(header.timestamp):
|
||||
if header.parentBeaconBlockRoot.isNone:
|
||||
return err("Post-Cancun block header must have parentBeaconBlockRoot")
|
||||
|
@ -144,10 +147,10 @@ proc procBlkEpilogue(
|
|||
|
||||
if not skipReceipts:
|
||||
let bloom = createBloom(vmState.receipts)
|
||||
|
||||
|
||||
if header.logsBloom != bloom:
|
||||
return err("bloom mismatch")
|
||||
|
||||
|
||||
let receiptsRoot = calcReceiptsRoot(vmState.receipts)
|
||||
if header.receiptsRoot != receiptsRoot:
|
||||
# TODO replace logging with better error
|
||||
|
|
|
@ -157,6 +157,36 @@ proc processBeaconBlockRoot*(vmState: BaseVMState, beaconRoot: Hash256):
|
|||
statedb.persist(clearEmptyAccount = true)
|
||||
ok()
|
||||
|
||||
proc processParentBlockHash*(vmState: BaseVMState, prevHash: Hash256):
|
||||
Result[void, string] =
|
||||
## processParentBlockHash stores the parent block hash in the
|
||||
## history storage contract as per EIP-2935.
|
||||
let
|
||||
statedb = vmState.stateDB
|
||||
call = CallParams(
|
||||
vmState : vmState,
|
||||
sender : SYSTEM_ADDRESS,
|
||||
gasLimit : 30_000_000.GasInt,
|
||||
gasPrice : 0.GasInt,
|
||||
to : HISTORY_STORAGE_ADDRESS,
|
||||
input : @(prevHash.data),
|
||||
|
||||
# It's a systemCall, no need for other knicks knacks
|
||||
sysCall : true,
|
||||
noAccessList: true,
|
||||
noIntrinsic : true,
|
||||
noGasCharge : true,
|
||||
noRefund : true,
|
||||
)
|
||||
|
||||
# runComputation a.k.a syscall/evm.call
|
||||
let res = call.runComputation(string)
|
||||
if res.len > 0:
|
||||
return err("processParentBlockHash: " & res)
|
||||
|
||||
statedb.persist(clearEmptyAccount = true)
|
||||
ok()
|
||||
|
||||
proc processTransaction*(
|
||||
vmState: BaseVMState; ## Parent accounts environment for transaction
|
||||
tx: Transaction; ## Transaction to validate
|
||||
|
|
|
@ -234,6 +234,18 @@ proc exec(ctx: var TransContext,
|
|||
vmState.processBeaconBlockRoot(ctx.env.parentBeaconBlockRoot.get).isOkOr:
|
||||
raise newError(ErrorConfig, error)
|
||||
|
||||
if vmState.com.isPragueOrLater(ctx.env.currentTimestamp) and
|
||||
ctx.env.blockHashes.len > 0:
|
||||
let
|
||||
prevNumber = ctx.env.currentNumber - 1
|
||||
prevHash = ctx.env.blockHashes.getOrDefault(prevNumber)
|
||||
|
||||
if prevHash == static(Hash256()):
|
||||
raise newError(ErrorConfig, "previous block hash not found for block number: " & $prevNumber)
|
||||
|
||||
vmState.processParentBlockHash(prevHash).isOkOr:
|
||||
raise newError(ErrorConfig, error)
|
||||
|
||||
for txIndex, txRes in txList:
|
||||
if txRes.isErr:
|
||||
rejected.add RejectedTx(
|
||||
|
|
Loading…
Reference in New Issue