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.
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.
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!”
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.