Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: medium
Invalid

[M-01] Improper Handling of Negative SD59x18 Inputs in convertSd59x18ToTokenAmount

Summary

The function convertSd59x18ToTokenAmount is responsible for converting a signed decimal (SD59x18) amount to an unsigned integer (uint256) token amount, but it lacks input validation for negative values. Since SD59x18 is a signed type, passing a negative value could result in an underflow when converting to uint256, leading to a large, incorrect token amount.

Vulnerability Details

Impacted code:

function convertSd59x18ToTokenAmount(Data storage self, SD59x18 amountX18) internal view returns (uint256) {
return Math.convertSd59x18ToTokenAmount(self.decimals, amountX18);
}

Impact

I've rated this as a Medium because the lack of input validation can lead to significant financial discrepancies or system inconsistencies. While it does not directly allow unauthorized access or control, it can be exploited to manipulate token amounts.

A negative SD59x18 value is passed to the convertSd59x18ToTokenAmount function.

  • The function converts this negative value to uint256, resulting in a large unintended value due to underflow.

  • This incorrect token amount is then used in subsequent calculations or transactions, leading to financial discrepancies.

Recommendations

implement input validation to check for negative values before conversion. If a negative value is detected, revert the transaction with an appropriate error message.

function convertSd59x18ToTokenAmount(Data storage self, SD59x18 amountX18) internal view returns (uint256) {
// Check if the input amount is negative
if (amountX18 < SD59x18.wrap(0)) {
revert Errors.NegativeAmountNotAllowed();
}
return Math.convertSd59x18ToTokenAmount(self.decimals, amountX18);
}

This update ensures only valid, non-negative values are processed.

Updates

Lead Judging Commences

inallhonesty Lead Judge
6 months ago
inallhonesty Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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