Skip to content
Race condition Audit finding Advanced

Using LayerZero for synchronizing global states between two chains may lead to overwriting of global states

The protocol synchronises global state between two chains via LayerZero without locking, so near-simultaneous deposits on both chains can overwrite each other's totals. This leaves both chains with incorrect accounting values, such as the total borrower volume.

0x37 Follow with 0x73696d616f, 0xNirix and 4 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/848

Found by

0x37, 0x73696d616f, 0xNirix, EgisSecurity, LZ_security, santiellena, valuevalk

Summary

Due to the lack of a locking mechanism and the non-atomic nature of cross-chain operations, global states may be at risk of being overwritten.

Root Cause

https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/Core_logic/GlobalVariables.sol#L43 In both Optimism and Mode, there is a global variable omniChainData, which contains numerous data items as follows:

JavaScript
struct OmniChainData {
        uint256 normalizedAmount;
        uint256 vaultValue;
        uint256 cdsPoolValue;
        uint256 totalCDSPool;
        uint256 collateralRemainingInWithdraw;
        uint256 collateralValueRemainingInWithdraw;
        uint128 noOfLiquidations;
        uint64 nonce;
        uint64 cdsCount;
        uint256 totalCdsDepositedAmount;
        uint256 totalCdsDepositedAmountWithOptionFees;
        uint256 totalAvailableLiquidationAmount;
        uint256 usdtAmountDepositedTillNow;
        uint256 burnedUSDaInRedeem;
        uint128 lastCumulativeRate;
        uint256 totalVolumeOfBorrowersAmountinWei;
        uint256 totalVolumeOfBorrowersAmountinUSD;
        uint128 noOfBorrowers;
        uint256 totalInterest;
        uint256 abondUSDaPool;
        uint256 collateralProfitsOfLiquidators;
        uint256 usdaGainedFromLiquidation;
        uint256 totalInterestFromLiquidation;
        uint256 interestFromExternalProtocolDuringLiquidation;
        uint256 totalNoOfDepositIndices;
        uint256 totalVolumeOfBorrowersAmountLiquidatedInWei;
        uint128 cumulativeValue; // cumulative value
        bool cumulativeValueSign; // cumulative value sign whether its positive or not negative
        uint256 downsideProtected;
    }

The design of this protocol ensures that any changes to omniChainData on one chain are synchronized to other chains via Layer_Zero.

However, due to the lack of a locking mechanism and the non-atomic nature of cross-chain operations, this could lead to overwriting of global states. The following is a simple explanation using a borrow example: 1. Alice deposits 1 ETH on Optimism, and almost simultaneously, Bob deposits 100 ETH on the Mode chain. 2. The totalVolumeOfBorrowersAmountinWei on Optimism becomes 1e18, while on the Mode chain, it becomes 100 * 1e18. 3. Both Optimism and Mode chains send globalVariables.send to synchronize their local data to the other chain. 4. As a result, totalVolumeOfBorrowersAmountinWei on Optimism becomes 100 * 1e18, while on the Mode chain, it becomes 1e18.

Both chains now hold incorrect totalVolumeOfBorrowersAmountinWei values. The correct value should be 101 * 1e18.

The fundamental issue is that when Alice deposits on Optimism, the cross-chain synchronization to the Mode chain cannot prevent users from performing nearly simultaneous actions on the Mode chain, leading to overwriting of global states.

Furthermore, there could also be scenarios where a message is successfully sent via Layer_Zero on Optimism but encounters an error when executing receive() on the Mode chain, leading to additional inconsistencies.

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

Errors in global accounting data can lead to incorrect calculations in critical system processes.

PoC

No response

Mitigation

Modify and improve the relevant data synchronization mechanism.

The original report as published on Sherlock, by 0x37. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the cross-chain state synchronisation lacks locking and atomicity, so concurrent updates on different chains overwrite each other instead of being merged.

Impact

Errors in global accounting data could lead to incorrect calculations in critical system processes.

What the attacker needed

Two supported chains; near-simultaneous deposits on both chains

The fix

The data synchronisation mechanism should be modified and improved to prevent overwriting, for example by adding locking or making updates atomic.

How it was found

  1. Alice deposits 1 ETH on Optimism while Bob deposits 100 ETH on Mode almost simultaneously.
  2. Each chain updates its local total borrower volume to reflect only its own deposit.
  3. Both chains send their local data to the other chain via LayerZero.
  4. The incoming updates overwrite the local totals, leaving both chains with incorrect values.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Two blockchains keep a shared record of totals and copy updates to each other. If two people change the totals at the same time on different chains, the copies can overwrite each other, so both chains end up with wrong numbers.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by 0x37

View all

79 more disclosed reports, best first.

More from Autonomint Colored Dollar V1

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.