processBeaconBlockRoot in TxPool(EIP-4788)
This commit is contained in:
parent
b8e3fc5859
commit
c005281391
|
@ -34,12 +34,12 @@ type
|
||||||
# Private helpers
|
# Private helpers
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc setWithdrawals(xp: TxPoolRef, attrs: PayloadAttributes) =
|
proc setWithdrawals(ctx: CasperRef, attrs: PayloadAttributes) =
|
||||||
case attrs.version
|
case attrs.version
|
||||||
of Version.V2, Version.V3:
|
of Version.V2, Version.V3:
|
||||||
xp.withdrawals = ethWithdrawals attrs.withdrawals.get
|
ctx.withdrawals = ethWithdrawals attrs.withdrawals.get
|
||||||
else:
|
else:
|
||||||
xp.withdrawals = @[]
|
ctx.withdrawals = @[]
|
||||||
|
|
||||||
template wrapException(body: untyped): auto =
|
template wrapException(body: untyped): auto =
|
||||||
try:
|
try:
|
||||||
|
@ -159,7 +159,7 @@ proc generatePayload*(ben: BeaconEngineRef,
|
||||||
if attrs.parentBeaconBlockRoot.isSome:
|
if attrs.parentBeaconBlockRoot.isSome:
|
||||||
pos.parentBeaconBlockRoot = ethHash attrs.parentBeaconBlockRoot.get
|
pos.parentBeaconBlockRoot = ethHash attrs.parentBeaconBlockRoot.get
|
||||||
|
|
||||||
xp.setWithdrawals(attrs)
|
pos.setWithdrawals(attrs)
|
||||||
|
|
||||||
if headBlock.blockHash != xp.head.blockHash:
|
if headBlock.blockHash != xp.head.blockHash:
|
||||||
# reorg
|
# reorg
|
||||||
|
|
|
@ -86,7 +86,7 @@ func u256*(x: Web3Quantity): UInt256 =
|
||||||
u256(x.uint64)
|
u256(x.uint64)
|
||||||
|
|
||||||
func ethTime*(x: Web3Quantity): common.EthTime =
|
func ethTime*(x: Web3Quantity): common.EthTime =
|
||||||
common.EthTime(x.unsafeQuantityToInt64)
|
common.EthTime(x)
|
||||||
|
|
||||||
func ethHash*(x: Web3PrevRandao): common.Hash256 =
|
func ethHash*(x: Web3PrevRandao): common.Hash256 =
|
||||||
common.Hash256(data: distinctBase x)
|
common.Hash256(data: distinctBase x)
|
||||||
|
@ -171,6 +171,12 @@ func w3Qty*(x: common.EthTime, y: int): Web3Quantity =
|
||||||
func w3Qty*(x: Web3Quantity, y: int): Web3Quantity =
|
func w3Qty*(x: Web3Quantity, y: int): Web3Quantity =
|
||||||
Web3Quantity(x.uint64 + y.uint64)
|
Web3Quantity(x.uint64 + y.uint64)
|
||||||
|
|
||||||
|
func w3Qty*(x: Web3Quantity, y: EthTime): Web3Quantity =
|
||||||
|
Web3Quantity(x.uint64 + y.uint64)
|
||||||
|
|
||||||
|
func w3Qty*(x: Web3Quantity, y: uint64): Web3Quantity =
|
||||||
|
Web3Quantity(x.uint64 + y)
|
||||||
|
|
||||||
func w3Qty*(x: Option[uint64]): Option[Web3Quantity] =
|
func w3Qty*(x: Option[uint64]): Option[Web3Quantity] =
|
||||||
if x.isNone: none(Web3Quantity)
|
if x.isNone: none(Web3Quantity)
|
||||||
else: some(Web3Quantity x.get)
|
else: some(Web3Quantity x.get)
|
||||||
|
|
|
@ -87,10 +87,10 @@ const
|
||||||
MAX_ALLOWED_BLOB* = MAX_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB
|
MAX_ALLOWED_BLOB* = MAX_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB
|
||||||
|
|
||||||
# EIP-4788 addresses
|
# EIP-4788 addresses
|
||||||
# BeaconRootsStorageAddress is the address where historical beacon roots are stored as per EIP-4788
|
# BEACON_ROOTS_ADDRESS is the address where historical beacon roots are stored as per EIP-4788
|
||||||
BeaconRootsStorageAddress* = hexToByteArray[20]("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02")
|
BEACON_ROOTS_ADDRESS* = hexToByteArray[20]("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02")
|
||||||
# SystemAddress is where the system-transaction is sent from as per EIP-4788
|
# SYSTEM_ADDRESS is where the system-transaction is sent from as per EIP-4788
|
||||||
SystemAddress* = hexToByteArray[20]("0xfffffffffffffffffffffffffffffffffffffffe")
|
SYSTEM_ADDRESS* = hexToByteArray[20]("0xfffffffffffffffffffffffffffffffffffffffe")
|
||||||
|
|
||||||
RIPEMD_ADDR* = block:
|
RIPEMD_ADDR* = block:
|
||||||
proc initAddress(x: int): EthAddress {.compileTime.} =
|
proc initAddress(x: int): EthAddress {.compileTime.} =
|
||||||
|
|
|
@ -11,10 +11,11 @@ import
|
||||||
|
|
||||||
type
|
type
|
||||||
CasperRef* = ref object
|
CasperRef* = ref object
|
||||||
feeRecipient : EthAddress
|
feeRecipient: EthAddress
|
||||||
timestamp : EthTime
|
timestamp : EthTime
|
||||||
prevRandao : Hash256
|
prevRandao : Hash256
|
||||||
parentBeaconBlockRoot: Hash256
|
withdrawals : seq[Withdrawal] ## EIP-4895
|
||||||
|
beaconRoot : Hash256 ## EIP-4788
|
||||||
|
|
||||||
proc prepare*(ctx: CasperRef, header: var BlockHeader) =
|
proc prepare*(ctx: CasperRef, header: var BlockHeader) =
|
||||||
header.coinbase = ctx.feeRecipient
|
header.coinbase = ctx.feeRecipient
|
||||||
|
@ -41,8 +42,11 @@ func timestamp*(ctx: CasperRef): EthTime =
|
||||||
func prevRandao*(ctx: CasperRef): Hash256 =
|
func prevRandao*(ctx: CasperRef): Hash256 =
|
||||||
ctx.prevRandao
|
ctx.prevRandao
|
||||||
|
|
||||||
|
proc withdrawals*(ctx: CasperRef): seq[Withdrawal] =
|
||||||
|
ctx.withdrawals
|
||||||
|
|
||||||
func parentBeaconBlockRoot*(ctx: CasperRef): Hash256 =
|
func parentBeaconBlockRoot*(ctx: CasperRef): Hash256 =
|
||||||
ctx.parentBeaconBlockRoot
|
ctx.beaconRoot
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Setters
|
# Setters
|
||||||
|
@ -57,5 +61,8 @@ proc `timestamp=`*(ctx: CasperRef, val: EthTime) =
|
||||||
proc `prevRandao=`*(ctx: CasperRef, val: Hash256) =
|
proc `prevRandao=`*(ctx: CasperRef, val: Hash256) =
|
||||||
ctx.prevRandao = val
|
ctx.prevRandao = val
|
||||||
|
|
||||||
|
proc `withdrawals=`*(ctx: CasperRef, val: sink seq[Withdrawal]) =
|
||||||
|
ctx.withdrawals = system.move(val)
|
||||||
|
|
||||||
proc `parentBeaconBlockRoot=`*(ctx: CasperRef, val: Hash256) =
|
proc `parentBeaconBlockRoot=`*(ctx: CasperRef, val: Hash256) =
|
||||||
ctx.parentBeaconBlockRoot = val
|
ctx.beaconRoot = val
|
||||||
|
|
|
@ -26,12 +26,12 @@ type
|
||||||
|
|
||||||
const
|
const
|
||||||
BLS_MODULUS_STR = "52435875175126190479447740508185965837690552500527637822603658699938581184513"
|
BLS_MODULUS_STR = "52435875175126190479447740508185965837690552500527637822603658699938581184513"
|
||||||
BLS_MODULUS = parse(BLS_MODULUS_STR, UInt256, 10)
|
BLS_MODULUS* = parse(BLS_MODULUS_STR, UInt256, 10).toBytesBE
|
||||||
PrecompileInputLength = 192
|
PrecompileInputLength = 192
|
||||||
|
|
||||||
proc pointEvaluationResult(): Bytes64 {.compileTime.} =
|
proc pointEvaluationResult(): Bytes64 {.compileTime.} =
|
||||||
result[0..<32] = FIELD_ELEMENTS_PER_BLOB.u256.toBytesBE[0..^1]
|
result[0..<32] = FIELD_ELEMENTS_PER_BLOB.u256.toBytesBE[0..^1]
|
||||||
result[32..^1] = BLS_MODULUS.toBytesBE[0..^1]
|
result[32..^1] = BLS_MODULUS[0..^1]
|
||||||
|
|
||||||
const
|
const
|
||||||
PointEvaluationResult* = pointEvaluationResult()
|
PointEvaluationResult* = pointEvaluationResult()
|
||||||
|
@ -39,7 +39,7 @@ const
|
||||||
|
|
||||||
|
|
||||||
# kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
|
# kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
|
||||||
proc kzgToVersionedHash(kzg: kzg.KZGCommitment): VersionedHash =
|
proc kzgToVersionedHash*(kzg: kzg.KZGCommitment): VersionedHash =
|
||||||
result = sha256.digest(kzg)
|
result = sha256.digest(kzg)
|
||||||
result.data[0] = VERSIONED_HASH_VERSION_KZG
|
result.data[0] = VERSIONED_HASH_VERSION_KZG
|
||||||
|
|
||||||
|
|
|
@ -141,10 +141,10 @@ proc processBeaconBlockRoot*(vmState: BaseVMState, beaconRoot: Hash256):
|
||||||
statedb = vmState.stateDB
|
statedb = vmState.stateDB
|
||||||
call = CallParams(
|
call = CallParams(
|
||||||
vmState : vmState,
|
vmState : vmState,
|
||||||
sender : SystemAddress,
|
sender : SYSTEM_ADDRESS,
|
||||||
gasLimit : 30_000_000.GasInt,
|
gasLimit : 30_000_000.GasInt,
|
||||||
gasPrice : 0.GasInt,
|
gasPrice : 0.GasInt,
|
||||||
to : BeaconRootsStorageAddress,
|
to : BEACON_ROOTS_ADDRESS,
|
||||||
input : @(beaconRoot.data),
|
input : @(beaconRoot.data),
|
||||||
|
|
||||||
# It's a systemCall, no need for other knicks knacks
|
# It's a systemCall, no need for other knicks knacks
|
||||||
|
|
|
@ -436,7 +436,8 @@ import
|
||||||
chronicles,
|
chronicles,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
stew/[keyed_queue, results],
|
stew/[keyed_queue, results],
|
||||||
../common/common
|
../common/common,
|
||||||
|
./casper
|
||||||
|
|
||||||
export
|
export
|
||||||
TxItemRef,
|
TxItemRef,
|
||||||
|
@ -627,7 +628,7 @@ proc ethBlock*(xp: TxPoolRef, someBaseFee: bool = false): EthBlock
|
||||||
|
|
||||||
let com = xp.chain.com
|
let com = xp.chain.com
|
||||||
if com.forkGTE(Shanghai):
|
if com.forkGTE(Shanghai):
|
||||||
result.withdrawals = some(xp.chain.withdrawals)
|
result.withdrawals = some(com.pos.withdrawals)
|
||||||
|
|
||||||
if someBaseFee:
|
if someBaseFee:
|
||||||
# make sure baseFee always has something
|
# make sure baseFee always has something
|
||||||
|
@ -778,9 +779,6 @@ proc `minTipPrice=`*(xp: TxPoolRef; val: GasPrice) =
|
||||||
xp.pMinTipPrice = val
|
xp.pMinTipPrice = val
|
||||||
xp.pDirtyBuckets = true
|
xp.pDirtyBuckets = true
|
||||||
|
|
||||||
proc `withdrawals=`*(xp: TxPoolRef, val: sink seq[Withdrawal]) =
|
|
||||||
xp.chain.withdrawals = system.move(val)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions, per-tx-item operations
|
# Public functions, per-tx-item operations
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -70,7 +70,6 @@ type
|
||||||
limits: TxChainGasLimits ## Gas limits for packer and next header
|
limits: TxChainGasLimits ## Gas limits for packer and next header
|
||||||
txEnv: TxChainPackerEnv ## Assorted parameters, tx packer environment
|
txEnv: TxChainPackerEnv ## Assorted parameters, tx packer environment
|
||||||
prepHeader: BlockHeader ## Prepared Header from Consensus Engine
|
prepHeader: BlockHeader ## Prepared Header from Consensus Engine
|
||||||
withdrawals: seq[Withdrawal] ## EIP-4895
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Private functions
|
# Private functions
|
||||||
|
@ -232,7 +231,7 @@ proc getHeader*(dh: TxChainRef): BlockHeader
|
||||||
excessBlobGas: dh.txEnv.excessBlobGas)
|
excessBlobGas: dh.txEnv.excessBlobGas)
|
||||||
|
|
||||||
if dh.com.forkGTE(Shanghai):
|
if dh.com.forkGTE(Shanghai):
|
||||||
result.withdrawalsRoot = some(calcWithdrawalsRoot(dh.withdrawals))
|
result.withdrawalsRoot = some(calcWithdrawalsRoot(dh.com.pos.withdrawals))
|
||||||
|
|
||||||
if dh.com.forkGTE(Cancun):
|
if dh.com.forkGTE(Cancun):
|
||||||
result.parentBeaconBlockRoot = some(dh.com.pos.parentBeaconBlockRoot)
|
result.parentBeaconBlockRoot = some(dh.com.pos.parentBeaconBlockRoot)
|
||||||
|
@ -321,10 +320,6 @@ proc vmState*(dh: TxChainRef): BaseVMState =
|
||||||
## Getter, `BaseVmState` descriptor based on the current insertion point.
|
## Getter, `BaseVmState` descriptor based on the current insertion point.
|
||||||
dh.txEnv.vmState
|
dh.txEnv.vmState
|
||||||
|
|
||||||
proc withdrawals*(dh: TxChainRef): seq[Withdrawal] =
|
|
||||||
## Getter, `BaseVmState` descriptor based on the current insertion point.
|
|
||||||
dh.withdrawals
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions, setters
|
# Public functions, setters
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -387,9 +382,6 @@ proc `txRoot=`*(dh: TxChainRef; val: Hash256) =
|
||||||
## Setter
|
## Setter
|
||||||
dh.txEnv.txRoot = val
|
dh.txEnv.txRoot = val
|
||||||
|
|
||||||
proc `withdrawals=`*(dh: TxChainRef, val: sink seq[Withdrawal]) =
|
|
||||||
dh.withdrawals = system.move(val)
|
|
||||||
|
|
||||||
proc `excessBlobGas=`*(dh: TxChainRef; val: Option[uint64]) =
|
proc `excessBlobGas=`*(dh: TxChainRef; val: Option[uint64]) =
|
||||||
## Setter
|
## Setter
|
||||||
dh.txEnv.excessBlobGas = val
|
dh.txEnv.excessBlobGas = val
|
||||||
|
|
|
@ -21,7 +21,7 @@ import
|
||||||
../../../db/[accounts_cache, core_db],
|
../../../db/[accounts_cache, core_db],
|
||||||
../../../common/common,
|
../../../common/common,
|
||||||
../../../utils/utils,
|
../../../utils/utils,
|
||||||
"../.."/[dao, executor, validate, eip4844],
|
"../.."/[dao, executor, validate, eip4844, casper],
|
||||||
../../../transaction/call_evm,
|
../../../transaction/call_evm,
|
||||||
../../../transaction,
|
../../../transaction,
|
||||||
../../../vm_state,
|
../../../vm_state,
|
||||||
|
@ -164,6 +164,11 @@ proc vmExecInit(xp: TxPoolRef): TxPackerStateRef
|
||||||
xp.chain.vmState.mutateStateDB:
|
xp.chain.vmState.mutateStateDB:
|
||||||
db.applyDAOHardFork()
|
db.applyDAOHardFork()
|
||||||
|
|
||||||
|
# EIP-4788
|
||||||
|
if xp.chain.nextFork >= FkCancun:
|
||||||
|
let beaconRoot = xp.chain.com.pos.parentBeaconBlockRoot
|
||||||
|
discard xp.chain.vmState.processBeaconBlockRoot(beaconRoot)
|
||||||
|
|
||||||
TxPackerStateRef( # return value
|
TxPackerStateRef( # return value
|
||||||
xp: xp,
|
xp: xp,
|
||||||
tr: newCoreDbRef(LegacyDbMemory).mptPrune,
|
tr: newCoreDbRef(LegacyDbMemory).mptPrune,
|
||||||
|
@ -225,7 +230,7 @@ proc vmExecCommit(pst: TxPackerStateRef)
|
||||||
|
|
||||||
# EIP-4895
|
# EIP-4895
|
||||||
if xp.chain.nextFork >= FkShanghai:
|
if xp.chain.nextFork >= FkShanghai:
|
||||||
for withdrawal in xp.chain.withdrawals:
|
for withdrawal in xp.chain.com.pos.withdrawals:
|
||||||
vmState.stateDB.addBalance(withdrawal.address, withdrawal.weiAmount)
|
vmState.stateDB.addBalance(withdrawal.address, withdrawal.weiAmount)
|
||||||
|
|
||||||
# EIP-3675: no reward for miner in POA/POS
|
# EIP-3675: no reward for miner in POA/POS
|
||||||
|
|
|
@ -455,7 +455,7 @@ proc subBalance*(ac: AccountsCache, address: EthAddress, delta: UInt256) {.inlin
|
||||||
# This zero delta early exit is important as shown in EIP-4788.
|
# This zero delta early exit is important as shown in EIP-4788.
|
||||||
# If the account is created, it will change the state.
|
# If the account is created, it will change the state.
|
||||||
# But early exit will prevent the account creation.
|
# But early exit will prevent the account creation.
|
||||||
# In this case, the SystemAddress
|
# In this case, the SYSTEM_ADDRESS
|
||||||
return
|
return
|
||||||
ac.setBalance(address, ac.getBalance(address) - delta)
|
ac.setBalance(address, ac.getBalance(address) - delta)
|
||||||
|
|
||||||
|
|
|
@ -455,7 +455,7 @@ proc subBalance*(ac: AccountsCache, address: EthAddress, delta: UInt256) {.inlin
|
||||||
# This zero delta early exit is important as shown in EIP-4788.
|
# This zero delta early exit is important as shown in EIP-4788.
|
||||||
# If the account is created, it will change the state.
|
# If the account is created, it will change the state.
|
||||||
# But early exit will prevent the account creation.
|
# But early exit will prevent the account creation.
|
||||||
# In this case, the SystemAddress
|
# In this case, the SYSTEM_ADDRESS
|
||||||
return
|
return
|
||||||
ac.setBalance(address, ac.getBalance(address) - delta)
|
ac.setBalance(address, ac.getBalance(address) - delta)
|
||||||
|
|
||||||
|
|
|
@ -442,7 +442,7 @@ proc subBalance*(ac: AccountsLedgerRef, address: EthAddress, delta: UInt256) =
|
||||||
# This zero delta early exit is important as shown in EIP-4788.
|
# This zero delta early exit is important as shown in EIP-4788.
|
||||||
# If the account is created, it will change the state.
|
# If the account is created, it will change the state.
|
||||||
# But early exit will prevent the account creation.
|
# But early exit will prevent the account creation.
|
||||||
# In this case, the SystemAddress
|
# In this case, the SYSTEM_ADDRESS
|
||||||
return
|
return
|
||||||
ac.setBalance(address, ac.getBalance(address) - delta)
|
ac.setBalance(address, ac.getBalance(address) - delta)
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,8 @@ proc debug*(h: BlockHeader): string =
|
||||||
result.add "blobGasUsed : " & $h.blobGasUsed.get() & "\n"
|
result.add "blobGasUsed : " & $h.blobGasUsed.get() & "\n"
|
||||||
if h.excessBlobGas.isSome:
|
if h.excessBlobGas.isSome:
|
||||||
result.add "excessBlobGas : " & $h.excessBlobGas.get() & "\n"
|
result.add "excessBlobGas : " & $h.excessBlobGas.get() & "\n"
|
||||||
|
if h.parentBeaconBlockRoot.isSome:
|
||||||
|
result.add "beaconRoot : " & $h.parentBeaconBlockRoot.get() & "\n"
|
||||||
result.add "blockHash : " & $blockHash(h) & "\n"
|
result.add "blockHash : " & $blockHash(h) & "\n"
|
||||||
|
|
||||||
proc dumpAccount(stateDB: AccountsCache, address: EthAddress): JsonNode =
|
proc dumpAccount(stateDB: AccountsCache, address: EthAddress): JsonNode =
|
||||||
|
|
Loading…
Reference in New Issue