# User's assets can be stolen when removing them from the Singularity market through the Magnetar contract

Magnetar grants YieldBox allowance to an unvalidated BigBang address, letting an attacker pass a fake market and transfer a user's removed Singularity assets to themselves.

- Payout: Contest reward
- Severity: high
- Program: Tapioca DAO
- Credited: 0xStalin
- Disclosed: 2023-11-16
- Write-up quality: 8/10
- Original: https://github.com/code-423n4/2023-07-tapioca-findings/issues/849
- Library page: https://bugbountylibrary.com/r/c4%3A2023-07-tapioca%3AH-47
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:business-logic

**Target:** Magnetar market module (exitPositionAndRemoveCollateral) on YieldBox
**Root cause:** Magnetar does not validate that the supplied BigBang/Singularity addresses are registered protocol markets before granting YieldBox allowance and calling repay on them.
**Steps:**
1. Deploy `FakeBigBang` implementing `repay(from,to,skim,part)` that calls `yieldBox.transfer(magnetar, address(this), assetId, yieldBox.balanceOf(magnetar, assetId))`.
2. Configure FakeBigBang with the real Singularity market's assetId/yieldBox via `setMarket` and `setMagnetar`.
3. Victim approves Magnetar on Singularity and BigBang (standard flow).
4. Attacker calls `magnetar.exitPositionAndRemoveCollateral(victim, {magnetar, singularity: realSGL, bigBang: fakeBigBang}, {removeAssetFromSGL: true, removeShare: X, repayAssetOnBB: true, repayAmount: Y, ...})`.
5. Magnetar removes victim's assets from Singularity, grants ALL YieldBox allowance to FakeBigBang, calls `fakeBigBang.repay()`, which transfers the assets out to attacker.
**How found:** Code reading of MagnetarMarketModule: noticed externalData.bigBang/singularity are used without Penrose registration checks, and that Magnetar grants YieldBox allowance to the caller-supplied BigBang before calling repay.
**Exploitation:** Attacker needs only the victim's prior Magnetar approval (granted for normal use). By substituting a fake BigBang address in the externalData, Magnetar pulls the victim's Singularity assets into itself, approves the fake contract in YieldBox, and the fake repay() drains the Magnetar's YieldBox balance to the attacker.
**Insight:** Router/aggregator contracts that grant token approvals to caller-supplied addresses are prime targets: check whether the 'market' or 'spender' parameter is validated against a registry before any approve/transferFrom happens.
