Root + Impact
Description
The deposit function in BriVault.sol overrides the ERC4626 deposit function but incorrectly mints shares to msg.sender instead of the specified receiver parameter. This violates the ERC4626 specification, which requires shares to be minted to the receiver address.
function deposit(uint256 assets, address receiver) public override returns (uint256) {
require(receiver != address(0));
@> _mint(msg.sender, participantShares);
}
Risk
Likelihood:
Impact:
Proof of Concept
function test_DepositMintsToWrongAddress() public {
vm.startPrank(user1);
mockToken.approve(address(briVault), 5 ether);
uint256 user1SharesBefore = briVault.balanceOf(user1);
uint256 user2SharesBefore = briVault.balanceOf(user2);
console.log("Before deposit:");
console.log(" user1 shares:", user1SharesBefore);
console.log(" user2 shares:", user2SharesBefore);
uint256 sharesMinted = briVault.deposit(5 ether, user2);
uint256 user1SharesAfter = briVault.balanceOf(user1);
uint256 user2SharesAfter = briVault.balanceOf(user2);
console.log("\nAfter deposit(5 ether, user2):");
console.log(" user1 shares:", user1SharesAfter);
console.log(" user2 shares:", user2SharesAfter);
console.log(" shares minted:", sharesMinted);
vm.stopPrank();
assertEq(user1SharesAfter, user1SharesBefore + sharesMinted,
"Shares incorrectly minted to msg.sender (user1)");
assertEq(user2SharesAfter, user2SharesBefore,
"Receiver (user2) did not receive shares");
}
Recommended Mitigation
Fix the minting line to use receiver instead of msg.sender:
function deposit(uint256 assets, address receiver) public override returns (uint256) {
require(receiver != address(0));
if (block.timestamp >= eventStartDate) {
revert eventStarted();
}
uint256 fee = _getParticipationFee(assets);
// charge on a percentage basis points
if (minimumAmount + fee > assets) {
revert lowFeeAndAmount();
}
uint256 stakeAsset = assets - fee;
stakedAsset[receiver] = stakeAsset;
uint256 participantShares = _convertToShares(stakeAsset);
IERC20(asset()).safeTransferFrom(msg.sender, participationFeeAddress, fee);
IERC20(asset()).safeTransferFrom(msg.sender, address(this), stakeAsset);
- _mint(msg.sender, participantShares);
+ _mint(receiver, participantShares);
emit deposited (receiver, stakeAsset);
return participantShares;
}