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

The `MarketUtils::sumReturnUint256` function will underflow revert if value of a is less than b.

Summary

The MarketUtils::sumReturnUint256 function will revert if the value a is less than b.

Vulnerability Details

The below given function will revert if the value of b is bigger than a, since the contarct is using the solidity version ^0.8.0.

function sumReturnUint256(uint256 a, int256 b) internal pure returns (uint256) {
if (b > 0) {
return a + uint256(b);
}
@>> return a - uint256(-b);
}

https://github.com/CodeHawks-Contests/2025-02-gamma/blob/84b9da452fc84762378481fa39b4087b10bab5e0/contracts/libraries/gmx/MarketUtils.sol#L160

Impact

The function will revert if the value of a is less than b. there is no check implemented to prevent that.

Recommendations

function sumReturnUint256(uint256 a, int256 b) internal pure returns (uint256) {
if (b > 0) {
return a + uint256(b);
}
- return a - uint256(-b);
+ uint256 absB = uint256(-b); // get absolute value of b
+ // Compare and subtract smaller from larger
+ if (a >= absB) {
+ return a - absB;
+ } else {
+ return absB - a;
+ }
}
Updates

Lead Judging Commences

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

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

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!