Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
LABS
Glossary

Simulation Phase

A pre-execution validation step in account abstraction where a user operation is tested for validity and gas cost before being included in a block.
Chainscore © 2026
definition
BLOCKCHAIN VALIDATION

What is the Simulation Phase?

A critical pre-execution step in blockchain transaction processing where the outcome of a transaction is predicted before it is finalized on-chain.

The Simulation Phase is the process of virtually executing a transaction against the current state of a blockchain to predict its outcome—including success, failure, gas consumption, and state changes—without broadcasting it to the network. This is performed by running the transaction code in a sandboxed environment, often called a virtual machine or simulator, that mirrors the live network's rules and state. The primary goals are to estimate gas fees, validate logic, and detect potential errors or security vulnerabilities before committing real assets. This phase is essential for developers building dApps and for wallets providing accurate fee estimations and transaction previews to users.

During simulation, the system checks for several critical failure points: insufficient gas (out-of-gas errors), failed smart contract conditions (e.g., require statements), and reverts. It also calculates the precise gas used and any resulting state changes, such as token balances or storage updates. Advanced simulation can model complex interactions, including MEV (Miner/Maximal Extractable Value) opportunities and the impact of pending transactions in the mempool. Tools like Tenderly, Hardhat, and Ganache provide robust simulation environments for development and debugging, allowing developers to test transactions against forked mainnet states.

For end-users, the simulation phase is often invisible but crucial. Wallets like MetaMask use it to generate the familiar transaction confirmation screen, showing the estimated gas cost and predicting potential token approvals or transfers. In the context of rollups and Layer 2 solutions, simulation is used to validate transactions before they are batched and submitted to the base layer (L1), ensuring efficiency and cost-effectiveness. The rise of flashbots and private transaction bundles has also made simulation a key tool for searchers and validators to optimize transaction ordering and profitability.

how-it-works
BLOCKCHAIN VALIDATION

How the Simulation Phase Works

A technical breakdown of the simulation phase, a critical pre-execution step in blockchain transaction processing that validates logic and predicts outcomes before committing to the ledger.

The simulation phase is a deterministic, read-only execution environment where a blockchain node or client processes a transaction locally to verify its validity and predict its outcome without altering the on-chain state. This process, also known as dry-running a transaction, involves executing the transaction's code against a recent copy of the blockchain's state to check for errors, estimate gas fees, and determine the final state changes. It is a fundamental mechanism for ensuring transaction safety and providing user feedback before broadcast.

During simulation, the node constructs a virtual machine (VM) context identical to the one used for actual execution but with key constraints: all operations are read-only, and any attempted state modifications are tracked in a temporary sandbox. The phase validates critical preconditions such as - sufficient account balance, - correct smart contract logic, - proper authorization (signatures), and - adequate gas for the computation. This prevents users from submitting transactions that are destined to fail, saving on wasted gas fees and network congestion.

For developers and applications, the simulation phase is essential for building reliable user experiences (UX). Wallets use it to provide accurate gas estimates, while decentralized applications (dApps) simulate contract interactions to show users the precise outcome—such as token swap amounts or lending rates—before they sign the transaction. Services like Chainscore's Transaction Simulator formalize this process into an API, offering enhanced debugging, risk scoring, and state diffs by simulating transactions against multiple blockchain forks and future states.

Under the hood, simulation relies on accessing a state provider—a service that supplies the necessary blockchain data (account balances, contract code, storage slots). The fidelity of a simulation depends entirely on the accuracy and freshness of this state data. Advanced simulation tools can also execute "what-if" scenarios, such as simulating a transaction with a higher gas price or at a future block, to model complex DeFi strategies or arbitrage opportunities without financial risk.

The phase is distinct from estimation, which typically only calculates gas, and from static analysis, which reviews code without execution. True simulation executes the bytecode, making it the definitive method for predicting the behavior of Turing-complete smart contracts. Its role is expanding with account abstraction (ERC-4337) and intents-based systems, where complex user operations require robust pre-checking to ensure bundle viability before submission to a mempool or bundler.

key-features
MECHANICAL BREAKDOWN

Key Features of the Simulation Phase

The simulation phase is a pre-execution step where a transaction's effects are computed to verify safety and estimate costs without altering on-chain state. This section details its core operational components.

01

Stateful Pre-Execution

A simulation is a stateful computation that uses a copy of the current blockchain state (e.g., account balances, smart contract storage) as its starting point. It processes the transaction logic step-by-step, tracking all potential state changes, reverts, and gas consumption. This is distinct from a static analysis, which only examines code without runtime context.

02

Gas Estimation & Validation

A primary function is to calculate the precise gas required for execution. The simulator runs the transaction and sums the gas cost of every opcode. This provides an accurate gas estimate for users and allows nodes to validate that the gas limit in the transaction header is sufficient, preventing out-of-gas failures during actual execution.

03

Revert & Error Detection

The phase detects all possible execution failures before they are broadcast. This includes:

  • Reverts from failed require/assert statements.
  • Insufficient funds for value transfers.
  • Invalid opcode sequences or stack over/underflows.
  • Failed signature verification. By surfacing these errors, it prevents wasted gas on doomed transactions.
04

Read-Only State Access

During simulation, all reads from the blockchain state (e.g., balanceOf, getReserves) are performed on the forked state copy. However, any attempted writes are discarded after the simulation completes. This ensures the canonical state remains immutable until a valid, signed transaction is included in a block.

05

MEV & Frontrunning Analysis

Searchers and validators use simulations to analyze the profitability of Maximal Extractable Value (MEV) opportunities. By simulating bundles of transactions in different orders, they can identify arbitrage, liquidations, or optimal trade sequencing. This analysis occurs in private mempools or builder environments.

technical-details
SIMULATION PHASE

Technical Details: The `simulateValidation` and `simulateHandleOp` Functions

The simulation phase is a critical pre-execution step in the ERC-4337 User Operation lifecycle, designed to validate the feasibility and safety of a bundled transaction before it is included on-chain. It is implemented through two core functions: `simulateValidation` and `simulateHandleOp`.

The simulation phase is a security and efficiency mechanism in ERC-4337 that allows a Bundler to verify the validity and resource requirements of a UserOperation before committing it to the blockchain. This off-chain dry-run prevents the bundler from paying for gas on operations that will revert, protecting its economic viability. The phase is executed in two distinct steps: first, simulateValidation checks the operation's signature and paymaster validity; second, simulateHandleOp simulates the full execution path, including the target contract call.

The simulateValidation function is the initial guard. It performs static checks on the UserOperation, such as verifying the ECDSA signature or ERC-1271 smart contract signature of the sender, validating the paymaster stake and deposit, and ensuring the operation does not use banned opcodes. Its primary output is a set of gas limits and a validAfter and validUntil timestamp window for the operation. Crucially, this function must be view and cannot statefully modify the blockchain, ensuring the simulation is free and non-invasive.

Following successful validation, the simulateHandleOp function executes a full simulation of the operation's core logic. It calls the EntryPoint contract's internal _validateAndExecute logic in a controlled environment, which in turn calls the sender's smart account for validation and the target contract for execution. This step calculates the precise gas consumption for both validation and execution, identifies any forbidden storage accesses (a key anti-reversion measure), and ensures the paymaster logic functions correctly. The bundler uses these gas estimates to price the operation competitively and safely.

A fundamental rule of the simulation phase is the ban on state changes. Both simulation functions must be view or pure and cannot persist any changes to blockchain state. To enforce this, the EntryPoint uses the STATICCALL opcode during simulation, which will revert if the called code attempts a state modification. Furthermore, the simulation tracks storage accesses; if the real execution later accesses storage outside the pre-declared set, it will revert. This prevents simulation griefing attacks where a contract behaves differently during simulation and actual execution.

The outputs of this phase are essential for the bundler's workflow. The gas limits and timestamps from simulateValidation determine if and when the operation can be bundled. The detailed execution trace from simulateHandleOp provides the data needed to construct a valid handleOps transaction with appropriate gas parameters. By front-running the costs and failure modes, the simulation phase enables a robust and decentralized network of bundlers, which is foundational for the account abstraction ecosystem's security and user experience.

security-considerations
SIMULATION PHASE

Security Considerations & Limitations

The simulation phase is a critical pre-execution step where a transaction is virtually run to predict its outcome. While powerful, it has inherent security assumptions and limitations that developers must understand.

01

State Assumption Risk

Simulations are based on a snapshot of blockchain state at a specific block. This creates a temporal vulnerability where the actual state at execution time may differ, leading to failed or exploited transactions. Key risks include:

  • Front-running: A malicious actor observes your simulated transaction and submits their own with a higher gas fee.
  • State changes: Another transaction confirms between simulation and execution, altering balances, allowances, or pool reserves.
  • Oracle price updates: Critical price feeds can change, making a simulated arbitrage or liquidation unprofitable.
02

Gas Estimation Inaccuracy

Simulated gas costs are estimates, not guarantees. Out-of-gas errors during live execution remain a primary cause of transaction failure. This is due to:

  • Path-dependent opcodes: Instructions like SSTORE and SLOAD have variable gas costs based on prior state, which simulation may not perfectly model.
  • Complex contract interactions: Unforeseen reverts in nested calls can cause early termination, consuming less gas than estimated.
  • Network conditions: Base fee volatility and priority fee (tip) bidding wars can render a simulation's gas prediction insufficient.
03

MEV Extraction Vulnerability

The act of simulating a profitable transaction can reveal it to searchers and MEV bots who monitor the public mempool or use privileged access (e.g., to RPC providers). This exposes users to:

  • Sandwich attacks: For token swaps, bots can buy before and sell after the user's transaction, worsening their price.
  • Generalized front-running: The profitable logic itself can be copied and executed first.
  • Privacy leakage: Simulation requests can reveal a wallet's trading strategy or intent before any transaction is signed.
04

RPC Provider Trust & Centralization

Simulations rely entirely on the integrity and correctness of the RPC provider. This introduces centralization and trust risks:

  • Malicious or buggy nodes: A provider could return incorrect simulation results to induce failed transactions or losses.
  • Censorship: Providers could selectively fail or delay simulations for certain types of transactions.
  • Service reliability: Downtime or rate-limiting at the RPC layer breaks simulation-dependent applications. Most providers are not Byzantine Fault Tolerant.
05

Limitations in Modeling Complexity

Simulations cannot perfectly model all on-chain execution paths, especially those involving:

  • True randomness: Outcomes from verifiable random functions (VRFs) or block hashes are unknown until the block is mined.
  • Cross-chain or layer-2 interactions: Simulations are typically isolated to one chain's state; they cannot account for pending actions on a bridging contract or state roots from other layers.
  • Extreme edge cases: Certain complex reentrancy patterns or deep call stack manipulations may behave differently in a simulated vs. live environment.
06

Mitigation Strategies

To reduce risks, developers implement several defensive strategies:

  • Slippage protection: Using tight tolerance bounds on expected output amounts for swaps.
  • Deadline parameters: Setting a hard timestamp (deadline) after which the transaction will revert.
  • Private transaction submission: Using services like Flashbots Protect or Taichi Network to submit transactions directly to block builders, bypassing the public mempool.
  • Local forking: Running simulations against a local, forked version of the chain for more control and privacy, though this adds complexity.
  • Redundant simulation: Simulating against multiple, independent RPC providers to check for consensus on the result.
ARCHITECTURAL COMPARISON

Simulation Phase vs. Traditional Transaction Validation

Contrasts the pre-execution simulation model used by some modern blockchains with the conventional, on-chain-only validation process.

Feature / MetricSimulation PhaseTraditional Validation

Execution Environment

Off-chain sandbox (e.g., RPC node)

On-chain state (block producer)

Primary Goal

Predict outcome & estimate gas before broadcast

Finalize state transition & reach consensus

State Access

Read-only fork of chain state

Read-write access to live chain state

Gas Estimation

Deterministic via execution trace

Heuristic / historical averages

Failure Cost

Zero gas (failed simulation)

Gas spent (failed transaction)

Frontrunning Detection

Explicit via simulation of mempool

Implicit, requires manual analysis

Key Enabling Tech

State forking, EVM tracing

Consensus protocol, execution client

User Experience

Predictable, with pre-flight checks

Unpredictable for complex interactions

ecosystem-usage
SIMULATION PHASE

Ecosystem Usage: Who Performs Simulation?

Transaction simulation is a critical security and optimization step performed by various actors across the blockchain ecosystem to predict outcomes before execution.

03

Block Builders & Validators

In Proof-of-Stake systems like Ethereum, block builders simulate the mempool to construct the most profitable block. Validators then re-simulate the proposed block to verify its validity and ensure it doesn't contain invalid transactions that would cause them to be slashed. This dual-layer simulation is core to consensus security.

12 sec
Avg. Block Time (Ethereum)
06

End-User Applications (dApps)

Decentralized applications integrate simulation to improve UX. A lending dApp simulates a liquidation to show a user's health factor. A DEX aggregator simulates multiple trade routes to find the best price. This provides pre-transaction transparency, showing exact output amounts, price impact, and potential errors directly in the UI.

< 1 sec
Typical UI Simulation Latency
SIMULATION PHASE

Frequently Asked Questions (FAQ)

Essential questions and answers about the simulation phase in blockchain transactions, covering its purpose, mechanics, and practical implications for developers and users.

A simulation phase is a preliminary, read-only execution of a smart contract transaction on a local node or specialized service to predict its outcome before it is broadcast to the network. It works by processing the transaction against the current state of the blockchain without committing any changes, allowing users to see potential results, gas consumption, and errors. This is a critical tool for user experience (UX) and security, as it prevents failed transactions and wasted gas fees. Services like Tenderly, OpenZeppelin Defender, and the Ethereum Execution API's eth_call method are commonly used to run these simulations. The phase evaluates all logic, including contract calls, state changes, and event emissions, providing a dry run of the transaction's execution path.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected direct pipeline