Skip to content

Commit 72bea5f

Browse files
clabbymattsse
andauthored
feat(rpc): Add 4844 checks to ethCallBundle (#7078)
Co-authored-by: Matthias Seitz <[email protected]>
1 parent f217482 commit 72bea5f

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

crates/rpc/rpc/src/eth/bundle.rs

+44-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use crate::eth::{
88
};
99
use jsonrpsee::core::RpcResult;
1010
use reth_primitives::{
11+
constants::eip4844::MAINNET_KZG_TRUSTED_SETUP,
1112
keccak256,
1213
revm_primitives::db::{DatabaseCommit, DatabaseRef},
13-
U256,
14+
PooledTransactionsElement, U256,
1415
};
1516
use reth_revm::database::StateProviderDatabase;
1617
use reth_rpc_api::EthCallBundleApiServer;
@@ -20,7 +21,7 @@ use revm::{
2021
db::CacheDB,
2122
primitives::{ResultAndState, TxEnv},
2223
};
23-
use revm_primitives::EnvWithHandlerCfg;
24+
use revm_primitives::{EnvWithHandlerCfg, MAX_BLOB_GAS_PER_BLOCK};
2425
use std::sync::Arc;
2526

2627
/// `Eth` bundle implementation.
@@ -57,8 +58,33 @@ where
5758
))
5859
}
5960

60-
let transactions =
61-
txs.into_iter().map(recover_raw_transaction).collect::<Result<Vec<_>, _>>()?;
61+
let transactions = txs
62+
.into_iter()
63+
.map(recover_raw_transaction)
64+
.collect::<Result<Vec<_>, _>>()?
65+
.into_iter()
66+
.map(|tx| tx.into_components())
67+
.collect::<Vec<_>>();
68+
69+
// Validate that the bundle does not contain more than MAX_BLOB_NUMBER_PER_BLOCK blob
70+
// transactions.
71+
if transactions
72+
.iter()
73+
.filter_map(|(tx, _)| {
74+
if let PooledTransactionsElement::BlobTransaction(tx) = tx {
75+
Some(tx.transaction.blob_gas())
76+
} else {
77+
None
78+
}
79+
})
80+
.sum::<u64>() >
81+
MAX_BLOB_GAS_PER_BLOCK
82+
{
83+
return Err(EthApiError::InvalidParams(
84+
EthBundleError::Eip4844BlobGasExceeded.to_string(),
85+
));
86+
}
87+
6288
let block_id: reth_rpc_types::BlockId = state_block_number.into();
6389
let (cfg, mut block_env, at) = self.inner.eth_api.evm_env_at(block_id).await?;
6490

@@ -96,8 +122,16 @@ where
96122
let mut results = Vec::with_capacity(transactions.len());
97123
let mut transactions = transactions.into_iter().peekable();
98124

99-
while let Some(tx) = transactions.next() {
100-
let tx = tx.into_ecrecovered_transaction();
125+
while let Some((tx, signer)) = transactions.next() {
126+
// Verify that the given blob data, commitments, and proofs are all valid for
127+
// this transaction.
128+
if let PooledTransactionsElement::BlobTransaction(ref tx) = tx {
129+
tx.validate(MAINNET_KZG_TRUSTED_SETUP.as_ref())
130+
.map_err(|e| EthApiError::InvalidParams(e.to_string()))?;
131+
}
132+
133+
let tx = tx.into_ecrecovered_transaction(signer);
134+
101135
hash_bytes.extend_from_slice(tx.hash().as_slice());
102136
let gas_price = tx
103137
.effective_tip_per_gas(basefee)
@@ -217,4 +251,8 @@ pub enum EthBundleError {
217251
/// Thrown if the bundle does not contain a block number, or block number is 0.
218252
#[error("bundle missing blockNumber")]
219253
BundleMissingBlockNumber,
254+
/// Thrown when the blob gas usage of the blob transactions in a bundle exceed
255+
/// [MAX_BLOB_GAS_PER_BLOCK].
256+
#[error("blob gas usage exceeds the limit of {MAX_BLOB_GAS_PER_BLOCK} gas per block.")]
257+
Eip4844BlobGasExceeded,
220258
}

0 commit comments

Comments
 (0)