Category: Coding Mistakes
The weightStrategy range violation
Low Impact
Low Severity
Low Likelihood
Description
The weightStrategy global variable determines the weight strategy used when deploying funds and can take one of three values:
for equal weight
for fixed weight
for threshold weight
However, the setWeightStrategy function allows the owner of the contract to set this value to a number less than or equal to strategyCount(), which is equal to 4.
function setWeightStrategy(
uint8 weightId,
uint16 proportion,
uint256[] calldata fixedWeights
) external onlyOwner {
...
if (weightId > strategyCount()) revert InvalidWeightId();
...
weightStrategy = weightId;
weightProportion = proportion;
vaultWeights = fixedWeights;
emit WeightStrategyUpdated(weightId, proportion, fixedWeights);
}
function strategyCount() public pure returns (uint256) {
return 4;
}Impact
If the weightStrategy is set to 4, the fetchWeights function will revert because there is a check that this value cannot be more than 3. As a result, the deployPosition function, which is called by the owner of the contract, will also revert, preventing the owner from deploying funds to Y2K vaults.
Recommendations
We recommend to change the condition from > to >=.
function setWeightStrategy(
uint8 weightId,
uint16 proportion,
uint256[] calldata fixedWeights
) external onlyOwner {
...
- if (weightId > strategyCount()) revert InvalidWeightId();
+ if (weightId >= strategyCount()) revert InvalidWeightId();
...
}Remediation
The issue was fixed in commit 2248d6f↗.