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.
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:
PositionUtils.sol: https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/position/PositionUtils.sol#L460-L474MarketUtils.sol: https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/market/MarketUtils.sol#L1773-L1793
In PositionUtils.sol
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
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
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.