Initial user of LMPVault can abuse rounding error to steal tokens
Summary
Similar to the well known attack vector - TOB-YEARN.
ERC4626 vault contracts suffer from a commonly known vulnerability due to division rounding. The initial user can
massively skew the ratio of shares to assets with a large"donation", and can profit off of later users.
Vulnerability Detail
In LMPVault, the deposit function has no minimum deposit limit or burn. It calls previewDeposit() with _convertToShares(assets, Math.Rounding.Down) to calculate the number of shares. This function _convertToShares() takes into account the totalAssets() returning the sum of totalIdle and totalDebt.
However, due to rounding errors, an attacker who deposits to a fresh vault can skew the ratio by transferring in a large quantity of TOKE tokens by following these steps.
Attacker deposits 1 wei of TOKE token, minting 1 wei of shares
Attacker then sends a large amount (1e18 wei) of TOKE tokens to the vault.
Normal user comes and deposits 2e18 wei of TOKE tokens. Shares calculated = 2e18 * 1 / (1e18+1) = 1 wei
User only gets minted 1 wei of token, giving him/her claim to only half the vault, which has 3e18 wei tokens, instantly losing their 0.5e18 tokens which is profited by the attacker.
Impact
Exploit by first user of vault. Loss of tokens by other users
Burn the first (if totalSupply() == 0) 10000wei of minted shares by sending them to address 0. This will make the cost to pull of this attack unfeasible.
hassan-truscova
medium
Initial user of LMPVault can abuse rounding error to steal tokens
Summary
Similar to the well known attack vector - TOB-YEARN. ERC4626 vault contracts suffer from a commonly known vulnerability due to division rounding. The initial user can massively skew the ratio of shares to assets with a large"donation", and can profit off of later users.
Vulnerability Detail
In LMPVault, the deposit function has no minimum deposit limit or burn. It calls
previewDeposit()
with_convertToShares(assets, Math.Rounding.Down)
to calculate the number of shares. This function_convertToShares()
takes into account the totalAssets() returning the sum oftotalIdle
andtotalDebt
.However, due to rounding errors, an attacker who deposits to a fresh vault can skew the ratio by transferring in a large quantity of TOKE tokens by following these steps.
Impact
Exploit by first user of vault. Loss of tokens by other users
Code Snippet
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L332-L344
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L328-L330
https://github.com/sherlock-audit/2023-06-tokemak/blob/main/v2-core-audit-2023-07-14/src/vault/LMPVault.sol#L587-L592
Tool used
Manual Review + in-house tool
Recommendation
Burn the first (if totalSupply() == 0) 10000wei of minted shares by sending them to address 0. This will make the cost to pull of this attack unfeasible.