Skinny Blood Mallard
Medium
Lack of integer bounds on the immutable variable exchangeRateDenominator
leads to incorrect calculations in preFeeStableAmountEquivalent
and postFeeStableAmountEquivalent
The variable exchangeRateDenominator
is not bounded to a specific range which may lead to incorrect calculations when calculating the fees in preFeeStableAmountEquivalent
and consequently in postFeeStableAmountEquivalent
.
The variable exchangeRateDenominator
isn't bound to a specific range which leads to incorrect fee calculations when set to an incorrect figure either maliciously or by mistake by the deployer of VVVVCInvestmentLedger
.
Given that immutable variables in Solidity can only be set once, this can be particularly devastating as it leads to either very high or very low fee calculations when calculating preFeeStableAmountEquivalent
and consequently in postFeeStableAmountEquivalent
which uses preFeeStableAmountEquivalent
for its calculations.
Admin/deployer of VVVVCInvestmentLedger
needs to set _exchangeRateDenominator
to a very high or very low figure during contract deployment.
A user invokes the VVVVCInvestmentLedger::invest()
with valid parameters while the exchangeRateDenominator
is set to an unreasonable value.
- The deployer of
VVVVCInvestmentLedger
setsexchangeRateDenominator
to an extremely high or low value during contract deployment. - An investor calls
VVVVCInvestmentLedger::invest()
with valid params as defined in the structInvestParams
- Calculation Distortion:
- For a low
exchangeRateDenominator
,preFeeStableAmountEquivalent
becomes disproportionately large:
uint256 preFeeStableAmountEquivalent = (_params.amountToInvest * _params.exchangeRateNumerator) / 1; // Example low denominator
- For a low
exchangeRateDenominator
, the value is rendered negligible:
uint256 preFeeStableAmountEquivalent = (_params.amountToInvest * _params.exchangeRateNumerator) / 10**18; // Example high denominator
If exchangeRateDenominator
is too low, the pre-fee equivalent will be inflated, leading to overestimated investment values. Conversely, if it is too high, the calculated equivalent becomes negligibly small, potentially misrepresenting the actual value of the investment and disrupting fee calculations.
Add a range check for _exchangeRateDenominator
during contract deployment, e.g
require(_exchangeRateDenominator > MIN_DENOMINATOR && _exchangeRateDenominator < MAX_DENOMINATOR, "Invalid denominator");