Status DataClose notification

Overlayer Disclosed Report

Audit Report

Cross-Chain Bridge Permanent Fund Loss via totalBridgedOut Underflow

Target

Target is hidden

This information is not publicly available.

Vulnerability details

Brief / Intro

OverlayerWrapCore._credit() unconditionally decrements totalBridgedOut on every inbound LayerZero OFT transfer. On spoke chains (where totalBridgedOut starts at 0 and is never incremented), this triggers a Solidity 0.8.x underflow revert. Result: complete, permanent denial-of-service on all inbound cross-chain transfers to every spoke chain. No O+ tokens can ever arrive on non-hub chains. The hub-and-spoke OFT design is fully bricked, breaking the core totalSupply() + totalBridgedOut supply invariant used for collateral backing.

Vulnerability Details

Inheritance & OFT Flow
OverlayerWrapCore inherits from LayerZero OFT. Standard burn-and-mint:

  • Source: _debit() → burn
  • Destination: _credit() → mint

Compiler
pragma solidity ^0.8.20; → checked arithmetic, underflow = revert.

State Variable

uint256 public totalBridgedOut; // defaults to 0 on spokes
uint256 public hubChainId;

The contract is deployed identically everywhere via OverlayerWrapFactory, differentiated only by hubChainId_.

Hub Awareness Exists
onlyHubChain modifier and hub checks are used for mint()/redeem(), _initialize(), etc. — but not for _debit() or _credit().

Vulnerable Functions

_debit() (runs on every chain):

function _debit(...) internal virtual override {
    (amountSentLD, amountReceivedLD) = super._debit(...);
    totalBridgedOut += amountSentLD;  // safe on all chains
}

_credit() (the killer):

function _credit(...) internal virtual override {
    amountReceivedLD = super._credit(...);  // mint succeeds
    totalBridgedOut -= amountReceivedLD;    // ← underflow on spokes
}

NatDoc claims both functions are hub-only, but no guard or if (block.chainid == hubChainId) exists.

Permanent Deadlock on Spokes
No code path can ever increment totalBridgedOut on a spoke before the first _credit():

  • _credit() decrements → reverts
  • _debit() requires existing balance (impossible)
  • mint()/redeem() gated by onlyHubChain
  • No admin setter, no constructor init.

Exact Failure Flow

  1. Mint 1000 O+ on hub → totalSupply=1000e18, totalBridgedOut=0
  2. Bridge 500 to spoke → hub _debit() burns + totalBridgedOut += 500e18
  3. Spoke _credit(): _mint() succeeds → then 0 - 500e18 → underflow revert
    LayerZero message fails permanently. Tokens burned on hub, never arrive on spoke.

Root Cause Commit
Introduced in f55efce6 ("Handled bridged out token causing underflow..."). The AaveHandler accounting fix (totalSupply() + totalBridgedOut) is correct; the _credit override is not.

Tests Missed It
All cross-chain tests run on single Hardhat chain where hubChainId == block.chainid. No spoke fixture ever calls testCredit() in isolation.

Impact

  • Critical DoS: All inbound OFT transfers to spokes permanently fail.
  • Invariant Broken: totalSupply() + totalBridgedOut cannot hold on spokes.
  • Hub Accounting Inflated: Repeated failed bridges make hub totalBridgedOut grow indefinitely, risking under-collateralization in AaveHandler.
  • Stuck Messages: LayerZero V2 retries will always revert.
  • Scope: Every spoke chain deployment. Core cross-chain feature completely non-functional.

Severity: Critical (certain to trigger on normal user flow, protocol-breaking, no workaround without new deployment).

Validation steps

cat << 'FINAL_POC' > test/foundry/CreditUnderflowPoC.t.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import "../../contracts/overlayer/OverlayerWrap.sol";
import "../../contracts/overlayer/interfaces/IOverlayerWrapDefs.sol";
import "../../contracts/overlayer/types/OverlayerWrapCoreTypes.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MockLzEndpoint {
    function setDelegate(address) external {}
    function eid() external pure returns (uint32) {
        return 30101;
    }
}

contract MockStablecoin is ERC20 {
    uint8 private _dec;
    constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) {
        _dec = decimals_;
        _mint(msg.sender, 1_000_000 * 10 ** decimals_);
    }
    function decimals() public view override returns (uint8) {
        return _dec;
    }
}

contract OverlayerWrapHarness is OverlayerWrap {
    constructor(IOverlayerWrapDefs.ConstructorParams memory params_) OverlayerWrap(params_) {}

    function exposed_credit(address to_, uint256 amountLD_, uint32 srcEid_) external returns (uint256) {
        return _credit(to_, amountLD_, srcEid_);
    }

    function exposed_debit(address from_, uint256 amountLD_, uint256 minAmountLD_, uint32 dstEid_) external returns (uint256, uint256) {
        return _debit(from_, amountLD_, minAmountLD_, dstEid_);
    }
}

contract CreditUnderflowPoC is Test {
    address admin = address(0xA);
    address alice = address(0xB);

    MockLzEndpoint lzEndpoint;
    MockStablecoin usdt;
    MockStablecoin aUsdt;
    OverlayerWrapHarness hubWrap;
    OverlayerWrapHarness spokeWrap;

    uint256 constant HUB_CHAIN_ID = 31337;
    uint256 constant SPOKE_HUB_CHAIN_ID = 1;
    uint32 constant ETHEREUM_EID = 30101;
    uint32 constant ARBITRUM_EID = 30110;

    function setUp() public {
        vm.chainId(HUB_CHAIN_ID);

        lzEndpoint = new MockLzEndpoint();
        usdt = new MockStablecoin("USDT", "USDT", 6);
        aUsdt = new MockStablecoin("aUSDT", "aUSDT", 6);

        // Deploy HUB instance
        IOverlayerWrapDefs.ConstructorParams memory hubParams = IOverlayerWrapDefs.ConstructorParams({
            admin: admin,
            lzEndpoint: address(lzEndpoint),
            name: "O",
            symbol: "O+",
            collateral: OverlayerWrapCoreTypes.StableCoin({addr: address(usdt), decimals: 6}),
            aCollateral: OverlayerWrapCoreTypes.StableCoin({addr: address(aUsdt), decimals: 6}),
            maxMintPerBlock: type(uint256).max,
            maxRedeemPerBlock: type(uint256).max,
            minValmaxRedeemPerBlock: 1,
            hubChainId: HUB_CHAIN_ID
        });
        hubWrap = new OverlayerWrapHarness(hubParams);

        // Deploy SPOKE instance
        IOverlayerWrapDefs.ConstructorParams memory spokeParams = IOverlayerWrapDefs.ConstructorParams({
            admin: admin,
            lzEndpoint: address(lzEndpoint),
            name: "O",
            symbol: "O+",
            collateral: OverlayerWrapCoreTypes.StableCoin({addr: address(usdt), decimals: 6}),
            aCollateral: OverlayerWrapCoreTypes.StableCoin({addr: address(aUsdt), decimals: 6}),
            maxMintPerBlock: type(uint256).max,
            maxRedeemPerBlock: type(uint256).max,
            minValmaxRedeemPerBlock: 1,
            hubChainId: SPOKE_HUB_CHAIN_ID
        });
        spokeWrap = new OverlayerWrapHarness(spokeParams);

        usdt.transfer(alice, 10_000e6);
        vm.prank(alice);
        usdt.approve(address(hubWrap), type(uint256).max);
    }

    function test_credit_reverts_on_spoke_chain_underflow() public {
        assertEq(spokeWrap.totalBridgedOut(), 0);
        assertTrue(spokeWrap.hubChainId() != block.chainid);

        uint256 bridgeAmount = 500e18;
        vm.expectRevert(abi.encodeWithSignature("Panic(uint256)", 0x11));
        spokeWrap.exposed_credit(alice, bridgeAmount, ETHEREUM_EID);

        console.log("CRITICAL BUG CONFIRMED: _credit() underflows on spoke chain");
    }

    function test_e2e_bridge_hub_to_spoke_tokens_lost() public {
        // Mint on hub
        OverlayerWrapCoreTypes.Order memory order = OverlayerWrapCoreTypes.Order({
            benefactor: alice,
            beneficiary: alice,
            collateral: address(usdt),
            collateralAmount: 1000e6,
            overlayerWrapAmount: 1000e18
        });
        vm.prank(alice);
        hubWrap.mint(order);

        // Debit (bridge out) on hub
        hubWrap.exposed_debit(alice, 500e18, 500e18, ARBITRUM_EID);

        // Credit on spoke → should revert with underflow
        vm.expectRevert(abi.encodeWithSignature("Panic(uint256)", 0x11));
        spokeWrap.exposed_credit(alice, 500e18, ETHEREUM_EID);

        console.log("FULL ATTACK PATH CONFIRMED: Tokens burned on hub but never arrive on spoke");
    }
}
FINAL_POC

echo "✅ PoC test created "
forge test --match-contract CreditUnderflowPoC

Attachments

Attachments are hidden

This information is not publicly available.

Comments are hidden

This information is not publicly available.