sherlock-audit / 2023-12-dodo-judging

5 stars 4 forks source link

bareli - Division by Zero: #32

Closed sherlock-admin2 closed 8 months ago

sherlock-admin2 commented 8 months ago

bareli

medium

Division by Zero:

Summary

Division by Zero: None of the division functions (div, divCeil, reciprocalFloor, reciprocalCeil) check for division by zero, which will revert the transaction. It is generally good practice to include checks for division by zero to provide clearer error messages or handle such cases gracefully.

Vulnerability Detail

function div(uint256 target, uint256 d) internal pure returns (uint256) { return target * (10 ** 18) / d; }

function divFloor(uint256 target, uint256 d) internal pure returns (uint256) {
    return target * (10 ** 18) / d;
}

Impact

check for division by zero, which will revert the transaction.

Code Snippet

https://github.com/sherlock-audit/2023-12-dodo/blob/main/dodo-v3/contracts/DODOV3MM/lib/DecimalMath.sol#L30

Tool used

Manual Review

Recommendation

use a require statement for 0.

sherlock-admin2 commented 8 months ago

1 comment(s) were left on this issue during the judging contest.

karanctf commented:

qa

nevillehuang commented 8 months ago

Invalid, solidity will revert naturally when a division by zero is performed, explicit check is not required