Skip to content
Business logic Write-up Advanced

Mushrooms Finance Logic Error Bug Fix Review

A logic error in the interaction between two smart contracts allowed an attacker to take flash loans from the vault and have the strategy contract repay them, potentially stealing 19 wBTC worth $635,000.

immunefi.com

Published on immunefi.com

Whitehat CKK Sec, who is a recipient of Immunefi’s Whitehat Scholarship, disclosed a critical vulnerability in Mushrooms Finance to Immunefi on June 8 that consisted of a logic error, leading to a flash loan attack vector that could have resulted in the loss of 19 wBTC, which at market rate at the time of the report…

The author, on immunefi.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the strategy contract's flashloan function was callable by anyone and allowed the caller to set the repayment amount and fee, so the strategy would withdraw its own funds to repay a loan taken from the vault.

Impact

The attacker could have stolen 19 wBTC, worth about $635,000 at the time, but the contracts were paused after the report.

What the attacker needed

Ability to call the strategy contract; access to a flash loan source; some wBTC to deposit initially

The fix

Flashloan support was disabled on all Mushrooms Vaults and flashloan-related logic was re-implemented according to EIP3156.

How it was found

  1. Flash loan wBTC from elsewhere (e.g. Uniswap)
  2. Deposit wBTC to MMVault, receiving shares of Mushroom cTokens
  3. Flashloan wBTC from MMVault to the attack contract
  4. Attack contract calls mushroomsFlashloan on StrategyCmpdWbtcV1, repaying the MMVault flash loan
  5. MMVault flash loan finishes, returning to caller (attack contract)
  6. Withdraw shares from wBTC MMVault, receiving additional wBTC

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 write-up has not been written yet. The Original tab links to the source.

A flash loan is a loan that must be borrowed and repaid within the same transaction. Here, a mistake in how two contracts talked to each other let an attacker borrow money from the vault and make a different contract pay it back, so the attacker kept the borrowed money.

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.

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.