{
 "item": "bridge-incident-acts",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge Version: 1.8.3 (older than 1.9; it accepted --use solar; solc 0.8.38 was already installed). Every test below was run with forge test --match-path test/scratch/<file> --use solar",
 "verdict": "findings",
 "findings": [
  {
   "id": "BIA-F1",
   "severity": "medium",
   "title": "A stranger's lzReceive, or a verify by the compromised DVNs, reverts the Safe's incident batch [pause, propose(ENDPOINT_NILIFY/BURN/SKIP)], and the pause is reverted with it",
   "property": "P1",
   "claim": "C1 ('No other') is refuted",
   "files": [
    "src/bridge/ImdBridge.sol:981-1001",
    "src/bridge/ImdBridge.sol:986",
    "src/bridge/ImdBridge.sol:994",
    "src/bridge/ImdBridge.sol:996",
    "src/bridge/ImdBridge.sol:999",
    "src/bridge/ImdBridge.sol:693-697",
    "src/Governed.sol:44-50"
   ],
   "sequence": "1) Compromised DVNs verify forged packets A (nonce n) and B (n+1) on the 4663 path from Ethereum. 2) The Safe signs a MultiSend [pause(HOME), propose(ENDPOINT_NILIFY(HOME, peer, n, hash(A)))]; the propose is valid when signed. 3) Before it lands, anyone executes A through EndpointV2.lzReceive (permissionless; the path is still open). This clears the stored hash, so cur != h and _check reverts InfeasibleEndpointAct at :994. The DVNs can get the same revert by verifying another payload over nonce n. For ENDPOINT_SKIP(next), they verify at `next`: inboundNonce moves and :986 reverts. BURN fails the same way at :994/:999. 4) The whole MultiSend reverts, so the path stays open. 5) The forger executes B and every other verified forged packet, which mint at once within the instant allowance (fuzz: 3,000 imdUSD each, minted at once). The rest queue, until the Safe re-signs a batch without the endpoint act.",
   "expected": "The batch lands whatever a stranger ran first (P1). An infeasible endpoint act is a no-op, as hold/cancelClaim/cancel/RELEASE(0)/UNCANCEL/UNPAUSE already are.",
   "actual": "Ran: testFuzz_P1_endpointActBatchLands fails for both routes (execute and DVN verify) and for SKIP; the batch returns false and paused(HOME) stays false. Control: with no stranger in front, both batches land (test_control_noStranger PASS).",
   "reachableAtDeploy": "yes: every open path, with compromised DVNs (in the threat model). Executing a verified packet needs no key.",
   "fix": "In _check, stop rejecting ENDPOINT_SKIP/NILIFY/BURN on endpoint state (cur != h, the lazy and inbound nonces) at propose. In _apply, re-read that state and make an infeasible item a no-op (skip the endpoint call; for NILIFY/BURN still set voided[h] = true, which can only tighten). Keep the PathOpen checks: the batch's own pause satisfies them.",
   "test": {
    "source": "// test/scratch/BIAProp.t.sol (imports: ../utils/W5Bridge.sol = repo harness: MockLzEndpoint with EndpointV2 channel rules, two ImdBridges, both paths open at launch values C 10,000/day, D 12 h, B 100,000)\n/// Safe MultiSend stand-in (etched at the governor address): all calls or none.\ncontract Batcher {\n    function exec(address t, bytes[] calldata calls) external {\n        for (uint256 i; i < calls.length; ++i) {\n            (bool ok, bytes memory r) = t.call(calls[i]);\n            if (!ok) assembly { revert(add(r, 32), mload(r)) }\n        }\n    }\n}\n\n/// P1: no stranger's transaction makes the Safe's incident batch revert.\ncontract BIAPropTest is W5Bridge {\n    function setUp() public {\n        _setUpW5();\n        vm.etch(safe, address(new Batcher()).code); // Safe MultiSend: all or nothing\n    }\n\n    function _run(bytes[] memory c) internal returns (bool ok) {\n        (ok,) = safe.call(abi.encodeCall(Batcher.exec, (address(rh), c)));\n    }\n\n    function _p(bytes memory payload) internal pure returns (bytes memory) {\n        return abi.encodeWithSignature(\"propose(bytes)\", payload);\n    }\n\n    /// [pause, propose(ENDPOINT_NILIFY(n,h))] / [pause, propose(ENDPOINT_SKIP(next))]; stranger in front:\n    /// who 0 executes the forged packet (lzReceive), 1 compromised DVNs verify over its nonce.\n    function testFuzz_P1_endpointActBatchLands(uint8 who, bool skip) public {\n        who = uint8(bound(who, 0, 1));\n        bytes32 snd = _b32(address(home));\n        uint64 next = rhEp.inboundNonce(address(rh), HOME, snd) + 1;\n        uint256 a = _forge(3_000e18);\n        bytes memory act = skip ? abi.encode(uint8(8), HOME, snd, next + 1) : abi.encode(uint8(9), HOME, snd, next, homeEp.payloadHashOf(a));\n        if (skip) homeEp.forgeAt(RH, _b32(address(rh)), snd, _msg(attacker, 50e18), next + 1); // DVNs verify the skipped nonce\n        else if (who == 0) homeEp.deliver(a);\n        else homeEp.forgeAt(RH, _b32(address(rh)), snd, _msg(attacker, 50e18), next);\n        bytes[] memory c = new bytes[](2);\n        (c[0], c[1]) = (abi.encodeCall(rh.pause, (HOME)), _p(act));\n        assertTrue(_run(c), \"P1: incident batch reverted by a stranger\");\n        assertTrue(rh.paused(HOME));\n    }\n    function test_skipVariantFails() public {\n        testFuzz_P1_endpointActBatchLands(0, true);\n    }\n    function test_control_noStranger() public {\n        bytes32 snd = _b32(address(home));\n        uint64 next = rhEp.inboundNonce(address(rh), HOME, snd) + 1;\n        uint256 a = _forge(3_000e18);\n        bytes[] memory c = new bytes[](2);\n        (c[0], c[1]) = (abi.encodeCall(rh.pause, (HOME)), _p(abi.encode(uint8(9), HOME, snd, next, homeEp.payloadHashOf(a))));\n        assertTrue(_run(c));\n        vm.prank(safe);\n        rh.cancel();\n        (c[0], c[1]) = (abi.encodeCall(rh.pause, (HOME)), _p(abi.encode(uint8(8), HOME, snd, next + 1)));\n        assertTrue(_run(c));\n    }\n}\n// loss (test/scratch/BIA.t.sol, same setUp + helpers _safeBatch/_c2):\n    /// Incident batch [pause, propose(ENDPOINT_NILIFY(n, h))] for a verified forged packet A, while forged B waits.\n    /// mode 0: nobody in front (control); 1: anyone executes A in front; 2: the DVNs verify another payload over A's nonce.\n    function testFuzz_F1_nilifyBatchRevertedByStranger(uint8 mode) public {\n        mode = uint8(bound(mode, 0, 2));\n        uint256 a = _forge(3_000e18);\n        uint256 b = _forge(3_000e18);\n        (uint64 na, bytes32 snd) = _origin(a);\n        bytes memory nil = abi.encode(uint8(9), HOME, snd, na, homeEp.payloadHashOf(a));\n        if (mode == 1) assertTrue(homeEp.deliver(a));\n        if (mode == 2) homeEp.forgeAt(RH, _b32(address(rh)), snd, _msg(attacker, 50e18), na);\n        bool ok = _safeBatch(_c2(abi.encodeCall(rh.pause, (HOME)), abi.encodeWithSignature(\"propose(bytes)\", nil)));\n        if (mode == 0) {\n            assertTrue(ok);\n            assertFalse(homeEp.deliver(b), \"B refused on the paused path\");\n            return;\n        }\n        // the stranger's transaction reverted the Safe's pause with the proposal\n        assertFalse(ok, \"batch landed\");\n        assertFalse(rh.paused(HOME), \"path still open\");\n        uint256 before = rhTok.balanceOf(attacker);\n        assertTrue(homeEp.deliver(b));\n        assertGt(rhTok.balanceOf(attacker), before, \"forged B minted at once after the reverted incident batch\");\n    }",
    "ran": "yes: forge 1.8.3 --use solar, fuzz runs 1000",
    "result": "[FAIL: P1: incident batch reverted by a stranger; args=[75, true]] testFuzz_P1_endpointActBatchLands(uint8,bool) (runs: 0, \u03bc: 0, ~: 0) | [FAIL: P1: incident batch reverted by a stranger; args=[9, false]] testFuzz_P1_endpointActBatchLands(uint8,bool) (runs: 0, \u03bc: 0, ~: 0) | [FAIL: P1: incident batch reverted by a stranger] test_skipVariantFails() (gas: 674445) | [PASS] test_control_noStranger() (gas: 811524) | [PASS] testFuzz_F1_nilifyBatchRevertedByStranger(uint8) (runs: 1000, \u03bc: 1051823, ~: 1070676) (the loss test asserts the defect: B mints at once after the reverted batch)"
   }
  },
  {
   "id": "BIA-F2",
   "severity": "low",
   "title": "RESET_BREAKER and UNVOID re-proposals in an incident batch are reverted by a stranger applying the matured original in front, and the pause or void in the same batch goes with them (README:773 covers only UNCANCEL and UNPAUSE)",
   "property": "P1",
   "claim": "C2 confirmed",
   "files": [
    "src/bridge/ImdBridge.sol:1003-1005",
    "src/bridge/ImdBridge.sol:1018-1025",
    "src/Governed.sol:69-80",
    "README.md:773"
   ],
   "sequence": "RESET_BREAKER: forged queue > B trips the path (trip 1). The Safe pauses, cancels the claim and proposes BATCH[RESET_BREAKER(HOME,1), UNPAUSE(HOME)]. At any second of [eta, eta+14 d] the Safe sends [pause(HOME), cancel(), propose(same)] to re-propose it. A stranger runs applyPending in front: tripped=false and the path is unpaused. Inside the Safe's batch, pause succeeds, cancel is a no-op, and propose reverts BadPayload at :1022 (!b.tripped). The MultiSend reverts, so the path stays open. One day later the forged stockpile verified while the path was closed mints at once (instant allowance refilled). UNVOID: [voidPayload(h2), cancel(), propose(UNVOID(h1))] after a stranger applies the matured UNVOID(h1) reverts at :1005. voidPayload(h2) is reverted with it, and the forged h2 mints 5,000 at once.",
   "expected": "P1: the Safe's batch lands. README:773 quoted: '- **Re-proposals inside an incident batch** (wave-7 judge L3, L4, fixed in this snapshot): UNCANCEL of any existing claim and UNPAUSE of an open path are accepted and apply as no-ops'. It names only UNCANCEL and UNPAUSE, so it does not cover RESET_BREAKER, UNVOID or ENDPOINT_*.",
   "actual": "testFuzz_P1_resetReproposalLands fails at every fuzzed apply time in the 14-day window. The loss tests (assert the defect) pass: the forged stockpile and h2 mint at once.",
   "reachableAtDeploy": "yes, once the Safe uses the re-proposal pattern (operator runbook). No key needed: applyPending is permissionless.",
   "fix": "UNVOID: accept a hash that is not voided and make the apply a no-op when !voided[h]. RESET_BREAKER: at propose require only trip == b.trips and paused, not tripped; at apply keep the trip-number staleness check and make it a no-op when !tripped. ENDPOINT_*: as in BIA-F1.",
   "test": {
    "source": "// test/scratch/BIAProp.t.sol (imports: ../utils/W5Bridge.sol = repo harness: MockLzEndpoint with EndpointV2 channel rules, two ImdBridges, both paths open at launch values C 10,000/day, D 12 h, B 100,000)\n// same contract BIAPropTest as F1\n    /// [pause, cancel, propose(BATCH[RESET_BREAKER(1), UNPAUSE])] after anyone applies the matured original in front.\n    function testFuzz_P1_resetReproposalLands(uint256 late) public {\n        (uint256 i,) = _forgeRun(B + 1e18);\n        vm.startPrank(safe);\n        rh.pause(HOME);\n        rh.cancelClaim(HOME, _claimKey(homeEp, i));\n        bytes memory reset = _b(abi.encode(uint8(14), HOME, uint256(1)), abi.encode(uint8(5), HOME));\n        rh.propose(reset);\n        vm.stopPrank();\n        _warp(48 hours + bound(late, 0, 14 days));\n        rh.applyPending(); // stranger\n        bytes[] memory c = new bytes[](3);\n        (c[0], c[1], c[2]) = (abi.encodeCall(rh.pause, (HOME)), abi.encodeWithSignature(\"cancel()\"), _p(reset));\n        assertTrue(_run(c), \"P1: incident batch reverted by a stranger\");\n    }\n// loss (test/scratch/BIA.t.sol):\n    /// RESET_BREAKER: tripped + paused path, BATCH[RESET_BREAKER(1), UNPAUSE] matured. The Safe re-proposes it inside\n    /// [pause, cancel, propose(same)]; a stranger applies the original in front at a chosen second of the 14-day window.\n    function testFuzz_F2_resetBreakerReproposal(uint256 late, bool front) public {\n        (uint256 i,) = _forgeRun(B + 1e18); // queues past B: trips (trip 1)\n        assertTrue(_tripped());\n        vm.startPrank(safe);\n        rh.pause(HOME);\n        rh.cancelClaim(HOME, _claimKey(homeEp, i));\n        vm.stopPrank();\n        bytes memory reset = _b(abi.encode(uint8(14), HOME, uint256(1)), abi.encode(uint8(5), HOME));\n        vm.prank(safe);\n        rh.propose(reset);\n        _warp(48 hours + bound(late, 0, 14 days));\n        uint256 stock = _forge(9_000e18); // forged stockpile verified while closed\n        if (front) rh.applyPending(); // stranger\n        bytes[] memory c = _c3(\n            abi.encodeCall(rh.pause, (HOME)), abi.encodeWithSignature(\"cancel()\"), abi.encodeWithSignature(\"propose(bytes)\", reset)\n        );\n        bool ok = _safeBatch(c);\n        if (!front) {\n            assertTrue(ok);\n            return;\n        }\n        assertFalse(ok, \"batch landed\");\n        assertFalse(rh.paused(HOME), \"path open: the Safe's pause was reverted\");\n        _warp(1 days); // until the Safe re-signs: the allowance (empty at the reopening) refills\n        uint256 before = rhTok.balanceOf(attacker);\n        assertTrue(homeEp.deliver(stock));\n        assertGt(rhTok.balanceOf(attacker), before, \"forged stockpile minted at once\");\n    }\n    /// UNVOID: [voidPayload(h2), cancel, propose(UNVOID(h1))]; a stranger applies the matured UNVOID(h1) in front.\n    function test_F2_unvoidReproposal() public {\n        uint256 p1 = _forge(5_000e18);\n        bytes32 h1 = homeEp.payloadHashOf(p1);\n        vm.prank(safe);\n        rh.voidPayload(h1);\n        vm.prank(safe);\n        rh.propose(abi.encode(uint8(11), h1));\n        _warp(48 hours);\n        uint256 p2 = _forge(5_000e18);\n        bytes32 h2 = homeEp.payloadHashOf(p2);\n        rh.applyPending(); // stranger\n        bool ok = _safeBatch(\n            _c3(\n                abi.encodeCall(rh.voidPayload, (h2)),\n                abi.encodeWithSignature(\"cancel()\"),\n                abi.encodeWithSignature(\"propose(bytes)\", abi.encode(uint8(11), h1))\n            )\n        );\n        assertFalse(ok, \"batch landed\");\n        assertFalse(rh.voided(h2), \"the Safe's void was reverted\");\n        assertTrue(homeEp.deliver(p2));\n        assertEq(rhTok.balanceOf(attacker), 5_000e18, \"voided-to-be payload minted at once\");\n    }",
    "ran": "yes: forge 1.8.3 --use solar, fuzz runs 1000",
    "result": "[FAIL: P1: incident batch reverted by a stranger; args=[16715 [1.671e4]]] testFuzz_P1_resetReproposalLands(uint256) (runs: 0, \u03bc: 0, ~: 0) | [FAIL: P1: incident batch reverted by a stranger; args=[1715537630745238222 [1.715e18]]] testFuzz_P1_resetReproposalLands(uint256) (runs: 0, \u03bc: 0, ~: 0) | [PASS] testFuzz_F2_resetBreakerReproposal(uint256,bool) (runs: 1000, \u03bc: 1510420, ~: 1371116) | [PASS] test_F2_unvoidReproposal() (gas: 1144463)"
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "refuted",
   "evidence": "The listed acts are right. hold (:708, :712 no-op), cancelClaim (:621 no-op), tighten clamps, tripBreaker trips again, voidPayload, cancel() (Governed:55-66 no-op) and propose(RELEASE 0) (:1012) all have their outcome changed by a stranger without reverting. propose(RELEASE h != 0) does revert at :1012 after a stranger ran a never-held nonce (test_C1_releaseNamedAfterStrangerRun PASS: named RELEASE batch reverts, DROP batch lands). 'No other' is false. propose(ENDPOINT_SKIP) (:986), propose(ENDPOINT_NILIFY/BURN) (:994,:996,:999) revert after a stranger's lzReceive or a DVN verify (BIA-F1). propose(UNVOID) (:1005) and propose(RESET_BREAKER) (:1022) revert after a stranger's applyPending (BIA-F2). So do propose(SET_DELAY shorter) (:1035) and propose(SET_PATH lowering inLimit) (:936) in a batch that relies on a still-paused path without its own pause(), after a stranger applies a matured UNPAUSE. That last case is read from the code, not tested."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "Confirmed with a loss for RESET_BREAKER and UNVOID: BIA-F2, tests testFuzz_P1_resetReproposalLands (FAIL), testFuzz_F2_resetBreakerReproposal and test_F2_unvoidReproposal (the forged stockpile and h2 mint at once). ENDPOINT_SKIP/NILIFY/BURN re-proposals fail the same way after the matured original is applied: after a skip, nonce != inboundNonce+1; after a nilify or burn, cur != h. Read from the code; the stranger-without-governance variant of the same checks is tested in BIA-F1."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "Breaker.trips and Breaker.version are uint32 (:213, :218). The checked increments are ++b.version (:669) and b.trips + 1 in _trip (:877-880). RESET_BREAKER compares trip (uint256) != b.trips (uint32, widened) at :1022, and SET_DELAY compares version != b.version at :1031, so a payload value >= 2^32 never matches. test_P2_countersBound: with trips stored at 2^32-1, tripBreaker reverts, the bound README:776 documents. Only the governor (tighten, tripBreaker) or a trip by the bridge (_queue/_setDelay, only when !tripped, so once per Safe RESET) can increment these counters."
  },
  {
   "id": "C4",
   "result": "refuted",
   "evidence": "The mechanism does not meet one soundness invariant at this commit (BIA-F1, BIA-F2). Invariant INV-SAFE: let W be the state any permissionless transaction can write: endpoint inboundPayloadHash and the lazy/inbound nonces (lzReceive, DVN verify), claims[].state (claim), and everything applyPending writes (paused, breakers, voided, holds, claims, pending). For every onlyGovernor entry point and for propose's _validate, no revert condition may read W, except the anti-loosening staleness checks evaluated at apply (version, trip number, paused-only shortening). Fuzz form: for any s0, any sequence T of {lzReceive, verify, claim, applyPending} and any Safe batch S that succeeds on s0, S succeeds on T(s0) and each field S names is at least as tight. Smallest replacement design: (1) propose runs only stateless checks (decoding, bounds, kinds, DuplicateInBatch, UnpauseWithChange); (2) every state-dependent feasibility check moves to _apply, where an infeasible item is a per-item no-op; (3) only the staleness guards (version, trip) and the paused-only rules revert at apply. Fixing the five kinds in BIA-F1 and BIA-F2 one by one would be the twelfth patch to this class."
  }
 ],
 "holds": [
  {
   "property": "P2",
   "tried": "No count a stranger can drive reaches the bound. trips moves only through governor tripBreaker or a trip by the bridge, which needs !tripped (one per Safe RESET_BREAKER). version moves only through governor tighten. _window's loops are bounded (BREAKER_DAYS=4). test_P2_countersBound shows the revert at trips = 2^32-1, exactly the bound README:776 documents ('P5 holds up to 2^32 - 1 governor acts per path'), not worse. tighten's other revert, NotTighter (:660), needs b.delay == 0, which is impossible once SET_PATH has run (SET_DELAY requires delay >= MIN_DELAY)."
  },
  {
   "property": "P3",
   "tried": "testFuzz_P3_tightenAfterStrangerApply, 1000 runs PASS (also 2000 runs). A fuzzed matured SET_DELAY (cap, breaker, cutoff any uint40, delay lengthened) is applied, or not, by a stranger at any second of [eta, eta+14 d] in front of tighten with fuzzed arguments. The test asserts that cap and breaker land as min(named, standing) floored to 1e12, delay as max(min(named, 7 d), standing), and cutoff as the earlier non-zero one. An unapplied SET_DELAY then reverts at apply (version bump). A shortening of the delay needs a paused path (:1035), so it cannot run in front of an open-path tighten."
  },
  {
   "property": "P1 (instant acts alone)",
   "tried": "Read every instant act's revert path. pause (:693), hold (:702-716, no-op on until != 0, no peer or nothing stored), cancelClaim (:618-626), voidPayload (:732), tripBreaker (:631) and tighten (:654) have no revert reachable by a stranger. cancel() is a no-op with nothing pending. _drop never reverts. A matured DROP applied in front of hold makes the hold a no-op: covered by the README 'DROP on a never-held nonce' line ('that nonce can never be held after'). P1 fails only through the propose items (BIA-F1, BIA-F2)."
  }
 ],
 "notRun": [
  "No [fork] or [data] claims in this sheet: NOT RUN, no RPC used.",
  "The ENDPOINT_* re-proposal variant of C2 (apply of the matured original) and the SET_DELAY-shorter/SET_PATH re-proposal after an applied UNPAUSE: reasoned from the code, not tested.",
  "Tested against MockLzEndpoint (repo harness test/utils, EndpointV2 channel rules), not the real EndpointV2."
 ]
}