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

The user's leverage could be set to 0, resulting in their inability to participate in trades and make profit

Summary

Description: The 5_deployPerpVault.js file is deploying the PerpetualVault.sol contract as an upgradable contract.

Vulnerabilities Details

const perpetualVault = await upgrades.deployProxy(
PerpetualVault,
[
"0x70d95587d40A2caf56bd97485aB3Eec10Bee6336",
keeper,
treasury,
jsonData.gmxUtilsAddress,
jsonData.vaultReaderAddress,
"100000000",
"10000000000000000000000000000",
],

The second argument of the deployProxy function above is an array of 7 parameters that are passed to the contract's initializer function.

PerpetualVault.sol uses an initializer function instead of a constructor with the following 8 initializer parameters:

function initialize(
address _market,
address _keeper,
address _treasury,
address _gmxProxy,
address _vaultReader,
uint256 _minDepositAmount,
uint256 _maxDepositAmount,
uint256 _leverage
) external initializer {

The deploy script contains 7 parameters whereas, the PerpetualVault initialize function is expecting 8 parameters. The leverage isn't passed on from the deploy script to the PerpetualVault.solcontract. It is high likely that the missing parameter is being interpreted as its default value, which is 0 in this case. The initial leverage parameter is set to 0.

The PerpetualVault.sol contract has a leverage state variable:

uint256 public leverage; // GMX position leverage value (decimals is 10000)

which is initialised in the PerpetualVault::initialize() function:

leverage = _leverage;

The PerpetualVault::_createIncreasePosition() function uses the leverage amount to create an increase position as per the extract below:

function _createIncreasePosition(bool _isLong, uint256 acceptablePrice, MarketPrices memory prices) internal {
// Check available amounts to open positions
uint256 amountIn;
if (flow == FLOW.DEPOSIT) {
amountIn = depositInfo[counter].amount;
flowData = vaultReader.getPositionSizeInTokens(curPositionKey);
} else {
amountIn = collateralToken.balanceOf(address(this));
}
Order.OrderType orderType = Order.OrderType.MarketIncrease;
collateralToken.safeTransfer(address(gmxProxy), amountIn);
uint256 sizeDelta = prices.shortTokenPrice.max * amountIn * leverage / BASIS_POINTS_DIVISOR;

Impact: If the leverage is 0 (since it wasn't passed through during initialisation), the user's position could be miscalculated and they potentially wouldn't have a trading position, meaning that they wouldn't be using the protocol as intended (preventing them to make profits).

Tools used:
slither and aderyn

Recommended Mitigation: Explicitly pass on all parameters to the initializer to avoid unexpected results. Given that "the leverage of each vault should stay consistent from start to finish", it could be set or calculated at the onset to avoid any issues and ensure that the position is accurate and the protocol works as intended.

If this isn't the case, the system should check for a zero leverage value as not doing so could lead to unexpected behaviour, whch could also potentially cause issues in the contract's logic.

In addition, as per the comment in the contract, the GMX position leverage value's decimals is 10000. It would be prudent to add a "require" check to ensure that the leverage is valid and within a defined range.

Updates

Lead Judging Commences

n0kto Lead Judge 5 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 5 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.