The _convertToShares function implements a flawed 1:1 conversion for the first depositor, making the vault vulnerable to a classic ERC-4626 inflation attack. This allows an attacker to steal the full deposit of the first legitimate user.
Normal Behavior: The _convertToShares function is supposed to calculate the number of shares a user receives for their assets. For the very first deposit (when totalSupply == 0), it's designed to mint shares at a 1:1 ratio with the assets deposited.
The Problem: An attacker can front-run a legitimate user by depositing 1 wei, which mints them 1 share. The attacker then donates a large amount of assets by directly transferring them to the vault. This donation by the attacker inflates the balanceOfVault but not the totalShares. So when the deposit of the legitimate user is processed, the share calculation rounds down to 0 and their entire deposit is stolen.
Likelihood: High
Reason 1: This attack is executed by any user at the time when the protocol launches.
Reason 2: The attacker simply front-runs the first legitimate deposit transaction, which is usually a standard procedure in MEV.
Impact: High
Impact 1: Total and direct loss of funds for the user whose deposit is front-run.
Impact 2: The attacker profits by the full amount of the victim's stolen deposit.
This test can be added to briVault.t.sol. It shows an attacker depositing 1 wei, donating 10 ether, and causing a victim who deposits 5 ether to receive 0 shares.
The best mitigation is to remove the custom _convertToShares function and rely on the inherited OpenZeppelin ERC4626 implementation. The openzeppelin contract's constructor mints and burns 1 wei of shares, which establishes a minimum totalSupply and prevents this attack.
To keep the custom function, replicate the mitigation in the BriVault constructor
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.