sherlock-audit / 2023-04-jojo-judging

7 stars 4 forks source link

Delvir0 - _isSafe and _isSolidSafe could become unavailable due to DoS #432

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

Delvir0

high

_isSafe and _isSolidSafe could become unavailable due to DoS

Summary

_isSafe and _isSolidSafe will revert if state.openPositions[trader].length is too big

Vulnerability Detail

Above functions are used when calculating if a position is liquidatable.
Both call getTotalExposure which illiterates over state.openPositions[trader]. Since the array is never decreased, over time or when a user sends multiple 0 value trades (which is not checked), it will get too big and revert when used by getTotalExposure

Impact

Liquidations become unavailable

Code Snippet

https://github.com/sherlock-audit/2023-04-jojo/blob/main/smart-contract-EVM/contracts/lib/Liquidation.sol#L53-L79

Tool used

Manual Review

Recommendation

Decrease state.openPositions[trader] when a trade is closed and prevent 0 value trades from increasing it

Duplicate of #348