{
 "angle": "accounting",
 "commit": "bbeda7b27ae80abcf070e0158cb8a31e87bb2286",
 "anySurvives": true,
 "environment": "Fresh clone of https://github.com/morpho-org/vault-v2 checked out at bbeda7b27ae80abcf070e0158cb8a31e87bb2286 with submodules initialised; git status showed only the untracked test/poc/ directory, and src/ and lib/ were unchanged. forge 1.7.1 (4072e487). This machine had no native solc 0.8.19/0.8.21/0.8.34/0.8.37. Downloading binaries from binaries.soliditylang.org and GitHub releases was refused here, so the official solc-js (soljson) builds of those exact versions were installed from npm and wrapped as solc executables for forge's svm directory. The compiler versions and settings come from foundry.toml unchanged, only the binaries are the JS builds. Before forge test, the PoC author's targeted prebuild was run as stated: forge build --offline lib/midnight/src/Midnight.sol lib/midnight/src/ratifiers/SetterRatifier.sol src/VaultV2.sol src/VaultV2Factory.sol src/adapters/midnight/MidnightAdapterFactory.sol src/adapters/midnight/ratifiers/MidnightAdapterPriceRatifierV1.sol test/imports/MidnightImport.sol (rc=0).",
 "checks": [
  {
   "id": "ACC-1",
   "title": "shortfallAllowance consumption is path-dependent: a shortfall sale split into pieces is charged more allowance than the same sale done at once, and an outside taker can split fills of the adapter's maker sell offer to exhaust the allowance early",
   "reran": true,
   "command": "forge test --offline --match-path test/poc/ShortfallAllowanceChunking.t.sol -vv   (repo root of morpho-org/vault-v2 @ bbeda7b2; PoC written unchanged to test/poc/ShortfallAllowanceChunking.t.sol)",
   "output": "Compiling 30 files with Solc 0.8.28\nCompiling 9 files with Solc 0.8.37\nCompiling 3 files with Solc 0.8.37\nCompiling 19 files with Solc 0.8.28\nCompiling 4 files with Solc 0.8.37\nCompiling 25 files with Solc 0.8.37\nCompiling 4 files with Solc 0.8.37\nCompiling 74 files with Solc 0.8.28\nSolc 0.8.28 finished in 298.80ms\nSolc 0.8.37 finished in 647.63ms\nSolc 0.8.37 finished in 816.45ms\nSolc 0.8.37 finished in 1.69s\nSolc 0.8.37 finished in 2.85s\nSolc 0.8.28 finished in 3.51s\nSolc 0.8.37 finished in 3.72s\nSolc 0.8.28 finished in 41.13s\nCompiler run successful!\nRan 10 tests for test/poc/ShortfallAllowanceChunking.t.sol:ShortfallAllowanceChunkingPoC\n[PASS] testAllocatorSaleInPiecesConsumesMoreAllowance() (gas: 3933897)\nLogs:\n  idle+realAssets before 100084346798178607255874\n  1 take:   allowance consumed 50069921111211219809\n  1 take:   idle+realAssets 100084346798189681319247\n  1 take:   netRate 8735599645\n  20 takes: allowance consumed 52599017994081945687\n  20 takes: idle+realAssets 100084346798608551701820\n  20 takes: netRate 8735599636\n  extra allowance consumed 2529096882870725878\n[PASS] testForceDeallocate() (gas: 1184052)\n[PASS] testForceSell() (gas: 1182009)\n[PASS] testMakerBuy() (gas: 881516)\n[PASS] testMakerSell() (gas: 1335294)\n[PASS] testMakerSellFilledInPiecesConsumesMoreAllowance() (gas: 3898644)\nLogs:\n  allowance before 51000000000000000000\n  sale price (WAD) 989932200000000000\n  1 fill:   allowance consumed 50069921111211219809\n  1 fill:   idle+realAssets 100084346798189681319247\n  fill reverted at piece 19\n  0x8ea54d94\n  20 fills: units filled 9500000000000000000000\n  20 fills: allowance consumed 49834436012548795750\n  20 fills: idle+realAssets 100084346798597656807086\n  idle+realAssets before 100084346798178607255874\n[PASS] testRepayWithdrawRedeem() (gas: 1166267)\n[PASS] testTakerBuy() (gas: 899462)\n[PASS] testTakerSell() (gas: 1362766)\n[PASS] testWrapperGateForceDeallocateAfterRevocation() (gas: 14735455)\nSuite result: ok. 10 passed; 0 failed; 0 skipped; finished in 20.11ms (42.93ms CPU time)\nRan 1 test suite in 21.44ms (20.11ms CPU time): 10 tests passed, 0 failed, 0 skipped (10 total tests)\nreal\t0m46.914s\nuser\t1m23.542s\nsys\t0m4.530s",
   "passes": true,
   "repairDiff": "",
   "refutationAttempts": [
    {
     "what": "Check whether src/ or lib/ were edited and whether Midnight or VaultV2 are mocked",
     "result": "git status in the clean clone showed only '?? test/poc/'. The PoC inherits test/integration/MidnightAdapterIntegrationTest.sol, which deploys the real Midnight via deployCode(\"Midnight.sol:Midnight\"), the real MidnightAdapterFactory/MidnightAdapter, the real MidnightAdapterPriceRatifierV1 and SetterRatifier, and the real VaultV2 from BaseTest. Only the collateral token and oracle are mocks (ERC20Mock, OracleMock), and they do not affect onSell accounting."
    },
    {
     "what": "Check cheatcodes for powers a real attacker lacks",
     "result": "No vm.store or vm.etch. deal() only funds the outside taker (lender) and the borrower's collateral. vm.prank(allocator) ratifies the sell offer and vm.prank(curator) calls decreaseShortfallAllowance: both are those roles' normal actions. The allowance increase goes through the vault timelock (_submitAndSet). In the maker-sell variant the splitting itself is done by an untrusted address (lender) calling midnight.take directly with units = sold/20."
    },
    {
     "what": "Vary the number of pieces with an outside taker filling the adapter's maker sell offer (scratch test test/poc/Variants.t.sol, 18 decimals, 100k assets bought at ~0.994 for 7 days, 1 day elapsed, 10k units sold at ~0.9899)",
     "result": "Allowance used: 1 fill 50.069921111211219809; 2 fills 51.379370952688378439 (+2.61%); 5 fills 52.188124924689545883 (+4.23%); 20 fills 52.599017994081945687 (+5.05%); 100 fills 52.709323859805051033 (+5.27%). The overcharge grows with the number of pieces and levels off near +5.3%."
    },
    {
     "what": "Vary the sale size relative to the position",
     "result": "1k of ~100.6k units: +0.24% (2 pieces) up to +0.49% (100 pieces) on 5.006992 tokens. 50k of ~100.6k units: single 250.349605556 tokens; 2 pieces 291.746986732 (+16.53%); 5 pieces 322.632984643 (+28.87%); 20 pieces 340.046431568 (+35.82%); 100 pieces 344.921221005 (+37.77%). The impact grows with the share of unearned interest held by the credit being sold."
    },
    {
     "what": "Change the price (shallower shortfall, tick price ~0.9958 instead of ~0.9899)",
     "result": "Single 8.384921111 tokens vs 20 pieces 8.808454412 (+5.05%) and 100 pieces 8.826926781 (+5.27%). The relative overcharge does not depend on the price, only on the share of the position sold."
    },
    {
     "what": "Dilute with a second active market (50k assets in market A, 50k in market B maturing 12h later; sell 10k or 5k units of A)",
     "result": "Selling 10k of A: single 50.069921111 vs 20 pieces 52.491612631 (+4.83%) and 100 pieces 52.597075607 (+5.04%). Selling 5k of A: single 25.034960555 vs 20 pieces 25.620759720 (+2.33%) and 100 pieces 25.645829944 (+2.44%). Other markets only take part of the re-counted shortfall. The overcharge stays at roughly half the sold credit's share of total unearned interest."
    },
    {
     "what": "6-decimal underlying (DECIMALS=6) for the original PoC and the variants",
     "result": "The original PoC passes: 1 take 50.069921 vs 20 takes 52.599028 (+2.529107 tokens). The maker-sell variant reverts with 0x8ea54d94 (ShortfallAllowanceExceeded) at piece 19 after 9,500 of 10,000 units with a 51-token allowance. The 50k sale gives the same +37.77% at 100 pieces. Result is the same as with 18 decimals."
    },
    {
     "what": "Is the effect real or only dust or a documented rounding direction?",
     "result": "Not dust and not rounding: 2.53 tokens on a 50.07-token shortfall, and 94.6 tokens on a 250.35-token shortfall. MidnightAdapter.sol:146 documents only a rounding effect in the opposite direction (interest reduced by slightly more than the allowance consumed). Book value is unchanged by splitting: in the PoC, idle+realAssets differ by 4.2e-7 tokens and netRate by 9 units (1e18-scaled per second). No depositor value is lost or mispriced. The only effect is the guardrail."
    },
    {
     "what": "Is the behaviour stated as intended?",
     "result": "Partly. README.md:117 says shortfallAllowance 'is consumed at every sale below amortized value', and MidnightAdapter.sol:145 says 'Each sale with a shortfall consumes it', so charging each piece at its current amortized value matches the literal text. Neither the README nor the NatSpec says that this makes consumption depend on how a sale is split, or that it exceeds the economic shortfall. README.md:112 says these constraints are 'intended for operational quality of life, not to provide guarantees to depositors'. No accepted-risk entry covers it."
    },
    {
     "what": "Is the failure direction harmful?",
     "result": "It fails safe. The guardrail becomes stricter than intended: sales revert instead of allowing more loss. What it causes is a temporary denial of service: shortfall sales in all non-forceSellable markets revert until the curator raises the allowance through the timelocked increaseShortfallAllowance (README.md:34, :123). Sales at or above amortized value, forceSellable sales and withdrawals are unaffected. A griefer can only consume allowance by filling offers the allocator has already ratified at shortfall prices, and the extra is bounded by the re-counted share."
    }
   ],
   "inPriorAudits": false,
   "priorAuditRef": "Neither draft has this root cause. Both reviewed commit 6476e9d9, where onSell spread the shortfall only to the sold market's own rate and there was no shortfallAllowance. The words 'shortfallAllowance' and 'netRate' appear in neither PDF. Closest items: Cantina draft 3.1.1 'Blended-rate updates hide allocator-controlled round-trip losses from redeeming shareholders' (PDF pp.5-7) is about losses deferred from redeemers, not about a loss budget being over-consumed. Cantina 3.6.6 (PDF p.19) covers buy-side rounding with partitioned fills. TrustSec TRST-R-14 'The rate rounding in onBuy() and onSell() should be documented' (PDF p.24) covers rounding drift from repeated takes. TRST-R-7 (PDF pp.19-20) covers sale-rate bounds. All of these are different root causes. Page numbers are PDF page indexes, and the PDFs were read by a reader subagent.",
   "outOfScope": false,
   "why": "Not in the prior audits and not listed as an accepted risk. The fill-splitting variant is driven by an untrusted taker of an allocator-ratified maker sell offer, so it is not a trusted role acting against the vault. Ordinary partial fills by many takers trigger it too. The variant where the allocator splits its own takes is trusted-role behaviour on its own and should be presented only as an illustration.",
   "verdict": "survives",
   "severity": "Low",
   "severityReasoning": "Impact Low: no funds are lost or misvalued, and book value and netRate are the same within rounding whether the sale is split or not. The effect is that a curator guardrail, which README.md:112 calls 'operational quality of life, not to provide guarantees to depositors', is used up faster than the economic shortfall: +2.4% to +5.3% for 5-10% of a position and up to +37.8% for half of one. Shortfall sales are then blocked until a timelocked increase, and the failure is fail-safe. Likelihood Medium: maker sell offers are routinely filled in pieces, any taker chooses the fill size, and deliberate splitting costs only gas. Cantina matrix Low x Medium = Low. The behaviour matches the literal per-sale consumption wording in README.md:117 and fails safe, so a judge may well downgrade it to Informational.",
   "affected": "src/adapters/midnight/MidnightAdapter.sol:643-648 (soldAmortizedValue at the market's current, already reduced netRate; allowance charged); src/adapters/midnight/MidnightAdapter.sol:649-686 (shortfall spread over all active markets including the sold market, raising per-unit amortized value of its remaining credit); src/adapters/midnight/MidnightAdapter.sol:145-148 (shortfallAllowance NatSpec); src/adapters/midnight/README.md:117",
   "notes": "Reproduced exactly: the original numbers match to the wei at 18 decimals. The write-up should: (1) Lead with the outside-taker or partial-fill path. The allocator-split path is trusted-role behaviour and only illustrates the mechanism. (2) State plainly that no depositor funds are lost, that the failure is fail-safe (stricter guardrail, sales revert), and that recovery is a timelocked increaseShortfallAllowance. (3) Not present the 51-token allowance as typical. It leaves only 1.86% margin over the 50.07-token single-sale shortfall. Give the scaling instead: the overcharge is roughly half the sold credit's share of total unearned interest (about +5% for 10% of a single-market position, +37.8% for half a position at 100 pieces, +2.4% for 5k of a 50k market next to an equal second market). (4) Acknowledge that README.md:117 literally says the allowance 'is consumed at every sale below amortized value', and argue that the path dependence is undocumented rather than that the code contradicts the docs. (5) Mark the suggested fixes as UNVERIFIED: they were not implemented or tested by the reviewer or by this check. The low/info items in the input (forceDeallocate fee rounding, buy rounding, zero-unit fills) were not candidates and were not re-checked here. The variant figures come from a scratch test written for this check (test/poc/Variants.t.sol in the scratch clone, not delivered). Its key outputs are in variantOutput below."
  }
 ],
 "variantOutput18": "Compiling 1 files with Solc 0.8.28\nSolc 0.8.28 finished in 18.90s\nCompiler run successful!\nRan 6 tests for test/poc/Variants.t.sol:VariantsChecker\n[PASS] testSize10k() (gas: 20437614)\nLogs:\n  sold 10k of ~100.6k units\n    pieces 1 allowance used 50069921111211219809\n    extra vs single (bps) 0\n  sold 10k of ~100.6k units\n    pieces 2 allowance used 51379370952688378439\n    extra vs single (bps) 261\n  sold 10k of ~100.6k units\n    pieces 5 allowance used 52188124924689545883\n    extra vs single (bps) 423\n  sold 10k of ~100.6k units\n    pieces 20 allowance used 52599017994081945687\n    extra vs single (bps) 505\n  sold 10k of ~100.6k units\n    pieces 100 allowance used 52709323859805051033\n    extra vs single (bps) 527\n[PASS] testSize10kPrice0995() (gas: 20378911)\nLogs:\n  sold 10k at ~0.9958\n    pieces 1 allowance used 8384921111211219809\n    extra vs single (bps) 0\n  sold 10k at ~0.9958\n    pieces 2 allowance used 8604207131068674434\n    extra vs single (bps) 261\n  sold 10k at ~0.9958\n    pieces 5 allowance used 8739644501107757656\n    extra vs single (bps) 423\n  sold 10k at ~0.9958\n    pieces 20 allowance used 8808454412869687577\n    extra vs single (bps) 505\n  sold 10k at ~0.9958\n    pieces 100 allowance used 8826926781745590652\n    extra vs single (bps) 527\n[PASS] testSize1k() (gas: 20437350)\nLogs:\n  sold 1k of ~100.6k units\n    pieces 1 allowance used 5006992111121121981\n    extra vs single (bps) 0\n  sold 1k of ~100.6k units\n    pieces 2 allowance used 5019497907326555044\n    extra vs single (bps) 24\n  sold 1k of ~100.6k units\n    pieces 5 allowance used 5027021475899446722\n    extra vs single (bps) 40\n  sold 1k of ~100.6k units\n    pieces 20 allowance used 5030788913171463919\n    extra vs single (bps) 47\n  sold 1k of ~100.6k units\n    pieces 100 allowance used 5031794209449149840\n    extra vs single (bps) 49\n[PASS] testSize50k() (gas: 20437438)\nLogs:\n  sold 50k of ~100.6k units\n    pieces 1 allowance used 250349605556056099045\n    extra vs single (bps) 0\n  sold 50k of ~100.6k units\n    pieces 2 allowance used 291746986732537014741\n    extra vs single (bps) 1653\n  sold 50k of ~100.6k units\n    pieces 5 allowance used 322632984643987009563\n    extra vs single (bps) 2887\n  sold 50k of ~100.6k units\n    pieces 20 allowance used 340046431568943547696\n    extra vs single (bps) 3582\n  sold 50k of ~100.6k units\n    pieces 100 allowance used 344921221005401580563\n    extra vs single (bps) 3777\n[PASS] testTwoMarkets10k() (gas: 23891458)\nLogs:\n  two markets, sold 10k of A (~50.3k)\n    pieces 1 allowance used 50069921111211219809\n    extra vs single (bps) 0\n  two markets, sold 10k of A (~50.3k)\n    pieces 2 allowance used 51324657243229554673\n    extra vs single (bps) 250\n  two markets, sold 10k of A (~50.3k)\n    pieces 5 allowance used 52098648641592295067\n    extra vs single (bps) 405\n  two markets, sold 10k of A (~50.3k)\n    pieces 20 allowance used 52491612631514877833\n    extra vs single (bps) 483\n  two markets, sold 10k of A (~50.3k)\n    pieces 100 allowance used 52597075607236713780\n    extra vs single (bps) 504\n[PASS] testTwoMarkets5k() (gas: 23891149)\nLogs:\n  two markets, sold 5k of A (~50.3k)\n    pieces 1 allowance used 25034960555605609905\n    extra vs single (bps) 0\n  two markets, sold 5k of A (~50.3k)\n    pieces 2 allowance used 25340975942463730905\n    extra vs single (bps) 122\n  two markets, sold 5k of A (~50.3k)\n    pieces 5 allowance used 25527038156972941479\n    extra vs single (bps) 196\n  two markets, sold 5k of A (~50.3k)\n    pieces 20 allowance used 25620759720354756323\n    extra vs single (bps) 233\n  two markets, sold 5k of A (~50.3k)\n    pieces 100 allowance used 25645829944433399531\n    extra vs single (bps) 244\nSuite result: ok. 6 passed; 0 failed; 0 skipped; finished in 95.47ms (422.02ms CPU time)\nRan 1 test suite in 98.77ms (95.47ms CPU time): 6 tests passed, 0 failed, 0 skipped (6 total tests)",
 "variantOutput6": "No files changed, compilation skipped\nRan 2 tests for test/poc/Variants.t.sol:VariantsChecker\n[PASS] testSize10k() (gas: 20437614)\nLogs:\n  sold 10k of ~100.6k units\n    pieces 1 allowance used 50069921\n    extra vs single (bps) 0\n  sold 10k of ~100.6k units\n    pieces 2 allowance used 51379372\n    extra vs single (bps) 261\n  sold 10k of ~100.6k units\n    pieces 5 allowance used 52188127\n    extra vs single (bps) 423\n  sold 10k of ~100.6k units\n    pieces 20 allowance used 52599028\n    extra vs single (bps) 505\n  sold 10k of ~100.6k units\n    pieces 100 allowance used 52709371\n    extra vs single (bps) 527\n[PASS] testSize50k() (gas: 20437438)\nLogs:\n  sold 50k of ~100.6k units\n    pieces 1 allowance used 250349606\n    extra vs single (bps) 0\n  sold 50k of ~100.6k units\n    pieces 2 allowance used 291746987\n    extra vs single (bps) 1653\n  sold 50k of ~100.6k units\n    pieces 5 allowance used 322632986\n    extra vs single (bps) 2887\n  sold 50k of ~100.6k units\n    pieces 20 allowance used 340046440\n    extra vs single (bps) 3582\n  sold 50k of ~100.6k units\n    pieces 100 allowance used 344921269\n    extra vs single (bps) 3777\nSuite result: ok. 2 passed; 0 failed; 0 skipped; finished in 78.23ms (143.65ms CPU time)\nRan 1 test suite in 79.89ms (78.23ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)",
 "pocOutput6Decimals": "No files changed, compilation skipped\nRan 2 tests for test/poc/ShortfallAllowanceChunking.t.sol:ShortfallAllowanceChunkingPoC\n[PASS] testAllocatorSaleInPiecesConsumesMoreAllowance() (gas: 3933897)\nLogs:\n  idle+realAssets before 100084346798\n  1 take:   allowance consumed 50069921\n  1 take:   idle+realAssets 100084346798\n  1 take:   netRate 8735599660\n  20 takes: allowance consumed 52599028\n  20 takes: idle+realAssets 100084346798\n  20 takes: netRate 8735599660\n  extra allowance consumed 2529107\n[PASS] testMakerSellFilledInPiecesConsumesMoreAllowance() (gas: 3898644)\nLogs:\n  allowance before 51000000\n  sale price (WAD) 989932200000000000\n  1 fill:   allowance consumed 50069921\n  1 fill:   idle+realAssets 100084346798\n  fill reverted at piece 19\n  0x8ea54d94\n  20 fills: units filled 9500000000\n  20 fills: allowance consumed 49834446\n  20 fills: idle+realAssets 100084346798\n  idle+realAssets before 100084346798\nSuite result: ok. 2 passed; 0 failed; 0 skipped; finished in 16.13ms (20.37ms CPU time)\nRan 1 test suite in 17.31ms (16.13ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)"
}