While depositing token into the `vaults` with the `VaultDepositController::_depositToVaults` function, the `group` is being fetched from `vaultGroups` at the start of the loop. Some properties of the `group` are then modified (such as `withdrawalIndex` and `totalDepositRoom`) during the loop. However, *after modifying `group`*, it is stored only in the local memory, and not reflected back to the `vaultGroups` state array. Meaning that the changes made to group will not persist beyond the loop:
function _depositToVaults(
uint256 _toDeposit,
uint256 _minDeposits,
uint256 _maxDeposits,
uint64[] memory _vaultIds
) private returns (uint256) {
uint256 toDeposit = _toDeposit;
uint256 totalRebonded;
GlobalVaultState memory globalState = globalVaultState;
@> VaultGroup[] memory groups = vaultGroups;
if (_vaultIds.length != 0 && _vaultIds[0] != globalState.groupDepositIndex)
revert InvalidVaultIds();
for (uint256 i = 0; i < _vaultIds.length; ++i) {
@> VaultGroup memory group = groups[groupIndex];
uint256 deposits = vault.getPrincipalDeposits();
uint256 canDeposit = _maxDeposits - deposits;
globalState.groupDepositIndex = uint64(vaultIndex);
if (deposits == 0 && vaultIndex == group.withdrawalIndex) {
@> group.withdrawalIndex += uint64(globalState.numVaultGroups);
if (group.withdrawalIndex > globalState.depositIndex) {
@> group.withdrawalIndex = uint64(groupIndex);
}
}
if (canDeposit != 0 && vaultIndex != group.withdrawalIndex && !vault.isRemoved()) {
if (toDeposit > canDeposit) {
vault.deposit(canDeposit);
toDeposit -= canDeposit;
@> group.totalDepositRoom -= uint128(canDeposit);
} else {
vault.deposit(toDeposit);
@> group.totalDepositRoom -= uint128(toDeposit);
toDeposit = 0;
break;
}
}
}
}
Manual review.
function _depositToVaults(
uint256 _toDeposit,
uint256 _minDeposits,
uint256 _maxDeposits,
uint64[] memory _vaultIds
) private returns (uint256) {
/// ... The rest of code
for (uint256 i = 0; i < _vaultIds.length; ++i) {
/// ... The other code
+ vaultGroups[groupIndex] = group; // Ensure group state is updated
}
/// ... The rest of code
}