Closed c4-bot-4 closed 8 months ago
Picodes marked the issue as primary issue
othernet-global (sponsor) confirmed
Added liquidity is now based on both addedAmount0 and addedAmount1: addedLiquidity = (totalLiquidity * (addedAmount0+addedAmount1) ) / (reserve0+reserve1);
Fixed in: https://github.com/othernet-global/salty-io/commit/0bb763cc67e6a30a97d8b157f7e5954692b3dd68
Picodes marked the issue as satisfactory
Picodes marked the issue as selected for report
Picodes marked the issue as duplicate of #221
Picodes marked the issue as not selected for report
I disagree with the severity of this finding. First of all, the author didn't show how this could break the system (as he stated at the very beginning). The only thing he demonstrated is that the precision isn't always optimal for the calculation of the LP tokens to mint. We are very far from a direct loss of fund, or breaking of the system. At best, this is a questionnable design decision from the developer.
The main benefit of this decision is that such formula ensures that the initial liquidity ratio doesn’t affect the value of a pool share. But what is the impact of such a situation? It seems it hasn't been explained or demonstrated. In fact, the impact is explained in this article here (at the end) : its to account correctly for the fees. Which are zero on Salty.IO.
So, the only thing that holds here is that the precision isn’t always the best, in cases like the one shown by the author of this issue. That’s why I think this cannot be considered high. I would even say its a QA as no fund impact has been demonstrated.
othernet-global marked the issue as disagree with severity
Hi @Picodes
Thank you for your judging.
But I don't think this report is a duplicate of #221
As I stated in my report, there are two issues in Pools._addLiquidity
function:
Pools._addLiquidity
incorrectly assume a larger amount of token can maintain better numeric resolution in Pools.sol#L128-L135
For this issue, it's not mentioned in 221The second part of the report shows a difference with Uniswap but isn't showing why this could be an issue.
As for the first part, I do agree with @InfectedIsm. The impact is very poorly demonstrated and isn't of high severity so I'll switch to partial credit. Thank you for flagging.
Picodes marked the issue as partial-25
Picodes changed the severity to 2 (Med Risk)
Lines of code
https://github.com/code-423n4/2024-01-salty/blob/53516c2cdfdfacb662cdea6417c52f23c94d5b5b/src/pools/Pools.sol#L90-L135
Vulnerability details
Impact
In
Pools._addLiquidity's
implemenation, there are two places that don't conform UniswapV2's whitepaper and algorithm, which might break the system.Proof of Concept
There are two places in Pools._addLiquidity that don't conform with UniswapV2's implemenation. 1) Initialization of liquidity supply in Pools._addLiquidity, the initialization liquidity supply will be maxAmount0 + maxAmount1
but in uniswapV2, the liquidity supply is calculated as:
And the quoting from the UniswapV Core paper:
2) Another issue is that while calclate the liquidity,
Pools._addLiquidity
incorrectly assume a larger amount of token can maintain better numeric resolution in Pools.sol#L128-L135while uniswapV2 using
liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);
to calculate the the liquidity in UniswapV2Pair.sol#L123C13-L123C112To prove the assumption is wrong, suppose there is a pool with tokenX=101e18, and tokenY=10e8 Alice stakes 10e18 TokenX and 99009900 TokenY to make the pool balance, in such case:
Which means
99009900 / 10e8 is smaller
, so the assumption is not correctTools Used
VS
Recommended Mitigation Steps
Assessed type
Uniswap