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

LiquidationBranch.sol can DOS due to an Uncontrolled Iteration

Summary

The 'liquidateAccounts' function of the contract iterates over the array of account IDs provided as input and attempts to liquidate each one.

The number of iterations can grow tremendously, leading to excessively large loops. A large number of iterations may cause a transaction to exceed the maximum available gas, thus leading to an out of gas error and transaction failure.

Vulnerability Details

Moreover, inside the iteration loop, the contract iterates over all active market IDs of a trading account.

For a complex or high-frequency trading account, the number of active market IDs can also be remarkably high.

function liquidateAccounts(uint128[] calldata accountsIds) external {
// ...
for (uint256 i; i < accountsIds.length; i++) {
// ... code to perform liquidation
}
// ...
}

Impact

These elements represent an uncontrolled iteration vulnerability, which can cause Denial of Service (DoS) to the contract functionalities, as operations may become unresponsive with excessive gas fees.

Tools Used

Manual Review

Recommendations

To mitigate this issue, it's recommended to control the loops by either:

  1. Limiting the input array length (for example, the accounts to liquidate): This approach can involve checking the input array's length and reverting the transaction if it exceeds a certain threshold.

  2. Implement a pagination mechanism to process large datasets: With this method, the processing of large array elements can be divided into smaller tasks performed over multiple transactions. This ensures that no single transaction requires an excessive amount of gas. However, it should be noted that this method may require additional complexity and care to ensure data consistency.

Also, consider checking if the TradingAccount can be liquidated before fetching and processing its details, which may limit unnecessary computations.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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