IERC20(asset()).balanceOf(address(this)) allows an attacker to donate assets and inflate the conversion rate.The finding has been idenfied within the _convertToShares function of the BriVault contract.
The _convertToShares functions tracks balance of assets in the contract using ERC20's balanceOf which returns the asset balance of the contract at that time. The weakness with this approach is that a malicious user can transfer assets to the contract directly without using the contract's deposit function, this increases the balance of assets which are not backed by shares hence inflating the conversion rate at which users mint shares.
A malicious first depositor will first deposit a few tokens, then donates tokens by transferring which drastically increases the conversion rate.
The next depositors will deposit and mint way less shares since the conversion rate has been inflated.
After the tournament has ended, the malicious user withdraws more assets and nets a profit
Likelihood:
This occurs when an attacker is the first to deposit.
Impact:
High
Donating assets inflates the conversion rate hence users will mint less shares for the amount of assets deposited, even worse, there is no slippage protection for the user to specify a minimum amount they are willing to receive. In some cases, users receive zero shares.
Proof of Concept:
Attacker who is the first depositor deposits a minimum amount
Then donates massive tokens to the vault
Conversion rate is inflated
Next depositors will mint less shares for their deposits or even zero shares at times
At the end of the tournament, attacker withdraws outsized assets netting massive profits
Add this test to briVault.t.sol, then run forge test --mt testDonationAttack -vvvv
Track the balance of assets in the contract using a storage variable and update it whenever a user deposits.
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.