Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

BugBusters - Potential Precision Loss in poolBorrow function #223

Closed
sherlock-admin opened this issue Jul 1, 2023 · 0 comments
Closed
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Jul 1, 2023

BugBusters

high

Potential Precision Loss in poolBorrow function

Summary

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.

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:

uint256 usedQuota = record.amount.mul(currentInterestIndex).div(oldInterestIndex);

Duplicate of #45

@github-actions github-actions bot closed this as completed Jul 5, 2023
@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jul 5, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant