DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

Missing check in `initialize` and `setMinMaxDepositAmount` functions in PerpetualVault contract, allowing `minDepositAmount` to be greater than `maxDepositAmount` which leads to DoS of `deposit` function.

Summary

Both initialize and setMinMaxDepositAmount functions set minDepositAmount (minimal amount per deposit) and maxDepositAmount(maximum total deposited amount) without ensuring that the first is lower than the second one:

function initialize(
address _market,
address _keeper,
address _treasury,
address _gmxProxy,
address _vaultReader,
uint256 _minDepositAmount,
uint256 _maxDepositAmount,
uint256 _leverage
) external initializer {
...
minDepositAmount = _minDepositAmount;
maxDepositAmount = _maxDepositAmount;
...
}
function setMinMaxDepositAmount(uint256 _minDepositAmount, uint256 _maxDepositAmount) external onlyOwner {
minDepositAmount = _minDepositAmount;
maxDepositAmount = _maxDepositAmount;
}

The problem arises because minDepositAmount can be accidentally set to a greater value than maxDepositAmount, or they can simply just be reversed. This will have consequences and will cause a denial of service of the deposit function.

Vulnerability Details

deposit function is defined as follows:

function deposit(uint256 amount) external payable nonReentrant {
_noneFlow();
if (depositPaused == true) {
revert Error.Paused();
}
if (amount < minDepositAmount) {
revert Error.InsufficientAmount();
}
if (totalDepositAmount + amount > maxDepositAmount) {
revert Error.ExceedMaxDepositCap();
}
flow = FLOW.DEPOSIT;
collateralToken.safeTransferFrom(msg.sender, address(this), amount);
counter++;
depositInfo[counter] = DepositInfo(amount, 0, msg.sender, 0, block.timestamp, address(0));
totalDepositAmount += amount;
EnumerableSet.add(userDeposits[msg.sender], counter);
if (positionIsClosed) {
MarketPrices memory prices;
_mint(counter, amount, false, prices);
_finalize(hex"");
} else {
_payExecutionFee(counter, true);
// mint share token in the NextAction to involve off-chain price data and improve security
nextAction.selector = NextActionSelector.INCREASE_ACTION;
nextAction.data = abi.encode(beenLong);
}
}

Any attempt to call deposit once minDepositAmount is greater than maxDepositAmount will revert because of the following check:

if (amount < minDepositAmount) {
revert Error.InsufficientAmount();
}

First, if amount is lower than the actual max total deposit amount (stored in minDepositAmount variable), it will always revert.

Impact

The impact of this vulnerability is medium, as it may lead to complete denial of service of the deposit function.

Although setMinMaxDepositAmount function is only callable by trusted roles, setMinMaxDepositAmount might be called multiple times as it is classic to progressively raise the max deposit cap. If an error occurs the perpetual vault would be made unusable for deposits for a certain time.

Tools Used

Manual review.

Recommendations

Add the following check to ensure there is no error when assigning these variables:

if (minDepositAmount >= maxDepositAmount) {
revert();
}
minDepositAmount = _minDepositAmount;
maxDepositAmount = _maxDepositAmount;
Updates

Lead Judging Commences

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Admin is trusted / Malicious keepers

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."

n0kto Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Admin is trusted / Malicious keepers

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point. Keepers are added by the admin, there is no "malicious keeper" and if there is a problem in those keepers, that's out of scope. ReadMe and known issues states: " * System relies heavily on keeper for executing trades * Single keeper point of failure if not properly distributed * Malicious keeper could potentially front-run or delay transactions * Assume that Keeper will always have enough gas to execute transactions. There is a pay execution fee function, but the assumption should be that there's more than enough gas to cover transaction failures, retries, etc * There are two spot swap functionalies: (1) using GMX swap and (2) using Paraswap. We can assume that any swap failure will be retried until success. " " * Heavy dependency on GMX protocol functioning correctly * Owner can update GMX-related addresses * Changes in GMX protocol could impact system operations * We can assume that the GMX keeper won't misbehave, delay, or go offline. " "Issues related to GMX Keepers being DOS'd or losing functionality would be considered invalid."

Support

FAQs

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