Rounding errors in integer division operations within the LibUnripe and LibChop libraries lead to inaccurate token conversion amounts. This can result in users receiving fewer Ripe Tokens than expected, with potential financial implications and loss of trust in the protocol.
Affected Functions
1: getRecapPaidPercentAmount:
2: _getUnderlying
3: LibChop.chop:
Consider a scenario where a user attempts to convert 1000 Unripe Tokens to Ripe Tokens. Suppose the internal calculations involve:
fertilizedIndex = 100
unfertilizedIndex = 3
The calculation in getRecapPaidPercentAmount would be:
100 * 1000 / 3 = 33333 (truncated from 33333.3333...)
Next, suppose:
balanceOfUnderlying = 50000
supply = 10000
The calculation in _getUnderlying would be:
50000 * 33333 / 10000 = 166665 (truncated from 166665.165...)
The user would expect to receive a precise conversion amount, but due to rounding, they receive 166665 instead of the expected 166666. This discrepancy grows with larger numbers or repeated operations.
Users will receive fewer Ripe Tokens than expected when converting Unripe Tokens, leading to potential financial losses and user dissatisfaction.
Cumulative rounding errors can propagate through the system, compounding inaccuracies over time.
Manual review
1: Scale calculations to use higher precision. For example, multiply the numerator by a scaling factor before performing the division, then scale down the result to the desired precision.uint256 scaledAmount = amount * 1e18; // Scale up by 1e18
uint256 result = (scaledAmount * numerator) / denominator;
result = result / 1e18; // Scale down to the original precision
uint256 result = (numerator * amount + (denominator / 2)) / denominator; // Round to nearest whole number
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.