TempleGold

TempleDAO
Foundry
25,000 USDC
View results
Submission Details
Severity: high
Invalid

Lack of Reentrancy Guard in the `bid` Function

Summary

Vulnerability Details

The function transfers amount of bidToken from msg.sender to the treasury.

  • After transferring the tokens, the function updates the state by increasing the bid amount for the current epoch.

  • An attacker can exploit this function by creating a reentrancy attack where the state is not updated correctly before making another call to bid.

function bid(uint256 amount) external virtual override onlyWhenLive {
if (amount == 0) { revert CommonEventsAndErrors.ExpectedNonZero(); }
bidToken.safeTransferFrom(msg.sender, treasury, amount);
uint256 epochIdCache = _currentEpochId;
depositors[msg.sender][epochIdCache] += amount;
EpochInfo storage info = epochs[epochIdCache];
info.totalBidTokenAmount += amount;
emit Deposit(msg.sender, epochIdCache, amount);
}

https://github.com/Cyfrin/2024-07-templegold/blob/57a3e597e9199f9e9e0c26aab2123332eb19cc28/protocol/contracts/templegold/DaiGoldAuction.sol#L132

Impact

  • Double Spending: The attacker can exploit the reentrancy to call the bid function multiple times, each time thinking they have more tokens than they actually do.

  • State Manipulation: The auction state (e.g., total bid amount) can be manipulated to show incorrect values.

  • Financial Loss: The contract could lose tokens or distribute more Temple Gold than intended due to manipulated bids.

Real-World Example

A famous real-world example of a reentrancy attack is the DAO hack, where an attacker exploited a reentrancy vulnerability to drain millions of dollars from the DAO smart contract.

How Reentrancy Attack Works:

  1. Initial Call: The attacker calls the bid function.

  2. Token Transfer: Before the state is updated, the safeTransferFrom function transfers tokens.

  3. Reenter: Using a fallback function or another contract, the attacker reenters the bid function before the previous execution completes.

  4. Repeat: The bid function is called again, possibly transferring more tokens or manipulating the state multiple times.

Tools Used

vs code

Recommendations

  • Use a reentrancy guard to prevent multiple simultaneous entries into the function.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.