Category: Business Logic
Missing a zero-value check for assetSupply
Informational Severity
Informational Impact
Low Likelihood
Description
When the collateralLevel
is less than or equal to COLLATERAL_THRESHOLD
and the token type is LEVERAGE
, the function getCreateAmount
does not check whether the levSupply
is zero.
function getCreateAmount(
// [...]
) public pure returns(uint256) {
if (bondSupply == 0) {
revert ZeroDebtSupply();
}
uint256 assetSupply = bondSupply;
uint256 multiplier = POINT_EIGHT;
! if (tokenType == TokenType.LEVERAGE) {
multiplier = POINT_TWO;
! assetSupply = levSupply;
}
// [...]
! if (collateralLevel <= COLLATERAL_THRESHOLD) {
! creationRate = (tvl * multiplier) / assetSupply;
} else if (tokenType == TokenType.LEVERAGE) {
if (assetSupply == 0) {
revert ZeroLeverageSupply();
}
uint256 adjustedValue = tvl - (BOND_TARGET_PRICE * bondSupply);
creationRate = (adjustedValue * PRECISION) / assetSupply;
}
// [...]
}
Impact
When the token type is LEVERAGE
and levSupply
is zero, a division-by-zero error may be thrown instead of a custom error, which may not be clear enough.
Recommendations
Consider adding a check for whether assetSupply
is zero when the collateralLevel
is not greater than the COLLATERAL_THRESHOLD
.
Remediation
This issue has been acknowledged by Plaza Finance, and a fix was implemented in commit bcdf67cf↗.