Link: https://github.com/Cyfrin/2024-09-stakelink/blob/f5824f9ad67058b24a2c08494e51ddd7efdbb90b/contracts/linkStaking/OperatorVCS.sol#L79
The value for GlobalVaultState.depositIndex is initialized with the wrong value, which causes several function, like: queueVaultRemoval and _depositToVaults to behave in a wrong way.
When the OperatorVCS contract is deployed, the initialize function will run automatically and the contract will be initialized to version 3 (because of the presence of the reinitializer(3) modifier). A version of the VaultControllerStrategy contract will already have been deployed previously, so, at this point, the token state variable will have a different value than address(0) and the else block in the code will be executed:
The problem here is that the globalVaultState.depositIndex will be set to the wrong value: uint64(maxDepositSizeBP + 1). maxDepositSizeBP will be a high value (something around 9000) and the number of vaults will be much lower than this value.
The globalVaultState.depositIndex is used in the queueVaultRemoval function:
Because of the wrong initialization of the depositIndex, the specified _index will always be lower than the depositIndex, even for vaults that are not part of a vault group. This means, the fundFlowController will potentially update the internal accounting of a vault group that should not be updated. Also, because the specified vault _index may not be part of a group, a vault that should not be removed may be removed.
The globalVaultState.depositIndex is also used in the _depositToVaults function:
In the following code section, vaultIndex will never be bigger than the globalState.depositIndex, so, this will never revert, even if an invalid _vaultId is provided:
In the following code section, the group.withdrawalIndex will never be bigger than the globalState.depositIndex, which means, the group.withdrawalIndex may be set to the wrong value:
In the following code section, the variable i will be set to an index thats far greater than the current number vaults. This means, the while loop will never be executed, it is not possible to deposit into the vault and the correct depositindex cannot be set
Manual Review
Replace the else block of the initialize function with the following code:
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.