[M-1] - BidBeastsNFTMarket::placeBid Divide before multiply cause precision loss for the requiredAmount calculation.
Solidity's integer division truncates. Thus, performing division before multiplication can lead to precision loss.
The function placeBid calculates the requiredAmount for a bid based on the previous bid amount and a minimum increment percentage. The division operation is performed before multiplication, which can lead to precision loss.
This is the actual code base for the placeBid function in the BidBeastsNFTMarket contract which is triggered on the --- Regular Bidding Logic --- section of the code.
Likelihood: Medium.
Reason : Every time a bid is placed, there is a risk of precision loss due to the division operation before multiplication.
Impact: Medium.
(Proof of Code)
In the BidBeastsMkartePlaceTest.t.sol unit test file, place the following unit test:
Run the unit test to demostrate the exploit.
By comparing the result of the actual requiredAmount formula against the correctRequiredAmountformula we can realize a round-down error because of integer division before multiplication.
Use the formula proposed at the unit test as correctRequiredAmountformula
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.