DittoETH

Ditto
DeFiFoundryOracle
55,000 USDC
View results
Submission Details
Severity: medium
Valid

Division before multiplication result in wrong price / unexpected behaviour

Summary

Multiplication is performed on the result of a division, which can lead to precision errors due to the truncation of decimal points in Solidity.

Vulnerability Details

contracts/libraries/LibOracle.sol#85:

In LibOracle.baseOracleCircuitBreaker(uint256,uint80,int256,uint256,uint256) - line 85

twapPriceInEther = (twapPrice / Constants.DECIMAL_USDC) * 1000000000000000000

performs a multiplication on the result of a division.

contracts/libraries/LibOrders.sol#39-57:

In LibOrders.increaseSharesOnMatch(address,STypes.Order,MTypes.Match,uint88) - line 51

shares = eth * (timeTillMatch / 86400)

also performs a multiplication on the result of a division.

Impact

These vulnerabilities can lead to incorrect calculations due to the loss of precision, which can have significant implications in a financial context (for example in the case of wrong "twapPriceInEther" calculation). The impact can range from minor discrepancies in value calculations to major financial losses, depending on the specific use case and the values involved.

Tools Used

Slither

Recommendations

To mitigate these vulnerabilities, consider rearranging the operations to perform multiplication before division. This can help to maintain precision and avoid potential rounding errors.
For example, can be used:

(twapPrice * 1000000000000000000) / Constants.DECIMAL_USDC
(eth * timeTillMatch) / 86400
Updates

Lead Judging Commences

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

finding-139

Support

FAQs

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