# Cross-Contract Reentrancy Vulnerability in CDS Withdraw Function

CDS withdraw transfers ETH via .call before writing back stale in-memory omniChainData, letting a reentrant borrower deposit/withdraw corrupt global accounting and block withdrawals.

- Payout: Audit contest
- Severity: high
- Program: Autonomint
- Found by: t.aksoy
- Disclosed: 2024-11-26
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/832
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-autonomint%3AH-24
- Tags: area:web3 domain:web3 impact:dos impact:integrity kind:contest platform:sherlock sev:high tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:dos vuln:reentrancy

**Target:** CDS withdraw / Treasury ETH transfer
**Root cause:** omniChainData is read into memory at withdraw start and written back to global state after the ETH .call to the user, so reentrant changes to global omniChainData are overwritten by stale data.
**Steps:**
1. Deploy attacker contract with fallback that calls Borrowing contract deposit on ETH receipt.
2. Deposit into CDS with optedLiquidation so withdraw pays ETH liquidation gains.
3. Call `CDS.withdraw(index, excessProfitCumulativeValue, nonce, signature)`.
4. During `treasury.transferEthToCdsLiquidators` `.call`, fallback deposits large X into Borrowing, increasing `totalVolumeOfBorrowersAmountinWei`.
5. Return; withdraw writes stale in-memory omniChainData back, erasing the increase.
6. Withdraw X from Borrowing, decreasing `totalVolumeOfBorrowersAmountinWei` below correct value; repeat to drive it artificially low.
**How found:** Code reading of withdraw flow: noticed omniChainData cached in memory and written back after an external ETH .call, a classic stale-cache-overwrite reentrancy pattern.
**Exploitation:** Attacker uses a contract depositor to reenter Borrowing during the ETH payout, inflating then erasing borrower volume accounting, then withdraws to push totalVolumeOfBorrowersAmountinWei artificially low, breaking CDS pool ratios and blocking borrowing withdrawals.
**Escalation:** Repeat with large X values to progressively corrupt global accounting and DoS borrowing-contract withdrawals.
**Insight:** When a function caches a global struct in memory and writes it back after an external call, any reentrant mutation to that struct is silently reverted — look for memory-cached global state written post-.call, not just balance reentrancy.

