Skip to content
Business logic Audit finding Intermediate

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.

pauliax Follow

Originally disclosed on Code4rena

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

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

More by pauliax

View all

16 more disclosed reports, best first.

More from InsureDAO 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.