Open code423n4 opened 1 year ago
Disagree. If we just define the TWA such that the price at the first time instant is also the price for the lookback period before the pool was started, then the TWA is valid.
gte620v marked the issue as sponsor disputed
I consider this issue to be a Low severity issue.
I appreciate the wardens sentiment on whether the time before the start should be included in the TWA and attributed to the initial price or if it should be ignored. However, both designs are valid.
kirk-baird changed the severity to QA (Quality Assurance)
kirk-baird marked the issue as grade-b
Adding #81 as a duplicate I consider this to be a grade-a
QA report as there are two unique issues not included in other reports which are of Low severity.
kirk-baird marked the issue as grade-a
Lines of code
https://github.com/code-423n4/2022-12-Stealth-Project/blob/fc8589d7d8c1d8488fd97ccc46e1ff11c8426ac2/maverick-v1/contracts/libraries/Twa.sol#L21
Vulnerability details
Impact
In function
getTwa()
, it calculates the time-weighted average price by taking average sum between last twa value and new price valueEven in case last price did not last for
_lookback - _timeDiff
for first lookback period, it still assumes that price last for that long, it will result in slight wrong value calculation ingetTwa()
. For example, since first price will have a huge proportion when calculating time-weighted price, for first lookback period, price cannot change too much. In addition, this lookback period is at least one hour and can be longer, TWA is not correct and it will still have slight effect after first period.Proof of Concept
Consider the scenario with
lookback = 3600
value = 100
and updated att = 10
. Sotwa = 100
t = 15
withprice = 200
, the newtwa
value ist = 20
withprice = 205
, the newtwa
value isWhile the correct value should be
Because
price = 100
has last5
seconds fromt = 10 -> 15
andprice = 200
has last5
seconds fromt = 15 -> 20
.Tools Used
Manual Review
Recommended Mitigation Steps
Consider updating how twa price is calculated correctly