DeFiFoundry
20,000 USDC
View results
Submission Details
Severity: medium
Invalid

Reentrancy Vulnerability

Summary

he claimTokens() function doesn't check if the bids mapping contains the address before accessing it. This could lead to reentrancy attacks if external calls are made during token transfer.

Vulnerability Details

The contract is potentially vulnerable to reentrancy attacks. Specifically, the claimTokens function allows for external calls to the auctionToken.transfer(msg.sender, claimable) function after state variables like bids[msg.sender] have been modified. If auctionToken is a contract that includes a callback mechanism, a reentrancy attack could be performed by recursively calling the function before the state update is finalized.

Impact

Tools Used

Recommendations

1 / Implement Checks-Effects-Interactions Pattern: Move the token transfer outside of the main logic flow. First, check if the user has bids and calculate the claimable tokens. Then, update the internal state and emit events. Finally, perform the actual token transfer.

2/ Use OpenZeppelin's ReentrancyGuard: Import and use OpenZeppelin's ReentrancyGuard contract. This provides a simple way to prevent reentrancy attacks.

3/ Implement a Token Transfer Function: Create a separate function for token transfers that checks for reentrancy and performs the actual transfer.

4/ Use Block Timestamp for State Updates: Update internal state variables before performing external calls.

Here's an example of how you might modify the claimTokens() function:

import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
contract FjordAuction is ReentrancyGuard {
// ... existing code ...
function claimTokens() external nonReentrant {
uint256 userBids = bids[msg.sender];
if (userBids == 0) {
revert NoTokensToClaim();
}
uint256 claimable = userBids.mul(multiplier).div(PRECISION_18);
// Update internal state
bids[msg.sender] = 0;
emit TokensClaimed(msg.sender, claimable);
// Perform token transfer
auctionToken.transfer(msg.sender, claimable);
}
}

By implementing these changes, you significantly reduce the risk of reentrancy attacks. The nonReentrant modifier ensures that the function cannot be called again during an ongoing transaction, preventing potential exploits through nested calls.

Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

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