Skip to main content

Provide an Example of How Two Functions Might Share a State That Could Be Exploited.

Consider a contract with a withdraw() function and a transfer() function, both of which rely on a userBalances mapping. The withdraw() function might incautiously make an external call to a third-party service before updating the user's balance.

An attacker could use this external call to re-enter the contract and call the transfer() function. Because the userBalances state is not yet updated, the transfer() function would see the original, pre-withdrawal balance, allowing the attacker to transfer funds they should no longer have access to.

How Did the DAO Hack in 2016 Utilize a Reentrancy Attack?
Can a Smart Contract Use More of a Token than What Is Specified in the Allowance?
What Is a Reentrancy Attack in Smart Contracts?
What Specific State Changes (Effects) Should Be Prioritized before an External Call?