# In Dolomite, when opening a borrow position, the holding position in the Registry will never be updated due to the removePosition flag being set to true

Dolomite connector's openBorrowPosition passes removePosition=true to registry.updateHoldingPosition, so new borrow positions are never recorded, breaking registry-based strategy accounting.

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

**Target:** Dolomite connector openBorrowPosition / Registry.updateHoldingPosition
**Root cause:** openBorrowPosition calls registry.updateHoldingPosition with removePosition=true, but the position was never added, so the circuit-breaker (positionIndex==0 && removePosition) returns early and the holding position is never recorded.
**Steps:**
1. Call `openBorrowPosition(marketId, _amountWei, accountId)` as manager on the Dolomite connector.
2. Observe it invokes `registry.updateHoldingPosition(vaultId, calculatePositionId(address(this), DOL_POSITION_ID, ""), abi.encode(accountId), "", true)` with removePosition=true.
3. In updateHoldingPosition, `positionIndex = vault.isPositionUsed[holdingPositionId]` is 0 since never added.
4. Circuit-breaker `if (positionIndex == 0 && removePosition) return type(uint256).max;` exits before adding the position.
5. Position never enters holdingPositions array; registry accounting is stale.
**How found:** Code review comparing openBorrowPosition against withdraw/closeBorrowPosition usage of the removePosition flag, spotting the inverted flag and tracing the circuit-breaker early-return.
**Escalation:** Stale registry data can cause strategy actions to miss the borrow position, failing to close in time and risking liquidation/bad debt.
**Insight:** When auditing registry/accounting connectors, diff the removePosition/add flag across every open vs close function; an open path passing removePosition=true silently no-ops because the position index is still zero.

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

**openBorrowPosition sets removePosition flag true**

```
function openBorrowPosition(uint256 marketId, uint256 _amountWei, uint256 accountId)
            public
            onlyManager
            nonReentrant
        {
            address token = dolomiteMargin.getMarketTokenAddress(marketId);

            if (!registry.isTokenTrusted(vaultId, token, address(this))) {
                revert IConnector_UntrustedToken(token);
            }
            // borrow
            borrowPositionProxy.openBorrowPosition(
                0, accountId, marketId, _amountWei, AccountBalanceHelper.BalanceCheckFlag.None
            );
            registry.updateHoldingPosition(
                vaultId, registry.calculatePositionId(address(this), DOL_POSITION_ID, ""), abi.encode(accountId), "", true
            );
        }
```

**Circuit-breaker returns max when removePosition**

```
if (positionIndex == 0 && removePosition) return type(uint256).max;
```

