Target is hidden
This information is not publicly available.
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
totalBridgedOut = 0 (default)OFT.send() to bridge 1000e18 OverlayerWrap to Arbitrum_debit burns 1000e18 from user, totalBridgedOut += 1000e18 (hub's totalBridgedOut = 1000e18)_credit called with amountReceivedLD = 1000e18totalBridgedOut -= 1000e18 => 0 - 1000e18 => REVERT: arithmetic underflowProof 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;
}
}
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;
+ }
}
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.
On the hub chain (Ethereum):
send() (LayerZero OFT) to bridge tokens to the spoke chain (Arbitrum)_debit() executes successfully, burning tokens and incrementing
totalBridgedOutOn the spoke chain (Arbitrum):
_credit() is called internally by LayerZero's lzReceive()super._credit() would mint tokens, but then totalBridgedOut -= amountReceivedLD
executestotalBridgedOut == 0 on the spoke (nothing was ever debited from this chain),
Solidity 0.8.x checked arithmetic causes an underflow revertlzReceive transaction revertsResult:
totalBridgedOut > 0 to receive tokens, but can only get
totalBridgedOut > 0 by first sending tokens out (which it doesn't have)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.
// 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 are hidden
This information is not publicly available.
Comments are hidden
This information is not publicly available.