mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Kiln mev boost (#3062)
## Issue Addressed MEV boost compatibility ## Proposed Changes See #2987 ## Additional Info This is blocked on the stabilization of a couple specs, [here](https://github.com/ethereum/beacon-APIs/pull/194) and [here](https://github.com/flashbots/mev-boost/pull/20). Additional TODO's and outstanding questions - [ ] MEV boost JWT Auth - [ ] Will `builder_proposeBlindedBlock` return the revealed payload for the BN to propogate - [ ] Should we remove `private-tx-proposals` flag and communicate BN <> VC with blinded blocks by default once these endpoints enter the beacon-API's repo? This simplifies merge transition logic. Co-authored-by: realbigsean <seananderson33@gmail.com> Co-authored-by: realbigsean <sean@sigmaprime.io>
This commit is contained in:
@@ -87,9 +87,9 @@ pub enum VerifyBlockRoot {
|
||||
/// re-calculating the root when it is already known. Note `block_root` should be equal to the
|
||||
/// tree hash root of the block, NOT the signing root of the block. This function takes
|
||||
/// care of mixing in the domain.
|
||||
pub fn per_block_processing<T: EthSpec>(
|
||||
pub fn per_block_processing<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &mut BeaconState<T>,
|
||||
signed_block: &SignedBeaconBlock<T>,
|
||||
signed_block: &SignedBeaconBlock<T, Payload>,
|
||||
block_root: Option<Hash256>,
|
||||
block_signature_strategy: BlockSignatureStrategy,
|
||||
verify_block_root: VerifyBlockRoot,
|
||||
@@ -129,7 +129,12 @@ pub fn per_block_processing<T: EthSpec>(
|
||||
BlockSignatureStrategy::VerifyRandao => VerifySignatures::False,
|
||||
};
|
||||
|
||||
let proposer_index = process_block_header(state, block, verify_block_root, spec)?;
|
||||
let proposer_index = process_block_header(
|
||||
state,
|
||||
block.temporary_block_header(),
|
||||
verify_block_root,
|
||||
spec,
|
||||
)?;
|
||||
|
||||
if verify_signatures.is_true() {
|
||||
verify_block_signature(state, signed_block, block_root, spec)?;
|
||||
@@ -172,28 +177,28 @@ pub fn per_block_processing<T: EthSpec>(
|
||||
/// Processes the block header, returning the proposer index.
|
||||
pub fn process_block_header<T: EthSpec>(
|
||||
state: &mut BeaconState<T>,
|
||||
block: BeaconBlockRef<'_, T>,
|
||||
block_header: BeaconBlockHeader,
|
||||
verify_block_root: VerifyBlockRoot,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<u64, BlockOperationError<HeaderInvalid>> {
|
||||
// Verify that the slots match
|
||||
verify!(
|
||||
block.slot() == state.slot(),
|
||||
block_header.slot == state.slot(),
|
||||
HeaderInvalid::StateSlotMismatch
|
||||
);
|
||||
|
||||
// Verify that the block is newer than the latest block header
|
||||
verify!(
|
||||
block.slot() > state.latest_block_header().slot,
|
||||
block_header.slot > state.latest_block_header().slot,
|
||||
HeaderInvalid::OlderThanLatestBlockHeader {
|
||||
block_slot: block.slot(),
|
||||
block_slot: block_header.slot,
|
||||
latest_block_header_slot: state.latest_block_header().slot,
|
||||
}
|
||||
);
|
||||
|
||||
// Verify that proposer index is the correct index
|
||||
let proposer_index = block.proposer_index() as usize;
|
||||
let state_proposer_index = state.get_beacon_proposer_index(block.slot(), spec)?;
|
||||
let proposer_index = block_header.proposer_index as usize;
|
||||
let state_proposer_index = state.get_beacon_proposer_index(block_header.slot, spec)?;
|
||||
verify!(
|
||||
proposer_index == state_proposer_index,
|
||||
HeaderInvalid::ProposerIndexMismatch {
|
||||
@@ -205,15 +210,15 @@ pub fn process_block_header<T: EthSpec>(
|
||||
if verify_block_root == VerifyBlockRoot::True {
|
||||
let expected_previous_block_root = state.latest_block_header().tree_hash_root();
|
||||
verify!(
|
||||
block.parent_root() == expected_previous_block_root,
|
||||
block_header.parent_root == expected_previous_block_root,
|
||||
HeaderInvalid::ParentBlockRootMismatch {
|
||||
state: expected_previous_block_root,
|
||||
block: block.parent_root(),
|
||||
block: block_header.parent_root,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
*state.latest_block_header_mut() = block.temporary_block_header();
|
||||
*state.latest_block_header_mut() = block_header;
|
||||
|
||||
// Verify proposer is not slashed
|
||||
verify!(
|
||||
@@ -221,15 +226,15 @@ pub fn process_block_header<T: EthSpec>(
|
||||
HeaderInvalid::ProposerSlashed(proposer_index)
|
||||
);
|
||||
|
||||
Ok(block.proposer_index())
|
||||
Ok(proposer_index as u64)
|
||||
}
|
||||
|
||||
/// Verifies the signature of a block.
|
||||
///
|
||||
/// Spec v0.12.1
|
||||
pub fn verify_block_signature<T: EthSpec>(
|
||||
pub fn verify_block_signature<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &BeaconState<T>,
|
||||
block: &SignedBeaconBlock<T>,
|
||||
block: &SignedBeaconBlock<T, Payload>,
|
||||
block_root: Option<Hash256>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), BlockOperationError<HeaderInvalid>> {
|
||||
@@ -250,9 +255,9 @@ pub fn verify_block_signature<T: EthSpec>(
|
||||
|
||||
/// Verifies the `randao_reveal` against the block's proposer pubkey and updates
|
||||
/// `state.latest_randao_mixes`.
|
||||
pub fn process_randao<T: EthSpec>(
|
||||
pub fn process_randao<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &mut BeaconState<T>,
|
||||
block: BeaconBlockRef<'_, T>,
|
||||
block: BeaconBlockRef<'_, T, Payload>,
|
||||
verify_signatures: VerifySignatures,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), BlockProcessingError> {
|
||||
@@ -314,34 +319,34 @@ pub fn get_new_eth1_data<T: EthSpec>(
|
||||
/// Contains a partial set of checks from the `process_execution_payload` function:
|
||||
///
|
||||
/// https://github.com/ethereum/consensus-specs/blob/v1.1.5/specs/merge/beacon-chain.md#process_execution_payload
|
||||
pub fn partially_verify_execution_payload<T: EthSpec>(
|
||||
pub fn partially_verify_execution_payload<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &BeaconState<T>,
|
||||
payload: &ExecutionPayload<T>,
|
||||
payload: &Payload,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), BlockProcessingError> {
|
||||
if is_merge_transition_complete(state) {
|
||||
block_verify!(
|
||||
payload.parent_hash == state.latest_execution_payload_header()?.block_hash,
|
||||
payload.parent_hash() == state.latest_execution_payload_header()?.block_hash,
|
||||
BlockProcessingError::ExecutionHashChainIncontiguous {
|
||||
expected: state.latest_execution_payload_header()?.block_hash,
|
||||
found: payload.parent_hash,
|
||||
found: payload.parent_hash(),
|
||||
}
|
||||
);
|
||||
}
|
||||
block_verify!(
|
||||
payload.prev_randao == *state.get_randao_mix(state.current_epoch())?,
|
||||
payload.prev_randao() == *state.get_randao_mix(state.current_epoch())?,
|
||||
BlockProcessingError::ExecutionRandaoMismatch {
|
||||
expected: *state.get_randao_mix(state.current_epoch())?,
|
||||
found: payload.prev_randao,
|
||||
found: payload.prev_randao(),
|
||||
}
|
||||
);
|
||||
|
||||
let timestamp = compute_timestamp_at_slot(state, spec)?;
|
||||
block_verify!(
|
||||
payload.timestamp == timestamp,
|
||||
payload.timestamp() == timestamp,
|
||||
BlockProcessingError::ExecutionInvalidTimestamp {
|
||||
expected: timestamp,
|
||||
found: payload.timestamp,
|
||||
found: payload.timestamp(),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -355,29 +360,14 @@ pub fn partially_verify_execution_payload<T: EthSpec>(
|
||||
/// Partially equivalent to the `process_execution_payload` function:
|
||||
///
|
||||
/// https://github.com/ethereum/consensus-specs/blob/v1.1.5/specs/merge/beacon-chain.md#process_execution_payload
|
||||
pub fn process_execution_payload<T: EthSpec>(
|
||||
pub fn process_execution_payload<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &mut BeaconState<T>,
|
||||
payload: &ExecutionPayload<T>,
|
||||
payload: &Payload,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(), BlockProcessingError> {
|
||||
partially_verify_execution_payload(state, payload, spec)?;
|
||||
|
||||
*state.latest_execution_payload_header_mut()? = ExecutionPayloadHeader {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
receipts_root: payload.receipts_root,
|
||||
logs_bloom: payload.logs_bloom.clone(),
|
||||
prev_randao: payload.prev_randao,
|
||||
block_number: payload.block_number,
|
||||
gas_limit: payload.gas_limit,
|
||||
gas_used: payload.gas_used,
|
||||
timestamp: payload.timestamp,
|
||||
extra_data: payload.extra_data.clone(),
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions_root: payload.transactions.tree_hash_root(),
|
||||
};
|
||||
*state.latest_execution_payload_header_mut()? = payload.to_execution_payload_header();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -394,24 +384,21 @@ pub fn is_merge_transition_complete<T: EthSpec>(state: &BeaconState<T>) -> bool
|
||||
.unwrap_or(false)
|
||||
}
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#is_merge_transition_block
|
||||
pub fn is_merge_transition_block<T: EthSpec>(
|
||||
pub fn is_merge_transition_block<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &BeaconState<T>,
|
||||
body: BeaconBlockBodyRef<T>,
|
||||
body: BeaconBlockBodyRef<T, Payload>,
|
||||
) -> bool {
|
||||
body.execution_payload()
|
||||
.map(|payload| {
|
||||
!is_merge_transition_complete(state) && *payload != <ExecutionPayload<T>>::default()
|
||||
})
|
||||
.map(|payload| !is_merge_transition_complete(state) && *payload != Payload::default())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#is_execution_enabled
|
||||
pub fn is_execution_enabled<T: EthSpec>(
|
||||
pub fn is_execution_enabled<T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &BeaconState<T>,
|
||||
body: BeaconBlockBodyRef<T>,
|
||||
body: BeaconBlockBodyRef<T, Payload>,
|
||||
) -> bool {
|
||||
is_merge_transition_block(state, body) || is_merge_transition_complete(state)
|
||||
}
|
||||
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#compute_timestamp_at_slot
|
||||
pub fn compute_timestamp_at_slot<T: EthSpec>(
|
||||
state: &BeaconState<T>,
|
||||
|
||||
@@ -7,7 +7,7 @@ use bls::{verify_signature_sets, PublicKey, PublicKeyBytes, SignatureSet};
|
||||
use rayon::prelude::*;
|
||||
use std::borrow::Cow;
|
||||
use types::{
|
||||
BeaconState, BeaconStateError, ChainSpec, EthSpec, Hash256, IndexedAttestation,
|
||||
BeaconState, BeaconStateError, ChainSpec, EthSpec, ExecPayload, Hash256, IndexedAttestation,
|
||||
SignedBeaconBlock,
|
||||
};
|
||||
|
||||
@@ -117,11 +117,11 @@ where
|
||||
/// contains invalid signatures on deposits._
|
||||
///
|
||||
/// See `Self::verify` for more detail.
|
||||
pub fn verify_entire_block(
|
||||
pub fn verify_entire_block<Payload: ExecPayload<T>>(
|
||||
state: &'a BeaconState<T>,
|
||||
get_pubkey: F,
|
||||
decompressor: D,
|
||||
block: &'a SignedBeaconBlock<T>,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
block_root: Option<Hash256>,
|
||||
spec: &'a ChainSpec,
|
||||
) -> Result<()> {
|
||||
@@ -131,9 +131,9 @@ where
|
||||
}
|
||||
|
||||
/// Includes all signatures on the block (except the deposit signatures) for verification.
|
||||
pub fn include_all_signatures(
|
||||
pub fn include_all_signatures<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T>,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
block_root: Option<Hash256>,
|
||||
) -> Result<()> {
|
||||
self.include_block_proposal(block, block_root)?;
|
||||
@@ -144,9 +144,9 @@ where
|
||||
|
||||
/// Includes all signatures on the block (except the deposit signatures and the proposal
|
||||
/// signature) for verification.
|
||||
pub fn include_all_signatures_except_proposal(
|
||||
pub fn include_all_signatures_except_proposal<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T>,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
) -> Result<()> {
|
||||
self.include_randao_reveal(block)?;
|
||||
self.include_proposer_slashings(block)?;
|
||||
@@ -160,9 +160,9 @@ where
|
||||
}
|
||||
|
||||
/// Includes the block signature for `self.block` for verification.
|
||||
pub fn include_block_proposal(
|
||||
pub fn include_block_proposal<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T>,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
block_root: Option<Hash256>,
|
||||
) -> Result<()> {
|
||||
let set = block_proposal_signature_set(
|
||||
@@ -177,7 +177,10 @@ where
|
||||
}
|
||||
|
||||
/// Includes the randao signature for `self.block` for verification.
|
||||
pub fn include_randao_reveal(&mut self, block: &'a SignedBeaconBlock<T>) -> Result<()> {
|
||||
pub fn include_randao_reveal<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
) -> Result<()> {
|
||||
let set = randao_signature_set(
|
||||
self.state,
|
||||
self.get_pubkey.clone(),
|
||||
@@ -189,7 +192,10 @@ where
|
||||
}
|
||||
|
||||
/// Includes all signatures in `self.block.body.proposer_slashings` for verification.
|
||||
pub fn include_proposer_slashings(&mut self, block: &'a SignedBeaconBlock<T>) -> Result<()> {
|
||||
pub fn include_proposer_slashings<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
) -> Result<()> {
|
||||
self.sets
|
||||
.sets
|
||||
.reserve(block.message().body().proposer_slashings().len() * 2);
|
||||
@@ -215,7 +221,10 @@ where
|
||||
}
|
||||
|
||||
/// Includes all signatures in `self.block.body.attester_slashings` for verification.
|
||||
pub fn include_attester_slashings(&mut self, block: &'a SignedBeaconBlock<T>) -> Result<()> {
|
||||
pub fn include_attester_slashings<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
) -> Result<()> {
|
||||
self.sets
|
||||
.sets
|
||||
.reserve(block.message().body().attester_slashings().len() * 2);
|
||||
@@ -241,9 +250,9 @@ where
|
||||
}
|
||||
|
||||
/// Includes all signatures in `self.block.body.attestations` for verification.
|
||||
pub fn include_attestations(
|
||||
pub fn include_attestations<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T>,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
) -> Result<Vec<IndexedAttestation<T>>> {
|
||||
self.sets
|
||||
.sets
|
||||
@@ -280,7 +289,10 @@ where
|
||||
}
|
||||
|
||||
/// Includes all signatures in `self.block.body.voluntary_exits` for verification.
|
||||
pub fn include_exits(&mut self, block: &'a SignedBeaconBlock<T>) -> Result<()> {
|
||||
pub fn include_exits<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
) -> Result<()> {
|
||||
self.sets
|
||||
.sets
|
||||
.reserve(block.message().body().voluntary_exits().len());
|
||||
@@ -301,7 +313,10 @@ where
|
||||
}
|
||||
|
||||
/// Include the signature of the block's sync aggregate (if it exists) for verification.
|
||||
pub fn include_sync_aggregate(&mut self, block: &'a SignedBeaconBlock<T>) -> Result<()> {
|
||||
pub fn include_sync_aggregate<Payload: ExecPayload<T>>(
|
||||
&mut self,
|
||||
block: &'a SignedBeaconBlock<T, Payload>,
|
||||
) -> Result<()> {
|
||||
if let Ok(sync_aggregate) = block.message().body().sync_aggregate() {
|
||||
if let Some(signature_set) = sync_aggregate_signature_set(
|
||||
&self.decompressor,
|
||||
|
||||
@@ -8,9 +8,9 @@ use crate::VerifySignatures;
|
||||
use safe_arith::SafeArith;
|
||||
use types::consts::altair::{PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, WEIGHT_DENOMINATOR};
|
||||
|
||||
pub fn process_operations<'a, T: EthSpec>(
|
||||
pub fn process_operations<'a, T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &mut BeaconState<T>,
|
||||
block_body: BeaconBlockBodyRef<'a, T>,
|
||||
block_body: BeaconBlockBodyRef<'a, T, Payload>,
|
||||
proposer_index: u64,
|
||||
verify_signatures: VerifySignatures,
|
||||
spec: &ChainSpec,
|
||||
@@ -217,9 +217,9 @@ pub fn process_attester_slashings<T: EthSpec>(
|
||||
}
|
||||
/// Wrapper function to handle calling the correct version of `process_attestations` based on
|
||||
/// the fork.
|
||||
pub fn process_attestations<'a, T: EthSpec>(
|
||||
pub fn process_attestations<'a, T: EthSpec, Payload: ExecPayload<T>>(
|
||||
state: &mut BeaconState<T>,
|
||||
block_body: BeaconBlockBodyRef<'a, T>,
|
||||
block_body: BeaconBlockBodyRef<'a, T, Payload>,
|
||||
proposer_index: u64,
|
||||
verify_signatures: VerifySignatures,
|
||||
spec: &ChainSpec,
|
||||
|
||||
@@ -8,10 +8,11 @@ use std::borrow::Cow;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{
|
||||
AggregateSignature, AttesterSlashing, BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec,
|
||||
DepositData, Domain, Epoch, EthSpec, Fork, Hash256, InconsistentFork, IndexedAttestation,
|
||||
ProposerSlashing, PublicKey, PublicKeyBytes, Signature, SignedAggregateAndProof,
|
||||
SignedBeaconBlock, SignedBeaconBlockHeader, SignedContributionAndProof, SignedRoot,
|
||||
SignedVoluntaryExit, SigningData, Slot, SyncAggregate, SyncAggregatorSelectionData, Unsigned,
|
||||
DepositData, Domain, Epoch, EthSpec, ExecPayload, Fork, Hash256, InconsistentFork,
|
||||
IndexedAttestation, ProposerSlashing, PublicKey, PublicKeyBytes, Signature,
|
||||
SignedAggregateAndProof, SignedBeaconBlock, SignedBeaconBlockHeader,
|
||||
SignedContributionAndProof, SignedRoot, SignedVoluntaryExit, SigningData, Slot, SyncAggregate,
|
||||
SyncAggregatorSelectionData, Unsigned,
|
||||
};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
@@ -70,10 +71,10 @@ where
|
||||
}
|
||||
|
||||
/// A signature set that is valid if a block was signed by the expected block producer.
|
||||
pub fn block_proposal_signature_set<'a, T, F>(
|
||||
pub fn block_proposal_signature_set<'a, T, F, Payload: ExecPayload<T>>(
|
||||
state: &'a BeaconState<T>,
|
||||
get_pubkey: F,
|
||||
signed_block: &'a SignedBeaconBlock<T>,
|
||||
signed_block: &'a SignedBeaconBlock<T, Payload>,
|
||||
block_root: Option<Hash256>,
|
||||
spec: &'a ChainSpec,
|
||||
) -> Result<SignatureSet<'a>>
|
||||
@@ -107,8 +108,8 @@ where
|
||||
/// Unlike `block_proposal_signature_set` this does **not** check that the proposer index is
|
||||
/// correct according to the shuffling. It should only be used if no suitable `BeaconState` is
|
||||
/// available.
|
||||
pub fn block_proposal_signature_set_from_parts<'a, T, F>(
|
||||
signed_block: &'a SignedBeaconBlock<T>,
|
||||
pub fn block_proposal_signature_set_from_parts<'a, T, F, Payload: ExecPayload<T>>(
|
||||
signed_block: &'a SignedBeaconBlock<T, Payload>,
|
||||
block_root: Option<Hash256>,
|
||||
proposer_index: u64,
|
||||
fork: &Fork,
|
||||
@@ -151,10 +152,10 @@ where
|
||||
}
|
||||
|
||||
/// A signature set that is valid if the block proposers randao reveal signature is correct.
|
||||
pub fn randao_signature_set<'a, T, F>(
|
||||
pub fn randao_signature_set<'a, T, F, Payload: ExecPayload<T>>(
|
||||
state: &'a BeaconState<T>,
|
||||
get_pubkey: F,
|
||||
block: BeaconBlockRef<'a, T>,
|
||||
block: BeaconBlockRef<'a, T, Payload>,
|
||||
spec: &'a ChainSpec,
|
||||
) -> Result<SignatureSet<'a>>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user