Skip to content
Business logic Audit finding Intermediate

Admin of the index pool can withdrawCredit() after applyCover() to avoid taking loss for the compensation paid for a certain pool

The index pool admin can withdraw credit from a pool after a cover incident is applied, avoiding responsibility for compensation and shifting the loss to the pool's liquidity providers. This allows the index pool to earn premium without paying its fair share.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

In the current implementation, when an incident is reported for a certain pool, the index pool can still withdrawCredit() from the pool, which in the best interest of an index pool, the admin of the index pool is preferred to do so.

This allows the index pool to escape from the responsibility for the risks of invested pools.

Making the LPs of the pool take an unfair share of the responsibility.

Proof of Concept

  • Pool A totalCredit = 10,000
  • Pool A rewardPerCredit = 1
  • [Index Pool 1] allocates 1,000 credits to Pool A:
  • totalCredit = 11,000
  • indicies[Index Pool 1] = 1,000
  • After a while, Pool A rewardPerCredit has grown to 1.1, and applyCover() has been called, [Index Pool 1] call withdrawCredit() get 100 premium
  • totalCredit = 10,000
  • indicies[Index Pool 1] = 0
  • After pendingEnd, the pool resume(),[ Index Pool 1] will not be paying for the compensation since credit is 0.

In our case, [Index Pool 1] earned premium without paying for a part of the compensation.

Recommendation

Change to:

https://github.com/code-423n4/2022-01-insure/blob/19d1a7819fe7ce795e6d4814e7ddf8b8e1323df3/contracts/PoolTemplate.sol#L416-L421

function withdrawCredit(uint256 _credit)
    external
    override
    returns (uint256 _pending)
{
    require(
        marketStatus == MarketStatus.Trading,
        "ERROR: WITHDRAW_CREDIT_BAD_CONDITIONS"
    );
    IndexInfo storage _index = indicies[msg.sender];

oishun1112 (Insure) confirmed and disagreed with severity:

to call PoolTemplate: withdrawCredit(), someone has to call IndexTemplate: withdraw(), set(), and adjustAlloc().

set() is onlyOwner, so we assume it’s fine() adjustAlloc() is public. this clean up and flatten the credit distribution. withdraw() is public. this reduce totalCredit to distribute. when exceed upperSlack, call adjustAlloc().

We should lock the credit control when pool is in payout status. This implementation, still allows small amount of withdraw, for users who were requested Withdraw.

oishun1112 (Insure) commented:

We have fixed with PVE02 (Peckshield audit) issue together.

The original report as published on Code4rena, by WatchPug. 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 the withdrawCredit function does not check whether the pool is in a payout or cover-applied state, allowing credit to be withdrawn after applyCover.

Impact

The index pool can earn premium without paying for part of the compensation, causing the pool's LPs to take an unfair share of the loss.

What the attacker needed

Index pool has credit in a pool; a cover incident is applied to that pool; index pool admin acts before compensation

The fix

The project fixed this together with a Peckshield audit issue, likely by locking credit control when the pool is in payout status.

How it was found

  1. Pool A has totalCredit 10,000 and rewardPerCredit 1.
  2. Index Pool 1 allocates 1,000 credits to Pool A, making totalCredit 11,000.
  3. After rewardPerCredit grows to 1.1 and applyCover is called, Index Pool 1 calls withdrawCredit and receives 100 premium.
  4. totalCredit returns to 10,000 and Index Pool 1's credit becomes 0.
  5. After pendingEnd, the pool resumes and Index Pool 1 pays nothing toward compensation because its credit is 0.

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.

An index pool invests in other pools. When a pool has a problem and needs to pay compensation, the index pool can quickly take its money out before the compensation is finalised. This means the people who actually put money into the pool lose more, while the index pool keeps its profit.

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 WatchPug

View all

197 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.