Status DataClose notification

Overlayer Disclosed Report

Audit Report

Missing Hub-Chain Guard in `OverlayerWrapCore._credit()` Causes Permanent Loss of Funds on Every Hub-to-Non-Hub Bridge Transfer

Target

Target is hidden

This information is not publicly available.

Vulnerability details

Target Files

OverlayerWrapCore


OverlayerWrapCore extends LayerZero's OFT and overrides both _debit() and _credit() to maintain totalBridgedOut, a cumulative counter of tokens that have left the hub chain so that AaveHandler.supply() can compute the correct collateral-to-supply ratio.

The developer's stated intent (NatSpec comment at L530–532) is explicit:

"Tracks tokens returning to the hub chain from cross-chain transfers"

The _debit() override correctly guards itself via the onlyHubChain modifier pattern used in the contract. The _credit() override does not:

// OverlayerWrapCore.sol L537–L544
function _credit(
    address to_,
    uint256 amountLD_,
    uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
    amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
    totalBridgedOut -= amountReceivedLD;  // ← no hub-chain guard; runs on ALL chains
}

_credit() is invoked by the LayerZero endpoint on the destination chain whenever a cross-chain message arrives. The same OverlayerWrap contract (inheriting OverlayerWrapCore) is deployed on every chain — hub and non-hub alike. On non-hub chains, totalBridgedOut is always 0 because:

  • totalBridgedOut has no external setter: it can only change via _debit() (increment) or _credit() (decrement).
  • _debit() only triggers on the source chain when tokens are sent out: a non-hub chain has never been the source of a hub → non-hub transfer.
  • _managerMint() is guarded by onlyHubChain, so OVA can only originate on the hub chain: non-hub chains can never independently increment totalBridgedOut.

Attack / Trigger Path

A regular user calls OverlayerWrap.send() on the hub chain to bridge OVA to a non-hub chain (e.g. Arbitrum, Base):

  1. Hub — _debit() runs: tokens burned from user, totalBridgedOut += amountSentLD. LayerZero message dispatched.
  2. Non-hub — LZ endpoint delivers message and calls _credit():
    • super._credit() attempts to mint tokens to to_.
    • totalBridgedOut -= amountReceivedLD → 0 - amountReceivedLD → Solidity 0.8 arithmetic underflow
  3. The entire lzReceive transaction is rolled back on non-hub. No tokens are minted.
  4. The LZ message is permanently stuck in failed state; every retry also reverts because totalBridgedOut remains 0 on non-hub forever.
  5. Hub-side burn is irreversible. User's funds lost.

State after hub→non-hub bridge of N OVA

Variable Hub Chain Non-Hub Chain
User OVA balance −N (burned) 0 (never minted)
totalBridgedOut +N (stale, overstated) 0 (unchanged, always)
LZ message status Delivered Permanently failed
Recovery path None None

The totalBridgedOut overstatement on hub also inflates the reported effective supply (totalSupply + totalBridgedOut) used by AaveHandler.supply(), meaning the collateral-backing ratio is calculated against a supply that doesn't exist in practice — a secondary accounting corruption that persists for the lifetime of the contract.

Recommended Fix

Add the same hub-chain guard that protects the corresponding accounting logic throughout the contract. The hubChainId state variable and onlyHubChain modifier already exist — _credit() simply needs to use them:

// OverlayerWrapCore.sol L537–L544
// Only decrement totalBridgedOut when tokens return to the hub chain
function _credit(
    address to_,
    uint256 amountLD_,
    uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
    amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
    if (block.chainid == hubChainId) {
        totalBridgedOut -= amountReceivedLD;
    }
}

This mirrors the developer's stated intent ("tokens returning to the hub chain") and is consistent with how _debit() is documented — only the hub-chain side of the accounting is relevant to the collateral-backing calculations.

Validation steps

Environment: Hardhat local node — no mainnet fork required

Step 1 — Deploy a non-hub instance Deploy OverlayerWrapMock with hubChainId = 1 while the test runs on Hardhat (chainId 31337). Confirm totalBridgedOut = 0 — the permanent initial state on any non-hub chain.

Step 2 — Simulate LZ delivering a hub→non-hub message Call testCredit(alice, 500e18, 0) — the exact execution path that lzReceive() takes on the destination chain when a hub user bridges 500 OVA.

Step 3 — Verify permanent revert

Assertion Result
testCredit() reverts with panic 0x11 (arithmetic underflow) ✅ 0 - 500e18 underflows
alice.balanceOf(nonHubMock) == 0 ✅ Minting rolled back by revert
totalBridgedOut == 0 ✅ State unchanged

Step 4 — Confirm retry is futile Call testCredit() a second time (simulating LZ retry). Same revert. totalBridgedOut has no path to become positive — every future retry permanently fails and the hub-side burn is irreversible.

The PoC test can be pasted in test/OverlayerWrap.ts under describe() Cross-Chain Bridge Accounting":

    it("_credit() on non-hub chain underflows totalBridgedOut causing permanent fund loss", async function () {
      const { collateral, acollateral, admin, alice } =
        await loadFixture(deployFixture);

      // ── Deploy OverlayerWrapMock as a NON-HUB chain instance ─────────────
      // hubChainId = 1 (ETH mainnet), but this test runs on hardhat (31337).
      // This simulates the same OverlayerWrap contract deployed on Arbitrum,
      // Base, or any chain that is NOT the hub.
      const NON_HUB_CHAIN_ID = 1; // ETH mainnet id; hardhat runs at 31337
      const OverlayerWrapMock =
        await ethers.getContractFactory("OverlayerWrapMock");
      const nonHubMock = await OverlayerWrapMock.deploy({
        admin: admin.address,
        lzEndpoint: LZ_ENDPOINT_ETH_MAINNET_V2,
        name: "OVA",
        symbol: "OVA",
        collateral: {
          addr: await collateral.getAddress(),
          decimals: await collateral.decimals()
        },
        aCollateral: {
          addr: await acollateral.getAddress(),
          decimals: await acollateral.decimals()
        },
        maxMintPerBlock: ethers.MaxUint256,
        maxRedeemPerBlock: ethers.MaxUint256,
        minValmaxRedeemPerBlock: 1n,
        hubChainId: NON_HUB_CHAIN_ID // ← block.chainid (31337) != hubChainId (1): NON-HUB
      });
      await nonHubMock.waitForDeployment();

      // ── Verify initial non-hub state ─────────────────────────────────────
      // totalBridgedOut is always 0 on non-hub chains:
      //   - _managerMint() is onlyHubChain so no OVA can ever originate here
      //   - _debit() has never been called for a hub → non-hub send (which is
      //     exactly what we are about to fail to receive)
      expect(await nonHubMock.totalBridgedOut()).to.equal(
        0n,
        "Non-hub totalBridgedOut must be 0"
      );

      // ── Simulate LayerZero delivering hub → non-hub bridge message ─────────
      // When a user on hub calls send(500 OVA → non-hub), the LZ endpoint on
      // non-hub calls lzReceive() → _lzReceive() → _credit().
      // We call testCredit() directly to reproduce that execution path.
      //
      // Inside _credit():
      //   amountReceivedLD = super._credit(to_, 500e18, srcEid_)   // mints
      //   totalBridgedOut -= amountReceivedLD                       // 0 - 500e18
      //                                                             // → REVERT (underflow)
      const bridgedAmount = ethers.parseEther("500");

      await expect(
        nonHubMock.testCredit(alice.address, bridgedAmount, 0)
      ).to.be.revertedWithPanic(
        0x11 // arithmetic underflow/overflow (Solidity 0.8+)
      );

      // ── Confirm the minting was rolled back ──────────────────────────────
      // The revert undoes super._credit() — alice receives 0 OVA on non-hub.
      expect(await nonHubMock.balanceOf(alice.address)).to.equal(
        0n,
        "Alice must have received no tokens — minting rolled back by revert"
      );

      // ── Confirm totalBridgedOut unchanged ────────────────────────────────
      expect(await nonHubMock.totalBridgedOut()).to.equal(
        0n,
        "totalBridgedOut must remain 0 — state unchanged after revert"
      );

      // ── Confirm retry is futile ───────────────────────────────────────────
      // LZ will attempt to re-deliver the message, but since totalBridgedOut
      // is permanently 0 on non-hub (no mechanism exists to seed it), every
      // retry also reverts. The hub-side burn is irreversible → funds lost.
      await expect(
        nonHubMock.testCredit(alice.address, bridgedAmount, 0)
      ).to.be.revertedWithPanic(0x11);
    });

Run PoC:

npm run unit -- --network hardhat --grep "PoC.*_credit"

✔ _credit() on non-hub chain underflows totalBridgedOut causing permanent fund loss


Attachments

Attachments are hidden

This information is not publicly available.

Comments are hidden

This information is not publicly available.