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.
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:
- Alice deposits in OP Chain in timestamp X.
lastEthPrice= 3500 USD. - Bob deposits in Mode Chain in timestamp X.
lastEthPrice= 3500 USD. - 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.cumulativeValueandomniChainData.cumulativeValueSign.lastEthPricein OP Chain is updated to 4000 USD. - 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
lastEthPriceis still 3500 USD. This will cause the gain/loss will be calculated repeatedly.
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));
}
if (ethPrice != lastEthPrice) {
updateLastEthPrice(ethPrice);
}
Internal pre-conditions
N/A
External pre-conditions
N/A
Attack Path
- Alice deposits in OP Chain in timestamp X.
lastEthPrice= 3500 USD. - Bob deposits in Mode Chain in timestamp X.
lastEthPrice= 3500 USD. - 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.cumulativeValueandomniChainData.cumulativeValueSign.lastEthPricein OP Chain is updated to 4000 USD. - 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
lastEthPriceis 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.
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
- Alice deposits on OP Chain at timestamp X, lastEthPrice set to 3500 USD.
- Bob deposits on Mode Chain at timestamp X, lastEthPrice set to 3500 USD.
- 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.
- 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.