fix: ensure extradata is 32 bytes or less (#2775)

This commit is contained in:
Matthias Seitz
2023-05-22 13:29:09 +02:00
committed by GitHub
parent d3aa36f19f
commit b70afbb37f
6 changed files with 98 additions and 14 deletions

View File

@@ -2,7 +2,8 @@
use reth_consensus_common::validation;
use reth_interfaces::consensus::{Consensus, ConsensusError};
use reth_primitives::{
Chain, ChainSpec, Hardfork, Header, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT, U256,
constants::MAXIMUM_EXTRA_DATA_SIZE, Chain, ChainSpec, Hardfork, Header, SealedBlock,
SealedHeader, EMPTY_OMMER_ROOT, U256,
};
use std::sync::Arc;
@@ -89,7 +90,7 @@ impl Consensus for BeaconConsensus {
/// 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: &Header) -> Result<(), ConsensusError> {
if header.extra_data.len() > 32 {
if header.extra_data.len() > MAXIMUM_EXTRA_DATA_SIZE {
Err(ConsensusError::ExtraDataExceedsMax { len: header.extra_data.len() })
} else {
Ok(())

View File

@@ -10,6 +10,9 @@ pub const RETH_CLIENT_VERSION: &str = concat!("reth/v", env!("CARGO_PKG_VERSION"
/// The first four bytes of the call data for a function call specifies the function to be called.
pub const SELECTOR_LEN: usize = 4;
/// Maximum extra data size in a block after genesis
pub const MAXIMUM_EXTRA_DATA_SIZE: usize = 32;
/// The duration of a slot in seconds.
///
/// This is the time period of 12 seconds in which a randomly chosen validator has time to propose a

View File

@@ -1,5 +1,5 @@
use reth_primitives::{
constants::MIN_PROTOCOL_BASE_FEE_U256,
constants::{MAXIMUM_EXTRA_DATA_SIZE, MIN_PROTOCOL_BASE_FEE_U256},
proofs::{self, EMPTY_LIST_HASH},
Address, Block, Bloom, Bytes, Header, SealedBlock, TransactionSigned, UintTryTo, Withdrawal,
H256, H64, U256, U64,
@@ -126,7 +126,7 @@ impl TryFrom<ExecutionPayload> for SealedBlock {
type Error = PayloadError;
fn try_from(payload: ExecutionPayload) -> Result<Self, Self::Error> {
if payload.extra_data.len() > 32 {
if payload.extra_data.len() > MAXIMUM_EXTRA_DATA_SIZE {
return Err(PayloadError::ExtraData(payload.extra_data))
}