Skip to content
Audit finding Intermediate

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

The finishLiquidation() function calculates realDebt by dividing before multiplying, causing precision loss due to Solidity's truncation. This leads to incorrect updates of totalBorrows, potentially affecting the protocol's accounting.

0xdice91 Follow with BugBusters, BugHunter101 and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-dodo-judging/issues/45

Found by

0xdice91, BugBusters, BugHunter101, Kalyan-Singh, MohammedRizwan, Oxhunter526, PRAISE, amaechieth, kutugu

Summary

finishLiquidation() divides before multiplying when calculating realDebt.

Vulnerability Detail

Solidity
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

Solidity
 info.totalBorrows = info.totalBorrows - realDebt;

Impact

Values that suffered from precision loss will be updated here

Solidity
 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

The original report as published on Sherlock, by 0xdice91. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely, the code performs division before multiplication, causing truncation and precision loss.

Impact

The precision loss could lead to incorrect totalBorrows values, potentially affecting the protocol's financial accounting.

What the attacker needed

None

The fix

The code should be fixed by multiplying before dividing to avoid precision loss.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a smart contract does maths with whole numbers, dividing first can lose small remainders. Here, the code divides before multiplying, so the final debt amount is slightly too small. That wrong number is then used to update the total borrowed amount, which could cause accounting errors.

More by 0xdice91

View all

5 more disclosed reports, best first.

More from DODO V3 update

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.