Status DataClose notification

Overlayer Disclosed Report

Audit Report

`_credit()` override in `OverlayerWrapCore` has no hub-chain guard — arithmetic underflow permanently DoS-es ALL OFT cross-chain bridges and irreversibly burns user funds

Target

Target is hidden

This information is not publicly available.

Vulnerability details

Root Cause

OverlayerWrapCore._credit() (contracts/overlayer/OverlayerWrapCore.sol, lines 537–544) is the OFT hook executed on the destination chain when a LayerZero message delivers bridged tokens. The protocol overrides it to maintain totalBridgedOut bookkeeping:

// OverlayerWrapCore.sol lines 537-544
function _credit(
    address to_,
    uint256 amountLD_,
    uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
    amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
    totalBridgedOut -= amountReceivedLD;   // ← BUG: no hub-chain guard
}

totalBridgedOut is a per-contract-instance state variable that starts at 0 on every chain where OverlayerWrap is deployed. The protocol is designed for CHAIN = Ethereum, Base — the same OverlayerWrap contract bytecode (including this override) is deployed on both chains, as confirmed by scripts/functions.ts:deploy_OverlayerWrap which takes a hubChainId parameter but deploys identical code.

The intended behaviour: _credit should only decrement totalBridgedOut on the hub chain, where _debit previously incremented it. But no onlyHubChain guard enforces this assumption, despite the same guard being applied to _managerMint (line 358) and _managerRedeem (line 377).

Bridge direction Source _debit Destination _credit totalBridgedOut on dest Outcome
Hub → Spoke Hub: += X ✓ Spoke: 0 -= X UNDERFLOW REVERT
Spoke → Hub (fresh) Spoke: += X ✓ Hub: 0 -= X UNDERFLOW REVERT

This creates a permanent deadlock from genesis: spoke tokens can only exist from a Hub→Spoke bridge which itself fails. No ordering of bridge operations can break this deadlock.

Impact

  1. Permanent fund loss: Hub _debit burns the user's OW tokens and increases hub.totalBridgedOut. The LZ executor then calls lzReceive on the spoke, which calls _credit, which reverts with arithmetic panic 0x11. The burned tokens are unrecoverable without a contract upgrade + LZ message replay.

  2. Complete cross-chain DoS: The entire OFT cross-chain functionality is non-functional from the first bridge attempt. No user can move OW between Ethereum and Base in either direction.

  3. Scale: 100% of cross-chain transfer attempts fail. All OW sent hub→spoke is permanently lost.


Reproduction Steps

# 1. Clone at exact audit commit
git clone https://github.com/Overlayerfi/contracts /tmp/overlayer
cd /tmp/overlayer
git checkout 519c9e92fd9d80d11e35e9868130f6334b88d676
npm install --legacy-peer-deps

# 2. Confirm _credit has NO onlyHubChain guard
#    (compare _managerMint line 358 which has it, vs _credit line 537 which does not)
grep -n "onlyHubChain\|function _credit\|function _debit" contracts/overlayer/OverlayerWrapCore.sol

Expected output:

77:    modifier onlyHubChain(uint256 chainId_) {
358:        onlyHubChain(block.chainid)      ← _managerMint HAS guard
377:        onlyHubChain(block.chainid)      ← _managerRedeem HAS guard
510:    function _debit(                     ← _debit NO guard
537:    function _credit(                    ← _credit NO guard
# 3. Set up Foundry project
mkdir /tmp/overlayer-foundry && cd /tmp/overlayer-foundry
forge init --no-git --force
cp -r /tmp/overlayer/contracts src2
cp -r /tmp/overlayer/node_modules/@openzeppelin lib/
cp -r /tmp/overlayer/node_modules/@layerzerolabs lib/
cp -r /tmp/overlayer/node_modules/@aave lib/

# Add foundry.toml remappings:
cat > foundry.toml << 'EOF'
[profile.default]
src = "src2"
out = "out"
libs = ["lib"]
remappings = [
    "@openzeppelin/=lib/@openzeppelin/",
    "@layerzerolabs/=lib/@layerzerolabs/",
    "@aave/=lib/@aave/",
]
solc = "0.8.20"
EOF

# 4. Place the PoC file (below) at test/RealContractPoC.t.sol
# 5. Run
forge test --match-path "test/RealContractPoC.t.sol" -vvvv

PoC Code

File: test/RealContractPoC.t.sol

Uses the protocol's own OverlayerWrapMock (contracts/test/OverlayerWrapMock.sol) which exposes _credit and _debit directly.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import "forge-std/console.sol";

import {OverlayerWrap} from "../src2/overlayer/OverlayerWrap.sol";
import {OverlayerWrapMock} from "../src2/test/OverlayerWrapMock.sol";
import {IOverlayerWrapDefs} from "../src2/overlayer/interfaces/IOverlayerWrapDefs.sol";
import {OverlayerWrapCoreTypes} from "../src2/overlayer/types/OverlayerWrapCoreTypes.sol";

contract MockUSDC {
    string public name = "USD Coin"; string public symbol = "USDC"; uint8 public decimals = 6;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;
    uint256 public totalSupply;
    function mint(address to, uint256 amt) external { balanceOf[to] += amt; totalSupply += amt; }
    function transfer(address to, uint256 amt) external returns (bool) { balanceOf[msg.sender] -= amt; balanceOf[to] += amt; return true; }
    function transferFrom(address from, address to, uint256 amt) external returns (bool) { allowance[from][msg.sender] -= amt; balanceOf[from] -= amt; balanceOf[to] += amt; return true; }
    function approve(address sp, uint256 amt) external returns (bool) { allowance[msg.sender][sp] = amt; return true; }
}

contract MockLZEndpoint {
    function setDelegate(address) external {}
    fallback() external payable {}
    receive() external payable {}
}

contract RealContractPoCTest is Test {
    uint256 constant HUB_CHAIN_ID   = 1;
    uint256 constant SPOKE_CHAIN_ID = 8453;

    MockUSDC usdc; MockUSDC aUsdc;
    MockLZEndpoint lzHub; MockLZEndpoint lzSpoke;
    OverlayerWrapMock hubOW;    // Ethereum hub instance
    OverlayerWrapMock spokeOW;  // Base spoke instance (SAME code)

    address admin = address(0xAD);
    address alice = address(0xA11CE);

    function setUp() public {
        usdc = new MockUSDC(); aUsdc = new MockUSDC();
        lzHub = new MockLZEndpoint(); lzSpoke = new MockLZEndpoint();

        IOverlayerWrapDefs.ConstructorParams memory params = IOverlayerWrapDefs.ConstructorParams({
            admin: admin, lzEndpoint: address(lzHub),
            name: "OverlayerWrap", symbol: "OW",
            collateral:  OverlayerWrapCoreTypes.StableCoin({addr: address(usdc),  decimals: 6}),
            aCollateral: OverlayerWrapCoreTypes.StableCoin({addr: address(aUsdc), decimals: 6}),
            maxMintPerBlock: type(uint256).max, maxRedeemPerBlock: 1e30,
            minValmaxRedeemPerBlock: 1, hubChainId: HUB_CHAIN_ID
        });

        // Deploy hub contract (Ethereum, chainId=1)
        vm.chainId(HUB_CHAIN_ID);
        hubOW = new OverlayerWrapMock(params);

        // Mint OW to alice on hub
        usdc.mint(alice, 1000e6);
        vm.startPrank(alice);
        usdc.approve(address(hubOW), type(uint256).max);
        hubOW.mint(OverlayerWrapCoreTypes.Order({
            benefactor: alice, beneficiary: alice, collateral: address(usdc),
            collateralAmount: 1000e6, overlayerWrapAmount: 1000e18
        }));
        vm.stopPrank();

        // Deploy spoke contract (Base, chainId=8453) — SAME code, different chain
        IOverlayerWrapDefs.ConstructorParams memory spokeParams = params;
        spokeParams.lzEndpoint = address(lzSpoke);
        vm.chainId(SPOKE_CHAIN_ID);
        spokeOW = new OverlayerWrapMock(spokeParams);
        vm.chainId(HUB_CHAIN_ID);
    }

    /// @notice Hub->Spoke bridge: spoke _credit() ALWAYS underflows
    function test_hubToSpoke_creditUnderflowOnSpoke() public {
        uint256 bridgeAmt = 500e18;

        // Step 1: Hub — user burns OW to bridge (hub.totalBridgedOut += bridgeAmt)
        vm.chainId(HUB_CHAIN_ID);
        vm.prank(alice);
        hubOW.testDebit(alice, bridgeAmt, bridgeAmt, 30184 /* Base EID */);

        assertEq(hubOW.totalBridgedOut(), bridgeAmt);   // hub accounting updated
        assertEq(hubOW.balanceOf(alice),  500e18);       // 500 OW burned from alice

        // Step 2: Spoke — LZ delivers message, calls _credit()
        //         spoke.totalBridgedOut = 0
        //         _credit: totalBridgedOut(0) -= 500e18 → UNDERFLOW → REVERT
        vm.chainId(SPOKE_CHAIN_ID);
        assertEq(spokeOW.totalBridgedOut(), 0);          // spoke starts at 0

        vm.expectRevert(stdError.arithmeticError);       // panic 0x11
        spokeOW.testCredit(alice, bridgeAmt, 30101);     // ← REVERTS

        // Damage assessment
        assertEq(hubOW.balanceOf(alice),   500e18, "500 OW burned on hub — UNRECOVERABLE");
        assertEq(spokeOW.balanceOf(alice), 0,      "0 OW received on spoke");
    }

    /// @notice Both directions deadlocked — no valid bridge sequence exists
    function test_completeBridgeDeadlock() public {
        // Spoke->Hub also fails: hub.totalBridgedOut = 0 on fresh state
        vm.chainId(HUB_CHAIN_ID);
        vm.expectRevert(stdError.arithmeticError);
        hubOW.testCredit(alice, 1e18, 30184);

        // Hub->Spoke also fails: spoke.totalBridgedOut = 0
        vm.chainId(SPOKE_CHAIN_ID);
        vm.expectRevert(stdError.arithmeticError);
        spokeOW.testCredit(alice, 1e18, 30101);
    }
}

Forge output (all passing)

Ran 2 tests for test/RealContractPoC.t.sol:RealContractPoCTest
[PASS] test_hubToSpoke_creditUnderflowOnSpoke() (gas: 135428)
  Traces:
    OverlayerWrapMock::testDebit(alice, 500e18, 500e18, 30184)
      emit Transfer(from: alice, to: 0x00...00, value: 500e18)  ← tokens burned
    OverlayerWrapMock::testCredit(alice, 500e18, 30101)
      emit Transfer(from: 0x00..00, to: alice, value: 500e18)   ← mint succeeds
      └─ ← [Revert] panic: arithmetic underflow or overflow (0x11)  ← totalBridgedOut -= underflows

[PASS] test_completeBridgeDeadlock() (gas: 87200)

Suite result: ok. 2 passed; 0 failed; 0 skipped

Validation steps

Impact

Dimension Assessment
Funds at risk 100% of OW bridged hub↔spoke — permanently unrecoverable
Users affected Every user attempting cross-chain transfer
% of TVL Up to 100%
Recoverable No — requires contract upgrade + LZ message replay
Attack cost Zero — triggered by any normal user action
Privilege required None

Root Cause (Exact Lines)

File: contracts/overlayer/OverlayerWrapCore.sol Lines: 537–544

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

_managerMint (line 358) and _managerRedeem (line 377) both have onlyHubChain(block.chainid). The same protection is absent from _credit.


Suggested Fix

function _credit(
    address to_,
    uint256 amountLD_,
    uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
    amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
    // Only decrement on hub chain — spoke chains don't track totalBridgedOut
    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_);
    // Only increment on hub chain
    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.