Closed sherlock-admin closed 11 months ago
4 comment(s) were left on this issue during the judging contest.
panprog commented:
invalid because scenario presented is incorrect (latest = 100 -> pending = 50 - invalidation will be +50, not -50) and no underflow happens in such scenario. POC reverts because of incorrect oracle setup (specifically line:
oracle.status.returns([oracleVersion2, TIMESTAMP + 100])
,oracleVersion2.timestamp = TIMESTAMP + 100
), where oracle latest and current return the same timestamp which is not possible. When the oracle setup is fixed (initial user update to long=1 done in oracle version 1 right after userB), POC works correctly without revert.
n33k commented:
invalid, out-of-scope because it's a public known issue, https://github.com/equilibria-xyz/perennial-v2/pull/103
0xyPhilic commented:
invalid because it can be considered low as the probability is extremelly low
polarzero commented:
High. This could indeed cause the loss of all or part of the funds for the users.
bin2chen
high
adjust() may underflow resulting in can't settle
Summary
If the difference of
invalidation
is greater than the original value, it will result inadjust()
underflow, the user will not be able to settle, and the collateral will be locked.Vulnerability Detail
in
adjust()
, we'll adjustposition
based on the difference betweenlatestPosition.invalidation
andself.invalidation
This difference may be greater than the original value, resulting in
adjust()
underflow
Take the following example Suppose
alice
has the followingPosition
(caused by orale delay during update()) t=100 long =100 invalidation = 0 (latestPosition) t=200 long = 50 invalidation = 0 (pending) t=300 long = 0 invalidation = 0 (pending)Subsequent
oralce
submissions, assumingt=200
is an invalidoralce
and t=300oralce
is validwhen settle : t=200 (oralce invalid) long = 100 invalidation = -50
when settle : t=300 (oralce valid) long = 0 + (-50) => **** underflow
POC
The following code demonstrates this scenario as described above
add to
Market.test.ts
Impact
When
adjust()
revert, causing the user to be unable tosettle
, resulting in the collateral being lockedCode Snippet
https://github.com/sherlock-audit/2023-09-perennial/blob/main/perennial-v2/packages/perennial/contracts/types/Position.sol#L155-L157
Tool used
Manual Review
Recommendation
in
adjust()
If less than 0, take 0