Status DataClose notification

Overlayer Disclosed Report

Audit Report

Integer Underflow in _credit() Permanently Locks Bridged Funds on Spoke Chains

Target

Target is hidden

This information is not publicly available.

Vulnerability details

Description

The _credit function in OverlayerWrapCore (line 543) performs totalBridgedOut -= amountReceivedLD without checking whether totalBridgedOut >= amountReceivedLD. On spoke chains, totalBridgedOut is initialized to 0. When the hub chain sends tokens to a spoke chain via LayerZero OFT, the spoke's _credit function is called to mint tokens on the destination. The subtraction 0 - amountReceivedLD causes an arithmetic underflow in Solidity 0.8.20, reverting the entire bridge receive transaction.

This means spoke chains can NEVER receive the initial bridged tokens from the hub chain. Users who hold OverlayerWrap on the hub chain cannot bridge to any spoke chain. The only way spoke chains could work is if a user first bridges FROM the spoke (incrementing totalBridgedOut), but that requires having tokens on the spoke, which is impossible without receiving them first. This creates a deadlock -- spoke chains are permanently unusable for OFT bridging.

Attack Path

  1. Protocol deploys OverlayerWrap on hub chain (e.g., Ethereum) and spoke chain (e.g., Arbitrum)
  2. Spoke chain totalBridgedOut = 0 (default)
  3. User on hub calls OFT.send() to bridge 1000e18 OverlayerWrap to Arbitrum
  4. Hub chain: _debit burns 1000e18 from user, totalBridgedOut += 1000e18 (hub's totalBridgedOut = 1000e18)
  5. LayerZero delivers message to Arbitrum
  6. Arbitrum: _credit called with amountReceivedLD = 1000e18
  7. totalBridgedOut -= 1000e18 => 0 - 1000e18 => REVERT: arithmetic underflow
  8. Bridge message fails. User's tokens were burned on hub but never minted on spoke
  9. LayerZero message retry will also fail -- same underflow every time
  10. User's funds are permanently lost (burned on hub, unmintable on spoke)

Impact

  • All hub-to-spoke bridging is permanently broken
  • Users who attempt to bridge lose their tokens permanently (burned on hub, never minted on spoke)
  • The entire cross-chain OFT functionality is non-operational
  • Affects 100% of bridged value

Proof of Concept

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;

import "forge-std/Test.sol";

contract CreditUnderflowTest is Test {
    uint256 public totalBridgedOut;

    function test_creditUnderflowOnSpokeChain() public {
        // Spoke chain state: totalBridgedOut = 0 (never debited)
        assertEq(totalBridgedOut, 0);

        // Simulate _credit being called when hub sends tokens to spoke
        uint256 amountReceivedLD = 1000e18;

        // This will revert with arithmetic underflow in Solidity 0.8.20
        vm.expectRevert(); // arithmetic underflow
        totalBridgedOut -= amountReceivedLD;
    }

    function test_hubDebitWorksButSpokesCreditFails() public {
        // Hub chain: _debit works fine
        uint256 amountSentLD = 1000e18;
        totalBridgedOut += amountSentLD; // Hub: 0 + 1000e18 = 1000e18, OK

        // Reset to simulate spoke chain (separate deployment)
        uint256 spokeTotalBridgedOut = 0;

        // Spoke chain: _credit tries to decrement
        uint256 amountReceivedLD = 1000e18;

        // This underflows: 0 - 1000e18
        vm.expectRevert();
        spokeTotalBridgedOut -= amountReceivedLD;
    }
}

Recommended Mitigation

The _credit function should only track totalBridgedOut on the hub chain, or should check for underflow before subtracting.

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

Similarly, _debit should also be guarded:

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

Validation steps

Steps to Reproduce

  1. Deploy OverlayerWrap.sol on two chains (e.g., Ethereum as hub, Arbitrum as spoke) with the same contract code, setting hubChainId to Ethereum's chain ID on both deployments.

  2. On the hub chain (Ethereum):

    • Mint OverlayerWrap tokens by depositing USDC collateral
    • Call send() (LayerZero OFT) to bridge tokens to the spoke chain (Arbitrum)
    • Observe: _debit() executes successfully, burning tokens and incrementing totalBridgedOut
  3. On the spoke chain (Arbitrum):

    • LayerZero delivers the cross-chain message
    • _credit() is called internally by LayerZero's lzReceive()
    • super._credit() would mint tokens, but then totalBridgedOut -= amountReceivedLD executes
    • Since totalBridgedOut == 0 on the spoke (nothing was ever debited from this chain), Solidity 0.8.x checked arithmetic causes an underflow revert
    • The entire lzReceive transaction reverts
  4. Result:

    • Tokens are burned on hub chain (irreversible)
    • Tokens are never minted on spoke chain
    • LayerZero stores the failed message for retry, but retries will always fail (same underflow)
    • This is a deadlock: spoke needs totalBridgedOut > 0 to receive tokens, but can only get totalBridgedOut > 0 by first sending tokens out (which it doesn't have)

Root Cause

File: contracts/overlayer/OverlayerWrapCore.sol, lines 537-544

The _credit() override unconditionally decrements totalBridgedOut regardless of which chain the contract is deployed on. This accounting variable was designed only for the hub chain (to track tokens that left and returned), but the override applies to ALL deployments including spoke chains where totalBridgedOut is always 0.

Vulnerable Code

// OverlayerWrapCore.sol:537-544
function _credit(
    address to_,
    uint256 amountLD_,
    uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
    amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
    totalBridgedOut -= amountReceivedLD; // UNDERFLOW on spoke chains
}

Recommended Fix

Guard the totalBridgedOut tracking with a hub chain check:

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

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

---

Attachments

Attachments are hidden

This information is not publicly available.

Comments are hidden

This information is not publicly available.