Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate request validation in EnginveValidator #13858

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/engine/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ reth-errors.workspace = true
alloy-primitives.workspace = true
alloy-consensus.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-eips = { workspace = true, features = ["kzg"] }
hoank101 marked this conversation as resolved.
Show resolved Hide resolved

# async
tokio = { workspace = true, features = ["sync"] }
Expand Down
24 changes: 20 additions & 4 deletions crates/engine/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use reth_payload_primitives::{BuiltPayload, PayloadAttributes};
mod error;

use core::fmt;
Expand All @@ -28,15 +29,17 @@ pub use event::*;
mod invalid_block_hook;
pub use invalid_block_hook::InvalidBlockHook;

pub use reth_payload_primitives::{
BuiltPayload, EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes,
PayloadTypes,
use reth_payload_primitives::{
validate_execution_requests, EngineApiMessageVersion,
EngineObjectValidationError, InvalidPayloadAttributesError, PayloadOrAttributes, PayloadTypes,
};
use reth_payload_primitives::{InvalidPayloadAttributesError, PayloadAttributes};
use reth_primitives::{NodePrimitives, SealedBlock};
use reth_primitives_traits::Block;
use serde::{de::DeserializeOwned, ser::Serialize};

use alloy_eips::eip7685::Requests;


/// This type defines the versioned types of the engine API.
///
/// This includes the execution payload types and payload attributes that are used to trigger a
Expand Down Expand Up @@ -114,6 +117,19 @@ pub trait PayloadValidator: fmt::Debug + Send + Sync + Unpin + 'static {

/// Type that validates the payloads processed by the engine.
pub trait EngineValidator<Types: EngineTypes>: PayloadValidator {
/// Validates the execution requests according to EIP-7685.
hoank101 marked this conversation as resolved.
Show resolved Hide resolved
///
/// This ensures that:
/// 1. The requests array is not empty
/// 2. Each request's ID is unique
/// 3. Each request's ID is non-zero
hoank101 marked this conversation as resolved.
Show resolved Hide resolved
fn validate_execution_requests(
&self,
requests: &Requests,
) -> Result<(), EngineObjectValidationError> {
validate_execution_requests(requests).map_err(|e| EngineObjectValidationError::from(e))
}

/// Validates the presence or exclusion of fork-specific fields based on the payload attributes
/// and the message version.
fn validate_version_specific_fields(
Expand Down
6 changes: 3 additions & 3 deletions crates/ethereum/engine-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub use alloy_rpc_types_engine::{
};
pub use payload::{EthBuiltPayload, EthPayloadBuilderAttributes};
use reth_chainspec::ChainSpec;
use reth_engine_primitives::{BuiltPayload, EngineTypes, EngineValidator, PayloadValidator};
use reth_engine_primitives::{EngineTypes, EngineValidator, PayloadValidator};
use reth_payload_primitives::{
validate_version_specific_fields, EngineApiMessageVersion, EngineObjectValidationError,
PayloadOrAttributes, PayloadTypes,
validate_version_specific_fields, BuiltPayload, EngineApiMessageVersion,
EngineObjectValidationError, PayloadOrAttributes, PayloadTypes,
};
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{Block, NodePrimitives, SealedBlock};
Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ where
.validator
.validate_version_specific_fields(EngineApiMessageVersion::V4, payload_or_attrs)?;

validate_execution_requests(&execution_requests)?;
hoank101 marked this conversation as resolved.
Show resolved Hide resolved

Ok(self
.inner
.beacon_consensus
Expand Down
Loading