Whole Bunch of Changes Sorry

This commit is contained in:
Mark Mackey
2024-11-30 16:09:35 -06:00
parent cd7b3cfa2d
commit dd571b5b4d
16 changed files with 692 additions and 272 deletions

View File

@@ -1,136 +0,0 @@
use super::signature_sets::{execution_envelope_signature_set, get_pubkey_from_state};
use crate::per_block_processing::compute_timestamp_at_slot;
use crate::per_block_processing::errors::{BlockProcessingError, ExecutionEnvelopeError};
use crate::VerifySignatures;
use tree_hash::TreeHash;
use types::{BeaconState, ChainSpec, EthSpec, Hash256, SignedExecutionEnvelope};
pub fn process_execution_envelope<E: EthSpec>(
state: &mut BeaconState<E>,
signed_envelope: SignedExecutionEnvelope<E>,
spec: &ChainSpec,
verify_signatures: VerifySignatures,
) -> Result<(), BlockProcessingError> {
if verify_signatures.is_true() {
block_verify!(
execution_envelope_signature_set(
state,
|i| get_pubkey_from_state(state, i),
&signed_envelope,
spec
)?
.verify(),
ExecutionEnvelopeError::BadSignature.into()
)
}
let envelope = signed_envelope.message();
let payload = &envelope.payload;
let previous_state_root = state.canonical_root()?;
if state.latest_block_header().state_root == Hash256::default() {
*state.latest_block_header_mut().state_root = *previous_state_root;
}
// Verify consistency with the beacon block
block_verify!(
envelope.tree_hash_root() == state.latest_block_header().tree_hash_root(),
ExecutionEnvelopeError::LatestBlockHeaderMismatch {
envelope_root: envelope.tree_hash_root(),
block_header_root: state.latest_block_header().tree_hash_root(),
}
.into()
);
// Verify consistency with the committed bid
let committed_bid = state.latest_execution_bid()?;
block_verify!(
envelope.builder_index == committed_bid.builder_index,
ExecutionEnvelopeError::BuilderIndexMismatch {
committed_bid: committed_bid.builder_index,
envelope: envelope.builder_index,
}
.into()
);
block_verify!(
committed_bid.blob_kzg_commitments_root == envelope.blob_kzg_commitments.tree_hash_root(),
ExecutionEnvelopeError::BlobKzgCommitmentsRootMismatch {
committed_bid: committed_bid.blob_kzg_commitments_root,
envelope: envelope.blob_kzg_commitments.tree_hash_root(),
}
.into()
);
if !envelope.payment_withheld {
// Verify the withdrawals root
block_verify!(
payload.withdrawals.tree_hash_root() == state.latest_withdrawals_root()?,
ExecutionEnvelopeError::WithdrawalsRootMismatch {
state: state.latest_withdrawals_root()?,
envelope: payload.withdrawals.tree_hash_root(),
}
.into()
);
// Verify the gas limit
block_verify!(
payload.gas_limit == committed_bid.gas_limit,
ExecutionEnvelopeError::GasLimitMismatch {
committed_bid: committed_bid.gas_limit,
envelope: payload.gas_limit,
}
.into()
);
block_verify!(
committed_bid.block_hash == payload.block_hash,
ExecutionEnvelopeError::BlockHashMismatch {
committed_bid: committed_bid.block_hash,
envelope: payload.block_hash,
}
.into()
);
// Verify consistency of the parent hash with respect to the previous execution payload
block_verify!(
payload.parent_hash == state.latest_block_hash()?,
ExecutionEnvelopeError::ParentHashMismatch {
state: state.latest_block_hash()?,
envelope: payload.parent_hash,
}
.into()
);
// Verify prev_randao
block_verify!(
payload.prev_randao == *state.get_randao_mix(state.current_epoch())?,
ExecutionEnvelopeError::PrevRandaoMismatch {
state: *state.get_randao_mix(state.current_epoch())?,
envelope: payload.prev_randao,
}
.into()
);
// Verify the timestamp
let state_timestamp = compute_timestamp_at_slot(state, state.slot(), spec)?;
block_verify!(
payload.timestamp == state_timestamp,
ExecutionEnvelopeError::TimestampMismatch {
state: state_timestamp,
envelope: payload.timestamp,
}
.into()
);
// Verify the commitments are under limit
block_verify!(
envelope.blob_kzg_commitments.len() <= E::max_blob_commitments_per_block(),
ExecutionEnvelopeError::BlobLimitExceeded {
max: E::max_blob_commitments_per_block(),
envelope: envelope.blob_kzg_commitments.len(),
}
.into()
);
}
Ok(())
}

View File

@@ -21,7 +21,6 @@ pub mod block_replayer;
pub mod common;
pub mod consensus_context;
pub mod epoch_cache;
pub mod execution_processing;
pub mod genesis;
pub mod per_block_processing;
pub mod per_epoch_processing;
@@ -33,7 +32,6 @@ pub mod verify_operation;
pub use all_caches::AllCaches;
pub use block_replayer::{BlockReplayError, BlockReplayer};
pub use consensus_context::{ConsensusContext, ContextError};
pub use execution_processing::process_execution_envelope;
pub use genesis::{
eth2_genesis_time, initialize_beacon_state_from_eth1, is_valid_genesis_state,
process_activations,

View File

@@ -63,7 +63,6 @@ pub enum BlockProcessingError {
ExecutionBidInvalid {
reason: ExecutionBidInvalid,
},
ExecutionEnvelopeError(ExecutionEnvelopeError),
BeaconStateError(BeaconStateError),
SignatureSetError(SignatureSetError),
SszTypesError(ssz_types::Error),
@@ -160,12 +159,6 @@ impl From<ExecutionBidInvalid> for BlockProcessingError {
}
}
impl From<ExecutionEnvelopeError> for BlockProcessingError {
fn from(e: ExecutionEnvelopeError) -> Self {
BlockProcessingError::ExecutionEnvelopeError(e)
}
}
impl From<BlockOperationError<HeaderInvalid>> for BlockProcessingError {
fn from(e: BlockOperationError<HeaderInvalid>) -> BlockProcessingError {
match e {
@@ -548,59 +541,3 @@ pub enum ExecutionBidInvalid {
bid_parent_root: Hash256,
},
}
#[derive(Debug, PartialEq, Clone)]
pub enum ExecutionEnvelopeError {
/// The signature is invalid.
BadSignature,
/// Envelope doesn't match latest beacon block header
LatestBlockHeaderMismatch {
envelope_root: Hash256,
block_header_root: Hash256,
},
/// The builder index doesn't match the committed bid
BuilderIndexMismatch {
committed_bid: u64,
envelope: u64,
},
/// The blob KZG commitments root doesn't match the committed bid
BlobKzgCommitmentsRootMismatch {
committed_bid: Hash256,
envelope: Hash256,
},
/// The withdrawals root doesn't match the state's latest withdrawals root
WithdrawalsRootMismatch {
state: Hash256,
envelope: Hash256,
},
// The gas limit doesn't match the committed bid
GasLimitMismatch {
committed_bid: u64,
envelope: u64,
},
// The block hash doesn't match the committed bid
BlockHashMismatch {
committed_bid: ExecutionBlockHash,
envelope: ExecutionBlockHash,
},
// The parent hash doesn't match the previous execution payload
ParentHashMismatch {
state: ExecutionBlockHash,
envelope: ExecutionBlockHash,
},
// The previous randao didn't match the payload
PrevRandaoMismatch {
state: Hash256,
envelope: Hash256,
},
// The timestamp didn't match the payload
TimestampMismatch {
state: u64,
envelope: u64,
},
// Blob committments exceeded the maximum
BlobLimitExceeded {
max: usize,
envelope: usize,
},
}

View File

@@ -406,8 +406,8 @@ where
state.genesis_validators_root(),
);
let message = signed_envelope.message().signing_root(domain);
let pubkey = get_pubkey(signed_envelope.message().builder_index as usize).ok_or(
Error::ValidatorUnknown(signed_envelope.message().builder_index),
let pubkey = get_pubkey(signed_envelope.message().builder_index() as usize).ok_or(
Error::ValidatorUnknown(signed_envelope.message().builder_index()),
)?;
Ok(SignatureSet::single_pubkey(