Status DataClose notification

Overlayer Disclosed Report

Audit Report

non-hub _credit() can underflow totalBridgedOut and corrupt downstream backing normalization

Target

Target is hidden

This information is not publicly available.

Vulnerability details

OverlayerWrapCore increments totalBridgedOut on _debit() but decrements it on every _credit() with no hub-only guard and no floor check. On a non-hub chain, a fresh inbound OFT credit can execute before any local debit exists, so _credit() subtracts from zero and reverts. Even when it does not revert immediately, leftover unmatched totalBridgedOut state can poison later supply normalization logic that depends on totalSupply() + totalBridgedOut().

Reproduction in clear steps:

  1. Deploy a non-hub OverlayerWrap instance where totalBridgedOut == 0.
  2. Trigger an inbound OFT credit path before any local _debit() has occurred.
  3. _credit() calls super._credit(...) and then executes totalBridgedOut -= amountReceivedLD.
  4. Because the local counter is still zero, the subtraction underflows and the receive path reverts.
  5. In a partial round-trip case, the counter can remain nonzero after a return credit.
  6. That leftover state contaminates accounting that treats totalSupply() + totalBridgedOut() as the effective liability base.

Exact vulnerable code:

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;
}

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

Validation steps

  1. Start from a non-hub deployment where totalBridgedOut is zero.
  2. Trigger an inbound _credit() path before any local _debit() has created an outbound liability.
  3. Verify that _credit() tries to subtract the credited amount from zero and reverts.
  4. Additional passing checks also prove that partial return credits leave unmatched residual bridge liability and that extra unmatched credits re-open the failure mode.

Passing result:

F-001 PoC
  ✔ reverts on a fresh non-hub credit-first path
  ✔ keeps only the unmatched amount bridged out after a partial return credit
  ✔ reverts on an extra unmatched credit after a balanced debit-credit round trip

3 passing

Exact passing PoC test code:

const HARDHAT_CHAIN_ID = 31337;

async function deployFixture(hubChainId: number) {
    const [admin, alice] = await ethers.getSigners();

    const block = await admin.provider.getBlock("latest");
    const baseFee = block?.baseFeePerGas ?? 1n;
    const defaultTransactionOptions = {
        maxFeePerGas: baseFee * 10n
    };

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

    const Endpoint = await ethers.getContractFactory("MockLayerZeroEndpointV2");
    const endpoint = await Endpoint.deploy();

    const OverlayerWrap = await ethers.getContractFactory("OverlayerWrapMock");
    const overlayerWrap = await OverlayerWrap.deploy(
        {
            admin: await admin.getAddress(),
            lzEndpoint: await endpoint.getAddress(),
            name: "O",
            symbol: "O+",
            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
        },
        defaultTransactionOptions
    );

    await collateral.connect(admin).transfer(alice.address, ethers.parseUnits("100", await collateral.decimals()));
    await collateral.connect(alice).approve(await overlayerWrap.getAddress(), ethers.MaxUint256);

    return { alice, collateral, overlayerWrap };
}

async function deployNonHubFixture() {
    return deployFixture(HARDHAT_CHAIN_ID + 1);
}

it("reverts on a fresh non-hub credit-first path", async function () {
    const { overlayerWrap, alice } = await loadFixture(deployNonHubFixture);

    const inboundAmount = ethers.parseEther("1");

    await expect(
        overlayerWrap.testCredit(alice.address, inboundAmount, 0)
    ).to.be.revertedWithPanic(0x11);

    expect(await overlayerWrap.totalBridgedOut()).to.equal(0);
    expect(await overlayerWrap.balanceOf(alice.address)).to.equal(0);
});

Attachments

Attachments are hidden

This information is not publicly available.

Comments are hidden

This information is not publicly available.