After a vault is deployed, an attacker can call the following Vault.deposit(uint256 assets, address to) function to deposit 1 wei of the vaults underlying token. Afterwards, a staker also calls the Vault.deposit(uint256 assets, address to) function to deposit some of the underlying token. While the stakers Vault.deposit transaction is in the mempool, the attacker frontruns such transaction by sending a very large amount of the underlying token directly to the vault, which increases the vaults totalAssets() by a lot. After the frontrunning, when the stakers Vault.deposit transaction calls soladys ERC4626.deposit, ERC4626.previewDeposit, and ERC4626.convertToShares functions, executing FixedPointMathLib.fullMulDiv(assets, totalSupply() + 1, _inc(totalAssets())) can return 0 because totalAssets() is higher than assets * (totalSupply() + 1). As a result, the staker fails to mint any shares even though he deposits some of the underlying token already, and the attacker can redeem his share for the deposits he and the staker made. This means that the attacker is able to steal the stakers deposit.
https://github.com/code-423n4/2024-07-karak/blob/53eb78ebda718d752023db4faff4ab1567327db4/src/Vault.sol#L78-L87
https://github.com/vectorized/solady/blob/main/src/tokens/ERC4626.sol#L376-L380
https://github.com/Vectorized/solady/blob/main/src/tokens/ERC4626.sol#L220-L222
https://github.com/Vectorized/solady/blob/main/src/tokens/ERC4626.sol#L167-L179
Certain amount of shares can be minted to address(0) during the deployment of the vault, and the first depositor can be required to mint a minimal amount of shares.
