# Malicious MarketHelper contract can be used in TOFTMarketReceiverModule's leverageUpReceiver and marketRemoveCollateralReceiver functions

Unwhitelisted marketHelper in TOFTMarketReceiverModule lets attacker craft arbitrary market.execute calls, stealing Magnetar's assets via mismatched withdraw recipient.

- Payout: Contest reward
- Severity: high
- Program: Tapioca
- Credited: bin2chen
- Disclosed: 2024-02-14
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-02-tapioca-judging/issues/90
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-02-tapioca%3AH-8
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high technique:source-review vuln:access-control vuln:business-logic

**Target:** TOFTMarketReceiverModule leverageUpReceiver and marketRemoveCollateralReceiver
**Root cause:** marketHelper contract is user-supplied and not whitelisted, so attacker controls the modules and calls passed to market.execute, breaking the assumption that calls follow intended operation logic.
**Steps:**
1. Craft a malicious contract implementing IMarketHelper with buyCollateral/removeCollateral returning arbitrary modules and calls.
2. Call leverageUpReceiver or marketRemoveCollateralReceiver with msg_.marketHelper set to the malicious contract.
3. In removeCollateral, set withdrawParams.withdraw=true and to=msg_.user instead of magnetar, so assets are sent directly to user while magnetar's balance is used for withdraw.
4. market.execute executes the crafted calls, draining magnetar's assets.
**How found:** Code review identified that marketHelper is not whitelisted in leverageUpReceiver and marketRemoveCollateralReceiver, unlike market, allowing arbitrary call construction.
**Exploitation:** Attacker deploys malicious MarketHelper, passes it as marketHelper in a cross-chain message to leverageUpReceiver or marketRemoveCollateralReceiver. The crafted calls cause market.execute to perform unintended operations, e.g., withdrawing collateral to the user while using Magnetar's balance, stealing Magnetar's assets.
**Insight:** When a contract accepts a user-supplied helper to build calls for a privileged executor, always whitelist the helper; otherwise the helper can bypass intended operation semantics.
