#  Ability to steal user funds and increase collateral share infinitely in BigBang and Singularity

addCollateral's allowedBorrow modifier checks the raw share arg (0) before toShare conversion, letting anyone spend another user's YieldBox approval to inflate collateral and borrow/mint infinitely.

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

**Target:** BigBang and Singularity market addCollateral (Solidity/YieldBox)
**Root cause:** allowedBorrow(from, share) runs before _addCollateral converts amount to shares when share==0, so the allowance check compares against 0 and always passes while the real share amount is later pulled from the victim's YieldBox approval.
**Steps:**
1. Victim approves BigBang/Singularity on YieldBox via setApprovalForAll.
2. Attacker calls `addCollateral(victim, attacker, false, amount, 0)` — allowedBorrow sees share=0 and passes.
3. _addCollateral computes share = yieldBox.toShare(collateralId, amount, false) and transfers that share from victim to market, crediting attacker's userCollateralShare.
4. Attacker calls `removeCollateral(attacker, attacker, shares)` to withdraw victim's shares.
5. For infinite inflation: repeatedly call `addCollateral(market, attacker, false, amount, 0)` so market transfers its own shares to itself while attacker's userCollateralShare grows each time.
6. Borrow USDO (BigBang) or borrow assets (Singularity) against the inflated collateral.
**How found:** Code reading: noticed the allowedBorrow modifier is applied to the raw `share` parameter while the actual share is computed inside _addCollateral only when share==0, so the check runs on the wrong value.
**Exploitation:** Attacker needs no capital beyond gas: uses the market's own YieldBox balance (or a victim's standing approval) as the `from`, passing share=0 to bypass allowance, then removes collateral or borrows against the inflated share to drain USDO/LPs or other users' collateral.
**Escalation:** Repeated addCollateral calls grow attacker share unboundedly (x/(x+1) of pool), enabling unlimited USDO mint/borrow and draining all markets where USDO has value.
**Insight:** When an access-control modifier guards a parameter that is later derived/normalized inside the function body, the check can be bypassed by passing the sentinel value (0) that triggers derivation — always verify checks run on the post-conversion value.
