Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jovial Ocean Elk - Incorrect use of nagative values in maintained() and margined() function in Position.sol #58

Open
sherlock-admin3 opened this issue Jan 31, 2025 · 0 comments
Labels
Sponsor Disputed The sponsor disputed this issue's validity

Comments

@sherlock-admin3
Copy link

Jovial Ocean Elk

High

Incorrect use of nagative values in maintained() and margined() function in Position.sol

Summary

The maintained() and margin() functions wrongly handle negative collateral values making a path for undercollateralized positions to appear solvent.

Vulnerability Details

https://github.com/sherlock-audit/2025-01-perennial-v2-4-update/blob/main/perennial-v2/packages/core/contracts/types/Position.sol#L211-L217
https://github.com/sherlock-audit/2025-01-perennial-v2-4-update/blob/main/perennial-v2/packages/core/contracts/types/Position.sol#L242-L250

maintained() and margin() functions
collateral is stored as Fixed6 which is signed but later converted to UFIXED6 which is unsigned using UFixed6Lib.unsafeFrom(collateral).
The negative values are wrapped around to large set of numbers due to two representation -1002^256 - 100 which will cause the check to return true for negative collateral.

Impact

Malicious users can maintain positions with negative collaterals bypassing solvency checks.
Malicious actors can also borrow funds without collateralizing.

Tools Used

Manual review.

Recommendations

Revert or return false if collateral is negative unless position is empty.

@sherlock-admin3 sherlock-admin3 added the Sponsor Disputed The sponsor disputed this issue's validity label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sponsor Disputed The sponsor disputed this issue's validity
Projects
None yet
Development

No branches or pull requests

1 participant