The withdraw function in the VaultDepositController contract performs an unsafe downcast from uint256 to uint128 when updating the totalDepositRoom of a vault group. This can lead to data truncation if the value being cast exceeds the maximum value that a uint128 can hold, resulting in incorrect accounting of deposit room and financial discrepancies.
The issue arises from the unsafe casting of totalWithdrawn from uint256 to uint128 without checking if the value fits within the uint128 range.
Context:
User A wants to withdraw a large amount of tokens from the vault.
The total number of tokens to be withdrawn is 2^130, which exceeds the limit of uint128.
Withdrawal Process:
The withdraw function is called with the withdrawal amount of 2^130.
totalWithdrawn is calculated as 2^130.
Downcasting:
When totalWithdrawn (2^130) is cast to uint128, it exceeds the maximum limit of uint128 (2^128 - 1).
As a result, the value of totalWithdrawn is truncated to a smaller value, such as 0, because only the lower half of the bits are taken.
Impact:
group.totalDepositRoom does not reflect the correct amount due to the truncated value.
User A does not receive the correct number of tokens, or may be shown the wrong deposit room.
The truncation can lead to incorrect accounting of the totalDepositRoom, causing discrepancies in the vault's financial records.
Maual review
use OpenZeppelin's SafeCast library to safely downcast integers.
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.