Closed code423n4 closed 1 year ago
This is not an issue. For all other ticks besides the active tick, the bin.addLiquidity computes the reserve ratio: https://github.com/code-423n4/2022-12-Stealth-Project/blob/main/maverick-v1/contracts/libraries/Bin.sol#L35-L40
We use the fact that if we aren't in the active tick, then the bin is either all A or all B, so we don't care about the existing reserves in those cases.
This finding is somewhat related to https://github.com/code-423n4/2022-12-Stealth-Project-findings/issues/103#issuecomment-1354109865
gte620v marked the issue as sponsor disputed
As the sponsor has stated, the reserve ratio is the same for all bins in the active tick.
For bins outside the active tick the value must be calculated since one side is always zero.
kirk-baird marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2022-12-Stealth-Project/blob/main/maverick-v1/contracts/models/Pool.sol#L113-L176
Vulnerability details
Impact
When doing
Pool.addLiquidity
, it would callbin.addLiquidity
to add liquidity to the bins. And the calculation inbin.addLiquidity
should be based on the amount of new tokens and the bin’s existing reserves.However,
Pool.addLiquidity
usestemp.deltaA
andtemp.deltaB
as the bin’s existing reserves. Buttemp.deltaA
andtemp.deltaB
are calculated from_firstKindAtTickLiquidity(currentState.activeTick);
. Which is not the bin’s existing reserves. This issue would causebin.addLiquidity
to calculate inaccurate results.Proof of Concept
Pool.addLiquidity
usestemp.deltaA
andtemp.deltaB
as the bin’s existing reserves.(temp.reserveA, temp.reserveB) = _firstKindAtTickLiquidity(currentState.activeTick);
And uses them as the bin’s existing reserves.https://github.com/code-423n4/2022-12-Stealth-Project/blob/main/maverick-v1/contracts/models/Pool.sol#L113-L176
Tools Used
None
Recommended Mitigation Steps
Use the bin’s existing reserves.