Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 16 additions & 1 deletion crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
let mut blocks: Vec<SimulatedBlock<RpcBlock<Self::NetworkTypes>>> =
Vec::with_capacity(block_state_calls.len());

// Track previous block number for validation
// Track previous block number and timestamp for validation
let mut prev_block_number = parent.number();
let mut prev_timestamp = parent.timestamp();

for block in block_state_calls {
// Validate block number ordering if overridden
Expand All @@ -112,6 +113,19 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
.into());
}
}
// Validate timestamp ordering if overridden
if let Some(time) = block
.block_overrides
.as_ref()
.and_then(|o| o.time)
.filter(|&t| t <= prev_timestamp)
{
return Err(EthApiError::other(EthSimulateError::BlockTimestampInvalid {
got: time,
parent: prev_timestamp,
})
.into());
}

let mut evm_env = this
.evm_config()
Expand Down Expand Up @@ -252,6 +266,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA

// Update tracking for next iteration's validation
prev_block_number = parent.number();
prev_timestamp = parent.timestamp();

let block = simulate::build_simulated_block::<Self::Error, _>(
result.block,
Expand Down
13 changes: 9 additions & 4 deletions crates/rpc/rpc-eth-types/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ pub enum EthSimulateError {
/// 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,
/// Block timestamp in sequence did not increase.
#[error("block timestamps must be in order: {got} <= {parent}")]
BlockTimestampInvalid {
/// The block timestamp that was provided.
got: u64,
/// The parent block timestamp.
parent: u64,
},
/// Transaction nonce is too low.
#[error("nonce too low: next nonce {state}, tx nonce {tx}")]
NonceTooLow {
Expand Down Expand Up @@ -102,7 +107,7 @@ impl EthSimulateError {
Self::InsufficientFunds { .. } => -38014,
Self::BlockGasLimitExceeded => -38015,
Self::BlockNumberInvalid { .. } => -38020,
Self::BlockTimestampInvalid => -38021,
Self::BlockTimestampInvalid { .. } => -38021,
Self::PrecompileSelfReference => -38022,
Self::PrecompileDuplicateAddress => -38023,
Self::SenderNotEOA => -38024,
Expand Down
Loading