Status DataClose notification

Overlayer Disclosed Report

Audit Report

Permanent Cross-Chain Asset Lock via totalBridgedOut Underflow on Non-Hub Chains

Target

Target is hidden

This information is not publicly available.

Vulnerability details

Summary

The Overlayer protocol implements a hub-and-spoke model using LayerZero's OFT standard. However, a critical arithmetic underflow in OverlayerWrapCore._credit() will cause all bridging transactions directed towards any non-hub chain to permanently revert. As a result, cross-chain OFT transfers to non-hub chains (like Optimism or Arbitrum) are completely broken from deployment, and any user assets transferred out of the hub chain are permanently locked (burned on the source, never minted on the destination).

What is the vulnerability?

The Overlayer protocol integrates LayerZero's OFT standard and overrides the internal _debit and _credit hooks to track the totalBridgedOut state variable. This variable tracks tokens that have left the hub chain to support AaveHandler yield accounting.

// OverlayerWrapCore.sol line 537
function _credit(
    address to_,
    uint256 amountLD_,
    uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
    amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
    totalBridgedOut -= amountReceivedLD; // <--- UNDERFLOW HERE
}

The bug is that the contract unconditionally subtracts from totalBridgedOut on every chain. On a non-hub chain (like the planned Optimism/Arbitrum deployments), totalBridgedOut starts at 0. Because mint() operations are restricted to the hub chain, tokens can only arrive on a remote chain via bridging. Therefore, the very first incoming bridge message attempts 0 -= amountReceivedLD, triggering a Solidity 0.8 Panic (0x11 Arithmetic underflow).

In clear steps, how do you reproduce it?

  1. The protocol is correctly deployed across a simulated Hub chain (e.g., Ethereum) and a Non-Hub chain (e.g., Optimism).
  2. On the Non-Hub chain, totalBridgedOut initializes at 0.
  3. A user on the Hub chain desires to move balances to Optimism and invokes LayerZero's send() function to bridge 10 tokens.
  4. On the Hub chain, _debit() executes, successfully burning 10 tokens from the user.
  5. The LayerZero relayer delivers the incoming payload to the Non-Hub chain, invoking OverlayerWrapCore._credit().
  6. Inside _credit(), the contract safely calculates amountReceivedLD but then attempts to execute totalBridgedOut -= amountReceivedLD (which equates to 0 - 10).
  7. The transaction fails with an Arithmetic Underflow revert. The LayerZero pathway permanently stores the payload as a failed transaction, and the user's funds remain permanently locked.

Validation steps

To logically validate this vulnerability quickly, you can run the provided Hardhat Proof of Concept (PoC) which accurately replicates the non-hub chain environment and isolates the failing _credit bridge loop.

Step 1: Setup the PoC File Navigate to the test/ directory of the contracts repository and create a new file named PoC.ts. Paste the following exact configuration into the file:

import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { ethers } from "hardhat";
import { expect } from "chai";
import { LZ_ENDPOINT_ETH_MAINNET_V2 } from "../scripts/addresses";

describe("OverlayerWrap PoC: Cross-chain brick on Non-Hub chains", function () {
  async function deployNonHubFixture() {
    const [admin, alice] = await ethers.getSigners();
    const block = await admin.provider.getBlock("latest");
    const defaultTransactionOptions = { maxFeePerGas: (block?.baseFeePerGas ?? 1n) * BigInt(10) };

    const Collateral = await ethers.getContractFactory("SixDecimalsUsd");
    const collateral = await Collateral.deploy(1000, "COLLATERAL", "COLLATERAL", defaultTransactionOptions);
    const aCollateral = await Collateral.deploy(1000, "aCOLLATERAL", "aCOLLATERAL", defaultTransactionOptions);

    // Deploy OverlayerWrap simulating a NON-HUB chain.
    // By setting hubChainId to 1 (Mainnet), we simulate this is a non-hub deployment locally.
    const hubChainId = 1;

    const OverlayerWrap = await ethers.getContractFactory("OverlayerWrapMock");
    const overlayerWrap = await OverlayerWrap.deploy(
      {
        admin: await admin.getAddress(),
        lzEndpoint: LZ_ENDPOINT_ETH_MAINNET_V2,
        name: "O",
        symbol: "O+",
        collateral: { addr: await collateral.getAddress(), decimals: 6 },
        aCollateral: { addr: await aCollateral.getAddress(), decimals: 6 },
        maxMintPerBlock: ethers.parseEther("100"),
        maxRedeemPerBlock: ethers.parseEther("100"),
        minValmaxRedeemPerBlock: ethers.parseEther("1"),
        hubChainId: hubChainId
      },
      defaultTransactionOptions
    );
    await overlayerWrap.waitForDeployment();

    return { overlayerWrap, alice };
  }

  it("Should underflow and revert on the first incoming cross-chain payload (_credit) on a non-hub chain", async function () {
    const { overlayerWrap, alice } = await loadFixture(deployNonHubFixture);

    // Verify we are on a non-hub chain environment (totalBridgedOut = 0)
    const network = await ethers.provider.getNetwork();
    expect(await overlayerWrap.hubChainId()).to.not.equal(network.chainId);
    expect(await overlayerWrap.totalBridgedOut()).to.equal(0);

    // Incoming OFT transfer scenario simulating receiving 10 tokens
    const incomingAmount = ethers.parseEther("10");

    // The underflow permanently causes Panic code 0x11 (Arithmetic over/underflow)
    await expect(
        overlayerWrap.testCredit(alice.address, incomingAmount, 0)
    ).to.be.revertedWithPanic(0x11);
  });
});

Step 2: Run the Validation Script Execute the hardhat test against the newly built file: npx hardhat test test/PoC.ts

Step 3: Analyze the Output The testing suite will successfully pass the test criteria revertedWithPanic(0x11). This confirms that because the state is attempting to subtract a balance on a remote network chain from 0 on the very first incoming payload, it triggers an arithmetic over/underflow protection native to solidity ^0.8.0, proving cross-chain is totally bricked and the funds are inaccessible.


Recommended Mitigation

Update _debit and _credit to specifically restrict tracking totalBridgedOut exclusively to the hub chain. Non-hub chains do not need to track this variable as there is no AaveHandler backing contract deployed there tracking yield calculations.

// OverlayerWrapCore.sol
    function _debit(
        address from_, uint256 amountLD_, uint256 minAmountLD_, uint32 dstEid_
    ) internal virtual override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
        (amountSentLD, amountReceivedLD) = super._debit(from_, amountLD_, minAmountLD_, dstEid_);
-       totalBridgedOut += amountSentLD;
+       if (block.chainid == hubChainId) {
+           totalBridgedOut += amountSentLD;
+       }
    }

    function _credit(
        address to_, uint256 amountLD_, uint32 srcEid_
    ) internal virtual override returns (uint256 amountReceivedLD) {
        amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
-       totalBridgedOut -= amountReceivedLD;
+       if (block.chainid == hubChainId) {
+           totalBridgedOut -= amountReceivedLD;
+       }
    }

Attachments

Attachments are hidden

This information is not publicly available.

Comments are hidden

This information is not publicly available.