Surveying Front-running attacks on Decentralized Exchanges - - PowerPoint PPT Presentation

surveying front running attacks on decentralized exchanges
SMART_READER_LITE
LIVE PREVIEW

Surveying Front-running attacks on Decentralized Exchanges - - PowerPoint PPT Presentation

Surveying Front-running attacks on Decentralized Exchanges Mingcheng & Sean 1 Goal Introduce a special kind of attck on decentralized exchange Try to propose a mitigation in the end 2 What is this? 3 Blockchain Introduction


slide-1
SLIDE 1

Surveying Front-running attacks on Decentralized Exchanges

Mingcheng & Sean

1

slide-2
SLIDE 2

Goal

2

  • Introduce a special kind of attck on decentralized

exchange

  • Try to propose a mitigation in the end
slide-3
SLIDE 3

What is this?

3

slide-4
SLIDE 4

Blockchain Introduction

blockchain is essentially a decentralized, distributed “database” (ledger) recording transactions, which cannot be altered retroactively without the alteration of all subsequent blocks.

  • Distributed
  • Decentralized
  • Non-centralized Trust
  • Immutable

4

slide-5
SLIDE 5

Blockchain workflow:

block and block generation

Blockchain consists of blocks.

5

Blockchain consists of blocks. Each block consists of a head and a body.

  • Body records transaction
  • Head includes the cryptographic hash (SHA256) of the body and the prior block
slide-6
SLIDE 6

Blockchain workflow:

block and block generation

6

Head: Time: Timestamp hashMerkleRoot: Hash of Body hashPrevBlock: Hash of previous Block Bits: Target Value Nonce: Magic Number …. Body: Transactions ... Data

slide-7
SLIDE 7

Blockchain workflow:

block and block generation

Head: Time: Timestamp hashMerkleRoot: Hash of Body hashPrevBlock: Hash of previous Block Bits: Target Value Nonce: Magic Number …. Body: Trasactions ... When SHA256(Head, Nonce++) < Bits (Target Max/Difficulty level) Data New Block

prev: H()

7

slide-8
SLIDE 8

prev: H()

Data Data

Blockchain workflow:

block and block generation

Blockchain consists of blocks. Each block consists of head and body.

  • Body records transaction
  • Head includes the cryptographic hash (SHA256) of the body and the prior block

Block Miner can get block reward and operation fee.

  • proof-of-work

8

slide-9
SLIDE 9

Blockchain workflow:

broadcast and census

9

  • If divergence, the chain has been seen by the majority will be validated

forever (7 confirmation).

slide-10
SLIDE 10

Blockchain workflow:

broadcast and census

10

  • If divert, the chain has been seen by the majority will be validated forever.
  • To keep consistent, bitcoin is designed to generate new block in average 10

mins by adjusting the difficulty level.

slide-11
SLIDE 11

Just ledger!! Wasting powers/resource!!

Problems with bitcoin blockchain:

11

slide-12
SLIDE 12

Add More Flavors: Ethereum Virtual Machine and Smart Contract

  • Lightweight computer programs executed on blockchain network without user

interaction when when certain conditions are made.

○ When someone wants to get a particular task done in Ethereum they initiate a smart contract with one or more peers.

  • The EVM provides better deterministic, terminable and isolated environment

for the smart contracts. (Like JVM)

○ EVM is turning complete

12

slide-13
SLIDE 13

The Etheruem Network

Smart Contract blockchain

13

slide-14
SLIDE 14

Smart Contracts blockchain Smart Contracts blockchain Smart Contracts blockchain

The Etheruem Network

Smart Contracts blockchain Smart Contracts blockchain Smart Contracts blockchain Smart Contracts blockchain

14

slide-15
SLIDE 15
  • Gas is a unit that measures the amount of computational effort that it will

take to execute certain operations.

○ Every line of code in Solidity requires a certain amount of gas to be executed.

Ethereum Gas and Fee

Gas Needed

  • Gas Limit >= Gas needed
  • Gas Fee = Gas Limit * Gas Price (Gwei)
  • Gas Fee is the maximum profit code runner can get

15

slide-16
SLIDE 16

The Scale of Ethereum Network

  • Ethereum is now the 2nd largest blockchain Network in th world

Market Cap = $ 20+ Billion

  • Frequent Transactions

Data Collected from etherscan https://etherscan.io/

slide-17
SLIDE 17

ICO on Ethereum = Fundraising

Initial Coin Offering Smart Contract Public Developer

Ether ERC20 Tokens Gather Piles of Ether

=> Money

17

(ERC20 is a Protocol for Etheurm Cryptocurrencies, it allow direct interaction bewteen parties)

slide-18
SLIDE 18

Functionalities of ERC20 Tokens

18

  • Toll: A token can act as a gateway to the Dapp.
  • Value Exchange: Tokens can help create an internal economic

system within the application.

  • Voting Rights: The tokens may also qualify the holders to have

certain voting rights.

slide-19
SLIDE 19

A Need for Exchange

TokenA TokenB TokenC Cryptocurrency Exchange

19

slide-20
SLIDE 20

Centralized Exchange

20

slide-21
SLIDE 21

Decentralized Exchange (DEXs)

Core Contract

1A for 2B _________ _________

Order Book

Matcher

The Exchange Smart Contracts

Maker TokenA

“I offer 1 TokenA for 2 TokenB”

_________ _________ _________

Taker

TokenB “I take the TokenA with 2 TokenB” Great Deal!

1A for 2B _________ _________

Proxy Contract 1A for 2B 21

slide-22
SLIDE 22

Decentralized Exchange

Core Contract Algorithmic Matcher Algorithmic Marketmaker

Maker TokenA “I want to buy TokenB with TokenA” Taker TokenB “I want to buy TokenA with TokenB”

Proxy Contract A ⇔ B With a Calculated Rate

22

Buy Order -> Price UP Sell Order -> Price DOWN

slide-23
SLIDE 23

Algorithmic DEX Example - Bancor

23

slide-24
SLIDE 24

Industry Designs are more complexed

24

Kyber Network

“Kyber: An On-Chain Liquidity Protocol,” Apr. 22, 2019. https://files.kyber.network/Kyber_Protocol_22_April_v0.1.pdf (accessed Apr. 13, 2020).

slide-25
SLIDE 25

Transaction Visibility

25

slide-26
SLIDE 26

Transaction Delay

2 Block Confirmations Generally Required at least 7 Confirmations

26

slide-27
SLIDE 27

Transaction Order is Not Guaranteed

Miner’s Block Confirmed Block Confirmed Block

TX1 TX2 TX3 TX4

TX5, 0.01 Gwei

Pending TX Queue

TX6, 0.03 Gwei TX7, 0.02 Gwei TX8, 0.15 Gwei

TX8 TX6

TX8 is more likely to be included in a block along the chain

27

slide-28
SLIDE 28

Profit Through Change TX Order

TX1: Buys 1000 TokenA 0.01 Gwei

Time

TokenA price goes up

Algorithmic Exchange

TX2: Buys 10 TokenA 0.02 Gwei TX3: Sells 10 TokenA 0.009 Gwei

Frontrunning Attack

28

slide-29
SLIDE 29

Another Frontrunning Scenario

DEX A

Decentralized Exchange

Sell 1 for 5 ETH

Decentralized Exchange

Buy 1 for 6 ETH

TX: Buy 5 from A and Sell to B 0.2 Gwei

DEX B

Bot

Confirm TX Pending TX 0.1 Gwei

29

slide-30
SLIDE 30

Another Frontrunning Scenario

DEX A

Decentralized Exchange

Sell 1 for 5 ETH

Decentralized Exchange

Buy 1 for 6 ETH TX: Buy 5 from A and Sell to B 0.2 Gwei

DEX B

Bot

Confirm TX Pending TX 0.1 Gwei

TX: Buy 5 from A and Sell to B 0.3 Gwei Bot*

30

slide-31
SLIDE 31

Another Frontrunning Scenario

DEX A

Decentralized Exchange

Sell 1 for 5 ETH

Decentralized Exchange

Buy 1 for 6 ETH TX... 0.2 Gwei

DEX B

Bot

Confirm TX Pending TX 0.1 Gwei

TX... 0.3 Gwei Bot* TX... 0.4 Gwei Bot**

31

slide-32
SLIDE 32

Another Frontrunning Scenario

DEX A

Decentralized Exchange

Sell 1 for 5 ETH

Decentralized Exchange

Buy 1 for 6 ETH TX... 0.2 Gwei

DEX B

Bot

Confirm TX Pending TX 0.1 Gwei

TX... 0.3 Gwei Bot* TX... n Gwei Bot**

...

Inefficiency to the blockchain And Slows down the confirmation of other TXs

32

slide-33
SLIDE 33

Scale of Frontrunning Bots

Philip Daian, Steven Goldfeder, et al. “Flash Boys 2.0: Frontrunning, Transaction Reordering, and Consensus Instability in Decentralized Exchanges”. ArXiv abs/1904.05234 .2019.

33

slide-34
SLIDE 34

Scale of Frontrunning Bots

Philip Daian, Steven Goldfeder, et al. “Flash Boys 2.0: Frontrunning, Transaction Reordering, and Consensus Instability in Decentralized Exchanges”. ArXiv abs/1904.05234 .2019.

34

slide-35
SLIDE 35

Frontrunning Vulnerability

35

TX are visible to everyone + TX takes time to get confirmed = Frontrunning Attack! + Pending TX can be reordered.

E

!

slide-36
SLIDE 36

Mitigation - Reduce Visibility

36

slide-37
SLIDE 37

Mitigation - Encryption

Core Contract

1A for 2B _________ _________

Order Book

Matcher The Exchange Smart Contracts

Maker TokenA “I offer 1 TokenA for 2 TokenB” Taker TokenB “I take the TokenA with 2 TokenB”

37

slide-38
SLIDE 38

Mitigation - Encryption

Core Contract

1A for 2B _________ _________

Order Book

Matcher The Exchange Smart Contracts

Maker TokenA “I offer 1 TokenA for 2 TokenB” Taker TokenB “I take the TokenA with 2 TokenB”

38

Key Map

Wallet Address Key Wallet Address Key

slide-39
SLIDE 39

Mitigation - Encryption

Core Contract

E for E _________ _________

Order Book

Trader The Exchange Smart Contracts

Maker TokenA “I offer ENCRYPT for ENCRYPT” Taker TokenB “I take the ENCRYPT with ENCRYPT

Matcher

E f

  • r

E _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Trusted Execution Environment (Inspired by Tesseart) Trade Info 39

Key

slide-40
SLIDE 40

Countering Algorithmic Frontrunning

TX1: Buys 1000 TokenA 0.01 Gwei

Time

TokenA price goes up

Algorithmic Exchange

40

slide-41
SLIDE 41

Countering Algorithmic Frontrunning

TX1: Buys ENCRYPT 0.01 Gwei

Time

??? price goes up

Algorithmic Exchange

??? ???

Create Transaction: 41

slide-42
SLIDE 42

DEX A

Decentralized Exchange

Sell 1 for 5 ETH

Decentralized Exchange

Buy 1 for 6 ETH

TX: Buy 5 from A and Sell to B 0.2 Gwei

DEX B

Bot

Confirm TX Pending TX 0.1 Gwei

42

Countering Frontrunning Bot

slide-43
SLIDE 43

Countering Frontrunning Bot

43

DEX A

Decentralized Exchange

Sell 1 for 5 ETH

Decentralized Exchange

Buy 1 for 6 ETH

TX: Buy E from A and Sell E to B 0.2 Gwei

DEX B

Bot

Confirm TX Pending TX 0.1 Gwei

Bot*

What is E and how many?

slide-44
SLIDE 44

Our current progress

  • Last semester, one of the research in the lab developed a blockchain network that

allows cross-chain exchange between Bitcoin and Ethereum

  • We got the task to survey current exchange, their vulnerabilities, and possible

mitigations

  • The lab group we work with are designing the protocl for communications between TEE

and Blockchain Network.

44