Skip to content
Business logic Audit finding Intermediate

Invalid handling of holding positions in DolomiteConnector::transferBetweenAccounts

The DolomiteConnector's transferBetweenAccounts function moves collateral between accounts but does not update the protocol's record of holding positions. This causes the protocol's total value locked (TVL) calculation to be inaccurate, as it continues to use the old holding position even after funds are moved.

0xAlix2 Follow with bigtone and BenRai

Originally disclosed on Code4rena

Submitted by 0xAlix2, also found by bigtone and BenRai

Impact

In Dolomite protocol, transferBetweenAccounts transfers the collateral from 1 account to another under the same owner. So the owner of both accounts still owns these funds regardless of the account they’re deposited in. In DolomiteConnector, when calling transferBetweenAccounts the protocol isn’t updating the holding position of either account.

So when the manager moves the collateral to account ID 1 for example, the protocol doesn’t know about the new holding position (which is the position related to account ID 1) and will remain calculating the TVL according to the old holding position (account Id 0), even if the whole amount of account 0 was moved to account 1.

This will cause an inaccurate representation of the Connector’s TVL affecting the whole protocol’s TVL.

Proof of Concept

    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);
    }

Recommended Mitigation Steps

Add the following at the bottom of DolomiteConnector::transferBetweenAccounts:

    (uint256[] memory markets0,,,) = dolomiteMargin.getAccountBalances(Info(address(this), 0));
    registry.updateHoldingPosition(
        vaultId,
        registry.calculatePositionId(address(this), DOL_POSITION_ID, ""),
        abi.encode(0),
        "",
        markets0.length == 0
    );

    (uint256[] memory markets1,,,) = dolomiteMargin.getAccountBalances(Info(address(this), accountId));
    registry.updateHoldingPosition(
        vaultId,
        registry.calculatePositionId(address(this), DOL_POSITION_ID, ""),
        abi.encode(accountId),
        "",
        markets1.length == 0
    );

This updates the holding positions of both accounts, by either setting or removing the position according to the open markets of each.

gzeon (judge) increased severity to High

HadiEsna (NOYA) confirmed


The original report as published on Code4rena, by 0xAlix2. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

The transferBetweenAccounts function does not call the registry to update the holding position for either the source or destination account after transferring collateral.

Impact

The protocol's TVL is calculated incorrectly, which could affect the entire protocol's accounting and decision-making.

What the attacker needed

Manager role or owner privileges; collateral deposited in Dolomite

The fix

The transferBetweenAccounts function should be updated to call registry.updateHoldingPosition for both the source and destination accounts after the transfer, based on their current open markets.

How it was found

  1. Deposit 200 DAI into the connector, which records a TVL of about 199 base tokens.
  2. Call transferBetweenAccounts to move the collateral from account 0 to account 1.
  3. Observe that the TVL drops to 0, even though account 1 now holds the collateral.

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 report is about a smart contract that manages investments. When money is moved between two accounts owned by the same person, the system's record of where the money is kept is not updated. So the system thinks the money is still in the old account, which makes the total value calculation 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 0xAlix2

View all

39 more disclosed reports, best first.

More from NOYA

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.