When calculating platformFees
, precision loss occurs due to Solidity's inherent truncation during division. This results in the protocol collecting fewer fees than intended..
joinDAO() is implemented as follows:
The code calculates platformFees
, which are the fees the user must pay to the protocol. However, it lacks any rounding mechanism to prevent truncation, an inherent issue in Solidity when divisions involve decimals.
To better illustrate this issue, let’s use an example with USDC, a token the protocol will handle, which has only 6 decimal of precision.
Assume tierPrice = 999 wei USDC
The calculation for platformFees would be:
platformFees = (20 * tierPrice) / 100 = (20 * 999) / 100 = 199.8 = 199
In this case, 8 wei of USDC are lost. While this may seem insignificant, when multiplied across all transactions the protocol processes, it can lead to a substantial cumulative amount.
Precision loss in the calculation of platformFees
results in the protocol receiving less fees than intended.
Manual review.
One solution is to use Math.sol from OpenZeppelin to round up the result of platformFees
.
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.