BriVault

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

First Depositor Share Manipulation via Direct Asset Transfer

Root + Impact

The _convertToShares function uses the current vault balance to calculate shares. An attacker can manipulate the share price for subsequent depositors by directly transferring assets to the vault before the first deposit. This breaks the 1:1 initial ratio assumption and can cause significant precision loss for early depositors, similar to ERC4626 inflation attacks.

Impact

Early depositors receive significantly fewer shares than expected, leading to unfair distribution of winnings.
An attacker can grief the system by making shares extremely expensive, potentially causing rounding to zero for small deposits.

Scenario

// Step 1: Attacker directly transfers 1000 ether to vault
token.transfer(address(vault), 1000 ether);
// Step 2: Attacker deposits 1 wei
vault.deposit(minimumAmount + fee, attacker);
// Gets shares = minimumAmount (approximately)
// Vault balance = 1000 ether + minimumAmount
// Step 3: Victim deposits 100 ether
vault.deposit(100 ether, victim);
// Expected shares: 100 ether worth
// Actual shares = 100 ether * minimumAmount / (1000 ether + minimumAmount)
// ≈ 0.1 * minimumAmount (99.9% value loss)

Affected code

function _convertToShares(uint256 assets) internal view returns (uint256 shares) {
uint256 balanceOfVault = IERC20(asset()).balanceOf(address(this));
uint256 totalShares = totalSupply();
if (totalShares == 0 || balanceOfVault == 0) {
return assets; // 1:1 ratio for first depositor
}
shares = Math.mulDiv(assets, totalShares, balanceOfVault);
}

Proposed fix

uint256 constant VIRTUAL_SHARES_OFFSET = 1e3;
uint256 constant VIRTUAL_ASSETS_OFFSET = 1e3;
function _convertToShares(uint256 assets) internal view returns (uint256 shares) {
uint256 balanceOfVault = IERC20(asset()).balanceOf(address(this)) + VIRTUAL_ASSETS_OFFSET;
uint256 totalShares = totalSupply() + VIRTUAL_SHARES_OFFSET;
shares = Math.mulDiv(assets, totalShares, balanceOfVault);
}
Updates

Appeal created

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

Inflation attack

Support

FAQs

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

Give us feedback!