Skip to content
Business logic Audit finding Intermediate

Incorrect parameter ordering in function call

The function call to updateTotalBorrowing in PositionUtils.sol passed the borrowing factor and position size in the wrong order compared to the function definition in MarketUtils.sol. This could corrupt the system's internal accounting and lead to loss of user funds.

float-audits Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/97

Found by

float-audits

Summary

The ordering of parameters in function call made in updateTotalBorrowing() in PositionUtils.sol is incorrect.

Vulnerability Detail

The function call of updateTotalBorrowing() in PositionUtils.sol has a different parameter ordering to the one defined in the actual function being called in MarketUtils.sol.

More specifically, params.position.borrowingFactor() and params.position.sizeInUsd() are swapped around.

Impact

Updating the total borrowing function with incorrect parameter values would upset the internal accounting of the system and would result in loss of user funds.

Code Snippet

Loc:

In PositionUtils.sol

Solidity
function updateTotalBorrowing(
    PositionUtils.UpdatePositionParams memory params,
    uint256 nextPositionSizeInUsd,
    uint256 nextPositionBorrowingFactor
) internal {
    MarketUtils.updateTotalBorrowing(
        params.contracts.dataStore,
        params.market.marketToken,
        params.position.isLong(),
        params.position.borrowingFactor(),
        params.position.sizeInUsd(),
        nextPositionSizeInUsd,
        nextPositionBorrowingFactor
    );
}

In MarketUtils.sol

Solidity
function updateTotalBorrowing(
    DataStore dataStore,
    address market,
    bool isLong,
    uint256 prevPositionSizeInUsd,
    uint256 prevPositionBorrowingFactor,
    uint256 nextPositionSizeInUsd,
    uint256 nextPositionBorrowingFactor
) external {
    uint256 totalBorrowing = getNextTotalBorrowing(
        dataStore,
        market,
        isLong,
        prevPositionSizeInUsd,
        prevPositionBorrowingFactor,
        nextPositionSizeInUsd,
        nextPositionBorrowingFactor
    );

    setTotalBorrowing(dataStore, market, isLong, totalBorrowing);
}

Tool used

Manual Review

Recommendation

Correct the ordering of parameters in function call made in PositionUtils.sol so that it aligns to that defined in the function signature in MarketUtils.sol

Discussion

xvi10

Fix in https://github.com/gmx-io/gmx-synthetics/commit/3508caf10d1bda24f21e768e945494fd581c0986

The original report as published on Sherlock, by float-audits. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 arguments in the function call were passed in the wrong order: the borrowing factor and position size were swapped relative to the function signature.

Impact

Updating the total borrowing with incorrect parameter values would upset the internal accounting and could result in loss of user funds.

What the attacker needed

None

The fix

The parameter ordering in the function call was corrected to match the function signature.

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.

In programming, when you call a function, you must give its arguments in the same order as the function expects. Here, two numbers were swapped, so the function received the wrong values. This could mess up the system's records and cause users to lose money.

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 float-audits

View all

1 more disclosed report, best first.

More from GMX Update

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.