From f076502e2548a92c2a41cdf861433825c405e944 Mon Sep 17 00:00:00 2001 From: tersec Date: Fri, 1 Mar 2024 00:02:13 +0000 Subject: [PATCH] rm Capella builder API bid types and blinded block construction (#6002) --- .../eth2_apis/eth2_rest_serialization.nim | 2 - beacon_chain/spec/forks.nim | 4 +- beacon_chain/spec/mev/capella_mev.nim | 31 ----------- beacon_chain/spec/mev/deneb_mev.nim | 11 ++++ beacon_chain/spec/signatures.nim | 9 ++-- beacon_chain/validators/beacon_validators.nim | 52 ++----------------- 6 files changed, 19 insertions(+), 90 deletions(-) diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index f7cc3bdbf..8e2c14f6c 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -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, diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index 94877992d..193a6013c 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -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: diff --git a/beacon_chain/spec/mev/capella_mev.nim b/beacon_chain/spec/mev/capella_mev.nim index dd26c8167..7effc7ec9 100644 --- a/beacon_chain/spec/mev/capella_mev.nim +++ b/beacon_chain/spec/mev/capella_mev.nim @@ -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), diff --git a/beacon_chain/spec/mev/deneb_mev.nim b/beacon_chain/spec/mev/deneb_mev.nim index edf9b5573..ca18920c2 100644 --- a/beacon_chain/spec/mev/deneb_mev.nim +++ b/beacon_chain/spec/mev/deneb_mev.nim @@ -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), diff --git a/beacon_chain/spec/signatures.nim b/beacon_chain/spec/signatures.nim index 946966fab..2167fc60b 100644 --- a/beacon_chain/spec/signatures.nim +++ b/beacon_chain/spec/signatures.nim @@ -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) diff --git a/beacon_chain/validators/beacon_validators.nim b/beacon_chain/validators/beacon_validators.nim index 2912e3ca5..5775063ed 100644 --- a/beacon_chain/validators/beacon_validators.nim +++ b/beacon_chain/validators/beacon_validators.nim @@ -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 |