fix: ignore header extradata validation in goerli pre-merge (#2178)

This commit is contained in:
Dan Cline
2023-04-11 18:03:45 -04:00
committed by GitHub
parent 42a98a7194
commit 9e8d9883d1
2 changed files with 25 additions and 7 deletions

View File

@@ -1,7 +1,9 @@
//! Consensus for ethereum network
use reth_consensus_common::validation;
use reth_interfaces::consensus::{Consensus, ConsensusError};
use reth_primitives::{ChainSpec, Hardfork, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT, U256};
use reth_primitives::{
Chain, ChainSpec, Hardfork, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT, U256,
};
use std::sync::Arc;
/// Ethereum beacon consensus
@@ -53,12 +55,22 @@ impl Consensus for BeaconConsensus {
return Err(ConsensusError::TheMergeOmmerRootIsNotEmpty)
}
// validate header extradata for all networks post merge
validate_header_extradata(header)?;
// mixHash is used instead of difficulty inside EVM
// https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty
} else {
// TODO Consensus checks for old blocks:
// * difficulty, mix_hash & nonce aka PoW stuff
// low priority as syncing is done in reverse order
// Goerli exception:
// * If the network is goerli pre-merge, ignore the extradata check, since we do not
// support clique.
if self.chain_spec.chain != Chain::goerli() {
validate_header_extradata(header)?;
}
}
Ok(())
@@ -73,6 +85,18 @@ impl Consensus for BeaconConsensus {
}
}
/// Validates the header's extradata according to the beacon consensus rules.
///
/// From yellow paper: extraData: An arbitrary byte array containing data relevant to this block.
/// This must be 32 bytes or fewer; formally Hx.
fn validate_header_extradata(header: &SealedHeader) -> Result<(), ConsensusError> {
if header.extra_data.len() > 32 {
Err(ConsensusError::ExtraDataExceedsMax { len: header.extra_data.len() })
} else {
Ok(())
}
}
#[cfg(test)]
mod test {
use super::BeaconConsensus;

View File

@@ -33,12 +33,6 @@ pub fn validate_header_standalone(
})
}
// From yellow paper: extraData: An arbitrary byte array containing data
// relevant to this block. This must be 32 bytes or fewer; formally Hx.
if header.extra_data.len() > 32 {
return Err(ConsensusError::ExtraDataExceedsMax { len: header.extra_data.len() })
}
// Check if base fee is set.
if chain_spec.fork(Hardfork::London).active_at_block(header.number) &&
header.base_fee_per_gas.is_none()