{
 "item": "bridge-supply-isolation",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "1.8.3 (no --use solar: forge < 1.9; compiled at solc 0.8.34 on a pragma-patched scratch copy, solc 0.8.38 not installed)",
 "verdict": "holds",
 "findings": [],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "RAN. ImdBridge.sol: the instant meter refills at C per INSTANT_WINDOW (:838) and starts EMPTY at the first message/act after acceptance (:581, :1256-1269), so <= C x (1 + 72h/1d) = 4C mints at once; claims stop once the 4-UTC-day queue exceeds B (:856-861, claim :604), and the trip-causing message itself stays queued, so <= B is claimable; everything is also metered by the inbound limiter (:572, :883-895), L x (1 + t/W). Per path state only (instantIn, breakers, breakerBuckets, inbound, claims keyed by srcEid), so paths add. testFuzz_noAction72h (256 runs): forged streams on BOTH spoke paths into Ethereum, random sizes 10..60,000, 0 s / 12 s / up-to-6 h gaps (several per block, consecutive blocks, UTC-day crossings), anyone claiming every step for 72 h, optionally a matured honest SET_PATH (in limit 50k..250k, window 1 h..4 d) applied by a stranger at a random step: each path <= 140,000 (4C+B), the untouched path and both paths without the raise <= 87,500, supply == netMinted: PASS. test_greedyForger: fill instant room + rest of the limiter every hour for 72 h: 86,249.999999 minted + 1,250 queued = 87,500 exactly (bound tight, never exceeded): PASS. Into Ethereum: 2 x 87,500 = 175,000 at launch values (README:780), 2 x 140,000 = 280,000 once L is raised (script/LzPaths.sol:166-168). forge 1.8.3 (older than 1.9: no --use solar; solc 0.8.38 not installed). Tests ran on a scratch copy of the commit with every `pragma 0.8.38` / foundry.toml solc rewritten to 0.8.34 (installed), `forge test --offline --match-path test/scratch/Scratch.t.sol`, fuzz runs 256, using the repo's own rig (test/unit/ThreePaths.t.sol ThreeChains: three ImdBridges on test/utils/MockLzEndpoint, opened with the real LzPaths.launchBatch payloads). Test source (test/scratch/Scratch.t.sol):\n// SPDX-License-Identifier: MIT\npragma solidity 0.8.34;\n\nimport {ThreeChains} from \"../unit/ThreePaths.t.sol\";\nimport {ImdBridge, IMintableBurnable} from \"../../src/bridge/ImdBridge.sol\";\nimport {ImdUSD} from \"../../src/ImdUSD.sol\";\nimport {ILayerZeroEndpointV2, MessagingFee, Origin} from \"layerzero-v2/protocol/interfaces/ILayerZeroEndpointV2.sol\";\nimport {SendParam} from \"layerzero-v2/oft/interfaces/IOFT.sol\";\nimport {LzChains, LzPaths} from \"../../script/LzPaths.sol\";\nimport {MockLzEndpoint, MockMessageLib} from \"../utils/MockLzEndpoint.sol\";\n\ncontract ScratchBridge is ThreeChains {\n    address[3] forger;\n\n    function setUp() public {\n        _setUpThree();\n        _openAll();\n        forger[1] = makeAddr(\"forger1\");\n        forger[2] = makeAddr(\"forger2\");\n    }\n\n    /// C1 / P1: a forged stream on BOTH spoke paths into Ethereum, any sizes, several per block or consecutive blocks,\n    /// anyone claiming whatever matures, optionally a matured honest SET_PATH (raised L, shorter W) applied in front by a\n    /// stranger. Nobody (Safe) acts for 72 h.\n    function testFuzz_noAction72h(uint256 seed, bool raise, uint256 newL, uint256 newW, uint256 raiseAt) public {\n        newL = bound(newL, 50_000e18, 250_000e18) / 1e12 * 1e12;\n        newW = bound(newW, 1 hours, 4 days);\n        raiseAt = bound(raiseAt, 0, 40);\n        if (raise) {\n            vm.prank(safe);\n            br[0].propose(abi.encode(uint8(1), RH, _b32(address(br[1])), uint256(50_000e18), uint256(4 days), newL, newW, LzPaths.enforcedOptions(1)));\n            // proposed 48 h before the stream starts; matured, anyone may apply it at any moment\n            vm.warp(vm.getBlockTimestamp() + 48 hours);\n        }\n        uint256 t0 = vm.getBlockTimestamp();\n        uint256[][3] memory pk;\n        pk[1] = new uint256[](200);\n        pk[2] = new uint256[](200);\n        uint256[3] memory n;\n        for (uint256 s; s < 200; ++s) {\n            uint256 r = uint256(keccak256(abi.encode(seed, s)));\n            uint256 i = 1 + (r & 1);\n            uint256 amt = (10e18 + (r >> 8) % 60_000e18) / 1e12 * 1e12;\n            uint256 dt = (r >> 128) % 4 == 0 ? 0 : (r >> 128) % 4 == 1 ? 12 : (r >> 140) % 6 hours;\n            if (vm.getBlockTimestamp() + dt > t0 + 72 hours) break;\n            vm.warp(vm.getBlockTimestamp() + dt);\n            if (raise && s == raiseAt) br[0].applyPending();\n            (uint256 p, bool ok) = _inbound(i, forger[i], amt);\n            if (ok) pk[i][n[i]++] = p;\n            for (uint256 j = 1; j < 3; ++j) {\n                for (uint256 k; k < n[j]; ++k) {\n                    try br[0].claim(ep[j].eid(), _key(j, pk[j][k])) {} catch {}\n                }\n            }\n        }\n        vm.warp(t0 + 72 hours);\n        for (uint256 j = 1; j < 3; ++j) {\n            for (uint256 k; k < n[j]; ++k) {\n                try br[0].claim(ep[j].eid(), _key(j, pk[j][k])) {} catch {}\n            }\n        }\n        uint256 a = tok[0].balanceOf(forger[1]);\n        uint256 b = tok[0].balanceOf(forger[2]);\n        assertLe(a, 140_000e18, \"4C+B, 4663 path\");\n        assertLe(b, 140_000e18, \"4C+B, Base path\");\n        if (!raise) assertLe(a, 87_500e18, \"L(1+72h/W), 4663 path\");\n        assertLe(b, 87_500e18, \"L(1+72h/W), Base path (untouched)\");\n        assertEq(int256(tok[0].totalSupply()), br[0].netMinted(), \"supply == received - sent\");\n    }\n\n    /// C1 tightness: a greedy forger on one path (fill the instant room, queue the rest of the limiter every hour).\n    function test_greedyForger() public {\n        uint256 t0 = vm.getBlockTimestamp();\n        uint256[] memory pk = new uint256[](200);\n        uint256 n;\n        for (uint256 h; h <= 72; ++h) {\n            vm.warp(t0 + h * 1 hours);\n            uint256 inst = br[0].availableInstant(RH) / 1e12 * 1e12;\n            if (inst >= 10e18) { (uint256 p,) = _inbound(1, forger[1], inst); pk[n++] = p; }\n            uint256 avail = br[0].availableIn(RH) / 1e12 * 1e12;\n            if (avail >= 10e18) { (uint256 p, bool ok) = _inbound(1, forger[1], avail); if (ok) pk[n++] = p; }\n            for (uint256 k; k < n; ++k) try br[0].claim(RH, _key(1, pk[k])) {} catch {}\n        }\n        emit log_named_decimal_uint(\"greedy forger minted in 72h\", tok[0].balanceOf(forger[1]), 18);\n        emit log_named_decimal_uint(\"still queued\", br[0].queued(), 18);\n        assertLe(tok[0].balanceOf(forger[1]) + br[0].queued(), 87_500e18);\n    }\n\n    /// P1 / P2: honest sends both ways with a fee, delivered in any order and timing, claimed when queued.\n    function testFuzz_honestRoundTrip(uint256 seed, uint16 bps) public {\n        bps = uint16(bound(bps, 0, 25));\n        _apply(br[0], abi.encode(uint8(7), RH, uint256(bps)));\n        address tr = makeAddr(\"treasury\");\n        uint256 premint;\n        uint256 owed;\n        for (uint256 s; s < 30; ++s) {\n            uint256 r = uint256(keccak256(abi.encode(seed, s)));\n            uint256 amt = 11e18 + (r % 49_000e18);\n            vm.deal(sender, 1 ether);\n            vm.prank(address(br[0]));\n            tok[0].mint(sender, amt);\n            premint += amt;\n            vm.prank(sender);\n            try br[0].send{value: 0.0001 ether}(SendParam(RH, _b32(alice), amt, 0, \"\", \"\", \"\"), MessagingFee(0.0001 ether, 0), sender) {} catch {}\n            vm.warp(vm.getBlockTimestamp() + (r >> 200) % 8 hours);\n        }\n        owed = br[0].sent();\n        assertEq(_drain(), 0, \"every honest packet executed\");\n        assertGt(owed, 0);\n        assertEq(tok[1].balanceOf(alice), owed, \"every delivered amount minted\");\n        assertEq(br[1].queued(), 0, \"nothing left queued\");\n        assertEq(int256(tok[0].totalSupply()) - int256(premint), br[0].netMinted(), \"ETH: supply delta == received - sent\");\n        assertEq(tok[0].balanceOf(tr), br[0].fees(), \"fee to treasury\");\n        assertEq(int256(tok[1].totalSupply()), br[1].netMinted(), \"4663: supply == received - sent\");\n    }\n\n    /// @dev Deliver everything on 4663 (an executor retries a refused packet), then claim what queued; returns the undelivered.\n    function _drain() internal returns (uint256 m) {\n        uint256 cnt = ep[0].packetCount();\n        for (uint256 round; round < 40; ++round) {\n            for (uint256 k; k < cnt; ++k) {\n                if (!ep[0].isDelivered(k)) ep[0].deliver(k);\n            }\n            vm.warp(vm.getBlockTimestamp() + 1 days);\n            for (uint256 k; k < cnt; ++k) {\n                try br[1].claim(ET, _key(0, k)) {} catch {}\n            }\n        }\n        for (uint256 k; k < cnt; ++k) if (!ep[0].isDelivered(k)) ++m;\n    }\n}\n\n\n/// C2 (local, not the fork): lzReceive with the real ImdUSD, under 250,000 gas, every branch's worst case.\ncontract ScratchGas is ThreeChains {\n    ImdUSD usd;\n    ImdBridge b;\n    MockLzEndpoint e;\n    address public governor;\n    address public treasury;\n\n    function setUp() public {\n        vm.warp(1_800_000_000);\n        governor = safe;\n        treasury = makeAddr(\"treasury\");\n        LzChains.Chain[] memory c = LzChains.all();\n        e = new MockLzEndpoint(c[0].eid);\n        usd = new ImdUSD(address(this), 0, address(e));\n        usd.wire(address(this), address(this), address(this));\n        b = new ImdBridge(ILayerZeroEndpointV2(address(e)), IMintableBurnable(address(usd)), safe, treasury);\n        usd.setBridge(address(b));\n        vm.etch(c[0].sendUln, address(new MockMessageLib()).code);\n        vm.etch(c[0].receiveUln, address(new MockMessageLib()).code);\n        _apply(b, LzPaths.launchBatch(1, 4663, bytes32(uint256(0xbeef))));\n        vm.warp(vm.getBlockTimestamp() + 1 days + 1);\n    }\n\n    function _rx(uint64 nonce, address to, uint256 amt) internal returns (uint256 used) {\n        Origin memory o = Origin(RH, bytes32(uint256(0xbeef)), nonce);\n        bytes memory m = abi.encodePacked(bytes32(uint256(uint160(to))), uint64(amt / 1e12));\n        vm.prank(address(e));\n        uint256 g = gasleft();\n        b.lzReceive{gas: 250_000}(o, bytes32(uint256(nonce)), m, address(0), \"\");\n        used = g - gasleft();\n    }\n\n    function test_gasInstantFirstMint() public {\n        emit log_named_uint(\"instant mint, fresh recipient, first mint\", _rx(1, makeAddr(\"r1\"), 5_000e18));\n    }\n\n    function test_gasQueueTrip() public {\n        // first-ever queue, tripping the breaker in the same message (a 4-day-old bucket cleared; breaker tightened to 1,000)\n        vm.prank(safe);\n        b.tighten(RH, 10_000e18, 12 hours, 1_000e18, 0);\n        vm.warp(vm.getBlockTimestamp() + 5 days);\n        emit log_named_uint(\"queue + trip, first queue\", _rx(1, makeAddr(\"r2\"), 50_000e18));\n    }\n\n    function test_gasClaim() public {\n        _rx(1, makeAddr(\"r3\"), 20_000e18);\n        vm.warp(vm.getBlockTimestamp() + 13 hours);\n        bytes32 guid = keccak256(abi.encodePacked(uint64(1), RH, bytes32(uint256(0xbeef)), ET, bytes32(uint256(uint160(address(b))))));\n        b.claim(RH, guid);\n        assertEq(usd.balanceOf(makeAddr(\"r3\")), 20_000e18);\n        assertEq(int256(usd.totalSupply()), b.netMinted());\n    }\n}\n\ncontract Wiring {\n    address public governor;\n    address public treasury;\n    constructor(address g, address t) { (governor, treasury) = (g, t); }\n}\n\n/// P3 / C3 / C4: minters are exactly ledger, hub, one bridge; wire and setBridge are one-shot; checkBridge takes only lzEndpoint.\ncontract ScratchMinters is ThreeChains {\n    function testFuzz_minterSet(address who, address other) public {\n        MockLzEndpoint e = new MockLzEndpoint(30101);\n        MockLzEndpoint e2 = new MockLzEndpoint(30184);\n        address tr = makeAddr(\"treasury\");\n        Wiring ledger = new Wiring(safe, tr);\n        Wiring hub = new Wiring(safe, tr);\n        Wiring params = new Wiring(safe, tr);\n        address deployer = makeAddr(\"deployer\");\n        ImdUSD u = new ImdUSD(deployer, 0, address(e));\n        vm.prank(who == deployer ? address(1) : who);\n        vm.expectRevert(ImdUSD.Unauthorized.selector);\n        u.wire(address(ledger), address(hub), address(params));\n        vm.prank(deployer);\n        u.wire(address(ledger), address(hub), address(params));\n        address w2 = address(new Wiring(safe, tr));\n        vm.prank(deployer);\n        vm.expectRevert(ImdUSD.AlreadySet.selector);\n        u.wire(w2, w2, w2);\n        // a bridge on another endpoint is refused; the right one passes once\n        ImdBridge wrong = new ImdBridge(ILayerZeroEndpointV2(address(e2)), IMintableBurnable(address(u)), safe, tr);\n        vm.prank(address(params));\n        vm.expectRevert(ImdUSD.InvalidMinter.selector);\n        u.setBridge(address(wrong));\n        ImdBridge b = new ImdBridge(ILayerZeroEndpointV2(address(e)), IMintableBurnable(address(u)), safe, tr);\n        vm.prank(who == address(params) ? address(1) : who);\n        vm.expectRevert(ImdUSD.Unauthorized.selector);\n        u.setBridge(address(b));\n        vm.prank(address(params));\n        u.setBridge(address(b));\n        ImdBridge b2 = new ImdBridge(ILayerZeroEndpointV2(address(e)), IMintableBurnable(address(u)), safe, tr);\n        vm.prank(address(params));\n        vm.expectRevert(ImdUSD.AlreadySet.selector);\n        u.setBridge(address(b2));\n        bool expect = other == address(ledger) || other == address(hub) || other == address(b);\n        assertEq(u.isMinter(other), expect && other != address(0));\n        assertTrue(u.isMinter(address(ledger)) && u.isMinter(address(hub)) && u.isMinter(address(b)));\n        assertFalse(u.isMinter(address(params)) || u.isMinter(deployer) || u.isMinter(address(b2)));\n        // C3: the bridge has no deployer power: every power is the governor's (the Safe)\n        vm.startPrank(deployer);\n        vm.expectRevert();\n        b.propose(abi.encode(uint8(7), uint32(30184), uint256(1)));\n        vm.expectRevert();\n        b.pause(30184);\n        vm.stopPrank();\n    }\n}\n"
  },
  {
   "id": "C2",
   "result": "not-checked",
   "evidence": "[fork] NOT RUN: test/fork/AuditW4BridgeEndpoint.t.sol at mainnet block 26,418,627 via a public RPC (publicnode) failed in setUp: 'Archive requests require a personal token'; no archive RPC available. Local measurement instead (RAN, mock endpoint, real ImdUSD): lzReceive called with an explicit {gas: 250_000} succeeds on every branch: instant mint to a fresh recipient as the first mint 162,421 gas; first-ever queue tripping the breaker 113,233 gas (ScratchGas tests: PASS). Endpoint overhead of the real EndpointV2 not included. 250,000 is the enforced executor option (script/LzPaths.sol:30 RECEIVE_GAS, :301-303); an under-gassed execution reverts and stays retryable at the endpoint (no loss). Glamsterdam ~653k is README:783 (known); its fix route exists: SET_PATH carries enforcedOptions (ImdBridge.sol:1136). README:783 names LZ_RECEIVE_GAS, which is the house config's constant (script/house/DeployConfig.sol:1217); the day-1 path constant is LzPaths RECEIVE_GAS (script/LzPaths.sol:30), same 250,000."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "RAN + code. ImdBridge has no wirer/initializer: constructor fixes endpoint, token, governor, treasury (ImdBridge.sol:451-461); every power is onlyGovernor (pause :693, hold :702, voidPayload :732, cancelClaim :618, tighten :654, tripBreaker :631) or Governed.propose (onlyGovernor, 48 h) + permissionless apply. The deploy creates it with governor = the Safe (script/deploy/StageChain.sol:33). ImdUSD.bridgeSetter is written only by wire (ImdUSD.sol:101-111, msg.sender == wirer, once: ledger != 0 -> AlreadySet), wired to Parameters at genesis (script/deploy/StageCore.sol:103; script/house/deploy/StageCore.sol:133-140 also checks it). testFuzz_minterSet: a stranger's wire reverts Unauthorized, a second wire AlreadySet, the deployer cannot propose or pause on the bridge: PASS."
  },
  {
   "id": "C4",
   "result": "holds",
   "evidence": "RAN + code. checkBridge requires w.endpoint() == lzEndpoint, an immutable from the constructor (ImdUSD.sol:45, :96, :123), refuses all when lzEndpoint is 0, and the deploy passes cfg.bridge.endpoint (script/deploy/StageCore.sol:53): Ethereum LzChains.ethereum().endpoint (script/DeployConfig.sol:268), 4663 LzChains.robinhood().endpoint (:599), Base LzChains.base().endpoint (:809); 0x1a44076050125825900e736c501f859c50fE728c on 1 and 8453, 0x6F475642a6e85809B1c36Fa62763669b1b48DD5B on 4663 (script/LzPaths.sol:79,98,116). testFuzz_minterSet: an ImdBridge on another endpoint is refused InvalidMinter; the configured one passes once: PASS. The candidate's views are trusted (README:1052, known). Not verified: that these addresses equal LayerZero's published EndpointV2 per chain (the docs pages did not render)."
  }
 ],
 "holds": [
  {
   "property": "P1",
   "tried": "Supply: the only bridge mints/burns are lzReceive (ImdBridge.sol:588-590), claim (:609-611), send (:519-523: burns amount, re-mints the fee to the Treasury, sent += delivered), so token net = received - sent. Writers of received/sent/fees/queued: :519, :522, :588, :609-610, :623, :853, :1210; readers: netMinted (:688) only (grep src/ script/: no other reader; MinterHub.sol:458 reads token.bridge() only to refuse it as a spoke). Isolation: every limit is keyed by srcEid (inbound, instantIn, breakers, breakerBuckets, claims, paused, holds); the shared sums are read by nothing that gates; voided/unvoided are by hash (cross-path replay -> DROP, documented). Tests: testFuzz_noAction72h (two paths, per-path bounds, raised L on one path leaves the other <= 87,500, supply == netMinted), testFuzz_honestRoundTrip (fee 0..25 bps, 30 random sends ETH->4663, random gaps, delivered and claimed: ETH supply delta == netMinted, Treasury balance == fees, 4663 supply == netMinted), ThreePaths.t.sol (repo, 8/8 PASS including testFuzz_oneWorldsIncidentIsNotTheOthers). All PASS, 256 runs."
  },
  {
   "property": "P2",
   "tried": "testFuzz_honestRoundTrip: every honest packet executed (retried after RateLimited, as an executor would), every queued one claimed after D, recipient balance == sum delivered, queued == 0: PASS (256 runs). By code: an inbound revert (RateLimited, PathPaused, OnlyPeer, Unconfigured, OOG) leaves the packet at the endpoint, retryable; a queued claim never expires (:598-613), a cancel/bulk cutoff/trip keeps it pending until UNCANCEL / SET_DELAY / RESET_BREAKER; claim amount fits uint48 because the inbound limit <= MAX_LIMIT (:269, :930); MIN_AMOUNT is the same both sides (:516, :571); a mint before SET_BRIDGE queues and the claim reverts in mint until acceptance (no loss). Residuals as documented: forged packets consuming honest nonces (header :99-106), lowering an inbound limit below in-flight only when paused (:936), a send to bytes32(0) mints to 0xdead and a non-EVM bytes32 is truncated to its low 160 bits (OFT's rule, :573-574: sender error, not an honest-transfer loss)."
  },
  {
   "property": "P3",
   "tried": "isMinter is exactly ledger || bridge || hub, non-zero (ImdUSD.sol:136-139); ledger/hub/bridgeSetter written only in wire (:107-109), once; bridge only in setBridge (:132), callable only by bridgeSetter = Parameters, once (checkBridge returns the set bridge -> AlreadySet :131), reached only via Parameters SET_BRIDGE apply (src/ParametersRules.sol:163-165, validated at propose :47-51, 48 h Governed). Flash mint (ERC20FlashMint) is repaid in the same call. testFuzz_minterSet (256 runs, fuzzed caller and probe address): only the three are minters; Parameters, the deployer and a second bridge are not; a stranger cannot wire or setBridge; a second setBridge reverts AlreadySet: PASS. Deployer before wire: covered by item x-deployer-oneshot (wire is spent in the genesis sequence)."
  }
 ],
 "notRun": [
  "C2 [fork]: AuditW4BridgeEndpoint at mainnet 26,418,627 (public RPC refused archive state; no archive RPC)",
  "Real EndpointV2 gas overhead on lzReceive (only the bridge+ImdUSD part was measured, on the mock endpoint)",
  "Matching the 1 / 4663 / 8453 endpoint addresses against LayerZero's published deployments",
  "solc 0.8.38 build: tests compiled at 0.8.34 (pragma-patched scratch copy)"
 ]
}