Skip to content

Commit

Permalink
construct Deneb blinded blobs from builder API getHeader (#5513)
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec authored Oct 19, 2023
1 parent 726b8fb commit 769316d
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions beacon_chain/validators/beacon_validators.nim
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,17 @@ proc getBlindedExecutionPayload[
blindedBlckPart: blindedHeader.data.data.message.header,
blockValue: blindedHeader.data.data.message.value))
elif EPH is deneb_mev.ExecutionPayloadHeaderAndBlindedBlobsBundle:
template bbb: untyped = blindedHeader.data.data.message.blinded_blobs_bundle

if bbb.proofs.len != bbb.blob_roots.len or
bbb.proofs.len != bbb.commitments.len:
return err("getBlindedExecutionPayload: mismatched blob_roots, commitments, and proofs lengths: " &
$bbb.blob_roots.len & ", " & $bbb.commitments.len & ", and" & $bbb.proofs.len)

return ok((
blindedBlckPart: ExecutionPayloadHeaderAndBlindedBlobsBundle(
execution_payload_header: blindedHeader.data.data.message.header,
blinded_blobs_bundle:
blindedHeader.data.data.message.blinded_blobs_bundle),
blinded_blobs_bundle: bbb),
blockValue: blindedHeader.data.data.message.value))
else:
static: doAssert false
Expand All @@ -628,10 +634,12 @@ func constructSignableBlindedBlock[T: capella_mev.SignedBlindedBeaconBlock](

blindedBlock

func constructSignableBlindedBlock[T: deneb_mev.SignedBlindedBeaconBlockContents](
proc constructSignableBlindedBlock[T: deneb_mev.SignedBlindedBeaconBlockContents](
blck: deneb.BeaconBlock,
executionPayloadHeader: deneb_mev.ExecutionPayloadHeaderAndBlindedBlobsBundle):
executionPayloadHeaderContents:
deneb_mev.ExecutionPayloadHeaderAndBlindedBlobsBundle):
T =
# Leaves signature field default, to be filled in by caller
const
blckFields = getFieldNames(typeof(blck))
blckBodyFields = getFieldNames(typeof(blck.body))
Expand All @@ -644,9 +652,30 @@ func constructSignableBlindedBlock[T: deneb_mev.SignedBlindedBeaconBlockContents
copyFields(blindedBlock.message.body, blck.body, blckBodyFields)
assign(
blindedBlock.message.body.execution_payload_header,
executionPayloadHeader.execution_payload_header)

debugRaiseAssert $denebImplementationMissing & ": handle blinded blobs"
executionPayloadHeaderContents.execution_payload_header)

template bbb: untyped = executionPayloadHeaderContents.blinded_blobs_bundle

# Checked in getBlindedExecutionPayload, so it's a logic error here
doAssert bbb.proofs.len == bbb.blob_roots.len
doAssert bbb.proofs.len == bbb.commitments.len

if blindedBlockContents.signed_blinded_blob_sidecars.setLen(bbb.proofs.len):
for i in 0 ..< blindedBlockContents.signed_blinded_blob_sidecars.lenu64:
assign(
blindedBlockContents.signed_blinded_blob_sidecars[i],
deneb_mev.SignedBlindedBlobSidecar(message: deneb_mev.BlindedBlobSidecar(
block_root: hash_tree_root(blck),
index: i,
slot: distinctBase(blck.slot),
block_parent_root: blck.parent_root,
proposer_index: blck.proposer_index,
blob_root: bbb.blob_roots[i],
kzg_commitment: bbb.commitments[i],
kzg_proof: bbb.proofs[i])))
else:
debug "constructSignableBlindedBlock: unable to set blinded blob sidecar length",
blobs_len = bbb.proofs.len

blindedBlockContents

Expand Down Expand Up @@ -736,8 +765,6 @@ proc blindedBlockCheckSlashingAndSign[
return err("Unable to sign block: " & res.error())
res.get()

debugRaiseAssert $denebImplementationMissing & ": sign the blinded blobs"

return ok blindedBlockContents

proc getUnsignedBlindedBeaconBlock[
Expand Down Expand Up @@ -838,8 +865,6 @@ proc getBlindedBlockParts[

let forkedBlck = newBlock.get()

debugRaiseAssert $denebImplementationMissing & ": handle blobs"

return ok(
(executionPayloadHeader.get.blindedBlckPart,
executionPayloadHeader.get.blockValue,
Expand Down

0 comments on commit 769316d

Please sign in to comment.