The _depositToVaults function in the VaultControllerStrategy contract contains a potential data corruption vulnerability due to unsafe downcasting from uint256 to uint64, which could lead to incorrect vault indexing and fund distribution.
In the _depositToVaults function, there's an unsafe downcasting operation:
Here, vaultIndex is a uint256, but it's being cast to a uint64. If vaultIndex is larger than the maximum uint64 value (18446744073709551615), this operation will silently truncate the value, potentially corrupting the groupDepositIndex.
Corrupted vault indexing: The contract may lose track of which vaults have been processed, leading to skipped vaults or repeated processing of the same vault.
Uneven fund distribution: Funds may not be distributed correctly across vaults, potentially favoring some vaults over others.
Stuck funds: In extreme cases, funds might become trapped in the contract due to incorrect indexing.
Silent failures: The issue doesn't cause a revert, making it hard to detect and potentially allowing the contract to operate with corrupted state.
The severity is high due to the potential for fund mismanagement and the silent nature of the failure.
The issue occurs in the _depositToVaults function of the VaultControllerStrategy contract. It's caused by the implicit assumption that the vaultIndex will always fit within a uint64, which may not hold true as the number of vaults grows.
In these examples, any input larger than 18446744073709551615 results in corrupted data without any error or revert.
Below are some suggestions which should be implemented for fixing this bug:
You can use SafeCast library from OZ:
This will revert if the value doesn't fit, preventing silent failures.
or you can also add explicit bounds checking:
or maybe consider using uint256 for groupDepositIndex if larger values are expected in the future.
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.