updateUserDeposit may overwrite user's existing deposit.
Summary
When updating user's deposit, if the user already has a deposit in userdetails, his existing deposit will be overridden. This will cause the user to lose his existing deposit, and subsequently receives fewer tokens upon claiming.
Vulnerability Detail
When updating user's deposit, updateUserDeposit does not check if the user already has a deposit in userdetails. It is possible that user may have existing deposits, as he can deposit multiple times through TokenSale.deposit. If the user does have a deposit, then his existing deposit will be overridden by the new deposit. In fact, the new deposit should be added to his existing deposits. This leads to user lose his existing deposits, and subsequently receives fewer tokens upon claiming, as the amount claimed is proportional to the user's total deposits.
53: function updateUserDeposit(
54: address[] memory _users,
55: uint256[] memory _amount
56: ) public onlyRole(DEFAULT_ADMIN_ROLE) {
57: require(_users.length <= 250, "array length should be less than 250");
58: require(_users.length == _amount.length, "array length should match");
59: uint256 amount;
60: for (uint256 i = 0; i < _users.length; i++) {
61:@> userdetails[_users[i]].userDeposit = _amount[i];
62: amount += _amount[i];
63: }
64: token.safeTransferFrom(distributionWallet, address(this), amount);
65: }
ydlee
high
updateUserDeposit
may overwrite user's existing deposit.Summary
When updating user's deposit, if the user already has a deposit in
userdetails
, his existing deposit will be overridden. This will cause the user to lose his existing deposit, and subsequently receives fewer tokens upon claiming.Vulnerability Detail
When updating user's deposit,
updateUserDeposit
does not check if the user already has a deposit inuserdetails
. It is possible that user may have existing deposits, as he can deposit multiple times throughTokenSale.deposit
. If the user does have a deposit, then his existing deposit will be overridden by the new deposit. In fact, the new deposit should be added to his existing deposits. This leads to user lose his existing deposits, and subsequently receives fewer tokens upon claiming, as the amount claimed is proportional to the user's total deposits.https://github.com/sherlock-audit/2024-03-zap-protocol/blob/main/zap-contracts-labs/contracts/Vesting.sol#L53-L65
https://github.com/sherlock-audit/2024-03-zap-protocol/blob/main/zap-contracts-labs/contracts/Vesting.sol#L67-L92
Impact
User may lose his existing deposits, and subsequently receives fewer tokens upon claiming.
Code Snippet
https://github.com/sherlock-audit/2024-03-zap-protocol/blob/main/zap-contracts-labs/contracts/Vesting.sol#L53-L65
Tool used
Manual Review
Recommendation
New deposits should be added to the user's existing deposit, not overwrite it.
Duplicate of #55