This commit is contained in:
realbigsean
2023-01-22 05:54:25 +01:00
parent a83fd1afb4
commit 75320ff8bc
8 changed files with 57 additions and 27 deletions

View File

@@ -18,6 +18,8 @@ pub struct ConsensusContext<T: EthSpec> {
/// Cache of indexed attestations constructed during block processing.
indexed_attestations:
HashMap<(AttestationData, BitList<T::MaxValidatorsPerCommittee>), IndexedAttestation<T>>,
/// Whether `verify_kzg_commitments_against_transactions` has successfully passed.
kzg_commitments_consistent: bool,
}
#[derive(Debug, PartialEq, Clone)]
@@ -40,6 +42,7 @@ impl<T: EthSpec> ConsensusContext<T> {
proposer_index: None,
current_block_root: None,
indexed_attestations: HashMap::new(),
kzg_commitments_consistent: false,
}
}
@@ -155,4 +158,13 @@ impl<T: EthSpec> ConsensusContext<T> {
pub fn num_cached_indexed_attestations(&self) -> usize {
self.indexed_attestations.len()
}
pub fn set_kzg_commitments_consistent(mut self, kzg_commitments_consistent: bool) -> Self {
self.kzg_commitments_consistent = kzg_commitments_consistent;
self
}
pub fn kzg_commitments_consistent(&self) -> bool {
self.kzg_commitments_consistent
}
}

View File

@@ -180,10 +180,7 @@ pub fn per_block_processing<T: EthSpec, Payload: AbstractExecPayload<T>>(
)?;
}
process_blob_kzg_commitments(block.body())?;
//FIXME(sean) add `validate_blobs_sidecar` (is_data_available) and only run it if the consensus
// context tells us it wasnt already run
process_blob_kzg_commitments(block.body(), ctxt)?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use crate::BlockProcessingError;
use crate::{BlockProcessingError, ConsensusContext};
use eth2_hashing::hash_fixed;
use itertools::{EitherOrBoth, Itertools};
use safe_arith::SafeArith;
@@ -11,13 +11,17 @@ use types::{
pub fn process_blob_kzg_commitments<T: EthSpec, Payload: AbstractExecPayload<T>>(
block_body: BeaconBlockBodyRef<T, Payload>,
ctxt: &mut ConsensusContext<T>,
) -> Result<(), BlockProcessingError> {
// Return early if this check has already been run.
if ctxt.kzg_commitments_consistent() {
return Ok(());
}
if let (Ok(payload), Ok(kzg_commitments)) = (
block_body.execution_payload(),
block_body.blob_kzg_commitments(),
) {
if let Some(transactions) = payload.transactions() {
//FIXME(sean) only run if this wasn't run in gossip (use consensus context)
if !verify_kzg_commitments_against_transactions::<T>(transactions, kzg_commitments)? {
return Err(BlockProcessingError::BlobVersionHashMismatch);
}