Platform: Code4rena
Start Date: 01/08/2023
Pot Size: $91,500 USDC
Total HM: 14
Participants: 80
Period: 6 days
Judge: gzeon
Total Solo HM: 6
Id: 269
League: ETH
Rank: 29/80
Findings: 1
Award: $482.48
🌟 Selected for report: 0
🚀 Solo Findings: 0
482.4792 USDC - $482.48
https://github.com/code-423n4/2023-08-goodentry/blob/main/contracts/TokenisableRange.sol#L338
For some pools like ETH-DAI, BTC-DAI, and many others, claimFee
functionality will always revert due to math overflow in returnExpectedBalanceWithoutFees
calculation --> this will leave all users unable to claim the accrued trading fees at all.
In the returnExpectedBalanceWithoutFees
calculation, it tries to compute the sqrtPriceX96. However, this calculation may overflow for some token pairs for example:
ETH-DAI pair, say TOKEN0 is ETH, and TOKEN1 is DAI: TOKEN0_PRICE will then be 1800 * 1018 TOKEN1_PRICE will then be 1 * 1018 Now, let's look at the calculation:
(2 ** 192 * ((TOKEN0_PRICE * 10 ** TOKEN1.decimals) / TOKEN1_PRICE) = 2**192 * (1800 * 10**18 * 10**18 / (1 * 10**18)) = 1.12 * 10**79
which will exceed uint256
maximum value, leading to integer overflow. This can also happen to other token pairs as well (where the relative token price is sufficiently high and token1 decimals is 18).
Manual Review
((TOKEN0_PRICE * 10 ** TOKEN1.decimals) / TOKEN1_PRICE)
exceeds 264. If yes, then instead of multiplying the value by 2192 in the front, we can reduce it to 2128 in this case to prevent overflow, and then multiply by another 232 outside sqrt.So, it'll look sth like:
uint val = ((TOKEN0_PRICE * 10 ** TOKEN1.decimals) / TOKEN1_PRICE); if (val >= 2**64) { ... sqrt(2**128 * val) * 2**32 ... // pull some factors out of sqrt to prevent overflow } else { ... sqrt(2**192 * val) ... // won't overflow in this case }
Math
#0 - c4-pre-sort
2023-08-10T13:36:16Z
141345 marked the issue as duplicate of #58
#1 - 141345
2023-08-10T13:38:26Z
Maybe not an issue if https://github.com/code-423n4/2023-08-goodentry-findings/issues/58 is fixed
#2 - c4-judge
2023-08-20T17:30:16Z
gzeon-c4 marked the issue as satisfactory