This repository was archived by the owner on Mar 3, 2024. It is now read-only.
inspecktor - Inflation share price by first depositor in LMPVault.sol #779
Labels
Excluded
Excluded by the judge without consulting the protocol or the senior
Non-Reward
This issue will not receive a payout
inspecktor
false
Inflation share price by first depositor in LMPVault.sol
Summary
Inflation share price can be done by depositing as soon as the vault is created.
Impact:
The problem exists because the exchange rate is calculated as the ratio between shares totalSupply and totalAssets().
When an attacker transfers assets, totalAssets() incrementally increases and hence the exchange rate also increases.
ERC4626 vaults are subject to a share price manipulation attack that allows an attacker to steal the underlying tokens from other contributors (this is a known issue with the Solmate ERC4626 implementation (transmissions11/solmate#178)).
Vulnerability Detail
Alice - the first storekeeper;
Alice contributes 1 wei tokens;
In the deposit() function, the number of shares is calculated using the previewDeposit() function:
function deposit(
uint256 assets,
address receiver
) public virtual override nonReentrant noNavChange ensureNoNavOps returns (uint256 shares) {
Errors.verifyNotZero(assets, "assets");
if (assets > maxDeposit(receiver)) {
revert ERC4626DepositExceedsMax(assets, maxDeposit(receiver));
}
shares = previewDeposit(assets);
_transferAndMint(assets, shares, receiver);
}
Since Alice is the first contributor (totalSupply is 0), she gets 1 share (1 wei);
Then Alice sends 9999999999999999999 tokens (10e18 - 1) to the vault;
The price for 1 share is now 10 tokens: Alice is the only depositor in the vault, she holds 1 wei of shares, and the pool balance is 10 tokens;
Bob contributes 19 tokens and only gets 1 share due to rounding in the convertToShares function: 19e18 * 1 / 10e18 == 1;
Alice redeems her share and receives half of the deposited assets, 14.5 tokens (minus the withdrawal fee);
Bob redeems his share and receives only 14.5 tokens (minus withdrawal fees) instead of the 19 tokens he deposited.
Tool used
Manual Review
Recommendation
Consider any of these options:
The text was updated successfully, but these errors were encountered: