Take a look at https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/perpetuals/branches/LiquidationBranch.sol#L42-L86
This function is used to get the liquidatable accounts, and it does this with the help of the lowerBound and the upperBound of the accounts to check.
Now would be key to note that this function is directly used while checking for up keeps in the LiquidationKeeper#checkUpkeep() , see https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/external/chainlink/keepers/liquidation/LiquidationKeeper.sol#L57-L65
Issue however is that there is a high chance the LiquidationBranch#checkLiquidatableAccounts() reverts.
This is because the lowerBound is not always going to be 0, but while preparing the output array size, this is being done liquidatableAccountsIds = new uint128[](upperBound - lowerBound);, now in a case where say lowerBound is 13 and upperBound is 23, we have our array to be liquidatableAccountsIds = new uint128[](10);.
Now while looping through to check if the accounts are liquidatable the i value being used are not reset to start from 0, but rather from lowerBound up until upperBound, i.e for (uint256 i = lowerBound; i < upperBound; i++) {.
Now where this reverts is here:
Which is because in our example above, let's assume even the first account is liquidatable, while trying to attach the tradingAccountId to the i index in our case which would be 13, the execution is going to run into an OOB error, cause we are trying to access liquidatableAccountsIds[13] whereas the maximum length is liquidatableAccountsIds[10]
Impact is massive, this revert bubbles from LiquidationBranch#checkLiquidatableAccounts() back up to LiquidationKeeper#checkUpkeep() and all functions that query it, note that both Log and the AutomationCompatible have this as a core functionality, considering performUpkeep is heavily dependent on what's being returned by this query. CC: https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/external/chainlink/keepers/market-order/MarketOrderKeeper.sol#L162-L170.
Manual review
Consider applying these changes:
Or use a logic similar to what's here: https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/external/chainlink/keepers/liquidation/LiquidationKeeper.sol#L44-L88.
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.