Skip to content
Business logic Audit finding Intermediate

treasury is vulnerable to sandwich attack

A permissionless function in the treasury allowed anyone to trigger a large CRV purchase, which an attacker could sandwich with a flash loan to profit at the treasury's expense. The attacker could potentially steal all funds in the treasury.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005

Impact

There’s a permissionless function veCRVlock in MochiTreasury. Since everyone can trigger this function, the attacker can launch a sandwich attack with flashloan to steal the funds. MochiTreasuryV0.sol#L73-L94

Attackers can possibly steal all the funds in the treasury. I consider this is a high-risk issue.

Proof of Concept

MochiTreasuryV0.sol#L73-L94

Here’s an exploit pattern

  1. Flashloan and buy CRV the uniswap pool
  2. Trigger veCRVlock()
  3. The treasury buys CRV at a very high price.
  4. Sell CRV and pay back the loan.

Recommended Mitigation Steps

Recommend to add onlyOwner modifier.

ryuheimat (Mochi) confirmed

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

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

The function that performs a large token purchase lacked access control, allowing anyone to trigger it and manipulate the market around it.

Impact

Attackers could potentially steal all funds in the treasury.

What the attacker needed

Ability to call a public function; flash loan availability; liquidity in the Uniswap pool

The fix

The function should be restricted to the owner by adding an onlyOwner modifier.

How it was found

  1. Borrow funds via flash loan and buy CRV on the Uniswap pool.
  2. Call the veCRVlock function.
  3. The treasury buys CRV at the inflated price.
  4. Sell the CRV and repay the flash loan.

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 sandwich attack is when someone sees a large trade coming and places their own trades just before and after it to profit from the price change. Here, a treasury function that buys a token could be called by anyone, so an attacker could use borrowed money to push the price up, let the treasury buy at the inflated price, then sell and repay the loan, keeping the difference.

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.

More by jonah1005

View all

39 more disclosed reports, best first.

More from Mochi contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.