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.
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
depositofInsurance.solto make sure that the pool is sufficiently filled (poolHoldings>poolTarget) - call the function
executeTradeof Trader.solwith a minimal trade (possibly of value 0, see finding ”executeTradewith same trades”) executeTradecallsmatchOrders, which callsrecordTraderecordTradecallsupdateFundingRate(); (once per hour, so you have to be sure you do it in time before other trades trigger this)updateFundingRatecallsgetPoolFundingRategetPoolFundingRatedetermines the insurance rate, but because the insurance pool is sufficiently full (due to the flash loan), the rate is 0updateFundingRatestores the 0 rate viasetInsuranceFundingRate(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.
Marking this as medium risk as a front-runner could keep doing this for not paying any funding using a bot.
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
- Use a flash loan or large amount of tokens to call deposit of Insurance.sol and fill the pool above the target.
- Call executeTrade of Trader.sol with a minimal trade (possibly value 0).
- executeTrade calls matchOrders, which calls recordTrade.
- recordTrade calls updateFundingRate(), which calls getPoolFundingRate.
- getPoolFundingRate sets the insurance rate to 0 because the pool is sufficiently full.
- 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.