The vulnerability lies in the claim function of a smart contract which deals with TempleGold tokens. The function transfers tokens to the caller and then updates the state variable depositors[msg.sender][epochId]. This sequence of operations opens the door for a reentrancy attack, where an attacker can repeatedly call the claim function before the state is updated, allowing them to drain the contract of its tokens.
The attacker initiates the attack by calling the attack function on the Attack contract, specifying the epochId they want to exploit.
This triggers the claim function on the DaiGoldAuction contract.
Inside the claim function, TempleGold tokens are transferred to the attacker before updating the state.
The transfer triggers the onTempleGoldReceived function in the Attack contract.
The onTempleGoldReceived function reenters the claim function before the state is updated, allowing the attacker to claim more tokens than they are entitled to.
This process repeats, draining the DaiGoldAuction contract of its TempleGold tokens until the balance is insufficient for another transfer.
vs code
Update State First: Ensure that any changes to the contract’s state (like updating balances or marking that a function has been executed) are done before making external calls.
Use Reentrancy Guard: Use OpenZeppelin's ReentrancyGuard to prevent reentrant calls to functions.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.