reth_payload_validator/
prague.rs

1//! Prague rules for new payloads.
2
3use alloy_consensus::{BlockBody, Typed2718};
4use alloy_rpc_types_engine::{PayloadError, PraguePayloadFields};
5
6/// Checks block and sidecar well-formedness w.r.t new Prague fields and new transaction type
7/// EIP-7702.
8///
9/// Checks that:
10/// - Prague fields are not present unless Prague is active
11/// - does not contain EIP-7702 transactions if Prague is not active
12#[inline]
13pub fn ensure_well_formed_fields<T: Typed2718>(
14    block_body: &BlockBody<T>,
15    prague_fields: Option<&PraguePayloadFields>,
16    is_prague_active: bool,
17) -> Result<(), PayloadError> {
18    ensure_well_formed_sidecar_fields(prague_fields, is_prague_active)?;
19    ensure_well_formed_transactions_field(block_body, is_prague_active)
20}
21
22/// Checks that Prague fields are not present on sidecar unless Prague is active.
23#[inline]
24pub const fn ensure_well_formed_sidecar_fields(
25    prague_fields: Option<&PraguePayloadFields>,
26    is_prague_active: bool,
27) -> Result<(), PayloadError> {
28    if !is_prague_active && prague_fields.is_some() {
29        // prague _not_ active but prague fields present
30        return Err(PayloadError::PrePragueBlockRequests)
31    }
32
33    Ok(())
34}
35
36/// Checks that transactions field doesn't contain EIP-7702 transactions if Prague is not
37/// active.
38#[inline]
39pub fn ensure_well_formed_transactions_field<T: Typed2718>(
40    block_body: &BlockBody<T>,
41    is_prague_active: bool,
42) -> Result<(), PayloadError> {
43    if !is_prague_active && block_body.has_eip7702_transactions() {
44        return Err(PayloadError::PrePragueBlockWithEip7702Transactions)
45    }
46
47    Ok(())
48}