Vulnerable Pool initial rate.
A pool's initial token price is set when the pool is created at a predictable address, so an attacker can send tokens to that address before creation and skew the starting rate. This lets the attacker mint synthetic tokens at an artificially cheap price and profit from the resulting arbitrage.
Submitted by jonah1005
Pool is created in function createPoolADD. The price (rate) of the token is determined in this function. Since the address is deterministic, the attacker can front-run the createPoolADD transaction and sends tokens to Pool’s address. This would make the pool start with an extreme price and create a huge arbitrage space.
I assume pools would be created by the deployer rather than DAO at the early stage of the protocol. If the deployer calls createPoolADD and addCuratedPool at the same time then an attacker/arbitrager could actually get (huge) profit by doing this.
Assume that the deployer wants to create a BNB pool at an initial rate of 10000:300 and then make it a curated pool. An arbitrager can send 2700 BNB to the (precomputed) pool address and make iBNB 10x cheaper. The arbitrager can mint the synth at a 10x cheaper price before the price becomes normal.
poolFactory.sol L45-L62
pre_computed_dai_pool_address = '0x1007BDBA1BCc3C94e20d57768EF9fc0b1Cc2844b'
dai.functions.transfer(pre_computed_dai_pool_address, initial_amount*10).transact({'from': w3.eth.accounts[1]})
initial_amount = 10000*10**18
dai.functions.approve(pool_factory.address, initial_amount*10).transact()
base.functions.approve(pool_factory.address, initial_amount).transact()
pool_factory.functions.createPoolADD(initial_amount, initial_amount, dai.address).transact()
Recommend adding:
require(iBEP20(BASE).balanceOf(address(pool)) == 0 && iBEP20(token).balanceOf(address(pool)) == 0, "initial balance should be zero");
In createPoolADD
verifyfirst (Spartan) acknowledged:
Curated pools will only be added once the community feel a pool is deep enough in Liquidity. Other safeguard measures are also in place for this scenario which probably weren’t documented well enough.
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 pool creation function derives the initial rate from whatever token balances already exist at the deterministic pool address, without checking that the balances are zero beforehand.
Impact
An attacker could gain a large arbitrage profit by making the synthetic token up to ten times cheaper at pool creation, though the project says other safeguards exist and curated pools are only added once liquidity is deep enough.
What the attacker needed
Attacker can predict the pool address; attacker can front-run the creation transaction; attacker holds the base token to send
The fix
The pool creation function should require that both token balances at the pool address are zero before setting the initial rate.
How it was found
- Work out the pool address in advance from the deterministic deployment.
- Send tokens to that address before the creation transaction is mined.
- Let the deployer's createPoolADD transaction run, which sets an extreme starting price.
- Mint the synthetic token at the skewed cheap price and profit from arbitrage.
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 a new trading pool is created, its starting price is calculated from the tokens already sitting at its address. Because the address can be worked out in advance, someone can send tokens there first and change that starting price. The attacker then buys the pool's token cheaply before the price corrects itself.
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.