Open c4-bot-5 opened 4 months ago
MiloTruck marked the issue as primary issue
MiloTruck marked issue #10 as primary and marked this issue as a duplicate of 10
MiloTruck marked the issue as satisfactory
MiloTruck changed the severity to QA (Quality Assurance)
MiloTruck marked the issue as grade-b
Lines of code
https://github.com/code-423n4/2024-07-karak/blob/f5e52fdcb4c20c4318d532a9f08f7876e9afb321/src/Vault.sol#L94
Vulnerability details
[M-01] A vault's first deposit can be frontrunned to grief deposits below a treshold
Since the Solady's implementation of ERC-4626 uses the balance of
depositToken
as the base to price shares, if the contract is initially sent somedepositToken
via direct transfer, each deposit after that which is below the transfer amount (price of each share) will get zero shares in return. Also note that this will worsen as more users deposit values below this threshold, as each deposit increases the 1 share price. Moreover, using thevault::deposit
with expected share does not solve this issue either because thevault::convertToShares
suffers from the same problem.Impact
Deposits below a certain threshold will be lost and no share will be issued for them. This threshold will rise as more users fall for this, causing the vault to be unusable in the long term.
Proof of Concept
The proof is rather easy, just add the following test to the existing
vault.t.sol
file: Here are the steps to exploit:vault::deposit
(initial deposit to this vault).Now there is 2.001 deposit tokens in the contract, and any deposit below this will not give any shares to the depositor.
Tools Used
Manual Review
Recommended Mitigation Steps
A quick fix would be adding an initial deposit to the
vault::initialize
function, or directly call deposit in thefactory/Core
contract. This will mint some initial shares for the operator and stop anyone from griefing the vaults.Assessed type
Other