Skip to content
Business logic Audit finding Intermediate

Lack of lastEthPrice sync between different chains

The lastEthPrice variable is not synchronised across chains, so when users deposit or withdraw on different chains, the same price change is counted multiple times in the cumulative value calculation. This leads to incorrect CDS owner withdrawal amounts, which could be higher or lower than expected.

0x37 Follow with valuevalk

Originally disclosed on Sherlock

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

Found by

0x37, valuevalk

Summary

The missing sync of lastEthPrice will cause incorrect cds cumulative value calculation.

Root Cause

When users deposit or withdraw in cds, we will timely update the cds cumulative value.

We will calculate the cds gain/loss according to the ether price change from lastEthPrice to current Ether price. We will update the lastEthPrice after our calculation.

The problem is that the cds gain/loss stands for the total cds deposit's gain or loss including Op chain and Mode chain. We just update the lastEthPrice variable in current chain and don't sync with the other chain. When users deposit/withdraw in the other chain and calculate the cds gain/loss accroding to the ether price change, we will re-calculate the previous gain/loss because of the un-synced lastEthPrice.

For example:

  1. Alice deposits in OP Chain in timestamp X. lastEthPrice = 3500 USD.
  2. Bob deposits in Mode Chain in timestamp X. lastEthPrice = 3500 USD.
  3. Cathy deposits in OP chain in timestamp X + 100, current Ether price = 4000 USD. We will calculate the cds gain/loss bettwne timestamp X and timestamp X + 100. The gain/loss will be updated to global variable omniChainData.cumulativeValue and omniChainData.cumulativeValueSign. lastEthPrice in OP Chain is updated to 4000 USD.
  4. Dean deposits in Mode Chain in timestamp X + 200, current Ether price = 4000 USD. When we calculate the cds gain/loss, we will calculate the gain/loss from 3500 USD to 4000 USD because the lastEthPrice is still 3500 USD. This will cause the gain/loss will be calculated repeatedly.
Solidity
    function calculateCumulativeValue(
        uint128 _price, // current ether price
        uint256 totalCdsDepositedAmount, // usda amount in the treasury
        uint128 lastEthPrice, // last ether price
        uint256 vaultBal // collateral ether amount
    ) public pure returns (CDSInterface.CalculateValueResult memory) {
            if (_price > lastEthPrice) {
                priceDiff = _price - lastEthPrice;
                gains = true;
            } else {
                priceDiff = lastEthPrice - _price;
                gains = false;
            }
            value = uint128((_amount * vaultBal * priceDiff * 1e6) / (PRECISION * totalCdsDepositedAmount));
}

Solidity
        if (ethPrice != lastEthPrice) {
            updateLastEthPrice(ethPrice);
        }

Internal pre-conditions

N/A

External pre-conditions

N/A

Attack Path

  1. Alice deposits in OP Chain in timestamp X. lastEthPrice = 3500 USD.
  2. Bob deposits in Mode Chain in timestamp X. lastEthPrice = 3500 USD.
  3. Cathy deposits in OP chain in timestamp X + 100, current Ether price = 4000 USD. We will calculate the cds gain/loss bettwne timestamp X and timestamp X + 100. The gain/loss will be updated to global variable omniChainData.cumulativeValue and omniChainData.cumulativeValueSign. lastEthPrice in OP Chain is updated to 4000 USD.
  4. Dean deposits in Mode Chain in timestamp X + 200, current Ether price = 4000 USD. When we calculate the cds gain/loss, we will calculate the gain/loss from 3500 USD to 4000 USD because the lastEthPrice is still 3500 USD. This will cause the gain/loss will be calculated repeatedly.

Impact

The cds cumulative value calculation will be incorrect. This will cause cds owner's withdraw amount will be incorrect, more or less than expected.

PoC

N/A

Mitigation

Sync the lastEthPrice with the other chain.

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 lastEthPrice state variable is updated only on the local chain and not synchronised with other chains, causing repeated calculation of the same price change.

Impact

The cds cumulative value calculation will be incorrect, causing cds owners' withdrawal amounts to be more or less than expected.

What the attacker needed

Multiple chains with CDS contracts; users deposit or withdraw on different chains

The fix

The lastEthPrice should be synchronised with the other chain.

How it was found

  1. Alice deposits on OP Chain at timestamp X, lastEthPrice set to 3500 USD.
  2. Bob deposits on Mode Chain at timestamp X, lastEthPrice set to 3500 USD.
  3. Cathy deposits on OP Chain at timestamp X+100, current Ether price 4000 USD; gain/loss from 3500 to 4000 is calculated and lastEthPrice on OP Chain updated to 4000 USD.
  4. Dean deposits on Mode Chain at timestamp X+200, current Ether price 4000 USD; because lastEthPrice on Mode Chain is still 3500 USD, the gain/loss from 3500 to 4000 is calculated again.

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.

This is a cross-chain smart contract issue. The contract tracks the price of ether to calculate gains or losses for depositors. It stores the last price it saw, but only on the chain where a deposit happens. If someone deposits on another chain, that chain still uses the old price, so the same price movement is counted again, making the total gain or loss wrong.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.