Wrong funding index in settle when no base?
The settle function sets a user's last updated funding index to the current global index when their base position is zero, but a comment and the else branch indicate it should be the previous index. This could let first-time depositors avoid paying the first funding rate period.
Submitted by cmichel
The TracerPerpetualSwaps.settle function updates the user’s last index to currentGlobalFundingIndex, however a comment states:
”// Note: global rates reference the last fully established rate (hence the -1), and not the current global rate. User rates reference the last saved user rate”
The code for the else branch also updates the last index to currentGlobalFundingIndex - 1 instead of currentGlobalFundingIndex.
if (accountBalance.position.base == 0) {
// set to the last fully established index
// @audit shouldn't this be global - 1 like below?
accountBalance.lastUpdatedIndex = currentGlobalFundingIndex;
accountBalance.lastUpdatedGasPrice = IOracle(gasPriceOracle).latestAnswer();
}
The impact is that it might be possible for first-time depositors to skip having to pay the first funding rate period as the accountLastUpdatedIndex + 1 < currentGlobalFundingIndex check will still return false when the funding rates are updated the next time.
Recommend to check if setting it to currentGlobalFundingIndex or to currentGlobalFundingIndex - 1 is correct.
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 an off-by-one error: the code uses the current global funding index instead of the last fully established index (current minus one) when the base position is zero.
Impact
First-time depositors might avoid paying the first funding rate period, though the reporter hedges with 'might be possible'.
What the attacker needed
First-time depositor; base position is zero
The fix
The code should be corrected to use the last fully established index (current minus one) to match the comment and the else branch.
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.
Funding rates are periodic payments between traders. The code tracks which funding period a user has paid up to. When a user has no position, the code sets their marker to the current period instead of the previous one, which may let them skip a payment.
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.