Skip to content
Business logic Audit finding Intermediate

Initial pool deposit can be stolen

The market creation function allows an attacker to front-run a legitimate market creation and create a market with different parameters, using the victim's pre-approved tokens as the initial deposit. The victim's tokens are transferred into the attacker-created market and effectively lost.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by WatchPug

Note that the PoolTemplate.initialize function, called when creating a market with Factory.createMarket, calls a vault function to transfer an initial deposit amount (conditions[1]) from the initial depositor (_references[4]):

// PoolTemplate
function initialize(
     string calldata _metaData,
     uint256[] calldata _conditions,
     address[] calldata _references
) external override {
     // ...

     if (_conditions[1] > 0) {
          // @audit vault calls asset.transferFrom(_references[4], vault, _conditions[1])
          _depositFrom(_conditions[1], _references[4]);
     }
}

function _depositFrom(uint256 _amount, address _from)
     internal
     returns (uint256 _mintAmount)
{
     require(
          marketStatus == MarketStatus.Trading && paused == false,
          "ERROR: DEPOSIT_DISABLED"
     );
     require(_amount > 0, "ERROR: DEPOSIT_ZERO");

     _mintAmount = worth(_amount);
     // @audit vault calls asset.transferFrom(_from, vault, _amount)
     vault.addValue(_amount, _from, address(this));

     emit Deposit(_from, _amount, _mintAmount);

     //mint iToken
     _mint(_from, _mintAmount);
}

The initial depositor needs to first approve the vault contract for the transferFrom to succeed.

An attacker can then frontrun the Factory.createMarket transaction with their own market creation (it does not have access restrictions) and create a market with different parameters but still passing in _conditions[1]=amount and _references[4]=victim.

A market with parameters that the initial depositor did not want (different underlying, old whitelisted registry/parameter contract, etc.) can be created with their tokens and these tokens are essentially lost.

Recommended Mitigation Steps

Can the initial depositor be set to Factory.createMarket’s msg.sender, instead of being able to pick a whitelisted one as _references[4]?

oishun1112 (Insure) confirmed:

https://github.com/code-423n4/2022-01-insure-findings/issues/224

The original report as published on Code4rena, by cmichel. 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 market creation function does not verify that the initial depositor is the caller, allowing anyone to specify any address as the depositor and pull their approved tokens.

Impact

The victim's initial deposit tokens are transferred into a market they did not intend to create and are essentially lost.

What the attacker needed

Victim approves vault for token transfer; attacker can front-run transaction

How it was found

  1. Victim approves the vault contract to spend their tokens.
  2. Victim submits a transaction to create a market with themselves as the initial depositor.
  3. Attacker sees the pending transaction and front-runs it with their own market creation, using different parameters but the victim's address as depositor.
  4. The attacker's transaction executes first, pulling the victim's tokens into the attacker-created market.

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.

When someone creates a market, they first approve the system to take some of their tokens as a deposit. An attacker can watch for this and quickly create their own market first, telling the system to take the victim's tokens for that market. The victim's tokens end up in a market they did not intend to create, and they cannot get them back.

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 cmichel

View all

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