Skip to content
Business logic Audit finding Intermediate

avoid paying insurance

The insurance funding rate is set to zero when the insurance pool is sufficiently full, allowing an attacker to avoid paying insurance by temporarily filling the pool with a flash loan and triggering a minimal trade. This can be repeated to keep the rate at zero, causing insurance depositors to miss interest payments.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon

It’s possible to avoid paying insurance in the following way:

  • once per hour (at the right moment), do the following:
  • using a flash loan, or with a large amount of tokens, call deposit of Insurance.sol to make sure that the pool is sufficiently filled (poolHoldings > poolTarget)
  • call the function executeTrade of Trader.sol with a minimal trade (possibly of value 0, see finding ”executeTrade with same trades”)
  • executeTrade calls matchOrders, which calls recordTrade
  • recordTrade calls updateFundingRate(); (once per hour, so you have to be sure you do it in time before other trades trigger this)
  • updateFundingRate calls getPoolFundingRate
  • getPoolFundingRate determines the insurance rate, but because the insurance pool is sufficiently full (due to the flash loan), the rate is 0
  • updateFundingRate stores the 0 rate via setInsuranceFundingRate (which is used later on to calculate the amounts for the insurances)
  • withdraw from the Insurance and pay back the flash loan

The insurance rates are 0 now and no-one pays insurance. The gas costs relative to the insurance costs + the flash loan fees determine if this is an economically viable attack. Otherwise it is still a grief attack. This will probably be detected pretty soon because the insurance pool will stay empty. However its difficult to prevent.

See issue page for code referenced in proof of concept.

Recommend setting a timelock on withdrawing insurance.

raymogg (Tracer) confirmed but disagreed with severity:

Really like this exploit idea. Currently this is possible since the Trader is not whitelisted (eg there is no whitelisted relayer address). With this added, this exploit is no longer possible as only off chain relayers can place orders with the trader.

Disagree with the severity mainly due to the fact that executing this exploit once would only cause insurance funding to not be paid for a single hour. For insurance funding to never be paid, you would have to time this transaction as the first transaction on each and every hour. This would quickly be noticed. The only affect on this would be insurance depositors miss interest payments for a few periods.

cemozerr (Judge) commented:

Marking this as medium risk as a front-runner could keep doing this for not paying any funding using a bot.

The original report as published on Code4rena, by gpersoon. 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 insurance funding rate is set to zero whenever the pool holdings exceed the target, without any time lock or restriction on who can trigger the update, allowing manipulation via temporary capital.

Impact

Insurance funding can be set to zero for an hour, causing insurance depositors to miss interest payments; repeating this every hour could keep the rate at zero, though it would likely be noticed.

What the attacker needed

Access to flash loan or large capital; ability to call deposit and executeTrade; timing within the hour before other trades

The fix

The project should add a timelock on withdrawing insurance and whitelist relayers so only off-chain relayers can place orders with the trader.

How it was found

  1. Use a flash loan or large amount of tokens to call deposit of Insurance.sol and fill the pool above the target.
  2. Call executeTrade of Trader.sol with a minimal trade (possibly value 0).
  3. executeTrade calls matchOrders, which calls recordTrade.
  4. recordTrade calls updateFundingRate(), which calls getPoolFundingRate.
  5. getPoolFundingRate sets the insurance rate to 0 because the pool is sufficiently full.
  6. updateFundingRate stores the 0 rate via setInsuranceFundingRate.

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.

Insurance in this system is a fee that traders pay into a pool. The fee rate is calculated based on how full the pool is: if the pool is full enough, the rate becomes zero. An attacker can borrow a large amount of tokens temporarily (a flash loan), deposit them to fill the pool, make a tiny trade that updates the fee rate to zero, then withdraw the tokens and repay the loan. This way, no insurance fees are charged for that period.

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 gpersoon

View all

47 more disclosed reports, best first.

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