requiredAmount in the BidBeastsNFTMarketPlace::placeBid function leads to precision lossNormal behaviour: In the NFT auction marketplace, every bid has to be higher compared to the previous bid by BidBeastsNFTMarketPlace::S_MIN_BID_INCREMENT_PERCENTAGE.
Problematic behaviour: To calculate the minimum new bid required, the previousBidAmount is first divided by 100 and then multiplied by (100 + S_MIN_BID_INCREMENT_PERCENTAGE). The division by 100 leads to precision loss as the remainder of integer division is truncated in Solidity.
Root cause:
Likelihood: High
Precision loss occurs whenever previousBidAmount % 100 != 0.
Impact: Low
The impact is low as the maximum precision loss in this case is max division remainder * (100 + S_MIN_BID_INCREMENT_PERCENTAGE) = 99 * 105 = 104 wei, which is 0.00000000000104 % of the minimum allowed bid amount.
As a PoC add the following Fuzz test to the Foundry test suite and run with forge test --fuzz-runs 10000 --mt testFuzz_requiredAmountLosesPrecision_FuzzedPreviousAmount:
To mitigate the vulnerability multiply first before dividing:
Integer division in requiredAmount truncates fractions, allowing bids slightly lower than intended.
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.