1/ πŸ› πŸ“ πŸ₯ž πŸ†š 2️⃣

🚨 Smart Contract Bug found in Pancake V2 🚨

πŸ›: Pancake new router is incompatible with Pancake LP implementation.

Users may get __revert__ txs upon __swaps__ due to the bug.

Vulnerability was reported to @PancakeSwap team asap.

Thread below πŸ‘‡
2/ After @PancakeSwap V2 announcement, we have been working on supporting the new V2 pools.

βœ… As with our security standard, we always perform smart contract review and testing, to ensure our users’ safety.

❗️ We have found and informed the @PancakeSwap team on the issue.
3/ πŸ› So, what is the actual bug?

The question comes down to: what changes from Pancake V1 to V2?

1️⃣ Swap fees: 0.2% ➑️ 0.25%
2️⃣ Fee distribution to LPs, to dev address

Below are the router __getAmountOut__ implementations (V1 & V2). The difference lies in the numbers. ImageImage
4/ On the LP pair side, __swap__ function also encodes the swap fee for constant product calculation. Here are the V1 and V2 implementation: ImageImage
5/ πŸ‘€ At first glance, the implementation seems correct, as the parameters reflect 0.2% and 0.25% in the old and new versions, respectively.

However, in Solidity, there is no floating-point.

All divisions will be rounded down ⬇️.
6/ So, __balance0Adjusted__ and __balance1Adjusted__ can have their actual values truncated, reverting the next __require__ statement when checked for the constant product monovariant. Image
7/ Instead of performing divisions, it’s mostly always better to compare the cross-multiplication. This should be the correct implementation: Image
9/ So, the next question is: How does this affect #AlphaHomora?

#AlphaHomora performs multiple complex txs into one, including swaps. This means that users who open new positions, refill existing positions, and also liquidations may get revert txs.
10/ πŸ’¦ As liquidation is one of the core security features of #AlphaHomora to keep the protocol solvent, this bug can cause security loopholes in our system.

Even if the chances of tx reversions are not high, security is one of @AlphaFinanceLab’s top priorities.
11/ After we’ve found the bug and made sure it’s reproducible, we immediately contacted @PancakeSwap team to inform them re:vulnerability.

They immediately responded and confirmed the vulnerability within minutes.
12/ To fix the issue, a new factory, router, and LP pairs need to be deployed.

We’ll be working towards supporting these new pools and again performing checks and tests on the new implementation.

πŸ›„ And so let the new migration begin...

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Nipun | Alpha

Nipun | Alpha Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @nipun_pit

28 Mar
1/ πŸ“– Just read @Uniswap v3 whitepaper πŸ¦„ and wanted to share some thoughts.

πŸ‘€ There are some pretty neat tricks in the paper that we @AlphaFinanceLab also use. πŸ‘€

Thread below πŸ‘‡
2/ Overall, πŸ¦„ V3 is a huge upgrade from and much more complex than V2. V3 introduces:

πŸ‘©β€πŸ’» User Flexibility: Users can supply within a specified price range.
πŸ’» Protocol Flexibility: Configurable swap fee & governance fee
πŸ’‘ Features: Built-in TWAP & liquidity oracle
3/ The most interesting feature is that users can supply liquidity to any desired price range, which then enables the __Concentrated Liquidity__ feature, as advertised.

πŸ€” This is a challenge in terms of technical implementation, since gas limits may explode if done naively.
Read 18 tweets
18 Dec 20
🚨 1/ The recent @warpfinance hack is the result of using vulnerable @UniswapProtocol πŸ¦„ LP token prices.

The attacker was able to drain ~$7.8M worth of $DAI for smaller collateral.

#AlphaHomoraV2 uses a different LP pricing method that is safe against such attack vector. πŸ‘‡
2/ The LP token pricing used is prone to the typical flash loan sandwich attack vector:

➑️ Flash loan and skew reserves
➑️ Fake LP price
➑️ Repay flash loan
➑️ Profit

So, how do we price an LP token in an unmanipulatable way?

Answer: **FAIR LP PRICING**
3/ What makes the **FAIR LP PRICE** safe from attacks?

There are two major components to the fair LP price that make the price safe:

β‘  Fair Asset Prices
β‘‘ Fair Asset Reserves
Read 9 tweets
6 Nov 20
1/ Last week, there has been a number of flash loan-related scenarios (and potential scenarios): @harvest_finance, @MakerDAO, @iearnfinance.

So, here’s a short thread on flash loans. πŸ‘‡
2/ Flash loan lets anyone borrow a very large amount of assets (as long as the amount + fee are paid back in the same transaction), which can be used to temporarily skew asset prices or balances.
3/ A typical flash loan attack pattern is a form of sandwich attack:
(1) Skew price/balance
(2) Main protocol uses the skewed price/balance (e.g. to open a position, deposit into AMM all at bad prices)
(3) Un-skew price/balance
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!