DeFiHardhat
21,000 USDC
View results
Submission Details
Severity: medium
Invalid

Division by activeFertilizer without checking it

Summary

The division by activeFertilizer without checking if it is zero can result in a division by zero error.

Vulnerability Details

If activeFertilizer is zero, a division by zero will occur, causing the transaction to fail. The function does not include a check to prevent this condition here is the vulnerable line :

uint256 newBpf = maxNewFertilized.div(s.activeFertilizer);

Any subsequent operations that depend on newBpf and the loop where newTotalBpf is compared against firstEndBpf would be affected if newBpf is derived from a division by zero.
Here is a Scenario Demonstrating the Bug
Let’s say we have :

- amount = 1000
- FERTILIZER_DENOMINATOR = 3
- activeFertilizer = 0
- oldTotalBpf = 10
- firstEndBpf = 50

Then we run the function rewardToFertilizer with these values and as result when activeFertilizer set to 0, the line
uint256 newBpf = maxNewFertilized.div(s.activeFertilizer)
will cause a division by zero error.

Impact

division by zero can cause the transaction to revert, leading to inconsistencies and failed transactions.

Tools Used

Manual review

Recommendations

Need to check to ensure that activeFertilizer is not zero before performing the division.

Updates

Lead Judging Commences

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

Support

FAQs

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