The LibFertilizer::addUnderlying function is vulnerable to a division by zero error. This occurs when the remainingRecapitalization function returns zero, indicating that no additional capital is needed.
The LibFertilizer::addUnderlying function calculates the percentToFill:
But when calculating this variable there is a possibility for division by zero error. This is due to the remainingRecapitalization function:
The LibFertilizer::remainingRecapitalization function can return 0 if s.recapitalized >= totalDollars.
Also, if C.unripeLP().totalSupply() is 0, then the totalDollars will be also 0. The totalDollars is uint256. So the line totalDollars.sub(s.recapitalized) will have an underflow issue.
If LibFertilizer::remainingRecapitalization() function returns zero, the division operation in the LibFertilizer::addUnderlying function will cause a revert, halting the execution of the addUnderlying function and any transaction that invokes it.
Also, if the totalSupply in the LibFertilizer::remainingRecapitalization() is 0, the totalDollars will be 0 and the function will have an underflow issue.
Manual Review
Implement a check before the division in the LibFertilizer::addUnderlying function to ensure that the returned value of remainingRecapitalization is greater than zero:
Also, ensure that the totalSupply in LibFertilizer::remainingRecapitalization is not 0 and this line return totalDollars.sub(s.recapitalized); will not cause an underflow issue.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.