# Invalid handling of holding positions in DolomiteConnector::transferBetweenAccounts

DolomiteConnector.transferBetweenAccounts moves collateral between Dolomite accounts without updating the registry holding position, so TVL drops to zero despite funds still owned.

- Payout: Audit contest
- Severity: high
- Program: NOYA
- Found by: 0xAlix2
- Disclosed: 2025-02-17
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-noya-findings/issues/153
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-noya%3AH-23
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** DolomiteConnector::transferBetweenAccounts (Dolomite margin account transfer)
**Root cause:** transferBetweenAccounts moves collateral between Dolomite accounts (same owner) but never calls registry.updateHoldingPosition for either account, so the registry keeps the old account-0 position and TVL is computed from a now-empty account.
**Steps:**
1. Deal 200e18 DAI to connector; as owner call `connector.deposit(marketId=1, amount)`; TVL ≈ 199 base tokens.
2. Call `connector.transferBetweenAccounts(accountId=1, marketId=1, amount, false)`.
3. Observe `accountingManager.TVL()` returns 0.
4. Verify via `IDolomiteMargin.getAccountBalances` that account 0 has 0 markets and account 1 holds the collateral.
**How found:** Code-reading of the connector: noticed transferBetweenAccounts lacked the registry.updateHoldingPosition calls that deposit/withdraw perform, then wrote a Foundry test asserting TVL after the transfer.
**Exploitation:** Vault manager (or any caller able to invoke transferBetweenAccounts) moves all collateral to a second Dolomite account; registry still references account 0, so protocol TVL reads zero while funds remain in account 1, corrupting share pricing and accounting across the vault.
**Insight:** When a connector exposes an operation that relocates funds between sub-accounts of the same owner, check that every such path re-syncs the registry holding position — TVL is derived from registry state, not live balances, so any unmirrored move silently zeroes or inflates it.

## Proof of concept (copied exactly from the original report)

**Foundry test proving TVL drops to zero after transferBetweenAccounts**

```
function testDolomiteInvalidHoldingPositions_transferBetweenAccounts() public {
        uint256 marketId = 1;
        uint256 defaultAccountId = 0;
        uint256 accountId = 1;
        uint256 amount = 200e18;

        _dealERC20(DAI, address(connector), amount);

        vm.startPrank(owner);

        // Deposits 200 DAI to Dolomite
        connector.deposit(marketId, amount);

        // TVL is around 200 Base Tokens
        assertEq(accountingManager.TVL() / 1e6, 199);

        // Transfer collateral from account 0 to account 1
        connector.transferBetweenAccounts(accountId, marketId, amount, false);

        // TVL has dropped to 0
        assertEq(accountingManager.TVL(), 0);

        // Connector's account 0 has no markets (no collateral left)
        (uint256[] memory markets,,,) =
            IDolomiteMargin(dolomiteMargin).getAccountBalances(Info(address(connector), defaultAccountId));
        assertEq(markets.length, 0);

        // Connector's account 1 has 1 market (some collateral exists)
        (markets,,,) = IDolomiteMargin(dolomiteMargin).getAccountBalances(Info(address(connector), accountId));
        assertEq(markets.length, 1);
    }
```

