Summary
Description: The 5_deployPerpVault.js
file is deploying the PerpetualVault.sol
contract as an upgradable contract.
Vulnerabilities Details
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:
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.sol
contract. 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:
which is initialised in the PerpetualVault::initialize()
function:
The PerpetualVault::_createIncreasePosition()
function uses the leverage amount to create an increase position as per the extract below:
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.
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."
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."
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.