DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: medium
Invalid

Liquidation Reverts Due to Block Gas Limit in `LiquidationBranch::liquidateAccounts`

Summary

The LiquidationBranch::liquidateAccounts function may revert due to block gas limits when processing accounts with numerous positions. This is caused by nested loops and extensive computations within the function.

Vulnerability Details

The vulnerability lies in the liquidateAccounts function of the LiquidationBranch contract, where nested loops are used to iterate through accounts, active markets, and positions for liquidation. This structure can potentially lead to hitting the block gas limit, especially when accounts hold multiple positions across various markets.

// Simplified version focusing on potential gas limit issue during liquidation
function liquidateAccounts() {
// Loop through accounts being liquidated
for (uint256 k; k < accountsIds.length; k++) {
// Check liquidation eligibility and deduct maintenance margin
// Close all positions for the account
// Loop through active markets for the account
// this loop is inside getAccountMarginRequirementUsdAndUnrealizedPnlUsd
for (uint256 i; i < cachedActiveMarketsIdsLength; i++) {
// Process market-specific liquidation logic
}
// Fetch active market IDs for the account
ctx.activeMarketsIds = tradingAccount.activeMarketsIds.values();
// Iterate over active market IDs
for (uint256 j; j < ctx.activeMarketsIds.length; j++) {
// Liquidate positions in each active market
}
}
}

Gas Limit Reverts: Processing accounts with many positions can exceed the block gas limit, causing the transaction to revert.

Impact

Transaction Reverts: Liquidation of accounts with many positions may fail due to gas limit reverts.

Incomplete Liquidations: Accounts that should be liquidated might not be processed, leading to potential financial risks.
Tools Used

Tools Used

Manual Review

Recommendations

Implement batch processing for liquidating positions across multiple markets to prevent hitting the gas limit.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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