Closed code423n4 closed 1 year ago
The twap values are in units of ticks and tick is capped by MAX_TICK = 460540
. So the mentioned overflows never happen
As @hansfriese said. This is not an issue.
gte620v marked the issue as sponsor disputed
Agreed that these values will not overflow due to the MAX_TICK
limit.
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#L18 https://github.com/code-423n4/2022-12-Stealth-Project/blob/fc8589d7d8c1d8488fd97ccc46e1ff11c8426ac2/maverick-v1/contracts/libraries/Twa.sol#L12
Vulnerability details
Impact
Unsafe casting operation in TWA.sol truncation price.
Proof of Concept
the pool relies on the TWAP price to function properly, however, the code in TWA.sol sliently downcasting the price, which can truncate the price and affect user's trading unexpectedly.
the most damaging truncation is in
as we can see, the original int256 is truncated into int96 for getTwa price and for floor price truncate from int256 to int32.
Tools Used
Manual Review
Recommended Mitigation Steps
We recommend the project use safeCasting like the project did in other code place.
For example,
In the Pool, the safeCasting is properly used when adding liquidity to used to make sure the code does not truncate value sliently.