mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
fix(rpc): add block number validation in eth_simulateV1 (#21396)
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -96,7 +96,23 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
|
||||
self.spawn_with_state_at_block(block, move |this, mut db| {
|
||||
let mut blocks: Vec<SimulatedBlock<RpcBlock<Self::NetworkTypes>>> =
|
||||
Vec::with_capacity(block_state_calls.len());
|
||||
|
||||
// Track previous block number for validation
|
||||
let mut prev_block_number = parent.number();
|
||||
|
||||
for block in block_state_calls {
|
||||
// Validate block number ordering if overridden
|
||||
if let Some(number) = block.block_overrides.as_ref().and_then(|o| o.number) {
|
||||
let number: u64 = number.try_into().unwrap_or(u64::MAX);
|
||||
if number <= prev_block_number {
|
||||
return Err(EthApiError::other(EthSimulateError::BlockNumberInvalid {
|
||||
got: number,
|
||||
parent: prev_block_number,
|
||||
})
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
let mut evm_env = this
|
||||
.evm_config()
|
||||
.next_evm_env(&parent, &this.next_env_attributes(&parent)?)
|
||||
@@ -234,6 +250,9 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
|
||||
|
||||
parent = result.block.clone_sealed_header();
|
||||
|
||||
// Update tracking for next iteration's validation
|
||||
prev_block_number = parent.number();
|
||||
|
||||
let block = simulate::build_simulated_block::<Self::Error, _>(
|
||||
result.block,
|
||||
results,
|
||||
|
||||
@@ -39,8 +39,13 @@ pub enum EthSimulateError {
|
||||
#[error("Client adjustable limit reached")]
|
||||
GasLimitReached,
|
||||
/// Block number in sequence did not increase.
|
||||
#[error("Block number in sequence did not increase")]
|
||||
BlockNumberInvalid,
|
||||
#[error("block numbers must be in order: {got} <= {parent}")]
|
||||
BlockNumberInvalid {
|
||||
/// The block number that was provided.
|
||||
got: u64,
|
||||
/// The parent block number.
|
||||
parent: u64,
|
||||
},
|
||||
/// Block timestamp in sequence did not increase or stay the same.
|
||||
#[error("Block timestamp in sequence did not increase")]
|
||||
BlockTimestampInvalid,
|
||||
@@ -96,7 +101,7 @@ impl EthSimulateError {
|
||||
Self::IntrinsicGasTooLow => -38013,
|
||||
Self::InsufficientFunds { .. } => -38014,
|
||||
Self::BlockGasLimitExceeded => -38015,
|
||||
Self::BlockNumberInvalid => -38020,
|
||||
Self::BlockNumberInvalid { .. } => -38020,
|
||||
Self::BlockTimestampInvalid => -38021,
|
||||
Self::PrecompileSelfReference => -38022,
|
||||
Self::PrecompileDuplicateAddress => -38023,
|
||||
|
||||
Reference in New Issue
Block a user