DeFiHardhat
12,000 USDC
View results
Submission Details
Severity: low
Invalid

Potential division by zero

Summary

The LibMath::roundUpDiv and MultiFlowPump::calcCapExponent functions can revert due to division by zero.

Vulnerability Details

In Solidity, a division by zero error will cause a transaction to fail and revert. This means that all changes made during the transaction will be rolled back and no state changes will be made to the blockchain. The entire transaction will be considered invalid and the gas used by the transaction will not be refunded.
There are two functions where there can be a division by zero. The first one is LibMath::roundUpDiv:

In LibMath:

function roundUpDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
@> return (a - 1) / b + 1;
}

And the second one is: MultiFlowPump::calcCapExponent:

In MultiFlowPump:

function calcCapExponent(uint256 deltaTimestamp, uint256 capInterval) private pure returns (uint256 capExponent) {
@> capExponent = ((deltaTimestamp - 1) / capInterval + 1);
}

In LibMath::roundUpDiv function there is no check if b is not 0. And in the MultiFlowPump::calcCapExponent there is no check to ensure that capInterval is not 0.

Impact

If the b in LibMath::roundUpDiv is 0 or the capInterval in MultiFlowPump::calcCapExponent is 0, the functions roundUpDiv and calcCapExponen will revert.
And the functions that rely on these functions will also fail and revert.

Tools Used

Manual Review

Recommendations

Add a require statement to check if b in LibMath::roundUpDiv and capInterval in MultiFlowPump::calcCapExponent are not 0:

In LibMath:

function roundUpDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
+ require(b > 0, "B can not be 0");
return (a - 1) / b + 1;
}

In MultiFlowPump:

function calcCapExponent(uint256 deltaTimestamp, uint256 capInterval) private pure returns (uint256 capExponent) {
+ require(capInterval > 0, "The capInterval can not be 0");
capExponent = ((deltaTimestamp - 1) / capInterval + 1);
}
Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

Informational/Invalid

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.