Target is hidden
This information is not publicly available.
OverlayerWrap inherits LayerZero's OFT and overrides _debit() and _credit() in OverlayerWrapCore.sol to track cross-chain token movement via a totalBridgedOut counter. When tokens leave a chain, _debit() (line 527) increments totalBridgedOut. When tokens arrive, _credit() (line 543) decrements it:
function _credit(
address to_,
uint256 amountLD_,
uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
totalBridgedOut -= amountReceivedLD; // @audit underflows on non-hub chains
}
totalBridgedOut is a uint256 declared at line 63 with no explicit initializer, so it defaults to 0 on every deployment. The subtraction at line 543 uses Solidity 0.8.20 checked arithmetic with no unchecked block.
On a non-hub chain (any chain where block.chainid != hubChainId), this creates a deadlock. The only function that increments totalBridgedOut is _debit(), which requires the caller to already hold tokens. But tokens can only arrive on a non-hub chain through OverlayerWrapCore.sol::_credit(). Since OverlayerWrapCore.sol::_credit() always attempts 0 - amountReceivedLD, the first inbound transfer reverts with arithmetic underflow (panic 0x11). It is not possible to bootstrap totalBridgedOut to a non-zero value, so no cross-chain transfer can ever be received.
When a user bridges OverlayerWrap tokens from the hub chain to any non-hub chain:
OverlayerWrapCore.sol::_debit() on the hub chain burns the user's tokens and increments hub-chain totalBridgedOutOverlayerWrapCore.sol::_credit() on the destination chain reverts with arithmetic underflow (panic 0x11)The impact is permanent fund loss. When a user bridges tokens from the hub chain, OverlayerWrapCore.sol::_debit() on the hub chain burns their tokens and sends a LayerZero message. When that message arrives at the destination, OverlayerWrapCore.sol::_credit() reverts. The tokens are already burned on the source chain and are never minted on the destination. Since the underflow condition is permanent (no code path can increment totalBridgedOut on a non-hub chain), retrying the failed LayerZero message will always revert with the same error, making the burned tokens irrecoverable.
This affects 100% of the bridged amount for every user attempting a cross-chain transfer to any non-hub chain. The entire LayerZero OFT cross-chain functionality is non-operational on receiving chains.
Restrict totalBridgedOut accounting to the hub chain only, where it serves its intended purpose of tracking the effective supply:
function _credit(
address to_,
uint256 amountLD_,
uint32 srcEid_
) internal virtual override returns (uint256 amountReceivedLD) {
amountReceivedLD = super._credit(to_, amountLD_, srcEid_);
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_
);
if (block.chainid == hubChainId) {
totalBridgedOut += amountSentLD;
}
}
OverlayerWrapMock (which already exists in the project's test contracts at contracts/test/OverlayerWrapMock.sol and exposes _credit()/_debit() as testCredit()/testDebit()) configured as a non-hub chain (hubChainId = 1, while Hardhat runs on chainId = 31337).testCredit() to simulate an inbound cross-chain transfer and proves the revert.test/H1_CreditUnderflow.ts:import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { ethers } from "hardhat";
import { expect } from "chai";
import { LZ_ENDPOINT_ETH_MAINNET_V2 } from "../scripts/addresses";
describe("H-1: totalBridgedOut underflow on non-hub chain", function () {
async function deployNonHubFixture() {
const [admin, alice] = await ethers.getSigners();
const block = await admin.provider.getBlock("latest");
const baseFee = block?.baseFeePerGas ?? 1n;
const defaultTransactionOptions = {
maxFeePerGas: baseFee * BigInt(10),
};
const Collateral = await ethers.getContractFactory("SixDecimalsUsd");
const collateral = await Collateral.deploy(
1000, "COLLATERAL", "COLLATERAL", defaultTransactionOptions
);
const aCollateral = await ethers.getContractFactory("SixDecimalsUsd");
const acollateral = await aCollateral.deploy(
1000, "aCOLLATERAL", "aCOLLATERAL", defaultTransactionOptions
);
// Deploy as NON-HUB chain: hubChainId=1 but Hardhat chainId=31337
const OverlayerWrap = await ethers.getContractFactory("OverlayerWrapMock");
const overlayerWrap = await OverlayerWrap.deploy(
{
admin: await admin.getAddress(),
lzEndpoint: LZ_ENDPOINT_ETH_MAINNET_V2,
name: "OverlayerWrap",
symbol: "OW+",
collateral: {
addr: await collateral.getAddress(),
decimals: await collateral.decimals(),
},
aCollateral: {
addr: await acollateral.getAddress(),
decimals: await acollateral.decimals(),
},
maxMintPerBlock: ethers.MaxUint256,
maxRedeemPerBlock: ethers.MaxUint256,
minValmaxRedeemPerBlock: 1n,
hubChainId: 1, // Not 31337 -> simulates non-hub chain
},
defaultTransactionOptions
);
await overlayerWrap.waitForDeployment();
return { overlayerWrap, collateral, acollateral, admin, alice };
}
it("PROOF: _credit() reverts on non-hub chain due to totalBridgedOut underflow", async function () {
const { overlayerWrap, alice } = await loadFixture(deployNonHubFixture);
// totalBridgedOut is 0 on a fresh non-hub chain deployment
expect(await overlayerWrap.totalBridgedOut()).to.equal(0n);
// Simulate inbound cross-chain transfer of 1 OW+ (1e18)
// _credit() does: totalBridgedOut -= amountReceivedLD
// With totalBridgedOut=0, this is 0 - 1e18 -> arithmetic underflow
const creditAmount = ethers.parseEther("1");
await expect(
overlayerWrap.testCredit(alice.address, creditAmount, 0)
).to.be.revertedWithPanic(0x11); // 0x11 = arithmetic underflow
});
it("CONTROL: _credit() works on hub chain (debit first, then credit)", async function () {
const [admin] = await ethers.getSigners();
const block = await admin.provider.getBlock("latest");
const baseFee = block?.baseFeePerGas ?? 1n;
const defaultTransactionOptions = { maxFeePerGas: baseFee * BigInt(10) };
const Collateral = await ethers.getContractFactory("SixDecimalsUsd");
const collateral = await Collateral.deploy(1000, "COLLATERAL", "COLLATERAL", defaultTransactionOptions);
const aCollateral = await ethers.getContractFactory("SixDecimalsUsd");
const acollateral = await aCollateral.deploy(1000, "aCOLLATERAL", "aCOLLATERAL", defaultTransactionOptions);
// Deploy as HUB chain (hubChainId == 31337 == block.chainid)
const OverlayerWrap = await ethers.getContractFactory("OverlayerWrapMock");
const overlayerWrap = await OverlayerWrap.deploy(
{
admin: await admin.getAddress(),
lzEndpoint: LZ_ENDPOINT_ETH_MAINNET_V2,
name: "OverlayerWrap", symbol: "OW+",
collateral: { addr: await collateral.getAddress(), decimals: await collateral.decimals() },
aCollateral: { addr: await acollateral.getAddress(), decimals: await acollateral.decimals() },
maxMintPerBlock: ethers.MaxUint256,
maxRedeemPerBlock: ethers.MaxUint256,
minValmaxRedeemPerBlock: 1n,
hubChainId: 31337, // Matches Hardhat chainId -> hub chain
},
defaultTransactionOptions
);
await overlayerWrap.waitForDeployment();
// Mint tokens on hub chain first
await collateral.connect(admin).approve(await overlayerWrap.getAddress(), ethers.MaxUint256);
await overlayerWrap.connect(admin).mint({
benefactor: admin.address, beneficiary: admin.address,
collateral: await collateral.getAddress(),
collateralAmount: ethers.parseUnits("100", await collateral.decimals()),
overlayerWrapAmount: ethers.parseEther("100"),
});
// Debit (bridge out) then credit (bridge back) works on hub chain
const bridgeAmount = ethers.parseEther("10");
await overlayerWrap.testDebit(admin.address, bridgeAmount, bridgeAmount, 0);
expect(await overlayerWrap.totalBridgedOut()).to.equal(bridgeAmount);
await overlayerWrap.testCredit(admin.address, bridgeAmount, 0);
expect(await overlayerWrap.totalBridgedOut()).to.equal(0n);
});
});
npx hardhat test test/H1_CreditUnderflow.ts --network hardhat
H-1: totalBridgedOut underflow on non-hub chain
✔ PROOF: _credit() reverts on non-hub chain due to totalBridgedOut underflow
✔ CONTROL: _credit() works on hub chain (debit first, then credit)
2 passing
Both tests pass, confirming:
_credit() always reverts with panic 0x11 (arithmetic underflow) on non-hub chains_debit() precedes _credit() (control test)Attachments are hidden
This information is not publicly available.
Comments are hidden
This information is not publicly available.