Multiple reentrancy vulnerabilities have been identified in the FjordAuction contract. These vulnerabilities occur in different functions where external calls are made before updating state variables or emitting events, breaking the Checks-Effects-Interactions pattern. These vulnerabilities could be exploited by malicious actors to manipulate auction outcomes, withdraw tokens without proper checks, or disrupt the auction process. Below is a detailed vulnerability report along with a proof-of-concept (PoC) fuzz-test using Foundry.
bid FunctionLocation: FjordAuction.bid
Description: The fjordPoints.transferFrom function call occurs before emitting the BidAdded event, allowing a reentrant call to manipulate bids and potentially disrupt the auction.
Code Snippet:
unbid FunctionLocation: FjordAuction.unbid
Description: The fjordPoints.transfer function call occurs before emitting the BidWithdrawn event, allowing a reentrant call to manipulate bid withdrawals and disrupt the auction.
Code Snippet:
claimTokens FunctionLocation: FjordAuction.claimTokens
Description: The auctionToken.transfer function call occurs before emitting the TokensClaimed event, allowing a reentrant call to manipulate token claims and disrupt the auction.
Code Snippet:
Add this two files to a folder inside the test folder
ReentrancyAttack.sol
FjordAuctionTest.sol:
Run `forge test --match-contract FjordAuctionTest -vvvvv``
Test Contract: FjordAuctionTest
Test Case: testFuzz_ReentrancyAttack(uint256)
Runs: 259
Average Execution Time: 215302 gas units
Deploy Contracts: ERC20Mock, FjordAuction, ReentrancyAttack.
Mint Tokens:
FjordAuctionTest: 1000 Tokens.
ReentrancyAttack: 100 Tokens.
Token Transfers and Approvals: Set up ReentrancyAttack with initial tokens and approvals.
Preparation: Transfer and approve 100 tokens to ReentrancyAttack.
Attack Execution:
Initial Bid Attempt: ReentrancyAttack:attack(1435).
Reentrant Call: Internal bid call triggered within attack contract.
Logs: Confirmation of successful bids and approvals.
Balance Assertions: Final check of ReentrancyAttack's balance confirms reentrancy by showing increased funds greater than expected (1435 * 2 tokens).
The output demonstrates that the ReentrancyAttack contract was able to reenter the FjordAuction contract and successfully manipulate its balance:
Initial Tokens: 100 tokens.
Post-Attack Tokens: Increased balance, validating reentrancy exploit.
Assertion: Balance > 2870 tokens post-exploit, proving the vulnerability.
This test proves the presence of a reentrancy vulnerability in the FjordAuction contract.
Manipulated Auction Outcomes: Reentrancy attacks could lead to unauthorized or manipulated auction outcomes, allowing malicious actors to gain more tokens than they are entitled to.
Unauthorized Withdrawals: Attackers could withdraw tokens multiple times or manipulate bid withdrawals, leading to loss of funds.
Disrupted Auction Process: Reentrancy could cause the overall auction process to malfunction, affecting the fairness and integrity of the auction.
Manual Code Review
Foundry
Follow Checks-Effects-Interactions Pattern: Ensure all state changes and event emissions occur before any external calls.
bid:
unbid:
claimTokens:
Use Reentrancy Guards: Implement Reentrancy guards from OpenZeppelin's ReentrancyGuard to prevent reentrant calls.
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.