MorpheusAI

MorpheusAI
Foundry
22,500 USDC
View results
Submission Details
Severity: medium
Invalid

Potential Precision Loss

Summary

In Solidity, when performing division, the result is always truncated towards zero. This means that any fractional part of the result is discarded. Since Solidity does not support floating-point numbers, this can lead to precision loss, especially in financial calculations where exact amounts are crucial.

Vulnerability Details

The getSharesByPooledEth and getPooledEthByShares functions in the provided smart contract perform such division operations:

function getSharesByPooledEth(uint256 _ethAmount) public view returns (uint256) {
return (_ethAmount * totalShares) / totalPooledEther;
}
function getPooledEthByShares(uint256 _sharesAmount) public view returns (uint256) {
return (_sharesAmount * totalPooledEther) / totalShares;
}

In these functions, the multiplication is performed first, followed by the division. This order of operations is intentional to minimize precision loss, as multiplication can increase the value before division potentially reduces it. However, even with this approach, some precision loss is inevitable when the result of the division is not a whole number.

For example, if totalShares is 1000 and totalPooledEther is 3, calling getSharesByPooledEth(1) would result in: 333.333

Impact

If assets do not balance as expected due to rounding down in the division, this effectively causes value to leak from the system. This could add up to a significant amount over thousands of transactions.

Tools Used

Manual Review

Recommendations

  • Use a higher base unit like Wei instead of Ether for calculations

  • Implement a fixed-point arithmetic library for divisions

Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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