rm Capella builder API bid types and blinded block construction (#6002)

This commit is contained in:
tersec 2024-03-01 00:02:13 +00:00 committed by GitHub
parent f5e9d3ffe4
commit f076502e25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 19 additions and 90 deletions

View File

@ -219,9 +219,7 @@ RestJson.useDefaultSerializationFor(
capella.SignedBeaconBlock,
capella_mev.BlindedBeaconBlock,
capella_mev.BlindedBeaconBlockBody,
capella_mev.BuilderBid,
capella_mev.SignedBlindedBeaconBlock,
capella_mev.SignedBuilderBid,
deneb.BeaconBlock,
deneb.BeaconBlockBody,
deneb.BeaconState,

View File

@ -17,12 +17,12 @@ import
block_id, eth2_merkleization, eth2_ssz_serialization,
forks_light_client, presets],
./datatypes/[phase0, altair, bellatrix, capella, deneb, electra],
./mev/bellatrix_mev, ./mev/capella_mev, ./mev/deneb_mev
./mev/[bellatrix_mev, capella_mev, deneb_mev]
export
extras, block_id, phase0, altair, bellatrix, capella, deneb, electra,
eth2_merkleization, eth2_ssz_serialization, forks_light_client,
presets, capella_mev, deneb_mev
presets, deneb_mev
# This file contains helpers for dealing with forks - we have two ways we can
# deal with forks:

View File

@ -13,19 +13,6 @@ from stew/byteutils import to0xHex
from ../eth2_merkleization import hash_tree_root
type
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/builder.md#builderbid
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/capella/builder.md#executionpayloadheader
BuilderBid* = object
header*: capella.ExecutionPayloadHeader # [Modified in Capella]
value*: UInt256
pubkey*: ValidatorPubKey
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/builder.md#signedbuilderbid
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/capella/builder.md#executionpayloadheader
SignedBuilderBid* = object
message*: BuilderBid # [Modified in Capella]
signature*: ValidatorSig
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/capella/builder.md#blindedbeaconblockbody
BlindedBeaconBlockBody* = object
randao_reveal*: ValidatorSig
@ -52,30 +39,12 @@ type
state_root*: Eth2Digest
body*: BlindedBeaconBlockBody # [Modified in Capella]
MaybeBlindedBeaconBlock* = object
case isBlinded*: bool
of false:
data*: capella.BeaconBlock
of true:
blindedData*: BlindedBeaconBlock
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/builder.md#signedblindedbeaconblock
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/capella/builder.md#blindedbeaconblockbody
SignedBlindedBeaconBlock* = object
message*: BlindedBeaconBlock
signature*: ValidatorSig
const
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/builder.md#domain-types
DOMAIN_APPLICATION_BUILDER* = DomainType([byte 0x00, 0x00, 0x00, 0x01])
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/validator.md#constants
EPOCHS_PER_VALIDATOR_REGISTRATION_SUBMISSION* = 1
# Spec is 1 second, but mev-boost indirection can induce delay when the relay
# itself has already consumed the entire second.
BUILDER_PROPOSAL_DELAY_TOLERANCE* = 1500.milliseconds
func shortLog*(v: BlindedBeaconBlock): auto =
(
slot: shortLog(v.slot),

View File

@ -89,6 +89,17 @@ type
execution_payload_header*: deneb.ExecutionPayloadHeader
blob_kzg_commitments*: KzgCommitments # [New in Deneb]
const
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/builder.md#domain-types
DOMAIN_APPLICATION_BUILDER* = DomainType([byte 0x00, 0x00, 0x00, 0x01])
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/validator.md#constants
EPOCHS_PER_VALIDATOR_REGISTRATION_SUBMISSION* = 1
# Spec is 1 second, but mev-boost indirection can induce delay when the relay
# itself has already consumed the entire second.
BUILDER_PROPOSAL_DELAY_TOLERANCE* = 1500.milliseconds
func shortLog*(v: BlindedBeaconBlock): auto =
(
slot: shortLog(v.slot),

View File

@ -79,9 +79,7 @@ proc verify_epoch_signature*(
func compute_block_signing_root*(
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
blck: Eth2Digest | SomeForkyBeaconBlock | BeaconBlockHeader |
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/builder.md#signing
capella_mev.BlindedBeaconBlock): Eth2Digest =
blck: Eth2Digest | SomeForkyBeaconBlock | BeaconBlockHeader): Eth2Digest =
let
epoch = epoch(slot)
domain = get_domain(
@ -373,8 +371,7 @@ proc verify_contribution_and_proof_signature*(
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/builder.md#signing
func compute_builder_signing_root(
fork: Fork,
msg: capella_mev.BuilderBid | deneb_mev.BuilderBid |
ValidatorRegistrationV1): Eth2Digest =
msg: deneb_mev.BuilderBid | ValidatorRegistrationV1): Eth2Digest =
# Uses genesis fork version regardless
doAssert fork.current_version == fork.previous_version
@ -389,7 +386,7 @@ proc get_builder_signature*(
blsSign(privkey, signing_root.data)
proc verify_builder_signature*(
fork: Fork, msg: capella_mev.BuilderBid | deneb_mev.BuilderBid,
fork: Fork, msg: deneb_mev.BuilderBid,
pubkey: ValidatorPubKey | CookedPubKey, signature: SomeSig): bool =
let signing_root = compute_builder_signing_root(fork, msg)
blsVerify(pubkey, signing_root.data, signature)

View File

@ -576,11 +576,7 @@ proc getBlindedExecutionPayload[
blindedHeader.data.message.pubkey, blindedHeader.data.signature):
return err "getBlindedExecutionPayload: signature verification failed"
when EPH is capella.ExecutionPayloadHeader:
return ok((
blindedBlckPart: blindedHeader.data.message.header,
blockValue: blindedHeader.data.message.value))
elif EPH is deneb_mev.BlindedExecutionPayloadAndBlobsBundle:
when EPH is deneb_mev.BlindedExecutionPayloadAndBlobsBundle:
template builderBid: untyped = blindedHeader.data.message
return ok((
blindedBlckPart: EPH(
@ -593,24 +589,6 @@ proc getBlindedExecutionPayload[
from ./message_router_mev import
copyFields, getFieldNames, unblindAndRouteBlockMEV
func constructSignableBlindedBlock[T: capella_mev.SignedBlindedBeaconBlock](
blck: capella.BeaconBlock,
executionPayloadHeader: capella.ExecutionPayloadHeader): T =
# Leaves signature field default, to be filled in by caller
const
blckFields = getFieldNames(typeof(blck))
blckBodyFields = getFieldNames(typeof(blck.body))
var blindedBlock: T
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/validator.md#block-proposal
copyFields(blindedBlock.message, blck, blckFields)
copyFields(blindedBlock.message.body, blck.body, blckBodyFields)
assign(
blindedBlock.message.body.execution_payload_header, executionPayloadHeader)
blindedBlock
proc constructSignableBlindedBlock[T: deneb_mev.SignedBlindedBeaconBlock](
blck: deneb.BeaconBlock,
blindedBundle: deneb_mev.BlindedExecutionPayloadAndBlobsBundle): T =
@ -633,25 +611,6 @@ proc constructSignableBlindedBlock[T: deneb_mev.SignedBlindedBeaconBlock](
blindedBlock
func constructPlainBlindedBlock[T: capella_mev.BlindedBeaconBlock](
blck: ForkyBeaconBlock,
executionPayloadHeader: capella.ExecutionPayloadHeader): T =
# https://github.com/nim-lang/Nim/issues/23020 workaround
static: doAssert T is capella_mev.BlindedBeaconBlock
const
blckFields = getFieldNames(typeof(blck))
blckBodyFields = getFieldNames(typeof(blck.body))
var blindedBlock: T
# https://github.com/ethereum/builder-specs/blob/v0.4.0/specs/bellatrix/validator.md#block-proposal
copyFields(blindedBlock, blck, blckFields)
copyFields(blindedBlock.body, blck.body, blckBodyFields)
assign(blindedBlock.body.execution_payload_header, executionPayloadHeader)
blindedBlock
func constructPlainBlindedBlock[T: deneb_mev.BlindedBeaconBlock](
blck: ForkyBeaconBlock,
blindedBundle: deneb_mev.BlindedExecutionPayloadAndBlobsBundle): T =
@ -676,10 +635,7 @@ func constructPlainBlindedBlock[T: deneb_mev.BlindedBeaconBlock](
blindedBlock
proc blindedBlockCheckSlashingAndSign[
T:
capella_mev.SignedBlindedBeaconBlock |
deneb_mev.SignedBlindedBeaconBlock](
proc blindedBlockCheckSlashingAndSign[T: deneb_mev.SignedBlindedBeaconBlock](
node: BeaconNode, slot: Slot, validator: AttachedValidator,
validator_index: ValidatorIndex, nonsignedBlindedBlock: T):
Future[Result[T, string]] {.async: (raises: [CancelledError]).} =
@ -711,9 +667,7 @@ proc blindedBlockCheckSlashingAndSign[
return ok blindedBlock
proc getUnsignedBlindedBeaconBlock[
T: capella_mev.SignedBlindedBeaconBlock |
deneb_mev.SignedBlindedBeaconBlock](
proc getUnsignedBlindedBeaconBlock[T: deneb_mev.SignedBlindedBeaconBlock](
node: BeaconNode, slot: Slot,
validator_index: ValidatorIndex, forkedBlock: ForkedBeaconBlock,
executionPayloadHeader: capella.ExecutionPayloadHeader |