Trace execution and rollback
By the end, explain the diagram in your own words, solve the case and justify the correction.
Prerequisites : Ethereum accounts and transactions · Ethereum gas and EIP-1559
Level 2 · Intermediate →Reading path · 10 / 35 · Intermediate
The Ethereum Virtual Machine executes instructions deterministically.
The essentials
The Ethereum Virtual Machine executes instructions deterministically. Nodes starting from the same state and processing the same operations should reach the same result. A contract cannot freely fetch an arbitrary web price during execution; external information needs an explicit input mechanism such as an oracle.
How it works
Contracts can call other contracts, combining a swap, loan and repayment in one transaction. If a failure reverts the whole transaction, its state changes are rolled back while consumed computation still costs gas. Atomicity does not guarantee that the trade was economically sensible.
What to watch
Some deployed code is immutable; proxy systems can change the logic used at a stable address. Inspect upgrade authorities, delays and key controls. An audit of one implementation does not automatically cover a later upgrade. Composability also creates dependencies: another contract’s pause or failure can affect an otherwise correct application.
Understand the details
The EVM executes instructions deterministically against a given state. Contract storage persists between transactions; temporary execution memory does not. A call can invoke another contract, which may invoke more code. This composability is useful but expands the behavior that must be considered when reviewing a seemingly simple action.
Boundaries and common mistakes
A revert rolls back state changes within the reverted scope, while consumed gas still matters. A caller may deliberately handle a failed subcall, so not every internal failure means the entire transaction failed. Upgradeable proxies add another distinction: the address a user calls can delegate behavior to implementation code that may change under governance or administrator control.
The mechanism at a glance
- Initial state
- A calls B
- Success or handled failure
- Commit or revert scope
Apply the lesson to a case
Contract A records an order, calls contract B, then requires a successful result. B fails and A reverts. Trace the order record, token movement and fee. Then consider how the result differs if A catches the failure and continues without moving tokens.
A successful receipt only indicates that top-level execution did not revert. The expected economic event may not have occurred. Match contract address, decoded events and final balances to the intended action. Logs from reverted execution are not committed as successful transaction events.
Terms in this lesson
- Oracle
- A mechanism that supplies a contract with information originating outside its immediate execution context.
- Gas
- A measure of execution resources; gas units and the price per unit are separate quantities.
Prepare a correction note
Describe the passage and the proposed correction. This creates a local note for you to share; it sends nothing. Do not include personal or confidential information.