The removeOperators function in the OperatorStakingPool could fail to remove all specified operators particularly when multiple operators are meant to be removed in a single transaction.
The issue here is after swapping an operator to be removed with the last element in the array and then removing it, the loop continues to the next index without rechecking the current index. This can lead to skipping the check for the operator that was swapped into the current position.
Consider a case where wee have an operators array with five operators lets say: [A, B, C, D, E]
We want to remove operators B and D.
Function starts with: [A, B, C, D, E]
Loop starts, j = 0
Check A, not a match, j increments to 1
Check B, it's a match:
-- Swap B with E: [A, E, C, D, B]
-- Remove last element: [A, E, C, D]
-- Decrement numOperators to 4
-- j increments to 2
Check C, not a match, j increments to 3
Check D, it's a match:
--Swap D with the last element (which is now D itself): [A, E, C, D]
--Remove last element: [A, E, C]
-- Decrement numOperators to 3
-- j increments to 4
Loop ends because j (4) is not < numOperators (3)
Result: [A, E, C]
The issue heere is that: E was never checked for removal, even though it was in the removal list.
Skipped or incomplete removal of operators, leaving unintended operators
Manual
The loop in should recheck the same index after removing an operator:
With the fix sugested above , it means the case we looked at earlier will now be:
Function will start with: [A, B, C, D, E]
Loop starts, j = 0
Check A, not a match, j increments to 1
Check B, it's a match:
-- Swap B with E: [A, E, C, D, B]
-- Remove last element: [A, E, C, D]
-- Decrement numOperators to 4
-- j stays at 1
Check E (now at index 1), not a match, j increments to 2
Check C, not a match, j increments to 3
Check D, it's a match:
-- Swap D with the last element (C): [A, E, C, C]
-- Remove last element: [A, E, C]
-- Decrement numOperators to 3
-- j stays at 3
Loop ends because j (3) is not < numOperators (3)
Result: [A, E, C]
This means all operators were correctly checked including E which was swapped into B's position.
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.