Skip to content
Business logic Audit finding Intermediate

copy paste error in _batchConfirmOutstandingPendingActions

A copy-paste error in the smart contract caused the wrong state variable to be reset after processing, so a pending amount was never cleared and kept increasing. This could lead to far too many synthetic tokens being shifted from SHORT to LONG, corrupting internal accounting.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon, also found by cmichel and shw

The function _batchConfirmOutstandingPendingActions of LongShort.sol processes the variable batched_amountSyntheticToken_toShiftAwayFrom_marketSide, and sets it to 0 after processing. However, probably due to a copy/paste error, in the second instance, where batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][false] is processed, the wrong version is set to 0: batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][true] = 0

This means the next time the batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][false] is processed again. As it is never reset, it keeps increasing. The result is that the internal administration will be off and far too many tokens will be shifted tokens from SHORT to LONG.

LongShort.sol L1126

function _batchConfirmOutstandingPendingActions(
..
    amountForCurrentAction_workingVariable = batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][true];
    batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][true] = 0;
...
    amountForCurrentAction_workingVariable = batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][false];
    batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][true] = 0; // should probably be false
)

Recommend changing the second instance of the following (on line 1207) batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][true] = 0 to batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][false] = 0

p.s. confirmed by Jason of Floatcapital: “Yes, that should definitely be false!”

JasoonS (Float) commented:

Mitigation

- batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][true] = 0
+ batched_amountSyntheticToken_toShiftAwayFrom_marketSide[marketIndex][false] = 0

moose-code (Float) confirmed:

Good attention to detail. Silly on our part.

DenhamPreen (Float) patched:

https://github.com/Float-Capital/monorepo/pull/1087

Resolved PR

*note this repo is still private

The original report as published on Code4rena, by gpersoon. 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

Likely a copy-paste error where the wrong array index (true instead of false) was set to zero after processing.

Impact

The internal accounting would be incorrect and far too many tokens could be shifted from SHORT to LONG.

What the attacker needed

None

The fix

The second assignment should set the false index to zero instead of the true index; the project confirmed and patched it.

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 a smart contract, a variable tracks how many tokens are waiting to be moved. The code was supposed to reset that variable to zero after using it, but due to a copy-paste mistake it reset a different variable instead. So the original number kept growing, and the contract would move far more tokens than it should.

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 gpersoon

View all

47 more disclosed reports, best first.

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.