Status DataClose notification

Overlayer Disclosed Report

Audit Report

Cross-Chain totalBridgedOut Integer Underflow in OverlayerWrapCore._credit() Permanently Blocks Incoming Bridges and Causes Fund Los

Target

Target is hidden

This information is not publicly available.

Vulnerability details

An arithmetic underflow in OverlayerWrapCore._credit() (line 543) causes all incoming cross-chain transfers to revert on any chain where totalBridgedOut == 0.

Vulnerable code:

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

How it works

totalBridgedOut is a per-chain storage variable that defaults to 0. It's incremented in _debit() (line 527) when tokens bridge OUT from a chain. But _credit() runs on the DESTINATION chain when tokens arrive — and that chain may have never called _debit().

In Solidity ^0.8.20, 0 - amountReceivedLD triggers Panic(0x11). Since _debit() already burned tokens on the source chain before the cross-chain message, the user loses funds: burned on source, never minted on destination.

Note on developer intent: The NatDoc comments describe _credit() as "tracking tokens returning to the hub chain," but LayerZero's OFT architecture calls _credit() on ANY destination chain, not just the hub. This architectural misunderstanding is the root cause.

Root cause breakdown

  • totalBridgedOut is local to each chain's contract deployment
  • _debit() increments it on the source chain, _credit() decrements it on the destination chain
  • These are independent contracts with separate storage
  • A chain that never sent tokens outbound has totalBridgedOut == 0
  • Every incoming _credit() reverts with underflow

Reproduction steps

Step 1: Deploy OverlayerWrap on a new spoke chain (e.g., Arbitrum). Result: totalBridgedOut == 0.

Step 2: On hub chain (Ethereum), user calls OFTCore.send() to bridge 100 OVA. Hub chain executes _debit() which burns user's 100 OVA and increments totalBridgedOut to 100e18. LayerZero message committed.

Step 3: LayerZero delivers message to spoke chain. Call flow: lzReceive() → _lzReceive() → _credit(alice, 100e18, hubEid). The super._credit() mints 100 OVA (succeeds), then totalBridgedOut -= 100e18 attempts 0 - 100e18 and panics with code 0x11. Entire transaction reverts, including the mint.

Step 4: User loses funds. 100 OVA burned on Ethereum (irreversible), 0 OVA minted on Arbitrum (reverted). LayerZero stores message as failed; retries hit same underflow. No escape hatch exists: no admin function sets totalBridgedOut, and _debit() can't be called without tokens that only arrive via _credit() — a circular dependency.

Proof of Concept

PoC files are attached:

  • forge-tests/CriticalCrossChainUnderflow.t.sol — unit tests
  • forge-tests/CriticalCrossChainFork.t.sol — mainnet fork tests

Run with any Ethereum RPC:

MAINNET_RPC=https://rpc.mevblocker.io forge test \
  --match-path "forge-tests/CriticalCrossChainFork.t.sol" -vvv

Verified passing:

[PASS] test_Fork_FreshDeploymentHasZeroTotalBridgedOut()
[PASS] test_Fork_RealLzReceive_RevertsWithUnderflow() -- Panic(0x11)
[PASS] test_Fork_FundLoss_1000OVA()
[PASS] test_Fork_RetryAlwaysFails() -- 3 retries, all revert
[PASS] test_Fork_LzReceive_SucceedsWhenTotalBridgedOutIsSufficient() -- negative test

The fork test uses the production endpoint at 0x1a44076050125825900e736c501f859c50fE728c, real USDC/aUSDC from mainnet, and delivers OFT messages through the actual lzReceive() path.

Recommended fix

Guard the decrement to only execute on the hub chain:

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

Add the same guard to _debit() for consistency — totalBridgedOut is only consumed by AaveHandler.supply() on the hub chain.

Validation steps

Step 1: Verify totalBridgedOut starts at 0

Check OverlayerWrapCore.sol line 63:

uint256 public totalBridgedOut;

The default value is 0. No constructor or initializer modifies it.

grep -rn "totalBridgedOut" contracts/

Results: only declaration (line 63), increment in _debit (line 527), decrement in _credit (line 543), and read in AaveHandler.sol (line 241). No setter exists.

Step 2: Confirm _credit runs on destination chain

Trace the call flow in LayerZero OFT:

LZ executor → endpoint calls oapp.lzReceive() on DESTINATION chain
 → _lzReceive() [OFTCore:277]
 → _credit(toAddress, amountLD, srcEid) on DESTINATION chain

_credit executes on whichever chain receives the message, not only the hub.

Step 3: Verify checked arithmetic

Read OverlayerWrapCore.sol lines 537-544. The subtraction totalBridgedOut -= amountReceivedLD is not wrapped in unchecked{}. With pragma solidity ^0.8.20, underflow produces Panic(0x11).

Step 4: Verify circular dependency

To make totalBridgedOut > 0 on a spoke chain:

  • _debit() must execute first (line 527)
  • _debit() calls _burn() which requires tokens
  • Tokens only arrive via _credit()
  • _credit() reverts because totalBridgedOut == 0

This is an unbreakable circular dependency.

Step 5: Run the Foundry PoC

Copy the attached PoC files into the repository:

  • forge-tests/CriticalCrossChainUnderflow.t.sol
  • forge-tests/CriticalCrossChainFork.t.sol

Run with any mainnet RPC:

MAINNET_RPC=https://rpc.mevblocker.io forge test \
  --match-path "forge-tests/CriticalCrossChainFork.t.sol" -vvv

Expected output:

[PASS] test_Fork_FreshDeploymentHasZeroTotalBridgedOut() -- totalBridgedOut == 0
[PASS] test_Fork_RealLzReceive_RevertsWithUnderflow() -- Panic(0x11) via real LZ endpoint
[PASS] test_Fork_FundLoss_1000OVA() -- 1000 OVA burned, 0 minted
[PASS] test_Fork_RetryAlwaysFails() -- 3 retries, all revert
[PASS] test_Fork_LzReceive_SucceedsWhenTotalBridgedOutIsSufficient() -- negative test

The fork test uses the production endpoint at 0x1a44076050125825900e736c501f859c50fE728c and delivers OFT messages through the actual lzReceive() path.

Step 6: Verify fund loss is permanent

After the spoke chain revert:

  • Source chain: tokens burned by _burn() in OFT._debit() — irreversible
  • Destination chain: lzReceive reverted — no tokens minted, no state change
  • LayerZero: stores failed message; retry hits same underflow
  • Contract: grep confirms no admin setter for totalBridgedOut
  • LZ clear(): OApp owner can skip blocked message, but tokens are NOT refunded

Result: permanent, irrecoverable loss of user funds.

Attachments

Attachments are hidden

This information is not publicly available.

Comments are hidden

This information is not publicly available.