# TRSRY: reenter from OlympusTreasury::repayLoan to Operator::swap

OlympusTreasury.repayLoan measures received amount by balance delta; an ERC777 reserve token hook reenters Operator.swap to inflate the delta and over-credit debt repayment.

- Payout: Contest reward
- Severity: medium
- Program: Olympus DAO
- Credited: zzzitron
- Disclosed: 2022-10-26
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2022-08-olympus-findings/issues/403
- Library page: https://bugbountylibrary.com/r/c4%3A2022-08-olympus%3AM-19
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:reentrancy

**Target:** OlympusTreasury.repayLoan / Operator.swap (Solidity contracts)
**Root cause:** repayLoan computes received amount as balanceOf delta around safeTransferFrom; a token sender hook can reenter Operator.swap which transfers reserve into the treasury, inflating the delta so more debt is credited than actually paid.
**Steps:**
1. Deploy reserve token implementing ERC777 tokensToSend hook (or use weird ERC20 with sender hook).
2. Attacker contract takes debt of reserve token (1e18) from treasury.
3. Attacker calls `treasury.repayLoan(token, 1e17)` after approving treasury and operator.
4. During `safeTransferFrom`, token invokes `tokensToSend` on attacker contract.
5. Hook calls `operator.swap(token, 1e17, 0)`, which does `reserve.safeTransferFrom(msg.sender, address(TRSRY), amountIn_)`, increasing TRSRY balance.
6. repayLoan's post-balance delta now includes the swap amount, crediting 2e17 debt reduction for a 1e17 payment; attacker keeps the swapped OHM.
**How found:** Code reading of repayLoan's balance-delta accounting combined with knowledge of weird ERC20/ERC777 sender hooks; noticed Operator.swap transfers reserve into TRSRY, allowing the delta to be manipulated across two contracts whose nonReentrant guards don't cover each other.
**Exploitation:** Attacker needs outstanding reserve-token debt and a reserve token with a sender hook. On repayLoan, the hook reenters Operator.swap paying reserve into the treasury; the inflated balance delta over-reduces debt while the attacker receives OHM from the swap, netting value.
**Insight:** When a contract measures payment via balanceOf delta, any other path that credits the same token to that contract during the transfer (here Operator.swap) becomes a reentrancy primitive; cross-contract nonReentrant guards don't help.
