Why Must State Updates Occur before External Calls?
State updates must occur before external calls to prevent a reentrancy attack. If an external call is made before the contract's state variables (like a user's balance) are updated, the external contract can recursively call back into the original function.
The original function will then execute again, seeing the old, un-updated state, allowing the attacker to withdraw funds repeatedly. By updating the state first, the re-entrant call will see the correct, updated balance and fail the check, protecting the funds.
Glossar
Internal Calls
Mechanism ⎊ Internal Calls, within cryptocurrency and derivatives markets, represent privately disseminated information regarding order flow or trading intentions originating from institutional participants or market makers.
State Change
Transition ⎊ The atomic update of the distributed ledger's state, triggered by the successful validation of a new block, which incorporates all new transactions and modifies account balances or contract storage.
State Updates
Calibration ⎊ State updates within cryptocurrency, options, and derivatives markets represent the iterative refinement of model parameters to align theoretical pricing with observed market behavior, a process crucial for risk management and trading strategy execution.
State Variables
Mechanism ⎊ State variables, within cryptocurrency and financial derivatives, represent the core inputs defining a system’s present condition, crucial for modeling price dynamics and risk assessment.
External Call
Interaction ⎊ This describes a smart contract's necessary communication with an entity outside its immediate execution environment, most commonly an oracle network to fetch real-world asset prices or event outcomes.
External Calls
Call ⎊ External calls, within cryptocurrency derivatives and options trading, represent off-exchange communications impacting price discovery and order flow.