The FjordAuction smart contract contains a critical vulnerability related to precision handling when using USDC (that has 6 decimal places) as the auction token. The contract uses a fixed precision of 1e18 for calculations, which is inappropriate for tokens like USDC with 6 decimal places. This mismatch can result in users with smaller bids receiving no tokens due to precision loss, effectively losing their bids without compensation.
https://github.com/Cyfrin/2024-08-fjord/blob/main/src/FjordAuction.sol#L181
The vulnerability stems from the use of a fixed PRECISION_18 constant (1e18) in the contract, which is suitable for 18 decimal place tokens like Ether but not for 6 decimal place tokens ,USDC. This issue manifests in the auctionEnd()
and claimTokens() functions:
In auctionEnd():
In claimTokens():
Scenario:
Imagine we have an auction for 1,000,000 USDC tokens (6 decimal places). Two bidders participate:
Bidder1: Places a small bid of 0.00002 FjordPoints (equivalent to 2 * 10^13 wei)
Bidder2: Places a larger bid of 2 FjordPoints
Let's calculate this:
totalTokens = 1,000,000 * 10^6 (USDC has 6 decimal places)
totalBids = 2.00002 * 10^18
PRECISION_18 = 10^18
multiplier = (1,000,000 * 10^6 * 10^18) / (2.00002 * 10^18) ≈ 499,997,500,012,499,937.
For Bidder1: claimable = (0.00002 * 10^18 * 499,997,500,012,499,937) / 10^18 ≈ 9,999,950,000 This rounds down to 0 when converted to USDC's 6 decimal places.
For Bidder2: claimable = (2 * 10^18 * 499,997,500,012,499,937) / 10^18 ≈ 999,995,000,024,999,874 This rounds to 999,995 USDC.
Bidder1, despite participating in the auction and spending FjordPoints, receives absolutely nothing in return due to the precision mismatch between the contract's calculations (using 18 decimal places) and USDC's 6 decimal places. This unfairly penalizes smaller bidders and can lead to a loss of funds for these participants.
PoC
run
Result:
Users with smaller bids will lose their entire bid amount without receiving any tokens in return.
Manual Review
Update the multiplier calculation:
Update the claimable token calculation:
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.