In this track: Smart contract security foundations
advanced · 4 MIN READ

Checks, effects and interactions

Make the relevant state consistent before handing control away.

LET’S PICTURE IT

A clerk marks a ticket redeemed before asking another desk to deliver the prize.

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.

Check the authorization and inputs

Establish who may act and whether the action’s conditions hold. A frontend disabling a button does not replace checks in the contract.

Apply coherent state effects

Update the accounting needed to preserve the operation’s invariant. Think about the whole related state rather than moving one assignment mechanically.

Treat interaction as a handoff

An external call can execute untrusted code and call back into reachable functions. The state visible at that boundary must satisfy the intended assumptions.

Handle failure consistently

If the interaction fails, choose a response that keeps accounting correct. A propagated revert may restore earlier effects, while a caught failure requires deliberate handling.

Reason about the scenario

check entitlement
record redemption consistently
perform external interaction
handle its outcome

Pseudocode or a simplified scenario for local reasoning. This is not a production contract or a completed security review.

QUICK CHECK · NO PRESSURE

When should relevant accounting normally be coherent?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

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