Sandwich Attack on compound() Function Allows Value Extraction from Honest Depositors
The compound() function in MoneyBrinter.sol can be sandwiched: an attacker mints shares just before a compound transaction and redeems them just after, capturing part of the compounded rewards. This reduces the yield that honest depositors receive.
- Disclosed after under an hour
#41638 [SC-Medium] Sandwich Attack on `compound()` Function Allows Value Extraction from Honest Depositors
Submitted on Mar 17th 2025 at 07:53:19 UTC by @DoD4uFN for Audit Comp | Yeet
- Report ID: #41638
- Report Type: Smart Contract
- Report severity: Medium
- Target: https://github.com/immunefi-team/audit-comp-yeet/blob/main/src/contracts/MoneyBrinter.sol
- Impacts:
- Theft of unclaimed yield
Description
Brief/Intro
The compound() function in MoneyBrinter.sol allows the strategy manager to swap reward tokens and deposit them into BeradromeFarmPlugin, increasing the share price. However, this function is vulnerable to a sandwich attack, where an attacker can front-run the compound transaction by minting shares before it executes and then immediately selling after the share price increases, allowing them to extract a portion of the compounded rewards at the expense of honest depositors.
Vulnerability Details
The vulnerability arises due to the predictable and public nature of the compound() function’s execution. The attacker can monitor the mempool for compound() transactions and execute the following steps:
- Front-run the compound transaction: The attacker mints new shares by depositing right before the
compound()function executes. - Let the compound transaction execute: The function swaps reward tokens and deposits them into the farm, increasing the value of each share.
- Sell the inflated shares: The attacker then sells their shares immediately after, capturing a portion of the newly compounded rewards.
This results in an unfair redistribution of yield, where honest depositors receive less benefit from the compounding process while the attacker profits.
Relevant Code Snippet
function compound(
address[] calldata swapInputTokens,
IZapper.SingleTokenSwap[] calldata swapToToken0,
IZapper.SingleTokenSwap[] calldata swapToToken1,
IZapper.KodiakVaultStakingParams calldata stakingParams,
IZapper.VaultDepositParams calldata vaultStakingParams
) public override onlyStrategyManager nonReentrant returns (uint256) {
uint256 initialSupply = totalSupply();
uint256 shareValueBefore = previewRedeem(initialSupply);
_approveTokens(swapInputTokens, swapToToken0, swapToToken1);
(uint256 islandTokensMinted, uint256 vaultSharesMinted) =
zapper.zapInWithMultipleTokens(swapParams, stakingParams, vaultStakingParams);
_depositIntoFarm(islandTokensMinted);
uint256 shareValueAfter = previewRedeem(initialSupply);
require(shareValueAfter >= shareValueBefore, "MoneyBrinter: Bad Compound");
return islandTokensMinted;
}
Impact Details
This exploit enables an attacker to extract value from the yield compounding process, leading to loss of rewards for honest depositors.
References
Proof of Concept
Proof of Concept
- The attacker monitors the mempool for an impending
compound()transaction. - They submit a transaction to deposit assets and mint shares, ensuring it gets confirmed right before
compound()executes. - Once
compound()executes, increasing the share price, the attacker sells their shares immediately after, capturing the newly compounded rewards.
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 compound() function increases share value in a single transaction without any mechanism to prevent front-running or to distribute rewards only to shares that existed before the compound.
Impact
An attacker could extract a portion of the compounded rewards, causing honest depositors to receive less yield.
What the attacker needed
Attacker can monitor the mempool; attacker can submit transactions around compound()
How it was found
- Monitor the mempool for an impending compound() transaction.
- Submit a deposit transaction to mint shares, confirmed just before compound() executes.
- Let compound() execute, which increases the share price.
- Sell the shares immediately after to capture the newly compounded rewards.
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.
When a vault compounds its rewards, the value of each share goes up. If someone can buy shares just before that happens and sell just after, they pocket some of the increase that should have gone to existing depositors. This is called a sandwich attack because the attacker's two transactions wrap around the victim's transaction.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.