Closed code423n4 closed 1 year ago
Disagree. We only need to update the twap when the price of the AMM changes. Price changes only occur during a swap, so we only need to update twap on a swap. The twap does not get "stale". As time passes, the twap accounts for this time passing as part of its weighting math.
gte620v marked the issue as sponsor disputed
This issue is invalid. TWAP stands for Time Weighted Average Price and should only be updated when there are changes in price. Excluding the first add liquidity which sets the price, other movements of liquidity do not effect price.
kirk-baird marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2022-12-Stealth-Project/blob/fc8589d7d8c1d8488fd97ccc46e1ff11c8426ac2/maverick-v1/contracts/libraries/Twa.sol#L11 https://github.com/code-423n4/2022-12-Stealth-Project/blob/fc8589d7d8c1d8488fd97ccc46e1ff11c8426ac2/maverick-v1/contracts/models/Pool.sol#L121 https://github.com/code-423n4/2022-12-Stealth-Project/blob/fc8589d7d8c1d8488fd97ccc46e1ff11c8426ac2/maverick-v1/contracts/models/Pool.sol#L294
Vulnerability details
Impact
TWA Price should be updated in addLiquidity, removeLiqudity and swap and transferLiquidity
Proof of Concept
I want to quote from the documentation:
https://medium.com/maverick-protocol/maverick-amm-the-revolutionary-amm-that-enables-directional-lping-unlocking-greater-capital-34427f5ac22f
The Twa is crucial component in the protocol,
In the current implementation of the Pool, the twa is only updated when the first user addLiquidity or the swap happens.
However, when underlying liqudity change, the TWAP should be updated, otherwise, a invalid or stale price can be used.
THe operation addLiquidity, removeLiqudity and swap and migrateBinsUpStack and transferLiquidity change underlying liquditiy, so in each operation,
twa.updateValue should be called.
For example, when swap, the price used is:
We does not check if the twa.floor() price is stale or if it is updated after adding or remove liqudity.
Tools Used
Manual Review
Recommended Mitigation Steps
We recommend the project update the TWAP price when a operation change the underlying liqudity.