{
 "item": "bridge-hold-drop",
 "commit": "ff1c192b3798542997f600091f2dc73ff05e4c40",
 "forge": "forge Version: 1.9.0 (--use solar 0.8.38)",
 "verdict": "findings",
 "findings": [
  {
   "id": "F1",
   "severity": "low",
   "title": "The FR2 fix only covers NIL: a DROP over a hold on any other hash with no payload (junk, or the sentinel 1) lets through the replay the Safe meant to drop",
   "property": "P1 / C4 (the rule stated at ImdBridge.sol:1194-1197: 'a DROP never loosens a nonce'; 'a DROP over a NIL-bound hold closes the nonce too ... (NIL, 2) would refuse NIL only, letting the replay the Safe meant to drop run as a claim')",
   "claim": "C4. It also refutes the earlier submission 439d66ba (L5): 'Had the DVNs overwritten with any other junk hash, hold would have bound it and the replay would be refused there for good; NIL is the one value that slips through.' That is false once the batch's own DROP applies.",
   "files": [
    "src/bridge/ImdBridge.sol:1198-1201",
    "src/bridge/ImdBridge.sol:702-716",
    "src/bridge/ImdBridge.sol:565",
    "src/bridge/ImdBridge.sol:583"
   ],
   "sequence": "1) Compromised DVNs verify a replay P of the honest twin's payload (nonce A) at nonce B. 2) In the same block, ahead of the Safe's documented batch, they re-verify B with a hash X that has no payload (any value except 0 and NIL; EndpointV2 refuses only 0 and lets an unexecuted nonce be re-verified). 3) The Safe's MultiSend [hold(B), pause, propose(RELEASE B,0)] lands. hold binds X as (X, now+72h). 4) The DVNs re-verify P at B. Before any DROP, (X, ts) refuses P for good (test_junkHoldAloneRefuses passes). 5) After 48 h anyone calls applyPending. The DROP sees until >= 3 and payloadHash != NIL, so it writes (X, 2), which refuses only X. 6) Once the path reopens (UNPAUSE), anyone executes P at B. It runs (it queues as a claim). With X = bytes32(1) the record becomes (1, 2): the closed sentinel's hash, but with the open until value.",
   "expected": "The DROP leaves B closed to P, as it does when the front-run hash is NIL (test_nilFront_dropCloses passes: the record is (1, 1)).",
   "actual": "The record is (X, 2) (logged: 'record until: 2'). The dropped replay P runs at B and queues a claim for its amount. The Safe must cancelClaim within D (12 h) or catch it with the void sweep / a second DROP before reopening. Otherwise the honest twin's amount mints twice. Nothing mints at once (until != 0 queues), so P1's 'never mints at once' holds. What fails is the DROP's purpose, which FR2 restored for NIL only.",
   "reachableAtDeploy": true,
   "fix": "Close any held record on a DROP: in the RELEASE apply, `r.until != 0 ? (bytes32(uint256(1)), uint64(1)) : (r.payloadHash, uint64(2))`. This costs the same as the NIL case: the honest peer's own message at that nonce then needs a RELEASE naming it. Alternative that keeps the twin-at-nonce path: make the DROP name the hash it drops, RELEASE(eid, sender, nonce, 0, dropHash). Write (dropHash, 2) only if the record is bound to dropHash; otherwise write (1, 1).",
   "test": {
    "source": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.38;\n\nimport \"forge-std/Test.sol\";\nimport {W6B1EpMock, W6B1TokMock, W6B1Lib, W6B1SafeMock, W6B1CfgParam, W6B1Org} from \"../unit/AuditW6JudgeBridgeDrop.t.sol\";\nimport {ImdBridge, IMintableBurnable, UlnConfig} from \"../../src/bridge/ImdBridge.sol\";\nimport {ILayerZeroEndpointV2} from \"layerzero-v2/protocol/interfaces/ILayerZeroEndpointV2.sol\";\n\n/// DVNs store a hash with no payload (not NIL) over their waiting replay in front of the Safe's [hold, pause, propose(DROP)],\n/// and the replay back behind it: the DROP writes (junk, 2) and the replay runs at the dropped nonce. NIL (FR2) is closed.\ncontract JunkDropTest is Test {\n    uint32 constant BASE = 30184;\n    uint64 constant B = 7;\n    bytes32 peer = bytes32(uint256(0xBEEF));\n    W6B1EpMock ep;\n    W6B1TokMock tok;\n    ImdBridge br;\n    W6B1SafeMock safe;\n    bytes32 guid = keccak256(\"honest twin guid at nonce 5\");\n    bytes message = abi.encodePacked(bytes32(uint256(uint160(address(0xA11CE)))), uint64(100e6));\n\n    function setUp() public {\n        vm.warp(20_000 days);\n        ep = new W6B1EpMock();\n        tok = new W6B1TokMock();\n        safe = new W6B1SafeMock();\n        br = new ImdBridge(ILayerZeroEndpointV2(address(ep)), IMintableBurnable(address(tok)), address(safe), address(0x7EA));\n        tok.setBridge(address(br));\n        (address sl, address rl) = (address(new W6B1Lib()), address(new W6B1Lib()));\n        address[] memory d = new address[](3);\n        (d[0], d[1], d[2]) = (address(1), address(2), address(3));\n        W6B1CfgParam[] memory sp = new W6B1CfgParam[](1);\n        sp[0] = W6B1CfgParam(BASE, 2, abi.encode(UlnConfig(15, 3, 255, 0, d, new address[](0))));\n        W6B1CfgParam[] memory rp = new W6B1CfgParam[](1);\n        rp[0] = W6B1CfgParam(BASE, 2, abi.encode(UlnConfig(9000, 3, 255, 0, d, new address[](0))));\n        bytes[] memory it = new bytes[](5);\n        it[0] = abi.encode(uint8(1), BASE, peer, uint256(50_000e18), uint256(4 days), uint256(50_000e18), uint256(4 days), bytes(\"\"));\n        it[1] = abi.encode(uint8(3), BASE, sl);\n        it[2] = abi.encode(uint8(4), BASE, rl, uint256(0));\n        it[3] = abi.encode(uint8(2), sl, sp);\n        it[4] = abi.encode(uint8(2), rl, rp);\n        vm.prank(address(safe));\n        br.propose(abi.encode(uint8(6), it));\n        vm.warp(vm.getBlockTimestamp() + 48 hours);\n        br.applyPending();\n    }\n\n    function _run(bytes32 front) internal returns (bool ran) {\n        bytes32 replay = keccak256(abi.encodePacked(guid, message));\n        ep.verify(B, replay); // a replay of the honest twin's payload at nonce B\n        ep.verify(B, front); // compromised DVNs, same block, in front of the Safe's batch\n        bytes[] memory c = new bytes[](3);\n        c[0] = abi.encodeWithSignature(\"hold(uint32,uint64)\", BASE, B);\n        c[1] = abi.encodeWithSignature(\"pause(uint32)\", BASE);\n        c[2] = abi.encodeWithSignature(\"propose(bytes)\", abi.encode(uint8(12), BASE, peer, B, bytes32(0)));\n        safe.multiSend(address(br), c); // the documented [hold, pause, propose(DROP)]\n        ep.verify(B, replay); // the replay back behind the hold\n        vm.warp(vm.getBlockTimestamp() + 48 hours);\n        vm.prank(address(0x5157));\n        br.applyPending(); // anyone applies the DROP\n        (bytes32 h, uint64 u) = br.holds(BASE, peer, B);\n        emit log_named_bytes32(\"record hash\", h);\n        emit log_named_uint(\"record until\", u);\n        vm.prank(address(safe));\n        br.propose(abi.encode(uint8(5), BASE)); // UNPAUSE\n        vm.warp(vm.getBlockTimestamp() + 48 hours);\n        br.applyPending();\n        vm.prank(address(0xF00D));\n        try ep.lzReceive(address(br), W6B1Org(BASE, peer, B), guid, message) { ran = true; } catch {}\n    }\n\n    function test_nilFront_dropCloses() public {\n        assertFalse(_run(bytes32(type(uint256).max)), \"NIL\");\n    }\n\n    function test_junkFront_dropLetsTheReplayRun() public {\n        assertFalse(_run(keccak256(\"no preimage\")), \"junk-bound hold + DROP: the dropped replay ran at the nonce\");\n    }\n\n    function test_oneFront_dropLetsTheReplayRun() public {\n        assertFalse(_run(bytes32(uint256(1))), \"hash-1-bound hold + DROP: the dropped replay ran at the nonce\");\n    }\n}\n",
    "ran": "forge 1.9.0, forge test --use solar --match-path test/scratch/JunkDrop.t.sol -vv (mock EndpointV2 from test/unit/AuditW6JudgeBridgeDrop.t.sol)",
    "result": "[PASS] test_nilFront_dropCloses() (record 0x..01, until 1); [FAIL: junk-bound hold + DROP: the dropped replay ran at the nonce] test_junkFront_dropLetsTheReplayRun() (record hash 0x506004dae8099db678fa461e805e2c0489f8b2aad268d64587778b3c15b2c6f0, until 2); [FAIL: hash-1-bound hold + DROP: the dropped replay ran at the nonce] test_oneFront_dropLetsTheReplayRun() (record 0x..01, until 2). 1 passed, 2 failed."
   }
  }
 ],
 "claims": [
  {
   "id": "C1",
   "result": "holds",
   "evidence": "test_C1_table (PASS). Each of the 16 cells, until {0, 1, 2, now+72h} x hash {0, 1, NIL, P}, is written into holds[BASE][peer][B] with vm.store (slot 13, from forge inspect). In each cell all 7 acts are run and compared with a reference model of the documented semantics: lzReceive of the replay P and of the forgery Q inside the hold; all payloads after the hold time; hold over a stored Q (binds only when until == 0); RELEASE(H) (accepted iff until != 0, then only H runs, as a claim); DROP (record vs the model: until 0 gives (ph, 2); until 1 or 2, or a NIL-bound hold, gives (1, 1); a live hold on a payload gives (ph, 2); then every payload vs the model); voidPayload(Q) then claim (a claim queued at B mints after D whatever the record). Every cell also asserts P1: no mint at once when until != 0, and the twin at nonce A mints at once. Cells (h, 0), (1, 0), (NIL, 0) and (NIL, 2) cannot be reached by any writer and behave as never-held, (h, 2) and closed. Mutating the NIL clause of the DROP, or removing `until != 0` from the instant test at :583, makes the table fail."
  },
  {
   "id": "C2",
   "result": "holds",
   "evidence": "No forged payload mints at once over a DROP on a never-held nonce. The DROP writes (0, 2) (README:765 as written). lzReceive refuses only hash 0, which no payload has, and every payload queues because until != 0 (ImdBridge.sol:583). testFuzz_C2_dropNeverHeld: P, Q and H, 0-30 days later, after an attempted hold (a no-op, :708). 10,000 runs pass. The forged payload does run as a claim: the README's 'a later message there runs as a claim', not worse than written."
  },
  {
   "id": "C3",
   "result": "holds",
   "evidence": "testFuzz_C3_dropOverDrop (10,000 runs, held first or never held, 0-400 days): the record is (1, 1) and P, Q and H are all refused. After RELEASE(H), only H runs, as a claim. test_routes_batches: BATCH [DROP, DROP] gives (1, 1), [RELEASE(h), DROP] gives (1, 1), [DROP, RELEASE(h)] gives (h, 1)."
  },
  {
   "id": "C4",
   "result": "refuted",
   "evidence": "As written, a DROP over a NIL-bound hold closes the nonce: test_C4_dropOverNilHold and test_nilFront_dropCloses pass. It also composes with the J1 batch (hold no-op + DROP accepted), M1 (DROP over ended records closes) and the C5 sequences. But the fix only covers NIL. The same front-run with any other hash that has no payload (junk, or the sentinel 1) leaves the DROP open to the replay: finding F1."
  },
  {
   "id": "C5",
   "result": "holds",
   "evidence": "Invariant testFuzz_C5_sequence: 10,000 runs of 24 random acts each. The acts are: DVN re-verify of P/Q/H/NIL/junk/1 at B; a stranger's lzReceive at B; the Safe's hold; propose DROP; propose RELEASE(H|P), refused iff never held; a stranger's applyPending at ETA or up to 2 h later; warps (same block, +12 s, hours, days); voidPayload(Q); the twin. After every act the bridge's record must equal the reference model's, the lzReceive outcome at B must match the model, nothing may mint at once when until != 0, and the twin must never be refused. All pass. The model encodes the sentinel rules as written, so F1 is a gap in the specification itself, which the model shares. Smallest replacement design: drop the sentinel encoding for an explicit state {NONE, HELD(h, until), ALLOW(h), DENY(h), CLOSED}, with DROP naming the hash it drops (DENY(h) only if the record is bound to h, otherwise CLOSED)."
  }
 ],
 "holds": [
  {
   "property": "P1 (never mints at once; voids no honest hash; the twin runs)",
   "tried": "Every route into lzReceive with holds.until != 0 queues (ImdBridge.sol:583). This holds in all 16 x 7 table cells, in 10,000 x 24-act random sequences with several acts per block, in consecutive blocks and across hold/ETA/expiry edges, in C2/C3 fuzz runs, and over the junk route of F1 (the replay queues there; it does not mint). hold, RELEASE and DROP are per nonce and never write voided; the twin at nonce A ran in every cell and sequence. Over a DROP, another payload queues until a DROP over it closes the nonce (C3), so P1 holds as written. F1 is the DROP failing its purpose for one class of bound hash."
  },
  {
   "property": "P2 (holds written only by hold and RELEASE's apply; a hold binds the hash it names, NIL included)",
   "tried": "Grepped src/ and script/. Writers: hold (:713) and _apply RELEASE (:1198-1201). Readers: lzReceive (:562-565), hold (:704-708), _validate RELEASE (:1012), and the public getter. No sstore or delegatecall exists in ImdBridge (the assembly in _names/_accepted only reads); script/ only mentions holds in comments. The table's act 3 and C4/C5 check that hold binds the stored hash (NIL, 1 and junk included) only when until == 0, and that a RELEASE binds the hash it names (a NIL name is refused at :1012). The C5 record-equals-model check after every act would catch any other writer on the routes exercised."
  }
 ],
 "notRun": [
  "No [fork]/[data] claim on this sheet. Real EndpointV2 was NOT RUN (no fork): the tests use the mock endpoint from test/unit/AuditW6JudgeBridgeDrop.t.sol. F1 relies on EndpointV2 storing any non-empty hash over an unexecuted nonce and allowing re-verification; this was checked by reading LayerZero's MessagingChannel._inbound/EndpointV2._verifiable source, not by running them."
 ]
}