Skip to content
Business logic Audit finding Intermediate

Incorrect balance computed in getUsersConfirmedButNotSettledSynthBalance()

The function getUsersConfirmedButNotSettledSynthBalance() calculates a user's unsettled balance using the current market update index instead of the index at the time of the user's last action. This can show an incorrect balance to the user, potentially leading them to make poor financial decisions.

hack3r-0m Follow

Originally disclosed on Code4rena

Submitted by hack3r-0m and cmichel

Consider the following state:

long_synth_balace = 300;
short_synth_balace = 200;

marketUpdateIndex[1] = x;
userNextPrice_currentUpdateIndex = 0;
userNextPrice_syntheticToken_toShiftAwayFrom_marketSide[1][true] = 0;
batched_amountSyntheticToken_toShiftAwayFrom_marketSide[1][true] = 0;

User calls shiftPositionFromLongNextPrice(marketIndex=1, amountSyntheticTokensToShift=100)

This results in following state changes:

long_synth_balace = 200;
short_synth_balace = 200;
userNextPrice_syntheticToken_toShiftAwayFrom_marketSide[1][true] = 100;
batched_amountSyntheticToken_toShiftAwayFrom_marketSide[1][true] = 100;
userNextPrice_currentUpdateIndex = x+1 ;

Due to some other transactions, oracle updates twice, and now the marketUpdateIndex[1] is x+2 and also updating price snapshots.

When User calls getUsersConfirmedButNotSettledSynthBalance(user, 1)

initial condition:

if (
  userNextPrice_currentUpdateIndex[marketIndex][user] != 0 &&
  userNextPrice_currentUpdateIndex[marketIndex][user] <= currentMarketUpdateIndex
)

will be true; LongShort.sol L532

syntheticToken_priceSnapshot[marketIndex][isLong][currentMarketUpdateIndex]

This uses price of current x+2 th update while it should balance of accounting for price of x+1 th update.

JasoonS (Float) confirmed and disagreed with severity:

Yes good spot.

This function is view only, and is only used for view only purposes. The rest of the system will always operate correctly because it rather uses _executeOutstandingNextPriceSettlements than the getUsersConfirmedButNotSettledSynthBalance. Therefore I propose this as a 1 Low Risk vulnerability.

0xean (judge) (judge) commented:

I am going to align with the 2 (Med Risk) severity. Reporting the incorrect position in a UI to a user could definitely lead unexpected loss of funds in a sharp market move where a user is intending on hedging elsewhere.

The original report as published on Code4rena, by hack3r-0m and cmichel. 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

Impact

The incorrect balance shown to the user could lead to unexpected loss of funds if they act on it during a sharp market move.

What the attacker needed

User has a position in the market; Oracle updates at least twice after user's action

How it was found

  1. User calls shiftPositionFromLongNextPrice with marketIndex=1 and amountSyntheticTokensToShift=100.
  2. Oracle updates twice, making marketUpdateIndex[1] equal to x+2.
  3. User calls getUsersConfirmedButNotSettledSynthBalance(user, 1).
  4. The function uses the price snapshot at the current market update index (x+2) instead of the user's update index (x+1).

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 is a smart contract bug where a function that shows your balance uses the wrong price update. If prices change quickly, you might see a wrong number and make a bad trade.

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 from Float Capital contest

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.