2 variables not indexed by marketIndex
Two mapping variables in the Staker contract are not indexed by marketIndex, so if two markets share the same batched_stakerNextTokenShiftIndex value, their stored snapshot indices can overwrite each other. This can cause incorrect float issuance calculations, allocating too much or too little float.
Submitted by gpersoon
In the token contract: batched_stakerNextTokenShiftIndex is indexed by marketIndex, so it can have separate (or the same) values for each different marketIndex.
stakerTokenShiftIndex_to_longShortMarketPriceSnapshotIndex_mapping and stakerTokenShiftIndex_to_accumulativeFloatIssuanceSnapshotIndex_mapping are not indexed by marketIndex. So the values of stakerTokenShiftIndex_to_longShortMarketPriceSnapshotIndex_mapping and stakerTokenShiftIndex_to_accumulativeFloatIssuanceSnapshotIndex_mapping can be overwritten by a different market, if batched_stakerNextTokenShiftIndex[market1]==batched_stakerNextTokenShiftIndex[market2]
This will lead to weird results in_calculateAccumulatedFloat, allocating too much or too little float.
function pushUpdatedMarketPricesToUpdateFloatIssuanceCalculations(
...
stakerTokenShiftIndex_to_longShortMarketPriceSnapshotIndex_mapping[ batched_stakerNextTokenShiftIndex[marketIndex] ] = stakerTokenShiftIndex_to_longShortMarketPriceSnapshotIndex_mappingIfShiftExecuted;
stakerTokenShiftIndex_to_accumulativeFloatIssuanceSnapshotIndex_mapping[ batched_stakerNextTokenShiftIndex[marketIndex] ] = latestRewardIndex[marketIndex] + 1;
batched_stakerNextTokenShiftIndex[marketIndex] += 1;
...
)
Recommend adding an index with marketIndex to the variables:
stakerTokenShiftIndex_to_longShortMarketPriceSnapshotIndex_mappingstakerTokenShiftIndex_to_accumulativeFloatIssuanceSnapshotIndex_mapping
Also consider shortening the variable names, this way mistakes can be spotted easier.
Confirmed by Jason of Float Capital: Yes, you are totally right, it should use the marketIndex since they are specific per market!
Embarrassed by this one!
Thank you for the report.
Fixed!!
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 the mappings stakerTokenShiftIndex_to_longShortMarketPriceSnapshotIndex_mapping and stakerTokenShiftIndex_to_accumulativeFloatIssuanceSnapshotIndex_mapping are keyed only by the shift index, not by marketIndex, so different markets can collide on the same key.
Impact
This could lead to weird results in _calculateAccumulatedFloat, allocating too much or too little float.
What the attacker needed
Two markets with same shift index value
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 mapping is like a dictionary that stores values under keys. Here, two dictionaries use only a shift index as the key, not the market identifier, so two different markets can end up writing to the same entry and overwrite each other's data. This can make the contract calculate the wrong amount of float tokens to issue.
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.