fix blob validation for empty blobs

This commit is contained in:
realbigsean
2022-12-23 12:47:38 -05:00
parent 5db0a88d4f
commit 5e11edc612
13 changed files with 119 additions and 81 deletions
@@ -5,6 +5,7 @@ use crate::{kzg_utils, BeaconChainError};
use bls::PublicKey;
use state_processing::per_block_processing::eip4844::eip4844::verify_kzg_commitments_against_transactions;
use types::consts::eip4844::BLS_MODULUS;
use types::signed_beacon_block::BlobReconstructionError;
use types::{BeaconStateError, BlobsSidecar, Hash256, KzgCommitment, Slot, Transactions};
#[derive(Debug)]
@@ -91,6 +92,12 @@ pub enum BlobError {
MissingBlobs,
}
impl From<BlobReconstructionError> for BlobError {
fn from(_: BlobReconstructionError) -> Self {
BlobError::MissingBlobs
}
}
impl From<BeaconChainError> for BlobError {
fn from(e: BeaconChainError) -> Self {
BlobError::BeaconChainError(e)
@@ -87,6 +87,7 @@ use std::time::Duration;
use store::{Error as DBError, HotStateSummary, KeyValueStore, StoreOp};
use task_executor::JoinHandle;
use tree_hash::TreeHash;
use types::signed_beacon_block::BlobReconstructionError;
use types::signed_block_and_blobs::BlockWrapper;
use types::{
BeaconBlockRef, BeaconState, BeaconStateError, BlindedPayload, ChainSpec, CloneConfig, Epoch,
@@ -479,6 +480,12 @@ impl<T: EthSpec> From<ArithError> for BlockError<T> {
}
}
impl<T: EthSpec> From<BlobReconstructionError> for BlockError<T> {
fn from(e: BlobReconstructionError) -> Self {
BlockError::BlobValidation(BlobError::from(e))
}
}
/// Stores information about verifying a payload against an execution engine.
pub struct PayloadVerificationOutcome {
pub payload_verification_status: PayloadVerificationStatus,
@@ -905,7 +912,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
// Validate the block's execution_payload (if any).
validate_execution_payload_for_gossip(&parent_block, block.message(), chain)?;
if let Some(blobs_sidecar) = block.blobs() {
if let Some(blobs_sidecar) = block.blobs(Some(block_root))? {
let kzg_commitments = block
.message()
.body()
@@ -919,7 +926,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
.map_err(|_| BlockError::BlobValidation(BlobError::TransactionsMissing))?
.ok_or(BlockError::BlobValidation(BlobError::TransactionsMissing))?;
validate_blob_for_gossip(
blobs_sidecar,
&blobs_sidecar,
kzg_commitments,
transactions,
block.slot(),
@@ -1134,12 +1141,8 @@ impl<T: BeaconChainTypes> IntoExecutionPendingBlock<T> for Arc<SignedBeaconBlock
let block_root = check_block_relevancy(&self, block_root, chain)
.map_err(|e| BlockSlashInfo::SignatureNotChecked(self.signed_block_header(), e))?;
SignatureVerifiedBlock::check_slashable(
BlockWrapper::Block { block: self },
block_root,
chain,
)?
.into_execution_pending_block_slashable(block_root, chain, notify_execution_layer)
SignatureVerifiedBlock::check_slashable(BlockWrapper::Block(self), block_root, chain)?
.into_execution_pending_block_slashable(block_root, chain, notify_execution_layer)
}
fn block(&self) -> &SignedBeaconBlock<T::EthSpec> {
@@ -1563,7 +1566,7 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
if let Some(data_availability_boundary) = chain.data_availability_boundary() {
if block_slot.epoch(T::EthSpec::slots_per_epoch()) >= data_availability_boundary {
let sidecar = block
.blobs()
.blobs(Some(block_root))?
.ok_or(BlockError::BlobValidation(BlobError::MissingBlobs))?;
let kzg = chain.kzg.as_ref().ok_or(BlockError::BlobValidation(
BlobError::TrustedSetupNotInitialized,
@@ -1586,7 +1589,7 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
block.slot(),
block_root,
kzg_commitments,
sidecar,
&sidecar,
)
.map_err(|e| BlockError::BlobValidation(BlobError::KzgError(e)))?
{
+2 -4
View File
@@ -43,9 +43,7 @@ pub async fn publish_block<T: BeaconChainTypes>(
network_tx,
PubsubMessage::BeaconBlockAndBlobsSidecars(block_and_blobs.clone()),
)?;
BlockWrapper::BlockAndBlob {
block_sidecar_pair: block_and_blobs,
}
BlockWrapper::BlockAndBlob(block_and_blobs)
} else {
//FIXME(sean): This should probably return a specific no-blob-cached error code, beacon API coordination required
return Err(warp_utils::reject::broadcast_without_import(format!(
@@ -54,7 +52,7 @@ pub async fn publish_block<T: BeaconChainTypes>(
}
} else {
crate::publish_pubsub_message(network_tx, PubsubMessage::BeaconBlock(block.clone()))?;
BlockWrapper::Block { block }
BlockWrapper::Block(block)
};
// Determine the delay after the start of the slot, register it with metrics.
@@ -1699,7 +1699,7 @@ impl<T: BeaconChainTypes> BeaconProcessor<T> {
message_id,
peer_id,
peer_client,
BlockWrapper::Block { block },
BlockWrapper::Block(block),
work_reprocessing_tx,
duplicate_cache,
seen_timestamp,
@@ -1721,7 +1721,7 @@ impl<T: BeaconChainTypes> BeaconProcessor<T> {
message_id,
peer_id,
peer_client,
BlockWrapper::BlockAndBlob { block_sidecar_pair },
BlockWrapper::BlockAndBlob(block_sidecar_pair),
work_reprocessing_tx,
duplicate_cache,
seen_timestamp,
@@ -194,11 +194,9 @@ impl<T: BeaconChainTypes> Worker<T> {
let unwrapped = downloaded_blocks
.into_iter()
.map(|block| match block {
BlockWrapper::Block { block } => block,
BlockWrapper::Block(block) => block,
//FIXME(sean) handle blobs in backfill
BlockWrapper::BlockAndBlob {
block_sidecar_pair: _,
} => todo!(),
BlockWrapper::BlockAndBlob(_) => todo!(),
})
.collect();
@@ -51,16 +51,14 @@ impl<T: EthSpec> BlockBlobRequestInfo<T> {
{
let blobs_sidecar =
accumulated_sidecars.pop_front().ok_or("missing sidecar")?;
Ok(BlockWrapper::BlockAndBlob {
block_sidecar_pair: SignedBeaconBlockAndBlobsSidecar {
Ok(BlockWrapper::BlockAndBlob(
SignedBeaconBlockAndBlobsSidecar {
beacon_block,
blobs_sidecar,
},
})
))
} else {
Ok(BlockWrapper::Block {
block: beacon_block,
})
Ok(BlockWrapper::Block(beacon_block))
}
})
.collect::<Result<Vec<_>, _>>();
+14 -10
View File
@@ -734,14 +734,14 @@ impl<T: BeaconChainTypes> SyncManager<T> {
RequestId::SingleBlock { id } => self.block_lookups.single_block_lookup_response(
id,
peer_id,
beacon_block.map(|block| BlockWrapper::Block { block }),
beacon_block.map(|block| BlockWrapper::Block(block)),
seen_timestamp,
&mut self.network,
),
RequestId::ParentLookup { id } => self.block_lookups.parent_lookup_response(
id,
peer_id,
beacon_block.map(|block| BlockWrapper::Block { block }),
beacon_block.map(|block| BlockWrapper::Block(block)),
seen_timestamp,
&mut self.network,
),
@@ -756,7 +756,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
batch_id,
&peer_id,
id,
beacon_block.map(|block| BlockWrapper::Block { block }),
beacon_block.map(|block| BlockWrapper::Block(block)),
) {
Ok(ProcessResult::SyncCompleted) => self.update_sync_state(),
Ok(ProcessResult::Successful) => {}
@@ -780,7 +780,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
chain_id,
batch_id,
id,
beacon_block.map(|block| BlockWrapper::Block { block }),
beacon_block.map(|block| BlockWrapper::Block(block)),
);
self.update_sync_state();
}
@@ -930,9 +930,11 @@ impl<T: BeaconChainTypes> SyncManager<T> {
RequestId::SingleBlock { id } => self.block_lookups.single_block_lookup_response(
id,
peer_id,
block_sidecar_pair.map(|block_sidecar_pair| BlockWrapper::BlockAndBlob {
// TODO: why is this in an arc
block_sidecar_pair: (*block_sidecar_pair).clone(),
block_sidecar_pair.map(|block_sidecar_pair| {
BlockWrapper::BlockAndBlob(
// TODO: why is this in an arc
(*block_sidecar_pair).clone(),
)
}),
seen_timestamp,
&mut self.network,
@@ -940,9 +942,11 @@ impl<T: BeaconChainTypes> SyncManager<T> {
RequestId::ParentLookup { id } => self.block_lookups.parent_lookup_response(
id,
peer_id,
block_sidecar_pair.map(|block_sidecar_pair| BlockWrapper::BlockAndBlob {
// TODO: why is this in an arc
block_sidecar_pair: (*block_sidecar_pair).clone(),
block_sidecar_pair.map(|block_sidecar_pair| {
BlockWrapper::BlockAndBlob(
// TODO: why is this in an arc
(*block_sidecar_pair).clone(),
)
}),
seen_timestamp,
&mut self.network,
@@ -25,11 +25,11 @@ impl<T: EthSpec> BatchTy<T> {
match self {
BatchTy::Blocks(blocks) => blocks
.into_iter()
.map(|block| BlockWrapper::Block { block })
.map(|block| BlockWrapper::Block(block))
.collect(),
BatchTy::BlocksAndBlobs(block_sidecar_pair) => block_sidecar_pair
.into_iter()
.map(|block_sidecar_pair| BlockWrapper::BlockAndBlob { block_sidecar_pair })
.map(|block_sidecar_pair| BlockWrapper::BlockAndBlob(block_sidecar_pair))
.collect(),
}
}
@@ -413,7 +413,7 @@ impl<T: EthSpec, B: BatchConfig> BatchInfo<T, B> {
match self.batch_type {
ExpectedBatchTy::OnlyBlockBlobs => {
let blocks = blocks.into_iter().map(|block| {
let BlockWrapper::BlockAndBlob { block_sidecar_pair: block_and_blob } = block else {
let BlockWrapper::BlockAndBlob(block_and_blob) = block else {
panic!("Batches should never have a mixed type. This is a bug. Contact D")
};
block_and_blob
@@ -422,7 +422,7 @@ impl<T: EthSpec, B: BatchConfig> BatchInfo<T, B> {
}
ExpectedBatchTy::OnlyBlock => {
let blocks = blocks.into_iter().map(|block| {
let BlockWrapper::Block { block } = block else {
let BlockWrapper::Block(block) = block else {
panic!("Batches should never have a mixed type. This is a bug. Contact D")
};
block