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.
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
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
- Victim approves the vault contract to spend their tokens.
- Victim submits a transaction to create a market with themselves as the initial depositor.
- Attacker sees the pending transaction and front-runs it with their own market creation, using different parameters but the victim's address as depositor.
- 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.