# Incorrect call argument in THORChain_Router::_transferOutAndCallV5, leading to grief/steal of THORChain_Aggregator's funds or DoS

Router transfers fee-on-transfer tokens to Aggregator then calls swapOutV5 with the pre-fee amount, reverting or draining Aggregator's rescued funds.

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

**Target:** THORChain_Router::_transferOutAndCallV5 / THORChain_Aggregator::swapOutV5
**Root cause:** _transferOutAndCallV5 transfers fromAmount to the aggregator but passes the same fromAmount to swapOutV5, ignoring the fee-on-transfer deduction, so the aggregator receives less than the amount it is told to swap.
**Steps:**
1. Deploy a fee-on-transfer ERC20 (e.g. PAXG-like) and mint balance to THORChain_Aggregator to simulate rescued funds.
2. User approves Router and calls `depositWithExpiry(ASGARD, token, _20, '', expiry)`; Router balance becomes _20 - fee.
3. ASGARD calls `transferOutAndCallV5([AGG, token, _1, ETH, USER1, '0', 'MEMO', '0x', 'bc123'])`.
4. Router transfers _1 to AGG (AGG receives _1 - fee) then calls `swapOutV5` with _1; swapOutV5 tries to move _1 but only _1 - fee exists, so it reverts or consumes AGG's rescued balance to cover the fee.
5. Repeat swaps; assert AGG balance decreases below starting value.
**How found:** Code reading of _transferOutAndCallV5 noticed the transfer amount and the swapOutV5 argument are the same variable, then checked the token whitelist for fee-on-transfer tokens (PAXG) to confirm real impact.
**Exploitation:** Any vault-initiated transferOutAndCallV5 with a whitelisted fee-on-transfer token (e.g. PAXG) causes the aggregator to pay the transfer fee out of its own held/rescued tokens, or reverts the swap entirely (DoS) when the aggregator holds no buffer.
**Insight:** When a contract transfers tokens then instructs a downstream contract to pull/swap 'the same amount', check whether the token is fee-on-transfer or rebasing; cross-reference the protocol's own token whitelist for such tokens to turn a rounding mismatch into real fund loss.

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

**Fee-on-transfer ERC20 token contract used in PoC**

```
contract FeeOnTransferERC20Token is iERC20 {
    using SafeMath for uint256;

    string public name;
    string public symbol;
    uint256 public decimals = 18;
    uint256 public override totalSupply = 1 * 10 ** 6 * (10 ** decimals);
    uint256 immutable fee;

    mapping(address => uint256) public override balanceOf;
    mapping(address => mapping(address => uint256)) public override allowance;

    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Transfer(address indexed from, address indexed to, uint256 value);

    constructor(uint256 _fee) {
        balanceOf[msg.sender] = totalSupply;
        name = "Token";
        symbol = "TKN";
        emit Transfer(address(0), msg.sender, totalSupply);
        fee = _fee;
    }

    function mint(address to, uint256 value) public returns (bool success) {
        require(to != address(0), "address error");
        balanceOf[to] = balanceOf[to].add(value);
        emit Transfer(address(0), to, value);
        return true;
    }

    function transfer(address to, uint256 value) public override returns (bool success) {
        _transfer(msg.sender, to, value);
        return true;
    }

    function approve(address spender, uint256 value) public override returns (bool success) {
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

    function transferFrom(address from, address to, uint256 value) public override returns (bool success) {
        require(value <= allowance[from][msg.sender], "allowance error");
        allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
        _transfer(from, to, value);
        return true;
    }

    function _transfer(address _from, address _to, uint256 _value) internal {
        require(_to != address(0), "address error");
        require(balanceOf[_from] >= _value, "balance error");
        require(balanceOf[_to].add(_value) >= balanceOf[_to], "balance error");
        balanceOf[_from] = balanceOf[_from].sub(_value);
        balanceOf[_to] = balanceOf[_to].add(_value.sub(fee));
        balanceOf[address(0)] = balanceOf[address(0)].add(fee);
        emit Transfer(_from, _to, _value);
    }
}
```

