fill in transactions root and KZG commitments from deneb.BlindedBeaconBlock in state transition (#5553)

This commit is contained in:
tersec 2023-11-02 04:56:04 +01:00 committed by GitHub
parent 657de2721a
commit ab89e96265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 10 deletions

View File

@ -403,7 +403,8 @@ proc makeBeaconBlock*(
# removed if we don't use invalid signatures there
verificationFlags: UpdateFlags,
transactions_root: Opt[Eth2Digest],
execution_payload_root: Opt[Eth2Digest]):
execution_payload_root: Opt[Eth2Digest],
kzg_commitments: Opt[KzgCommitments]):
Result[ForkedBeaconBlock, cstring] =
## Create a block for the given state. The latest block applied to it will
## be used for the parent_root value, and the slot will be take from
@ -428,7 +429,7 @@ proc makeBeaconBlock*(
rollback(state)
return err(res.error())
# Override for MEV
# Override for Builder API
if transactions_root.isSome and execution_payload_root.isSome:
withState(state):
when consensusFork < ConsensusFork.Capella:
@ -455,6 +456,9 @@ proc makeBeaconBlock*(
execution_payload_root.get,
hash_tree_root(validator_changes.bls_to_execution_changes)])
elif consensusFork == ConsensusFork.Deneb:
forkyState.data.latest_execution_payload_header.transactions_root =
transactions_root.get
when executionPayload is deneb.ExecutionPayloadForSigning:
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/deneb/beacon-chain.md#beaconblockbody
forkyState.data.latest_block_header.body_root = hash_tree_root(
@ -469,7 +473,7 @@ proc makeBeaconBlock*(
hash_tree_root(sync_aggregate),
execution_payload_root.get,
hash_tree_root(validator_changes.bls_to_execution_changes),
hash_tree_root(executionPayload.kzgs)
hash_tree_root(kzg_commitments.get)
])
else:
raiseAssert "Attempt to use non-Deneb payload with post-Deneb state"
@ -517,7 +521,8 @@ proc makeBeaconBlock*(
attestations, deposits, validator_changes, sync_aggregate,
executionPayload, rollback, cache,
verificationFlags = {}, transactions_root = Opt.none Eth2Digest,
execution_payload_root = Opt.none Eth2Digest)
execution_payload_root = Opt.none Eth2Digest,
kzg_commitments = Opt.none KzgCommitments)
proc makeBeaconBlock*(
cfg: RuntimeConfig, state: var ForkedHashedBeaconState,
@ -536,4 +541,5 @@ proc makeBeaconBlock*(
executionPayload, rollback, cache,
verificationFlags = verificationFlags,
transactions_root = Opt.none Eth2Digest,
execution_payload_root = Opt.none Eth2Digest)
execution_payload_root = Opt.none Eth2Digest,
kzg_commitments = Opt.none KzgCommitments)

View File

@ -440,7 +440,8 @@ proc makeBeaconBlockForHeadAndSlot*(
execution_payload: Opt[PayloadType],
transactions_root: Opt[Eth2Digest],
execution_payload_root: Opt[Eth2Digest],
withdrawals_root: Opt[Eth2Digest]):
withdrawals_root: Opt[Eth2Digest],
kzg_commitments: Opt[KzgCommitments]):
Future[ForkedBlockResult] {.async.} =
# Advance state to the slot that we're proposing for
var cache = StateCache()
@ -528,7 +529,8 @@ proc makeBeaconBlockForHeadAndSlot*(
cache,
verificationFlags = {},
transactions_root = transactions_root,
execution_payload_root = execution_payload_root).mapErr do (error: cstring) -> string:
execution_payload_root = execution_payload_root,
kzg_commitments = kzg_commitments).mapErr do (error: cstring) -> string:
# This is almost certainly a bug, but it's complex enough that there's a
# small risk it might happen even when most proposals succeed - thus we
# log instead of asserting
@ -560,7 +562,8 @@ proc makeBeaconBlockForHeadAndSlot*(
execution_payload = Opt.none(PayloadType),
transactions_root = Opt.none(Eth2Digest),
execution_payload_root = Opt.none(Eth2Digest),
withdrawals_root = Opt.none(Eth2Digest))
withdrawals_root = Opt.none(Eth2Digest),
kzg_commitments = Opt.none(KzgCommitments))
proc getBlindedExecutionPayload[
EPH: capella.ExecutionPayloadHeader |
@ -846,6 +849,7 @@ proc getBlindedBlockParts[
template actualEPH: untyped = executionPayloadHeader.get.blindedBlckPart
let withdrawals_root =
Opt.some executionPayloadHeader.get.blindedBlckPart.withdrawals_root
const kzg_commitments = Opt.none KzgCommitments
var shimExecutionPayload: PayloadType
copyFields(
@ -855,7 +859,10 @@ proc getBlindedBlockParts[
type PayloadType = deneb.ExecutionPayloadForSigning
template actualEPH: untyped =
executionPayloadHeader.get.blindedBlckPart.execution_payload_header
let withdrawals_root = Opt.some actualEPH.withdrawals_root
let
withdrawals_root = Opt.some actualEPH.withdrawals_root
kzg_commitments = Opt.some(
executionPayloadHeader.get.blindedBlckPart.blinded_blobs_bundle.commitments)
var shimExecutionPayload: PayloadType
type DenebEPH =
@ -870,7 +877,8 @@ proc getBlindedBlockParts[
execution_payload = Opt.some shimExecutionPayload,
transactions_root = Opt.some actualEPH.transactions_root,
execution_payload_root = Opt.some hash_tree_root(actualEPH),
withdrawals_root = withdrawals_root)
withdrawals_root = withdrawals_root,
kzg_commitments = kzg_commitments)
if newBlock.isErr():
# Haven't committed to the MEV block, so allow EL fallback.