The PRECISION_18 variable is used in FjordAuction::auctionEnd and FjordAuction::claimTokens to maintain precision during calculation of the distribution of auction tokens. However when the total amount of tokens or the bids placed are too high comapred to PRECISION_18, it causes a precision loss. It allows high value bids or tokens with low decimals to cause a precision loss resulting in bidders not getting the expected amount of tokens and small amount of tokens being stuck in the contract, which cannot be claimed or retrieved, leading to permanent loss of those tokens.
Relevant links
https://github.com/Cyfrin/2024-08-fjord/blob/main/src/FjordAuction.sol#L197
https://github.com/Cyfrin/2024-08-fjord/blob/main/src/FjordAuction.sol#L217
The FjordAuction uses the PRECISION_18 variable to maintain precision during distribution of auction token among bidders. This value is used in FjordAuction::auctionEnd to calculate the multiplier for FjordAuction::claimTokens function and it is also used in FjordAuction::claimTokens to calculate the exact no of tokens a bidder should receive. If PRECISION_18 variable is too low compared to the total amount of tokens or the bids placed, it causes a rounding error or a precision loss, especially with high value bids or tokens with low decimals.
Small amount of tokens are stuck in the contract, which cannot be claimed or retrieved. It also means that bidders are not getting the expected amount of tokens as they are lost due to precision lost.
The impact is demonstrated with the following test, which can be executed with forge test --mt testTokensAreNotLostDuringCalculation.
This test confirms that tokens are being stuck in the contract and the bidders are not getting the expected amount of tokens if the bidAmount is high and the decimal of the auction token is low.
Manual Review, Foundry
Increase the value of PRECISION_18 to 1e28 or higher to ensure that the new precision variable is always larger than any number leading to accurate distribution. Also rename PRECISION_18 to reflect the updated value (e,g, PRECISION_28).
After adding this change, you can rerun the poc test provided earlier to verify that the bidders are getting the expected amount of tokens and tokens are not stuck inside the contract.
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.