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.
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.
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.
Manual Review
To mitigate this issue, it's recommended to control the loops by either:
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.
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.
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.