Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: low
Valid

Risk of Precision Loss in Token Transfer Calculations

Vulnerability Details:

The createTaker function within the PreMarkets contract is susceptible to precision loss when computing the transferAmount. This risk arises when there is a significant disparity between offerInfo.points and _points, leading to potential rounding inaccuracies.

Impact:

The loss of precision in these calculations can result in incorrect token transfer amounts. This could lead to users receiving fewer tokens than expected or the contract transferring more tokens than intended, causing potential financial discrepancies that could affect both users and the platform.

Proof of Concept:

Here’s an illustration of the issue in the createTaker function:

Link to code

function demonstratePrecisionLoss(uint256 _points, uint256 offerAmount, uint256 offerPoints) public pure returns (uint256) {
// Similar to the calculation in createTaker
uint256 depositAmount = _points.mulDiv(offerAmount, offerPoints, Math.Rounding.Ceil);
// Calculate the expected result using high-precision arithmetic
uint256 expectedAmount = (_points * offerAmount + offerPoints - 1) / offerPoints;
assert(depositAmount == expectedAmount);
return depositAmount;
}
// Test with:
// demonstratePrecisionLoss(1, 1000000000000000000, 1000000000000000001)
// This will fail the assertion due to precision loss

In the above scenario, precision loss leads to the assertion failing, which demonstrates how the contract could transfer an incorrect amount.

Tools Used

Recommendations:

  1. Increase Precision: Use a larger scale factor in intermediate calculations to mitigate precision loss and ensure accuracy in token transfers.

  2. Implement Range Checks: Introduce checks to verify that the computed transferAmount is within an acceptable range to prevent significant discrepancies.

  3. Safeguards for Disparities: Add mechanisms to handle situations where there is a substantial difference between _points and offerInfo.points, reducing the likelihood of precision-related errors.

Updates

Lead Judging Commences

0xnevi Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-PreMarkets-Rounding-Direction

Duplicate of #456, however, for issues noting rounding directions, will be low severity given the impact is not proven sufficiently with a PoC/numerical example and most rounding will not result in significant losses e.g. most examples only proved at most a 1 wei difference when computing `depositAmount/platFormFees` and involves lower amount offers

Support

FAQs

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