Closed code423n4 closed 1 year ago
While the order is changed, I believe the last subtraction makes it so that the any rounding error is not lost, but simply will be paid at the end: https://github.com/code-423n4/2023-01-drips/blob/9fd776b50f4be23ca038b1d0426e63a69c7a511d/src/Drips.sol#L1113
The submission also seems to miss any quantifiable risk so I would downgrade to QA at most.
Will flag but most likely invalid
[dispute validity] This is intended, the dripped amount is rounded down at the end of the cycle, so each cycle drips the same amount.
CodeSandwich marked the issue as sponsor disputed
GalloDaSballo marked the issue as unsatisfactory: Insufficient proof
Lines of code
https://github.com/code-423n4/2023-01-drips/blob/main/src/Drips.sol#L1103-L1114
Vulnerability details
Impact
In the
_drippedAmt()
function of theDrips.sol
contract, the assembly is used to calculate the amount dripped over a time range. Inside the assemblyamtPerCycle
is calculated by multiplyingcycleSecs
andamtPerSec
and dividing by_AMT_PER_SEC_MULTIPLIER
to remove the decimal places introduced byamtPerSec
. Due to the divisionamtPerCycle
will be rounded down to the nearest uint value. And the roundedamtPerCycle
is then multiplied byendedCycles
to calculateamt
value. Hence this multiplication enhances the rounding error introduced by the rounding down of theamtPerCycle
. Thus calculatedamt
value will be less than precise value.Similar rounding down is observed in the calculation of the
amtEnd
andamtStart
.Proof of Concept
Since the division by
_AMT_PER_SEC_MULTIPLIER
rounds down theamtPerCycle
, its multiplication byendedCycles
results in rounding error, which aggravates with the increasingendedCycles
number. Hence theamt
value is susceptible to rounding error.https://github.com/code-423n4/2023-01-drips/blob/main/src/Drips.sol#L1103-L1114
As shown above the calculation of
amtEnd
andamtStart
also introduces the rounding error to the final calculation of theamt
value.Tools Used
Manual and VS Code
Recommended Mitigation Steps
It is not required to eliminate the decimal places introduced by
amtPerSec
(by dividing by_AMT_PER_SEC_MULTIPLIER
) during each step of theamt
value calculation. Theamt
value can be calculated with the decimal places at each step of the calculation and ones the final amt value is determined then can divide by_AMT_PER_SEC_MULTIPLIER
to remove the decimal values and return the preciseamt
value.Code can be rewritten as follows: