You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
sherlock-admin opened this issue
Jul 1, 2023
· 0 comments
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
The function poolBorrow may suffer from potential precision loss due to the order of operations in the line uint256 usedQuota = record.amount.div(oldInterestIndex).mul(currentInterestIndex);. The division operation is performed before the multiplication, which can result in the truncation of decimal values and a loss of precision.
Vulnerability Detail
The issue arises from performing division before multiplication in the line record.amount.div(oldInterestIndex).mul(currentInterestIndex). When dividing two integers in Solidity, the result is truncated towards zero, discarding any decimal portion. Subsequently, multiplying the truncated result by currentInterestIndex can further amplify the precision loss introduced by the division operation.
Impact
The precision loss can lead to inaccurate calculations and unintended results.
To avoid potential precision loss, it is recommended to rearrange the operations and perform multiplication before division. The revised line of code should be:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
BugBusters
high
Potential Precision Loss in
poolBorrow
functionSummary
The function
poolBorrow
may suffer from potential precision loss due to the order of operations in the lineuint256 usedQuota = record.amount.div(oldInterestIndex).mul(currentInterestIndex);
. The division operation is performed before the multiplication, which can result in the truncation of decimal values and a loss of precision.Vulnerability Detail
The issue arises from performing division before multiplication in the line
record.amount.div(oldInterestIndex).mul(currentInterestIndex)
. When dividing two integers in Solidity, the result is truncated towards zero, discarding any decimal portion. Subsequently, multiplying the truncated result by currentInterestIndex can further amplify the precision loss introduced by the division operation.Impact
The precision loss can lead to inaccurate calculations and unintended results.
Code Snippet
https://github.com/sherlock-audit/2023-06-dodo/blob/main/new-dodo-v3/contracts/DODOV3MM/D3Vault/D3VaultFunding.sol#L70-L92
Tool used
Manual Review
Recommendation
To avoid potential precision loss, it is recommended to rearrange the operations and perform multiplication before division. The revised line of code should be:
Duplicate of #45
The text was updated successfully, but these errors were encountered: