🤖Simulation
Ethereum uses simulation to ensure UserOperation validity and finance. This process, driven by protocol rules, isolates data access and validates against strict criteria, ensuring network integrity.
Simulation Rationale Explained
For the Ethereum network to function effectively, it's imperative that every UserOperation
submitted for inclusion in the blockchain is both valid and able to finance its execution. To ensure this, the network employs a "simulation" mechanism before the actual execution. Here’s a breakdown of the reasoning behind this simulation process:
Validity & Cost Coverage Assurance:
Before adding a
UserOperation
to the mempool or a bundle, the network needs to ascertain two things:The
UserOperation
is genuine and adheres to the protocol rules.The
UserOperation
has sufficient funds to cover its execution cost.
Predictability & Consistency:
When simulating, it's crucial to ensure that the outcome remains consistent when the
UserOperation
is actually executed on-chain.To maintain this predictability, the simulation prohibits the
UserOperation
from accessing dynamic blockchain elements like the current block time, block number, or block hash. This is because these values can vary between the time of simulation and the time of actual execution, leading to discrepancies.
Isolated Access to Data:
A key principle for simulation is isolation. A
UserOperation
should only be able to access data related to its sender address.The reasoning behind this is simple: if multiple
UserOperations
could access the same storage, then a single alteration in the state could potentially invalidate numerousUserOperations
. This could lead to inefficiencies or even potential security vulnerabilities.
Interaction with Special Contracts:
Three particular types of contracts play a crucial role in the interaction with the user account:
Factory (initCode): This is responsible for deploying the contract.
Paymaster: This can cover the gas costs for the transaction, ensuring that even if the originating account doesn't have sufficient funds, the transaction can still be executed.
Signature Aggregator: This will be further elaborated upon later but pertains to signature management.
Each of these contracts, like the
UserOperation
, is also bounded by access restrictions. They are limited in their storage interactions to ensure that the validation processes forUserOperations
remain isolated and independent.
In essence, the simulation rationale is designed to maintain the integrity, efficiency, and security of the Ethereum network. By ensuring each UserOperation
is valid and its effects isolated, the network can maintain a smooth and predictable operation.
Simulation of a UserOperation Validation Explained
When a UserOperation needs to be validated, a simulation process is performed. Here’s a step-by-step breakdown of how this process works:
Initiation of the Simulation:
The client makes a view call to
simulateValidation(userop)
.This method is unique in that it always reverts with
ValidationResult
as a successful response.If the call reverts due to any other error, the client must reject the given
userOp
.
Simulation Steps:
If
initCode
is present, the account is created.The method
account.validateUserOp
is called.If a paymaster is specified,
paymaster.validatePaymasterUserOp
is invoked.
Validity Timestamps:
The methods
validateUserOp
orvalidatePaymasterUserOp
can providevalidAfter
andvalidUntil
timestamps, establishing when the UserOperation can be validly executed on-chain.If a
UserOperation
is close to expiration, nodes can choose to drop it.
Opcode Restrictions:
There are specific opcodes which are forbidden or have particular rules:
The
GAS
opcode is not allowed unless it's immediately followed by one of the call opcodes: {CALL
,DELEGATECALL
,CALLCODE
,STATICCALL
}.CREATE2
opcode is permitted only once ifop.initcode.length
is not zero.
Storage Access Limitations:
The simulation restricts access to the storage in the following ways:
Direct access to the self storage of the entity (factory or paymaster) is allowed, but the entity needs to be staked.
Access to the account storage is permitted.
Storage that's used by another UserOp sender in the same bundle is forbidden.
Limitations on Call Opcodes:
For the
CALL
opcodes (CALL
,DELEGATECALL
,CALLCODE
,STATICCALL
):They mustn't use any value unless it's from the account to the entry point.
The destination address must have some code.
Calls to EntryPoint’s methods are restricted.
Other Restrictions:
Address checks using
EXTCODEHASH
,EXTCODELENGTH
, andEXTCODECOPY
opcodes have specific limitations.If transient storage is enabled, any storage slots defined in EIP-1153 must adhere to the same rules as persistent storage.
In essence, the simulation process ensures that every UserOperation is validated against a set of strict rules before it gets executed. This process is crucial for maintaining the integrity, security, and efficiency of the Ethereum network.
Last updated