How Does a Reentrancy Attack Specifically Exploit Smart Contract Logic?
A reentrancy attack occurs when an external call from Contract A to Contract B is made, and Contract B then calls back into Contract A before A has finished updating its state, specifically the balance. This allows the attacker to recursively withdraw funds multiple times from the victim contract before the initial withdrawal transaction completes and the balance is properly reduced.
The classic defense involves using the Checks-Effects-Interactions pattern to update the state before making external calls.