Index compensate is 0 when totalLiquidity() is enough to cover the whole amount
In the IndexTemplate contract's compensate function, when the requested amount exceeds the value but is still within total liquidity, the compensated variable is never assigned and stays at zero. The function then calls offsetDebt with zero, so the debt offset is not applied as intended.
Submitted by pauliax
In IndexTemplate, function compensate, When \_amount > \_value, and <= totalLiquidity(), the value of \_compensated is not set, so it gets a default value of 0:
if (_value >= _amount) {
...
_compensated = _amount;
} else {
...
if (totalLiquidity() < _amount) {
...
_compensated = _value + _cds;
}
vault.offsetDebt(_compensated, msg.sender);
}
But nevertheless, in both cases, it calls vault.offsetDebt, even when the\_compensated is 0 (no else block).
Recommended Mitigation Steps
I think, in this case, it should try to redeem the premium (withdrawCredit?) to cover the whole amount, but I am not sure about the intentions as I didn’t have enough time to understand this protocol in depth.
oishun1112 (Insure) confirmed and resolved:
Right. totalLiquidity = underlyingValue + pendingPremium.
I will discuss how to fix this issue with my team
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 missing assignment: the branch where the amount is larger than the value but covered by total liquidity never sets the compensated amount, leaving it at its default of zero.
Impact
When the amount is above the value but within total liquidity, the debt offset is called with zero, so the intended compensation does not happen.
What the attacker needed
None
The fix
The reporter suggests redeeming the premium to cover the whole amount, but notes uncertainty about the protocol's intent; the team said it would discuss a fix.
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.
A smart contract is a program that runs on a blockchain and holds money. This one has a function that is meant to pay off part of a debt, but in one situation it forgets to calculate the amount and passes zero instead, so the debt is not reduced even though the contract has enough funds.
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.