# Audit report

> AUDIT src/bridge/ImdBridge.sol, imdUSD's LayerZero V2 burn-and-mint path (ships with Robinhood Chain after the beta, audited early; README has no bridge known issues: its trust model is the THREAT MODEL below), with ImdUSD's bridge minter and Parameters' SET_BRIDGE, at the pinned commit.
>
> imdUSD v2 is a multi-collateral CDP stablecoin; this is its capped mainnet beta on Ethereum (Robinhood Chain 4663 follows). README.md gives scope, invariants, trust model and known issues: read it first. Earlier public waves: GET https://api.imd.fun/jobs/<id>/submissions (wave 1 bd0ce553 oracles, wave 2 5a8d427d prices, wave 3 ff9ebb9d prices).
>
> 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/BridgeReview,invariant/BridgeInvariants}.t.sol'`; with Foundry 1.9+ `forge test --use solar --no-match-path 'test/fork/*'` builds and runs everything in seconds under 1 GB (confirm a proof with solc). Write each proof as test/unit/Proof<Name>.t.sol, add it to the glob, run it, paste it with its output, then delete it.
>
> PROPERTIES:
> P1 Supply: on each chain totalSupply equals the README equation with received minus sent, and across chains what is minted on arrival never exceeds what was burned on departure, except what a compromised verifier set can force before the path is paused: at most the available inbound limit plus limit x elapsed/window (deploy: 50,000/day into 4663, 10,000/day into Ethereum, script/DeployConfig.sol).
> P2 Bounded loss: forged packets mint at most the available inbound limit; a voided (nilified, skipped or burned) forged payload never executes. Verification commit and lzReceive are permissionless, so pause and void catch only what the limit holds back.
> P3 Floors: no proposal, batch, ordering of batch items or library change brings a path under MIN_REQUIRED_DVNS, under the source chain's confirmation floor, or onto a library that is not pinned.
> P4 No honest message is lost to a limit, a pause or an instant nilify: it waits at the endpoint and executes later (a nilified one once the DVNs re-verify it); only a timelocked ENDPOINT_BURN or ENDPOINT_SKIP drops one.
> P5 Only the 48 h timelock opens or raises anything; every instant act (pause, nilify) only closes.
> P6 No path carries value unless both its libraries are pinned and each holds a floor-checked ULN config set by this OApp; no SET_PATH, SET_SEND_LIBRARY or SET_RECEIVE_LIBRARY (or its grace period) leaves a path on LayerZero's default config or an unconfigured library.
>
> THREAT MODEL: compromised DVNs control which packets verify; LayerZero controls library registration, its default libraries and the default optional DVNs merged in when optionalDVNCount is 0; a compromised Safe controls proposals (any 3 DVN addresses, any registered library, limits, ENDPOINT_BURN of messages on a paused path) but not the floor counts in source; the guardian (a hot key; an operator watcher pauses when netMinted() disagrees with the supply equation) and the governor pause and nilify instantly, so a compromised guardian can hold every inbound message; users, relayers and permissionless executors control delivery timing, gas, and ordering within a block and across blocks, and can race a pause; the source chain can reorg (Robinhood Chain has one sequencer). Defended: compromised DVNs (to the limit), LayerZero default or library moves, users, relayers and executors, reorgs within the confirmation floors. Accepted: the Safe's timelocked acts (its own DVNs, limits up to MAX_LIMIT, ENDPOINT_BURN) and a compromised guardian holding inbound messages (liveness only). Find where an accepted actor does more than stated.
>
> PATH: ImdBridge.send (burn, fee minted to the Treasury) -> EndpointV2 -> DVNs + executor -> peer ImdBridge.lzReceive -> ImdUSD.mint through the one bridge minter -> a forged mint is spent through Redeemer.redeem, the peg pool, repaying debt, or ImdBridge.send back out. Governance through Governed (SET_PATH, SET_CONFIG, libraries, BATCH, endpoint acts); Parameters SET_BRIDGE wires it once. Deploy config in script/DeployConfig.sol: limits, the 4663 chain line (30,000), launch batches with pins and 3 required + 0 optional DVNs.
>
> CLAIMS TO CHECK: confirm or refute each with a test.
> C1 the Kelp sequence works: pause, nilify, fix the DVN config, unpause, without changing the peer;
> C2 the fee never leaves the chain and the supply equation is unchanged by it;
> C3 the library pins cannot be bypassed through BATCH ordering or a LayerZero default change;
> C4 a path with no limit set refuses everything;
> C5 the 50,000/day inbound limit into 4663 is a real bound although it exceeds the 4663 chain line (30,000): refute by spending one day's forged mint for more than the 4663 book can lose;
> C6 an instant nilify never loses an honest message: on the real endpoint a nilified nonce can be re-verified and executed (whether the live DVNs re-sign it unprompted is off-chain: state what it requires);
> C7 no library change or receive-library grace keeps a path on an unpinned or unconfigured library.
>
> SOUNDNESS: is a per-path rate limit plus DVN and confirmation floors a sound bound under LayerZero ULN302's real verification and library semantics? Where can the bound fail? Does pause-and-void add anything when a forged packet within the limit executes in the block it verifies, and is a count floor a bound when the Safe chooses the DVNs? If not, give the smallest sound design.
>
> PROOF STANDARD: invariant tests (extend test/invariant/BridgeInvariants.t.sol) over interleavings of sends, receives, forged packets, pauses, nilify, limit and config changes. The unit tests run on test/utils/MockLzEndpoint.sol, whose nilify, reverify and grace are ours, not LayerZero's: answers on P2-P4, P6, C1, C3, C6, C7 must be checked on a mainnet fork against the real EndpointV2 0x1a44076050125825900e736c501f859c50fE728c and its ReceiveUln302 (a mainnet RPC only; say if you could not), never on the mock alone.
>
> Answer each numbered question:
> 1. (P1, P2) Find a path that mints more than was burned beyond the stated bound: replays, reorgs, nonces, a skipped or burned nonce re-verified, the fee path, decimal conversion dust.
> 2. (P3, P5, P6) Governance: find a proposal, batch or ordering that lowers a floor, unpins a library, leaves a path on a default config, or opens anything without the 48 h delay.
> 3. (P2, P4) Stop and retry: can a forged payload execute after a pause, can nilify or a pause lose an honest message, can the limit strand one?
> 4. (P1) Interoperability with a standard OFT peer: wire format, shared decimals, compose and options. Find a message a peer can send that breaks accounting.
>
> Not findings: README 'Known issues' as written (a known issue worse than written IS a finding); test/ and mocks; src/dex and src/earn/LoopVault.sol.
>
> Every finding: severity by impact; file, line and the lines copied; the call sequence; the failing state, expected vs actual; reachable with the deploy config or not; the smallest fix; and 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/fa11up/imdusd-v2-audit.git |
| Commit | `67eadeac1e67db5f562e03eab8432a435debfb79` |
| Job | `34e546c2-837d-46c9-8a21-0671ec934a8b` |
| Judged | 2026-11-15 06:56 UTC |
| Findings | 2 high · 1 medium · 9 low · 2 info |

Four agents audited the code as it is at `67eadea`, 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. High: SET_PATH, SET_SEND_LIBRARY or SET_RECEIVE_LIBRARY without a floor-checked SET_CONFIG leaves the path on LayerZero's default ULN config (mainnet default for eid 30416: 1 DVN, 5 confirmations), bypassin

`src/bridge/ImdBridge.sol:406`

```
        } else if (kind == SET_SEND_LIBRARY || kind == SET_RECEIVE_LIBRARY) {
            (, uint32 eid, address lib) = abi.decode(payload, (uint8, uint32, address));
            if (lib.code.length == 0 || eid == 0 || eid == endpoint.eid()) revert BadPayload();
```

The floors (MIN_REQUIRED_DVNS = 3, 15/20 confirmations) are enforced only inside SET_CONFIG (_checkUln). _check for SET_PATH (lines 379-387) does not require the eid's send and receive libraries to be pinned, now or in the same BATCH, nor any ULN config to exist; _check for SET_SEND_LIBRARY / SET_RECEIVE_LIBRARY (406-408) requires only that the library has code; send() and lzReceive() never consult sendLibrary[eid]/receiveLibrary[eid]. On EndpointV2 the ULN config lives per (oapp, library, eid) and an OApp with no config of its own is verified by the library's DEFAULT config (ReceiveUln302.getUlnConfig merges the default when requiredDVNCount is 0). So (a) a SET_PATH alone opens a path on the endpoint's default libraries and their default config; (b) a BATCH [SET_PATH, pins] without SET_CONFIG, or a lone library move after a LayerZero deprecation (the header's documented case, line 47), lands the path on a library where this OApp has no config. Read on mainnet: ReceiveUln302.getUlnConfig(<unconfigured oapp>, 30416) = (confirmations 5, requiredDVNCount 1, [0x747C741496a507E4B404b50463e691A8d692f6Ac], no optional). That is below both floors and LayerZero can change it at will (the 'defended' default move). The header's claim that a careless or compromised Safe 'cannot propose a Kelp-style 1-of-1 downgrade at all' (lines 50-51) is false: it can, by omission, with a single 48h item and no DVN of its own named. Impact: mints up to the inbound limit (10,000/day into Ethereum, 50,000/day into 4663) decided by one DVN LayerZero chooses. Reachable with the deploy config: the launch BATCHes carry all five items, but nothing in the contract enforces that; every later proposal (new eid, library migration) is exposed. Accepted actor (Safe) does more than stated: the trust model gives it 'any 3 DVN addresses', not a 1-of-1 verifier. Smallest fix: in _check, SET_PATH requires _pinned(SET_SEND_LIBRARY, eid, batch) and _pinned(SET_RECEIVE_LIBRARY, eid, batch) non-zero and a ULN config for each (a `configured[lib][eid]` flag set in _apply(SET_CONFIG), or a SET_CONFIG item for (lib, eid, CONFIG_TYPE_ULN) in the same BATCH); SET_SEND_LIBRARY / SET_RECEIVE_LIBRARY require the same for the new library; optionally revert in send()/lzReceive() when the path's library is unpinned. Merged from four specialist reports (flow high, math medium, economics medium, permissions medium).

**Reproduction**

Mainnet fork against the real EndpointV2 0x1a44076050125825900e736c501f859c50fE728c and ReceiveUln302 0xc02Ab410f0734EFa3F14628780e6e695156024C2 (public RPC https://ethereum-rpc.publicnode.com, block ~26418627), ImdBridge deployed on the fork with the Safe as governor. Safe proposes SET_PATH = abi.encode(uint8(1), 30416, peer, 50_000e18, 1 days, 10_000e18, 1 days, '') alone; +48h; applyPending. Expected (P6/P3): refused, or no value until a floor-checked config exists. Actual: applied; endpoint.getReceiveLibrary(bridge, 30416) = (0xc02A..., isDefault = true); bridge.receiveLibrary(30416) == 0; ReceiveUln302.getUlnConfig(bridge, 30416) = requiredDVNCount 1, confirmations 5. The single default DVN 0x747C... calls ReceiveUln302.verify(header{nonce 1, src 30416, sender peer, dst 30101, receiver bridge}, payloadHash, 5); anyone calls commitVerification then EndpointV2.lzReceive: 9,000 imdUSD minted to the attacker. Run on this machine: forge test --match-path test/scratch/Fork.t.sol --fork-url <mainnet RPC> -vv -> [PASS] test_fork_setPathAloneLeavesPathOnDefault1of1 (behaviour present), Logs: effective required DVNs: 1 / effective confirmations: 5. Self-contained proof (fails on this commit): forge test --match-path test/scratch/ProofA.t.sol -> [FAIL: next call did not revert as expected] test_bareSendLibraryPinIsRefused, test_bareReceiveLibraryPinIsRefused, test_pathWithoutPinnedConfiguredLibrariesIsRefused; control test_launchBatchWithConfigsIsAccepted PASS.

**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} from "src/bridge/ImdBridge.sol";
import {ILayerZeroEndpointV2} from "layerzero-v2/protocol/interfaces/ILayerZeroEndpointV2.sol";
import {SetConfigParam} from "layerzero-v2/protocol/interfaces/IMessageLibManager.sol";

/// Minimal endpoint stand-in: records libraries and configs, as EndpointV2 does per (oapp, lib, eid, type).
contract Endpoint {
    uint32 public eid = 30416;
    mapping(address => mapping(uint32 => address)) public sendLib;
    mapping(address => mapping(uint32 => address)) public receiveLib;
    mapping(address => mapping(address => mapping(uint32 => mapping(uint32 => bytes)))) public config;

    function setSendLibrary(address oapp, uint32 e, address lib) external { sendLib[oapp][e] = lib; }
    function setReceiveLibrary(address oapp, uint32 e, address lib, uint256) external { receiveLib[oapp][e] = lib; }
    function setConfig(address oapp, address lib, SetConfigParam[] calldata p) external {
        for (uint256 i; i < p.length; ++i) config[oapp][lib][p[i].eid][p[i].configType] = p[i].config;
    }
}

contract Lib {
    function messageLibType() external pure returns (uint8) { return 2; }
}

contract Token {
    function mint(address, uint256) external pure returns (bool) { return true; }
    function burn(address, uint256) external pure returns (bool) { return true; }
}

struct UlnConfig { uint64 confirmations; uint8 requiredDVNCount; uint8 optionalDVNCount; uint8 optionalDVNThreshold; address[] requiredDVNs; address[] optionalDVNs; }

/// P6 / C7: a path must not be left on a library where this OApp has set no floor-checked ULN config (there the
/// endpoint's DEFAULT config verifies: on mainnet for eid 30416 that is 1 DVN with 5 confirmations). ImdBridge accepts a
/// bare SET_SEND_LIBRARY, a bare SET_RECEIVE_LIBRARY and a bare SET_PATH, none of which carries a config.
contract ProofUnconfiguredLibraryTest is Test {
    uint32 constant MAINNET = 30101;
    Endpoint ep;
    Lib sendLib;
    Lib receiveLib;
    ImdBridge bridge;

    function setUp() public {
        ep = new Endpoint();
        sendLib = new Lib();
        receiveLib = new Lib();
        bridge = new ImdBridge(
            ILayerZeroEndpointV2(address(ep)), IMintableBurnable(address(new Token())), address(this), address(this), address(1)
        );
    }

    function _dvns() internal pure returns (address[] memory d) {
        d = new address[](3);
        (d[0], d[1], d[2]) = (address(0x1000), address(0x2000), address(0x3000));
    }

    function _uln(uint64 conf) internal pure returns (bytes memory) {
        return abi.encode(UlnConfig(conf, 3, 0, 0, _dvns(), new address[](0)));
    }

    function _path() internal pure returns (bytes memory) {
        return abi.encode(uint8(1), MAINNET, bytes32(uint256(1)), uint256(10_000e18), uint256(1 days), uint256(50_000e18), uint256(1 days), bytes(""));
    }

    function _configs() internal view returns (bytes memory sendCfg, bytes memory recvCfg) {
        SetConfigParam[] memory sp = new SetConfigParam[](2);
        sp[0] = SetConfigParam(MAINNET, 1, abi.encode(uint32(10_000), address(0xE)));
        sp[1] = SetConfigParam(MAINNET, 2, _uln(20));
        SetConfigParam[] memory rp = new SetConfigParam[](1);
        rp[0] = SetConfigParam(MAINNET, 2, _uln(15));
        sendCfg = abi.encode(uint8(2), address(sendLib), sp);
        recvCfg = abi.encode(uint8(2), address(receiveLib), rp);
    }

    /// Control: the launch BATCH (path, both pins, both configs) must stay accepted by any fix.
    function test_launchBatchWithConfigsIsAccepted() public {
        (bytes memory sc, bytes memory rc) = _configs();
        bytes[] memory items = new bytes[](5);
        items[0] = _path();
        items[1] = abi.encode(uint8(3), MAINNET, address(sendLib));
        items[2] = abi.encode(uint8(4), MAINNET, address(receiveLib), uint256(0));
        items[3] = sc;
        items[4] = rc;
        bridge.propose(abi.encode(uint8(6), items));
        vm.warp(block.timestamp + 48 hours);
        bridge.applyPending();
        assertEq(bridge.sendLibrary(MAINNET), address(sendLib));
        assertGt(ep.config(address(bridge), address(receiveLib), MAINNET, 2).length, 0);
    }

    /// A SET_SEND_LIBRARY with no ULN config for (lib, eid), now or in the same batch, leaves sends verified under the
    /// library's default DVN set. Expected: refused at propose. Actual on this commit: accepted.
    function test_bareSendLibraryPinIsRefused() public {
        vm.expectRevert();
        bridge.propose(abi.encode(uint8(3), MAINNET, address(sendLib)));
    }

    /// Same for the receive library: inbound packets from `eid` are then verified by the default config.
    function test_bareReceiveLibraryPinIsRefused() public {
        vm.expectRevert();
        bridge.propose(abi.encode(uint8(4), MAINNET, address(receiveLib), uint256(0)));
    }

    /// A SET_PATH on an eid with neither library pinned opens the path on LayerZero's default libraries and defaults.
    function test_pathWithoutPinnedConfiguredLibrariesIsRefused() public {
        vm.expectRevert();
        bridge.propose(_path());
    }
}
```

### 2. High: Zero-amount (or dust) forged packets execute unmetered, consuming the honest peer's future nonces for good: compromised DVNs destroy honest in-flight sends beyond the inbound limit and unseen by netMi

`src/bridge/ImdBridge.sol:354`

```
        if (amount == 0) return; // a zero-amount message (inbound) moves no window
```

On the real EndpointV2, verify() of a nonce that has executed reverts (LZ_PathNotVerifiable: nonce <= lazyInboundNonce and EMPTY hash), and verify() of a not-yet-executed nonce OVERWRITES the stored hash. The peer's outbound nonces are assigned sequentially, so a forged packet executed at nonce n consumes the nonce of the honest send that carries n: that user's imdUSD was burned on the source chain and can never be minted here (no admin mint; ImdUSD.setBridge is once). ImdBridge meters inbound AMOUNT only: _consume returns at once for amount 0, so a zero-amount packet executes with the window full, on a path whose limit is 0 (C4 is literal only for amount > 0), changes neither `received` nor netMinted() (the operator watcher in the threat model sees nothing), and a 1e-6 imdUSD packet costs 1e12 of a 10,000e18 limit. A compromised 3-DVN set (the threat model's defended actor, 'to the limit') commits and executes hundreds of forged nonces in one block; every honest send at those nonces is dead on arrival; a payload WAITING at the endpoint (rate-limited or paused, the states P4 calls safe) is overwritten by a forged one at the same nonce and lost once that executes. The loss is bounded by honest flow until the SOURCE path is paused, not by the inbound limit, and no ImdBridge act (nilify, burn, skip, re-point) restores a consumed nonce. Reachable with the deploy config (3 required, 0 optional DVNs; unordered delivery). Smallest fix: in lzReceive revert when amount == 0 (send() already refuses a zero send) so such a packet stays at the endpoint where it can be nilified; add a per-path inbound MESSAGE COUNT limit per window so nonce consumption is bounded like the amount; make the watcher compare destination Received/lazyInboundNonce against source Sent events and pause the SOURCE path; state the residual (honest in-flight value during a DVN compromise is at risk in full) in the trust model, with a timelocked re-mint for a send proven burned at the peer and consumed by a forgery. Merged from three specialist reports (permissions high, math medium, flow medium).

**Reproduction**

Mainnet fork against the real EndpointV2 0x1a44076050125825900e736c501f859c50fE728c and ReceiveUln302 0xc02Ab410f0734EFa3F14628780e6e695156024C2 (public RPC https://ethereum-rpc.publicnode.com, block ~26418627), ImdBridge deployed on the fork with the Safe as governor. Path opened (in 10,000/day). (1) Forged nonce 1 (10,000 to attacker) verified (ReceiveUln302 -> endpoint.verify) and executed: availableIn == 0, lazyInboundNonce == 1. (2) Forged nonce 2 with amountSD = 0 verified and endpoint.lzReceive succeeds with the window full: lazyInboundNonce == 2, received unchanged, netMinted unchanged. (3) The honest message of nonce 1 or 2: endpoint.verifiable(Origin(30416, peer, n), bridge) == false and endpoint.verify reverts. Expected (P4): the honest message waits and executes later. Actual: lost permanently. (4) Honest 100 verified at nonce 1 but not executed; forged 1,000 verified at nonce 1: inboundPayloadHash is the forged hash; it executes; the honest 100 is unverifiable. Run: forge test --match-path test/scratch/Fork.t.sol --fork-url <mainnet RPC> -> [PASS] test_fork_nilifyReverifiable_burnSkipRevert_executedNonceLost, [PASS] test_fork_forgedVerifyOverwritesHonestHash (behaviour present). Self-contained proof (fails on this commit, no fork): forge test --match-path test/scratch/ProofC.t.sol -> [FAIL: zero-amount inbound message executed] test_forgedDustPacketsConsumeInboundNoncesUnmetered(). Also forge test --match-path test/scratch/Mock.t.sol: test_zeroLimitPathExecutesZeroAmount PASS (a limit-0 path executes a zero-amount packet).

**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} from "src/bridge/ImdBridge.sol";
import {
    ILayerZeroEndpointV2, MessagingParams, MessagingReceipt, MessagingFee, Origin
} from "layerzero-v2/protocol/interfaces/ILayerZeroEndpointV2.sol";
import {SetConfigParam} from "layerzero-v2/protocol/interfaces/IMessageLibManager.sol";
import {ILayerZeroReceiver} from "layerzero-v2/protocol/interfaces/ILayerZeroReceiver.sol";

contract Tok {
    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; }
}

/// The endpoint surface ImdBridge needs; `deliver` hands a verified packet to lzReceive as EndpointV2 does.
contract MiniEndpoint {
    uint32 public immutable eid;
    constructor(uint32 e) { eid = e; }
    function quote(MessagingParams calldata, address) external pure returns (MessagingFee memory) { return MessagingFee(0, 0); }
    function send(MessagingParams calldata, address) external payable returns (MessagingReceipt memory r) { r = MessagingReceipt(bytes32(0), 1, MessagingFee(0, 0)); }
    function setConfig(address, address, SetConfigParam[] calldata) external {}
    function setSendLibrary(address, uint32, address) external {}
    function setReceiveLibrary(address, uint32, address, uint256) external {}
    function nilify(address, uint32, bytes32, uint64, bytes32) external {}
    function deliver(address oapp, Origin calldata o, bytes calldata message) external returns (bool ok) {
        (ok,) = oapp.call(abi.encodeWithSelector(ILayerZeroReceiver.lzReceive.selector, o, bytes32(uint256(o.nonce)), message, address(this), bytes("")));
    }
}

/// On EndpointV2 an executed nonce is consumed for good: `verify` of the honest packet that carries the same nonce reverts
/// (LZ_PathNotVerifiable), so the honest sender's burn on the source chain is lost. ImdBridge meters inbound AMOUNT only:
/// a compromised DVN set executes any number of zero-amount (limit untouched, netMinted unchanged) or 1e-6 imdUSD packets
/// in one block, consuming that many future nonces of the honest peer. Fixed when lzReceive refuses amount 0 and caps the
/// number of inbound messages per window, so nonce consumption is bounded like the amount is.
contract ProofNonceConsumptionTest is Test {
    uint32 constant RH = 30416;
    address safe = makeAddr("safe");
    address attacker = makeAddr("attacker");
    bytes32 peer = bytes32(uint256(uint160(makeAddr("peer"))));
    MiniEndpoint ep;
    Tok tok;
    ImdBridge b;

    function setUp() public {
        ep = new MiniEndpoint(30101);
        tok = new Tok();
        b = new ImdBridge(ILayerZeroEndpointV2(address(ep)), IMintableBurnable(address(tok)), safe, makeAddr("guardian"), makeAddr("treasury"));
        vm.prank(safe);
        b.propose(abi.encode(uint8(1), RH, peer, uint256(50_000e18), uint256(1 days), uint256(10_000e18), uint256(1 days), bytes("")));
        vm.warp(vm.getBlockTimestamp() + 48 hours);
        b.applyPending();
    }

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

    function test_forgedDustPacketsConsumeInboundNoncesUnmetered() public {
        // a zero-amount forged packet must not execute (it would consume the honest nonce at no cost and unseen)
        assertFalse(ep.deliver(address(b), Origin(RH, peer, 1), _msg(attacker, 0)), "zero-amount inbound message executed");
        // 100 forged packets of 1e-6 imdUSD each, one block: a sound bound stops most of them
        uint256 executed;
        for (uint64 n = 2; n <= 101; ++n) {
            if (ep.deliver(address(b), Origin(RH, peer, n), _msg(attacker, 1))) executed++;
        }
        assertLt(executed, 100, "100 inbound nonces consumed in one block for 1e-4 imdUSD: every honest send at those nonces is lost");
        assertLe(tok.balanceOf(attacker), 100e12);
    }
}
```

### 3. Medium: nilify does not kill a forged payload on the real endpoint: a NIL nonce stays verifiable, the still-configured compromised DVNs re-verify it (also while paused), and it executes when UNPAUSE lands wit

`src/bridge/ImdBridge.sol:306`

```
    /// @notice Void a verified inbound payload now: guardian or governor, like `pause`. Re-verifiable by the DVNs,
    /// so it delays an honest message and kills a forged one; burning for good and skipping go through the timelock.
```

EndpointV2.nilify sets inboundPayloadHash to NIL (0xff..ff) and _verifiable() stays true for that nonce (non-empty hash), so whoever satisfies the path's CURRENT ULN config can commit the same forged payload again and the hash is restored; ReceiveUln302 reclaims the DVN attestations at commit, so the compromised DVNs simply sign again. The mock models 'nilified = refused until reverify()', which hides this. Consequences: (1) the comment at 306-307, P2 ('a voided forged payload never executes') and the header's Kelp order 'pause, nilify, fix the DVN config, then unpause' (56-57) are false as written: a nilify before the config fix is undone at will; (2) nothing in _validate stops UNPAUSE(eid) from sharing a BATCH with the SET_CONFIG that replaces the DVNs (the single pending slot invites it, else the path is shut 96h), and applyPending is permissionless, so the attacker bundles [verify x3, commitVerification, applyPending, endpoint.lzReceive] and mints the whole inbound limit the 48h pause refilled; (3) even with separate proposals the guardian must nilify AGAIN after the SET_CONFIG applies, which nothing states. Amounts stay within P2's 'available inbound limit', but it is a second full window the pause-and-void exists to prevent. Reachable with the deploy config whenever the 3 required DVNs are compromised. C6 holds for the honest case: a nilified honest nonce can be re-verified and executed on the real endpoint, but only if all currently configured required DVNs re-sign it off-chain (per-operator behaviour, not guaranteed). Smallest fix: record voided payload hashes in the bridge (nilify() and ENDPOINT_NILIFY set voided[payloadHash] = true) and make lzReceive revert when voided[keccak256(abi.encodePacked(guid, message))], with a timelocked un-void for an honest payload nilified by mistake; refuse a BATCH holding UNPAUSE(eid) together with SET_CONFIG/SET_RECEIVE_LIBRARY/SET_PATH for that eid; document the sound order pause -> SET_CONFIG (48h) -> nilify again -> UNPAUSE (48h). Merged from two specialist reports (flow medium, math medium).

**Reproduction**

Mainnet fork against the real EndpointV2 0x1a44076050125825900e736c501f859c50fE728c and ReceiveUln302 0xc02Ab410f0734EFa3F14628780e6e695156024C2 (public RPC https://ethereum-rpc.publicnode.com, block ~26418627), ImdBridge deployed on the fork with the Safe as governor. Path opened. Forged nonce 1 (10,000 to attacker) verified through ReceiveUln302 (inboundPayloadHash == ph). guardian: pause(30416); nilify(30416, peer, 1, ph) -> inboundPayloadHash == 0xff..ff and endpoint.verifiable(Origin(30416, peer, 1), bridge) == true. The receive library verifies the same ph again -> inboundPayloadHash == ph (restored, path still paused). After UNPAUSE applies, anyone calls endpoint.lzReceive(Origin(30416, peer, 1), bridge, guid, message, ''): 10,000 imdUSD minted to the attacker. Expected (P2/C1): a nilified forged payload never executes. Actual: it executes. Run: forge test --match-path test/scratch/Fork.t.sol --fork-url <mainnet RPC> -> [PASS] test_fork_nilifyReverifiable_burnSkipRevert_executedNonceLost (asserts 'same payload re-verified after nilify' and the mint after unpause).

### 4. Low: ENDPOINT_BURN and ENDPOINT_SKIP cannot void a verified forged payload at the head nonce of a PAUSED path on the real endpoint (LZ_InvalidNonce): 'void it for good' is unavailable exactly when the head

`src/bridge/ImdBridge.sol:494`

```
            else endpoint.burn(address(this), eid, sender, nonce, h);
```

MessagingChannel.burn requires nonce <= lazyInboundNonce (and a non-empty hash); lazyInboundNonce advances only when a HIGHER nonce executes or is skipped. skip requires nonce == inboundNonce + 1, i.e. the first nonce with NO stored hash, so a verified (or nilified) nonce cannot be skipped. ENDPOINT_BURN/ENDPOINT_SKIP are accepted only for a PAUSED path (line 416), where lzReceive reverts PathPaused, so the forged head nonce (the case lines 52-55 and 92-95 describe) can never be burned or skipped: applyPending reverts after the 48h and the single pending slot is held until the Safe cancels. The only durable sequence is nilify -> DVN fix + UNPAUSE (48h) -> a later honest nonce executes -> pause -> ENDPOINT_BURN(nonce, NIL) (48h). test/utils/MockLzEndpoint.burn/skip accept any nonce, so test_reviewF3 passes on behaviour the real endpoint does not have. No fund loss by itself (nilify plus the DVN change still neutralise the payload), but the stated power does not exist as written. Smallest fix: correct the header and the mock; in _check read endpoint.lazyInboundNonce / inboundNonce so an infeasible act is refused at propose; let ENDPOINT_BURN also be accepted for a nonce whose stored hash is NIL on an unpaused path so the final burn needs no second pause round. Merged from four specialist reports (flow low, math low, economics low, permissions medium).

**Reproduction**

Mainnet fork against the real EndpointV2 0x1a44076050125825900e736c501f859c50fE728c and ReceiveUln302 0xc02Ab410f0734EFa3F14628780e6e695156024C2 (public RPC https://ethereum-rpc.publicnode.com, block ~26418627), ImdBridge deployed on the fork with the Safe as governor. Path opened; forged nonce 1 verified (lazyInboundNonce 0, inboundNonce 1); guardian pause(30416). Safe proposes abi.encode(uint8(10), 30416, peer, uint64(1), payloadHash); +48h; applyPending() reverts (LZ_InvalidNonce); Safe cancels; proposes abi.encode(uint8(8), 30416, peer, uint64(1)); +48h; applyPending() reverts; inboundPayloadHash(bridge, 30416, peer, 1) still == payloadHash. Expected (header 52-55): the payload is dropped for good. Actual: both acts revert; the payload executes once unpaused. Run: forge test --match-path test/scratch/Fork.t.sol --fork-url <mainnet RPC> -> [PASS] test_fork_nilifyReverifiable_burnSkipRevert_executedNonceLost (both expectRevert on applyPending hold, 'forged hash still stored').

### 5. Low: _checkUln refuses optionalDVNCount = NIL (255), so every config this bridge can set (deploy: 3 required + 0 optional) inherits LayerZero's default optional DVNs and threshold; a default change makes t

`src/bridge/ImdBridge.sol:429`

```
        if (
            u.optionalDVNs.length != u.optionalDVNCount || u.optionalDVNThreshold > u.optionalDVNCount
                || (u.optionalDVNCount != 0 && u.optionalDVNThreshold == 0)
        ) revert WeakConfig(7);
```

In ULN302 an OApp optionalDVNCount of 0 means DEFAULT: getUlnConfig copies the library default's optional DVNs and threshold into the effective config; only 255 (NIL) with an empty list and threshold 0 means 'none'. _checkUln requires optionalDVNs.length == optionalDVNCount, so NIL is rejected with WeakConfig(7) and the bridge cannot express 'no optional DVNs'; DeployConfig._lzConfig ships optionalDVNCount 0. Effect of a LayerZero default move (owner key of ReceiveUln302/SendUln302, a 'defended' actor): the merged optional set becomes mandatory on top of the 3 required DVNs (ULN302 needs all required AND the optional threshold), so every honest inbound message stops committing and on the send side the default optional DVNs are assigned and paid; the Safe's only exit is a 48h SET_CONFIG naming an explicit optional DVN with threshold >= 1, a fourth mandatory signer. Safety is not weakened (the merge only adds signers); it is liveness, and the header's claim that a default move cannot change this OApp's verification. Reachable with the deploy config. Smallest fix: accept optionalDVNCount == NIL_DVN_COUNT with an empty list and threshold 0, refuse optionalDVNCount == 0, and ship 255 in DeployConfig. Merged from two specialist reports (math low, permissions medium).

**Reproduction**

Mainnet fork against the real EndpointV2 0x1a44076050125825900e736c501f859c50fE728c and ReceiveUln302 0xc02Ab410f0734EFa3F14628780e6e695156024C2 (public RPC https://ethereum-rpc.publicnode.com, block ~26418627), ImdBridge deployed on the fork with the Safe as governor. BATCH [SET_PATH, SET_RECEIVE_LIBRARY(30416, ReceiveUln302, 0), SET_CONFIG(ReceiveUln302, UlnConfig(20, 3, 0, 0, dvns, []))] applied: getUlnConfig(bridge, 30416) = 3 required / 0 optional. ReceiveUln302.owner() calls setDefaultUlnConfigs([30416: 1 optional DVN 0xBEEF, threshold 1]); getUlnConfig(bridge, 30416).optionalDVNCount == 1 with 0xBEEF. Safe proposes SET_CONFIG with UlnConfig(20, 3, 255, 0, dvns, []): revert WeakConfig(7). Expected: the OApp's config is unchanged by the default move and NIL is accepted. Actual: default optional DVN merged in and NIL refused. Run: forge test --match-path test/scratch/Fork.t.sol --fork-url <mainnet RPC> -> [PASS] test_fork_optionalZeroInheritsDefaults_nilRefused, Logs: optional DVNs now in this OApp's config: 1.

### 6. Low: SET_RECEIVE_LIBRARY takes an unbounded grace during which the old, now-unpinned library still verifies but can no longer be configured (SET_CONFIG refuses it); the new library needs no config (C7 refu

`src/bridge/ImdBridge.sol:479`

```
            (, uint32 eid, address lib, uint256 grace) = abi.decode(payload, (uint8, uint32, address, uint256));
```

_check for SET_RECEIVE_LIBRARY decodes only (kind, eid, lib) (line 407): grace is never bounded and is forwarded to endpoint.setReceiveLibrary, which keeps the OLD library valid until block.number + grace (receiveLibraryTimeout). _apply overwrites receiveLibrary[eid], so SET_CONFIG on the old library is refused with UnpinnedLibrary (line 394) although it still verifies this path, and the bridge has no way to call setReceiveLibraryTimeout; the only exit is a 48h BATCH re-pinning the old library with grace 0 and then the new one again. With grace 2^200 the old library verifies for this path forever. Combined with the default-config finding, the new library can hold no config of this OApp while value flows through it. Actor: the Safe's timelocked proposal (any registered library; the unbounded grace and the frozen old config are more than stated). Reachable on the first library migration the header describes (line 47); launch pins use grace 0. Smallest fix: bound grace in _check (decode the 4th word; e.g. <= 50,400 blocks or 0), let SET_CONFIG accept a library still inside its grace, and require a ULN config for the new library in the same BATCH.

**Reproduction**

Self-contained: forge test --match-path test/scratch/Mock.t.sol -> [PASS] test_receiveLibraryGraceUnboundedAndOldLibUnconfigurable: SET_RECEIVE_LIBRARY(30416, oldLib, 0) applied; SET_RECEIVE_LIBRARY(30416, newLib, 1 << 200) accepted at propose and applied, the endpoint receives grace 2^200; propose SET_CONFIG(oldLib, UlnConfig(20, 3, 0, 0, dvns, [])) reverts UnpinnedLibrary(30416, oldLib). Expected: grace bounded, the still-valid library configurable. Actual: unbounded grace, old library frozen. Endpoint side (EndpointV2.setReceiveLibrary): if gracePeriod > 0 the timeout records (oldLib, block.number + gracePeriod) and isValidReceiveLibrary stays true for oldLib until then.

### 7. Low: The limiter admits almost 2 x limit inside one window (limit at once, then limit x elapsed/window), while the header and DeployConfig state 'at most `limit` in any `window`' and '50,000 per day'

`src/bridge/ImdBridge.sol:61`

```
/// LIMITS. Per path, an outbound and an inbound limit in LayerZero RateLimiter's form: at most `limit` in any
/// `window`, with the amount in flight decaying linearly. Outbound bounds how much a failure on this chain can export; inbound
```

_available refills linearly from the last consume, so a full burst is followed by limit x elapsed/window more: 2 x limit - epsilon inside any window that starts with a burst. That matches P1's formula (available + limit x elapsed/window) and testFuzz_P1_limiterBound, but the source header (61-64) and DeployConfig (831-834, 'per day') state half of it, and C5's sizing reasons from one limit per day. With the deploy config a compromised DVN set mints 50,000 at once and ~100,000 within 24h into 4663 (chain line 30,000), 10,000 at once and ~20,000 within 24h into Ethereum. Smallest fix: state the bound as 2 x limit per window everywhere and size IN_LIMIT accordingly (25,000 to keep 50,000/day), or use a fixed-window bucket so 'limit per window' is literal.

**Reproduction**

Self-contained: forge test --match-path test/scratch/Mock.t.sol -vv -> [PASS] test_twiceLimitInsideOneWindow, Logs: available at t0 + 86,399 s: 9999.884259259259259259 / minted inside one window: 19999.884259. Input: inbound limit 10,000e18, window 1 day; lzReceive 10,000e18 at t0; at t0 + 86,399 s availableIn() = 9,999.88e18 and a second lzReceive of that amount executes. Expected (header): <= 10,000e18 in any 24h. Actual: 19,999.88e18 in 86,399 s.

### 8. Low: A BATCH of two SET_PATH items (inbound limit to 0, then back) erases what is in flight and resets the window in one block; the final limits are unchanged so the batch reads as a no-op

`src/bridge/ImdBridge.sol:510`

```
        if (limit < l.limit) inFlight = inFlight * limit / l.limit;
```

_setLimit scales inFlight by new/old when lowering; lowering to 0 (allowed, 0 is the documented 'closed') gives inFlight = 0, and a second SET_PATH in the same BATCH restoring the old limit then starts a fresh window. BATCH[SET_PATH(in = 0), SET_PATH(in = L)] ends on exactly the limits the path already has, so a reviewer diffing the final state sees no change, yet applyPending is permissionless for 14 days after the eta and can be timed to the moment the window is full: the burst doubles in one block (limit + limit instead of limit + limit x elapsed/window). The comment at 503-506 ('changing a limit cannot reset the window') does not hold. Actor: the Safe's timelocked proposal (it could also raise the limit openly, hence low). Smallest fix: refuse more than one SET_PATH for the same eid in a BATCH, and do not scale inFlight when the new limit is 0 (a closed path keeps its in-flight amount).

**Reproduction**

Self-contained: forge test --match-path test/scratch/Mock.t.sol -vv -> [PASS] test_batchLimitZeroThenBackResetsWindow, Logs: available right after the batch: 10000.0. Input: inbound 10,000e18 / 7 days; Safe proposes BATCH[SET_PATH(in 0), SET_PATH(in 10,000e18)]; after 48h a forged 10,000e18 fills the window (availableIn == 0); attacker calls applyPending(); availableIn == 10,000e18; a second forged 10,000e18 executes in the same block: 20,000e18 minted. Expected: availableIn stays 0. Actual: window reset.

### 9. Low: An honest message whose amount exceeds the (lowered) inbound limit is stranded indefinitely, not 'retry later': amount > limit never passes until a 48h raise

`src/bridge/ImdBridge.sol:356`

```
        if (amount > available) revert RateLimited(eid, amount, available);
```

_available never exceeds l.limit, so a message with amount > limit reverts in every block. The header (63-64) and P4 say an inbound message over the limit 'stays at the endpoint (retry later); nothing is lost'. The deploy mirrors limits so an honest send cannot exceed the destination limit at launch, but the two sides are set by two separate proposals on two chains and either side may be lowered while messages are in flight; the lowered side then holds those messages until governance raises it again (48h). Smallest fix: document that an inbound limit must never be set below the peer's outbound limit and that a lowering waits until the source path is paused and drained; or refuse in _check an inbound limit below the current one unless the path is paused.

**Reproduction**

Self-contained: forge test --match-path test/scratch/Mock.t.sol -> [PASS] test_loweredLimitStrandsOversizedMessage: inbound 10,000e18 then SET_PATH lowering it to 5,000e18; a 10,000e18 message fails RateLimited now and after 30 days. Expected (P4): waits and executes later. Actual: never executes until a raise.

### 10. Low: Re-pinning the library a path already uses passes _check but reverts at apply (EndpointV2 LZ_SameValue), failing the whole BATCH after 48h

`src/bridge/ImdBridge.sol:407`

```
            (, uint32 eid, address lib) = abi.decode(payload, (uint8, uint32, address));
```

EndpointV2.setSendLibrary and setReceiveLibrary revert LZ_SameValue when the new library equals the current one. _check does not compare with sendLibrary/receiveLibrary[eid], so a defensive or copied pin (the header's deprecation BATCH repeating the unchanged side) is accepted, waits 48h, then the whole BATCH reverts and must be re-proposed. The mock accepts a same-value pin. Smallest fix: in _check refuse a pin equal to the current (or batch-pinned) library, or skip the endpoint call in _apply when unchanged.

**Reproduction**

Mainnet fork against the real EndpointV2 0x1a44076050125825900e736c501f859c50fE728c and ReceiveUln302 0xc02Ab410f0734EFa3F14628780e6e695156024C2 (public RPC https://ethereum-rpc.publicnode.com, block ~26418627), ImdBridge deployed on the fork with the Safe as governor. SET_SEND_LIBRARY(30416, SendUln302 0xbB2Ea70C9E858123480642Cf96acbcCE1372dCe1) applied; Safe proposes the same item again; +48h; applyPending() reverts. Expected: no-op or refused at propose. Actual: revert at apply, proposal pending until cancel. Run: forge test --match-path test/scratch/Fork.t.sol --fork-url <mainnet RPC> -> [PASS] test_fork_rePinSameLibraryRevertsAtApply.

### 11. Low: IN_LIMIT into 4663 (50,000/day) exceeds the 4663 chain line (30,000): one day's forged mint is a bound on minting but not on what the 4663 book can lose (C5 refuted)

`script/DeployConfig.sol:834`

```
    uint256 internal constant IN_LIMIT = 50_000e18;
```

The inbound (mint) limit from mainnet into 4663 is 50,000e18 per day (and ~100,000 inside the first 24h given the limiter's refill) while the 4663 chain line is 30,000e18 and the outbound limit back to mainnet is 10,000e18 at once. A compromised DVN set mints 50,000 forged imdUSD on 4663 in the block it verifies (commitVerification and lzReceive are permissionless; pause-and-void sees nothing) and spends it the same day: Redeemer.redeem against the whole 4663 debt (<= 30,000 of collateral at face less the redemption fee), ImdBridge.send 10,000 back to mainnet (fits both mirrors, minted there as real imdUSD, redeemable against the Ethereum book), the rest into the 4663 peg pool and sleeve. The comment sizes IN_LIMIT 'so arrivals for repayment are not throttled', but repayments on 4663 cannot exceed the 30,000 line in total. Not an end-to-end spend test (arithmetic on the deploy constants and the redeem/send paths). Smallest fix: IN_LIMIT <= CHAIN_LINE (e.g. 10,000e18/day, mirroring OUT_LIMIT) or a per-message cap below the chain line. Merged from two specialist reports.

**Reproduction**

Deploy constants: CHAIN_LINE 30_000e18, IN_LIMIT 50_000e18, OUT_LIMIT 10_000e18, LIMIT_WINDOW 1 days. Forged inbound packets totalling 50,000e18 execute on 4663 within one window (availableIn == 50,000e18 at rest; the Mock.t.sol limiter tests show 2 x limit inside one window). Expected (C5): the daily forged mint is within what 4663 can lose. Actual: 50,000 > 30,000 line; 10,000 exports to mainnet the same day; the remainder dilutes 4663 holders.

### 12. Low: The operator watcher in the threat model cannot fire: the per-chain supply equation holds by construction after a forged mint because `received` counts it

`src/bridge/ImdBridge.sol:296`

```
    function netMinted() external view returns (int256) {
        return int256(received) - int256(sent);
    }
```

lzReceive adds every minted amount, forged or honest, to `received` before minting, so totalSupply == terms + received - sent holds on the receiving chain after any forged mint and netMinted() never 'disagrees with the supply equation'. The threat model relies on that disagreement to trigger the pause that P1's bound ('before the path is paused') depends on. Detection is only possible across chains (received here <= sent there + in flight, matched by guid), and a zero-amount forged packet (finding on line 354) moves neither. Smallest fix: state the cross-chain rule in the trust model and runbook; emit the source nonce in Received so the watcher matches by nonce.

**Reproduction**

Any forged mint: on the fork, after test_fork_setPathAloneLeavesPathOnDefault1of1 mints 9,000 to the attacker, bridge.received() == 9,000e18, tok.totalSupply() == 9,000e18, so totalSupply == received - sent holds exactly; nothing on this chain distinguishes it from an honest arrival. Expected (threat model): netMinted() disagrees with the equation. Actual: it agrees.

### 13. Info: lzReceive is payable and the bridge has no way to move native value: executor-supplied msg.value is stuck

`src/bridge/ImdBridge.sol:265`

```
    function lzReceive(Origin calldata origin, bytes32 guid, bytes calldata message, address, bytes calldata)
        external
        payable
```

A sender's extraOptions may carry an lzReceive native drop; EndpointV2 forwards it to lzReceive. ImdBridge keeps it with no sweep, and send requires msg.value == fee.nativeFee so it is never reused. Dust only.

**Reproduction**

Executor calls EndpointV2.lzReceive{value: v}(...); ImdBridge's balance grows by v with no function to withdraw it (no receive/fallback/sweep in the source).

### 14. Info: MIN_CONFIRMATIONS_FROM_OTHER = 20 is a few seconds of one sequencer's soft confirmations on 4663; the 'reorgs within the confirmation floors' defence covers only that

`src/bridge/ImdBridge.sol:114`

```
    uint64 public constant MIN_CONFIRMATIONS_FROM_OTHER = 20;
```

The floor is a block count compared in _checkUln with no notion of time or L1 inclusion. By the header's own figure (5 blocks ~1-2 s, line 112) 20 confirmations are ~4-8 s of unposted single-sequencer state on 4663 (a specialist measured ~0.11 s blocks on 4663, i.e. ~2.2 s; not re-measured here, no 4663 RPC). Any sequencer reorg or equivocation deeper than that after the DVNs sign leaves a mint on Ethereum whose burn on 4663 no longer exists (P1: minted > burned), bounded by Ethereum's inbound limit. It is LayerZero's default for Arbitrum-family sources, so a design note rather than a defect: size the floor in time (or to the batch-posting interval) and state the reorg depth covered.

**Reproduction**

UlnConfig(confirmations = 20, 3, 0, 0, dvns, []) for a receive library on Ethereum from eid 30416 passes _checkUln (the launch BATCH uses it). A 4663 reorg deeper than 20 blocks after verification leaves `received` on Ethereum above `sent` on 4663 by the message amount (up to availableIn(30416)). Not reproduced on chain.

---

Judge's submission `c582e67279db4d0c23d25176de3b5ffd038bbd0017d5dcb50d3a648ed9f2ba02`, 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.
