When a user provides liquidity with unbalanced balance. It should be the same as swapping tokens and adding lp. However, the liquidity the users get is calculated as follow:
The user can take a share of the swapping fee he's paying. It's like first add the liquidity then swap the tokens.
It may be a design choice. However, the pool is designed to hold billions of dollars. Any extra fee would be amplified. I consider this is a medium-risk issue.
I noticed that imbalanced mint and burnSingle may sometimes have a better price than swapping. It may be a lot of issues involved.
Tools Used
None
Recommended Mitigation Steps
// Note: what is the optimal value of computed
uint256 computed = TridentMath.sqrt((balance0) * (balance1));
// The user should get the lp based on post-swap-fee reserve.
uint256 k = TridentMath.sqrt(uint256(_reserve0 + fee) * _reserve1 + fee);
liquidity = ((computed - k) * _totalSupply) / k;
Handle
broccoli
Vulnerability details
Adding imbalanced liquidity earns extra rewards
Impact
When a user provides liquidity with unbalanced balance. It should be the same as swapping tokens and adding lp. However, the liquidity the users get is calculated as follow:
The user can take a share of the swapping fee he's paying. It's like first add the liquidity then swap the tokens.
It may be a design choice. However, the pool is designed to hold billions of dollars. Any extra fee would be amplified. I consider this is a medium-risk issue.
ConstantProductPool and HybridPool have the same issue. ConstantProductPool.sol#L83-L120
HybridPool.sol#L115-L139
Proof of Concept
I noticed that imbalanced mint and
burnSingle
may sometimes have a better price than swapping. It may be a lot of issues involved.Tools Used
None
Recommended Mitigation Steps