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

`PerpetualVault::run` Redundant Code Patterns [Code Maintainability]

Summary

The codebase contains repetitive code patterns that should be refactored into internal functions for better maintainability and gas efficiency.

Vulnerability Details

Repetitive pattern found in PerpetualVault.sol:

// Pattern appears multiple times
if (_isLongOneLeverage(beenLong)) {
_runSwap(metadata, false, prices);
} else {
(uint256 acceptablePrice) = abi.decode(metadata[0], (uint256));
_createDecreasePosition(0, 0, beenLong, acceptablePrice, prices);
}

Impact

  • Code duplication

  • Higher maintenance burden

  • Increased risk of errors during updates

  • Higher gas costs due to repeated code

Recommendations

Create a private function to handle this pattern:

function _handlePositionAction(
bytes[] memory metadata,
bool isLong,
MarketPrices memory prices
) private {
if (_isLongOneLeverage(isLong)) {
_runSwap(metadata, false, prices);
} else {
require(metadata.length > 0, "Empty metadata");
(uint256 acceptablePrice) = abi.decode(metadata[0], (uint256));
_createDecreasePosition(0, 0, isLong, acceptablePrice, prices);
}
}

Then use it in place of the repeated pattern:

_handlePositionAction(metadata, beenLong, prices);
Updates

Lead Judging Commences

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

Informational or Gas

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.

Support

FAQs

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

Give us feedback!