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

PRAISE - possible precision loss in D3VaultLiquidation.finishLiquidation() function when calculating realDebt because of division before multiplication #45

Open
sherlock-admin opened this issue Jul 1, 2023 · 4 comments
Labels
Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A valid Medium severity issue Reward A payout will be made for this issue Will Fix The sponsor confirmed this issue will be fixed

Comments

@sherlock-admin
Copy link
Contributor

PRAISE

medium

possible precision loss in D3VaultLiquidation.finishLiquidation() function when calculating realDebt because of division before multiplication

Summary

finishLiquidation() divides before multiplying when calculating realDebt.

Vulnerability Detail

uint256 realDebt = borrows.div(record.interestIndex == 0 ? 1e18 : record.interestIndex).mul(info.borrowIndex);

There will be precision loss when calculating the realDebt because solidity truncates values when dividing and dividing before multiplying causes precision loss.

Values that suffered from precision loss will be updated here

 info.totalBorrows = info.totalBorrows - realDebt;

Impact

Values that suffered from precision loss will be updated here

 info.totalBorrows = info.totalBorrows - realDebt;

Code Snippet

https://github.com/sherlock-audit/2023-06-dodo/blob/main/new-dodo-v3/contracts/DODOV3MM/D3Vault/D3VaultLiquidation.sol#L144

https://github.com/sherlock-audit/2023-06-dodo/blob/main/new-dodo-v3/contracts/DODOV3MM/D3Vault/D3VaultLiquidation.sol#L147

Tool used

Manual Review

Recommendation

don't divide before multiplying

@traceurl
Copy link

@IAm0x52
Copy link
Collaborator

IAm0x52 commented Sep 6, 2023

Doesn't address this issue. Though precision loss is very minimal given the decimal math utilized. Optional change here

@Attens1423
Copy link

There is another fix for this issue. We realised the last one does not work: https://github.com/DODOEX/new-dodo-v3/pull/54/files

@IAm0x52
Copy link
Collaborator

IAm0x52 commented Sep 13, 2023

Fix looks good. Creates the _borrowAmount function which fixes the order of operations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Has Duplicates A valid issue with 1+ other issues describing the same vulnerability Medium A valid Medium severity issue Reward A payout will be made for this issue Will Fix The sponsor confirmed this issue will be fixed
Projects
None yet
Development

No branches or pull requests

4 participants