In this track: Execution traces and low-level calls
advanced · 4 MIN READ

Reentrancy across call frames

An external handoff can lead back into unfinished application logic.

LET’S PICTURE IT

A customer can return to a second service window before the first clerk finishes updating the record.

SEE IT FOR YOURSELF
A valid counter call, step by stepStep 1 / 4
A valid counter call, step by stepFunction requestincrement()No argumentsBefore executionstored count0A local teaching example with a defined starting stateIncoming callCheck function dispatchCheck coded conditionsRules passConditions passContinue executionA failed check can revert insteadCalculation0 + 1Result: 1Storage writecount = 1Persists if call succeedsCalculating a local value and storing it are separate stepsPersistent statecount1Later readGetter reports 1No new incrementState, logs and browser display have different roles

This example begins with count zero and a request to call increment(). No real contract is deployed.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Mark the handoff point

An external call transfers control to other code. That code can call back into the original contract or another related contract before the first call returns.

Inspect unfinished state

If accounting still reflects the pre-action state, the callback may repeat an operation or observe an inconsistent condition. The danger depends on the reachable functions and shared state.

Protect the invariant

Apply a coherent state-transition design, suitable interaction ordering and guards where needed. A guard on one function may not cover every cross-function or cross-contract path.

Test the whole call sequence

A hostile mock should attempt relevant callbacks and inspect state at the boundary. A test that only calls the target function once cannot exercise reentry.

Follow the execution

A begins withdrawal
A calls B before consistent accounting
B calls back into A
A’s first frame has not finished

Review the invariant across both frames.

A local conceptual trace with explicit assumptions; this is not a trace of a live transaction.

QUICK CHECK · NO PRESSURE

Can reentry happen before the original external call returns?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.