DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

The `VaultReader::getPositionInfo` function will undeflow revert.

Summary

The VaultReader::getPositionInfo function will undeflow revert if the value of netValueis less than

positionInfo.basePnlUsd.

Vulnerability Details

the value of positionInfo.basePnlUsdis subtracted from netValue which can cause the undeflow revert since the value of netValuecan be less than positionInfo.basePnlUsd.

The positionInfo.basePnlUsd value can be too large than can be greater than netvalue and cause revert.

function getPositionInfo(bytes32 key, MarketPrices memory prices) external view returns (PositionData memory) {
......
......
if (positionInfo.basePnlUsd >= 0) {
netValue = netValue + uint256(positionInfo.basePnlUsd);
} else {
//-> revert if netvalue < positionInfo.basePnlUsd
netValue = netValue - uint256(-positionInfo.basePnlUsd);
}
......
......

https://github.com/CodeHawks-Contests/2025-02-gamma/blob/84b9da452fc84762378481fa39b4087b10bab5e0/contracts/VaultReader.sol#L83

Impact

Underflow revert in the function.

Recommendations

function getPositionInfo(bytes32 key, MarketPrices memory prices) external view returns (PositionData memory) {
......
......
-if (positionInfo.basePnlUsd >= 0) {
- netValue = netValue + uint256(positionInfo.basePnlUsd);
- } else {
- //-> revert if netvalue < positionInfo.basePnlUsd
- netValue = netValue - uint256(-positionInfo.basePnlUsd);
- }
+if (positionInfo.basePnlUsd >= 0) {
+ netValue += uint256(positionInfo.basePnlUsd);
+} else {
+ netValue = netValue >= uint256(-positionInfo.basePnlUsd)
+ ? netValue - uint256(-positionInfo.basePnlUsd)
+ : uint256(-positionInfo.basePnlUsd) - netValue;
+}
......
......
Updates

Lead Judging Commences

n0kto Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Suppositions

There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!