Target is hidden
This information is not publicly available.
SUMMARY
OverlayerWrapCore.sol overrides LayerZero V2 OFT's _credit hook to maintain
a per-chain totalBridgedOut accumulator. The override (lines 537-544 of
the contest commit 519c9e92) decrements totalBridgedOut by the credited
amount on every cross-chain delivery, but does not initialise totalBridgedOut,
does not provide an admin setter, does not gate the override behind an
onlyHubChain modifier, and does not clamp the subtraction.
On any peer chain (any chain that is NOT the hub), totalBridgedOut starts
at 0 and stays at 0 until a successful _debit. But _debit can only be
reached after a successful _credit (peer chains have no native mint path —
_managerMint is gated by onlyHubChain). The very first _credit on a peer
chain therefore evaluates totalBridgedOut -= amountReceivedLD as
0 - amountReceivedLD, which panics with arithmetic underflow (panic 0x11)
under Solidity 0.8.20.
The result is that every cross-chain bridge transfer to a peer chain fails in the receive path. The user's tokens are already burned on the source chain by super._debit before the LayerZero message is dispatched, so the funds are unrecoverable. LayerZero will retry the message; every retry hits the same underflow.
The bug fires on the first cross-chain transaction to any peer, on any amount including 1 wei, with no preconditions. It is reproduced by seven passing Foundry tests, including three that inherit from the real @layerzerolabs/oft-evm OFT.sol base. Likelihood is high (no preconditions, no special resources). Impact is permanent lockout of 100% of any bridged amount, satisfying the contest's >1% of user's deposit threshold.
This is brand-new code. The buggy override was introduced into the
codebase one month ago by PR #70, which was implementing a fix for a
related but distinct underflow elsewhere in the same totalBridgedOut
accounting system. In the process of implementing that fix, PR #70 added
this new underflow at a different code site (the OFT _credit override).
The new underflow has never been acknowledged as faulty anywhere in the
repo and is unpatched in main and in every branch. See the next section
for the chronology, the diff evidence, and the precise distinction
between the two underflows.
ORIGIN OF THE VULNERABLE CODE
The buggy _credit override is brand-new code that has never been
identified as faulty. It was introduced into the codebase on 2026-03-05
by pull request #70 (https://github.com/Overlayerfi/contracts/pull/70).
PR #70 itself was implementing a fix for a related but distinct
underflow at a different site in the same accounting subsystem (the
underflow inside AaveHandler.supply, where cross-chain burns reduced
totalSupply below totalSuppliedCollateral). In implementing that fix —
specifically, by introducing the totalBridgedOut accumulator and the
_debit/_credit overrides that maintain it — PR #70 added the new
underflow in the OFT _credit override that this submission reports.
The new underflow has never been mentioned in any GitHub issue, pull
request title or body, commit message, code comment, README, or doc
anywhere in the Overlayerfi/contracts repo. The merged code (verified
against the contest commit, against main, and against every other
branch on 2026-04-07) still contains it. PR #70 is therefore the
SOURCE of this bug, not a disclosure of it.
Diff evidence — PR #70 added, for the first time in the history of the codebase, the following lines into OverlayerWrapCore.sol:
…and the corresponding consumer in AaveHandler.sol:
+ IOverlayerWrap(overlayerWrap).totalBridgedOut();
The full diff is at https://github.com/Overlayerfi/contracts/pull/70/files.
The two underflows in this area of the code are distinct and must not be conflated:
A. AaveHandler.supply() — normalizedSupply - totalSuppliedCollateral
pre-existed before PR #70, was fixed by PR #70, and is the underflow
named in the PR title. Out of scope (already addressed).
B. OverlayerWrapCore._credit() — totalBridgedOut -= amountReceivedLD
did not exist before PR #70, was introduced by PR #70 as part of the
implementation of the fix for (A), and is what this submission
reports. In scope (brand-new, unpatched, undisclosed).
ROOT CAUSE
In contracts/overlayer/OverlayerWrapCore.sol:
Line 63 (state variable declaration): /// @notice Cumulative amount of tokens debited via OFT cross-chain transfers (not yet credited back) uint256 public totalBridgedOut;
Lines 510-528 (debit override — adds to the accumulator): 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; }
Lines 537-544 (credit override — THE BUG): function credit( address to, uint256 amountLD, uint32 srcEid_ ) internal virtual override returns (uint256 amountReceivedLD) { amountReceivedLD = super.credit(to, amountLD_, srcEid_); totalBridgedOut -= amountReceivedLD; // <-- unguarded underflow }
The dev's intent (visible in the doc comment at lines 500-503 and 530-532) was to track the global cross-chain bridge state on a SINGLE chain — the hub. The doc literally says "Tracks tokens leaving the hub chain". But the override is defined in OverlayerWrapCore, which is the same contract code deployed on every chain (hub + all peers). The override has no onlyHubChain check, so it fires on the destination chain (where it makes no sense) just as it fires on the source chain.
WHY THE BUG IS UNCONDITIONAL ON A FRESH PEER
For the bug NOT to fire on a peer chain, the peer's totalBridgedOut
must be greater than or equal to the incoming amountReceivedLD at the
moment _credit runs. The only way for totalBridgedOut to become positive
on a peer is via a previous successful _debit on the same peer. _debit is
only called when the peer's holders SEND tokens to another chain. For a
peer's holder to be able to send, they must FIRST receive — which routes
back through _credit and the same underflow.
Chicken and egg: a fresh peer chain has totalBridgedOut == 0, no init, no admin setter, no possible path to a non-zero value. Every first delivery to a fresh peer underflows.
Verified across every branch of the public Overlayerfi/contracts repo on 2026-04-07 (main, oft-underflow-accounting, try-catch-compound, add-time-lock-new-backing, cancel-proposal, grant-revoke-role, missing-events, remove-cooldown, remove-role-api, remove-try-catch, remove-unused-modifier, renounce-blacklist, fix-pause-mint-doc, update-scripts). NONE of them initialise, clamp, or gate the override.
EXPLOIT FLOW
A KYC'd user mints N OverlayerWrap on the hub chain. They call IOAppCore.send(SendParam{dstEid: peerEid, amountLD: N, ...}) to bridge to a peer chain. LayerZero V2 routes through OFTCore.send -> _debit on the hub: super._debit() burns N tokens from the user, and the override increments totalBridgedOut[hub] += N. LayerZero dispatches the message to the peer.
On the peer, the LZ executor calls peerEndpoint.lzReceive which routes
through OAppReceiver._lzReceive -> OFTCore._lzReceive -> _credit. The
override runs: super._credit() succeeds and would have minted N tokens to
the user, but the very next line is totalBridgedOut -= amountReceivedLD,
which is 0 - N because totalBridgedOut[peer] has never been touched.
This panics (0x11), reverting the entire lzReceive call. The mint inside
super._credit is rolled back. The user has nothing on the peer chain.
The tokens are still burned on the hub chain — the _debit happened in a separate, already-finalised transaction. LayerZero V2 stores the failed message and allows retry. Every retry re-runs _credit with the same totalBridgedOut == 0 and the same amountReceivedLD, so every retry reverts identically. The user's funds are permanently locked. There is no recovery path: no admin function to refund the user on the hub, no way to bootstrap totalBridgedOut on the peer, and bridging additional tokens (which would only accumulate totalBridgedOut on the hub, not the peer) does not help.
RECOMMENDATION
The simplest fix is to clamp the subtraction so it cannot underflow:
function _credit(
address to_,
uint256 amountLD_,
uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
if (totalBridgedOut >= amountReceivedLD) {
unchecked {
totalBridgedOut -= amountReceivedLD;
}
} else {
totalBridgedOut = 0;
}
}
A more architecturally honest fix is to gate both _debit and _credit
behind block.chainid == hubChainId. The totalBridgedOut accumulator
only makes semantic sense on the chain that holds the backing; peer
chains have no use for it and should not be touching it. With both
overrides hub-only, peer chains do not corrupt the state and cross-chain
delivery succeeds end-to-end.
The team should also consider whether totalBridgedOut accounting needs to be globally consistent across all chains. If so, an off-chain reconciliation service or a LayerZero ULN message-passing mechanism would be required, not per-chain local state.
The PoC requires Foundry. It does NOT require any RPC fork — the contest's protocol is pre-launch (no production deployment) and the bug is reproduced against the contest source compiled in isolation.
Two independent PoCs are provided. Both demonstrate the same underflow under different inheritance setups; the triager should run BOTH to be maximally confident.
PoC 1 — minimal stub OFT base (fastest, no external deps):
forge test --match-contract OverlayerOFTUnderflowTest -vvv
Expected: 4 tests, all PASS: - test_creditUnderflowOnFreshPeer Demonstrates that calling the (verbatim-copied) Overlayer override with totalBridgedOut == 0 and amountLD == 100 ether reverts with arithmetic underflow (panic 0x11). - test_creditUnderflowEvenWithOneWei Same bug but with amountLD == 1 wei. Confirms the bug is unconditional on amount. - test_creditWorksAfterDebit Sanity check: priming totalBridgedOut to 100 ether via vm.store and then calling _credit with 60 ether succeeds and decrements correctly. Confirms the bug IS the underflow, not some other issue elsewhere in the harness. - test_fullHubToPeerBridgeSimulation Full simulated flow: hub _debit succeeds (totalBridgedOut[hub] increments to 100 ether), then peer _credit reverts on the same 100 ether delivery. Demonstrates the asymmetric breakdown that causes permanent fund loss.
PoC 2 — REAL LayerZero V2 OFT base (gold standard):
forge install LayerZero-Labs/LayerZero-v2 --no-git forge install OpenZeppelin/openzeppelin-contracts --no-git
forge test --match-contract OverlayerOFTUnderflowRealTest -vvv
Expected: 3 tests, all PASS: - test_real_creditUnderflowOnFreshPeer The harness inherits from the REAL @layerzerolabs/oft-evm OFT.sol. It uses a no-op MockLzEndpoint that satisfies OAppCore's constructor (which calls endpoint.setDelegate(delegate)). The Overlayer override is byte-identical to lines 537-544 of OverlayerWrapCore.sol. Confirms the bug fires under the real LayerZero V2 OFT semantics: super._credit mints to the recipient, returns amountLD, and the override then panics on the subtraction. - test_real_creditUnderflowEvenWithOneWei Same as above with amountLD == 1 wei. - test_real_creditWorksAfterDebit Locates totalBridgedOut at storage slot 10 (after all inherited OFT/OFTCore/OApp/OAppSender/OAppReceiver/OAppCore/ERC20 storage), primes it to 100 ether via vm.store, then calls _credit with 60 ether and verifies the result decremented to 40 ether.
DIRECT VERIFICATION (no Foundry needed):
The override code is on lines 537-544 of the contest commit. To verify the source independently:
curl -s https://raw.githubusercontent.com/Overlayerfi/contracts/519c9e92fd9d80d11e35e9868130f6334b88d676/contracts/overlayer/OverlayerWrapCore.sol | sed -n '510,544p'
You will see the _credit and _debit overrides exactly as cited above. The state variable declaration is on line 63 and has no initialiser. There is no setter, no constructor init, no onlyHubChain guard, no clamp.
Attachments are hidden
This information is not publicly available.
Comments are hidden
This information is not publicly available.