DeFiHardhatOracleProxyUpdates
100,000 USDC
View results
Submission Details
Severity: low
Valid

No validation of total supply of unripe beans & Lp in `percentBeansRecapped` & `percentLPRecapped`

Summary

LibUnripe:percentBeansRecapped & LibUnripe:percentLPRecapped functions calculate the percentage of Unripe Beans and Unripe LPs that have been recapitalized, respectively. These percentages are calculated based on the underlying balance of the Unripe Tokens and their total supply. There is no check if the totalSupply is zero which is used as division in the calculation.

Vulnerability Details

See the following code for both the functions:

/**
* @notice Returns the percentage that Unripe Beans have been recapitalized.
*/
function percentBeansRecapped() internal view returns (uint256 percent) {
AppStorage storage s = LibAppStorage.diamondStorage();
return s.u[C.UNRIPE_BEAN].balanceOfUnderlying.mul(DECIMALS).div(C.unripeBean().totalSupply());
}
/**
* @notice Returns the percentage that Unripe LP have been recapitalized.
*/
function percentLPRecapped() internal view returns (uint256 percent) {
AppStorage storage s = LibAppStorage.diamondStorage();
return C.unripeLPPerDollar().mul(s.recapitalized).div(C.unripeLP().totalSupply());
}

Impact

If the totalSupply in these two functions becomes zero, the calculation of the percentage of recapitalized Unripe Beans or LP tokens would result in a division by zero error. This is because of the denominator in the calculation. When the total supply is zero, dividing by zero is not defined in Solidity, and the contract would revert with an error.

These functions are used widely across the different contracts at crucial places. So they will effect a lot of functionalities.

Tools Used

Manual Review

Recommendations

To handle this scenario, appropriate checks should be added to ensure that the totalSupply of Unripe Beans or LP tokens is non-zero before performing the division operation.

Updates

Lead Judging Commences

giovannidisiena Lead Judge
over 1 year ago
giovannidisiena Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Unripe division by zero

giovannidisiena Lead Judge
over 1 year ago
giovannidisiena Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Unripe division by zero

Support

FAQs

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