# A malicious user can steal money out of the vault and other users

THORChain Router approves rebasing AMPL by nominal amount; after a rebase the stale allowance lets an attacker drain other users' deposits from the vault.

- Payout: Audit contest
- Severity: high
- Program: Thorchain
- Found by: samuraii77
- Disclosed: 2024-08-05
- Write-up quality: 8/10
- Original: https://github.com/code-423n4/2024-06-thorchain-findings/issues/85
- Library page: https://bugbountylibrary.com/r/c4%3A2024-06-thorchain%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:race-window technique:source-review vuln:accounting-error vuln:business-logic

**Target:** THORChain_Router Ethereum contract with whitelisted rebasing token (AMPL)
**Root cause:** Router records vaultAllowance in token units at deposit time and approves routers for that nominal amount, but rebasing tokens change balance-per-unit over time, so the stored allowance no longer matches actual token value held.
**Steps:**
1. Attacker approves Router and calls `depositWithExpiry(malicious, AMPL, 1000, ...)`; vaultAllowance=1000, contract balance=1000.
2. AMPL `rebase(2)` sets `_gonsPerFragment=2`; contract balance now reads 500.
3. Attacker calls `transferAllowance(mRouter, malicious, AMPL, 1000, ...)`; router approves mRouter for 1000 AMPL while only 500 exist.
4. Victim deposits 1000 AMPL to legit vault; contract balance 1500, vaultAllowance 1000.
5. Attacker's MaliciousRouter calls `steal(1000, router, malicious, AMPL)` which calls `transferFrom(router, malicious, 1000)`; allowance check passes, attacker receives 1000 (2000/2).
6. Contract left with 500; victim's `transferOut(1000)` reverts, can only withdraw 500.
**How found:** Noticed AMPL is whitelisted and rebases via `_gonsPerFragment`; reasoned that Router's stored vaultAllowance assumes constant balance, then modeled deposit→rebase→transferAllowance→transferFrom sequence in Foundry.
**Exploitation:** Attacker deposits rebasing AMPL, waits for/frontruns a rebase that halves per-unit balance, converts his stale allowance into an approval to a malicious router, then pulls the full nominal amount via transferFrom, siphoning value deposited by a later victim.
**Escalation:** Simpler variants: call transferOut directly, or frontrun the rebase by depositing before and withdrawing after to steal from other users when balance decreases.
**Insight:** When a protocol whitelists tokens, check whether any are rebasing or otherwise non-constant-balance; any stored allowance/accounting in nominal units becomes exploitable across a rebase, especially if the rebase can be frontrun.

## Proof of concept (copied exactly from the original report)

**Malicious router transferFrom exploit contract**

```
contract MaliciousRouter {
    function depositWithExpiry(address, address, uint256, string calldata, uint) public {}

    function steal(uint256 amount, address from, address to, address target) public {
        (bool ok, ) = target.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", from, to, amount));
        if (!ok) revert();
    }
}
```

