Skip to content
Smart contracts Audit finding Intermediate

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.

DoD4uFN Follow

Originally disclosed on Immunefi

  • 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

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:

  1. Front-run the compound transaction: The attacker mints new shares by depositing right before the compound() function executes.
  2. Let the compound transaction execute: The function swaps reward tokens and deposits them into the farm, increasing the value of each share.
  3. 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

Solidity
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

MoneyBrinter:compound

Proof of Concept

Proof of Concept

  1. The attacker monitors the mempool for an impending compound() transaction.
  2. They submit a transaction to deposit assets and mint shares, ensuring it gets confirmed right before compound() executes.
  3. Once compound() executes, increasing the share price, the attacker sells their shares immediately after, capturing the newly compounded rewards.

The original report as published on Immunefi, by DoD4uFN. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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

  1. Monitor the mempool for an impending compound() transaction.
  2. Submit a deposit transaction to mint shares, confirmed just before compound() executes.
  3. Let compound() execute, which increases the share price.
  4. 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.

More by DoD4uFN

View all

6 more disclosed reports, best first.

More from Yeet

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.