BriVault

First Flight #52
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Valid

stakedAsset Overwritten on Multiple Deposits Leading to Loss of Funds

Title

stakedAsset Overwritten on Multiple Deposits Leading to Loss of Funds

Risk

Likelihood

Users depositing multiple times before the event starts.

Impact

Permanent loss of funds from previous deposits when canceling participation. Inconsistent state between stakedAsset and minted shares.

Reference Files

src/briVault.sol

Description

  • In normal operation, the deposit function should accumulate the total staked assets for each user to allow full refunds when canceling participation. This ensures that users can retrieve all their deposited funds if they choose to cancel before the event begins.

  • The issue is that stakedAsset[receiver] is assigned the current stakeAsset instead of adding to it, causing only the last deposit amount to be stored, while shares are correctly accumulated. This leads to a mismatch where the contract tracks more shares than the actual staked assets recorded, resulting in partial refunds and fund loss.

stakedAsset[receiver] = stakeAsset; // @> Assignment overwrites instead of accumulating

Proof of Concept

The following test demonstrates the vulnerability: a user deposits 5 ether twice, but stakedAsset only records the last 5 ether. When canceling, only 5 ether is refunded, but 10 shares are burned, causing a loss of 5 ether.

function testMultipleDepositsLoss() public {
vm.startPrank(user1);
mockToken.approve(address(briVault), 10 ether);
briVault.deposit(5 ether, user1); // First deposit: stakedAsset = 5, shares = 5
briVault.deposit(5 ether, user1); // Second deposit: stakedAsset overwritten to 5, shares = 10
briVault.cancelParticipation(); // Refunds only 5 ether, burns 10 shares, losing 5 ether
vm.stopPrank();
// User1 has lost 5 ether due to incorrect accumulation
}

Recommended Mitigation

To fix this, change the assignment to accumulation in the deposit function. This ensures stakedAsset correctly sums all deposits for proper refunds.

- stakedAsset[receiver] = stakeAsset;
+ stakedAsset[receiver] += stakeAsset;

Shares Minted to msg.sender Instead of Specified Receiver

Updates

Appeal created

bube Lead Judge 16 days ago
Submission Judgement Published
Validated
Assigned finding tags:

`stakedAsset` Overwritten on Multiple Deposits

Vault tracks only a single deposit slot per user and overwrites it on every call instead of accumulating the total.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!