Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: medium
Invalid

Potential Underflow Risk in Abort Ask Offer Refund Calculation

Vulnerability Details

In the abortAskOffer function, there's a subtraction operation that could potentially underflow if transferAmount is only slightly larger than totalDepositAmount and precision loss occurs in earlier calculations.

Impact

An underflow in this calculation could result in an incorrect makerRefundAmount, potentially leading to significant financial losses for users or the platform.

Proof of Concept

Link to code

function demonstrateUnderflowRisk(uint256 transferAmount, uint256 totalDepositAmount) public pure returns (uint256) {
if (transferAmount > totalDepositAmount) {
unchecked {
return transferAmount - totalDepositAmount;
}
} else {
return 0;
}
}
// Example:
// demonstrateUnderflowRisk(100, 99)
// This works fine, returning 1
// However:
// demonstrateUnderflowRisk(2^256 - 1, 2^256 - 2)
// This will return a very large number due to underflow, instead of 1

Tools Used

Manual Review

Recommendations

Implement a safety check to ensure the subtraction doesn't underflow:

require(transferAmount >= totalDepositAmount, "Underflow risk");
makerRefundAmount = transferAmount - totalDepositAmount;
Updates

Lead Judging Commences

0xnevi Lead Judge
about 1 year ago
0xnevi Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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