Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 2015-01-29-How-BitShares-Prevents-Front-Running.md #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions _posts/2015-01-29-How-BitShares-Prevents-Front-Running.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ redirect_from: "/article/2015/1/29/Why-BitShares-Front-Runs-Orders/"
---
Front running happens when a broker executes his own orders prior to executing the orders of his customers. This can be extremely profitable to the broker which can buy a stock just before a large buy order pushes the price up and then sell the stock just before a large sell order pushes the price down. This can occur any time one market participant has the ability to see orders from other participants and insert new orders in front of them. BitShares has an open order book and all transactions are broadcast for all to see with up to 10 seconds notice. This means that anyone can see your order and change their order to maximize their own profit. To protect users BitShares uses a *you get what you asked for* (YGWYAF) market engine that produces the same result for the market participants as perfect front running. This article explains why.

Before going any further about front running, I would like to describe BitShares from different perspective. Imagine that no one could see the order book except the broker. The broker's job is to know everyone and what they want. The traders know that the fastest, most convenient way to get their order matched is to go through the broker rather than attempt to find someone on their own. So the broker takes requests from everyone and attempts to meet them without telling the traders how he filled their order. All the clients know is that the broker sold them what they were looking for at the price they agreed to. The broker makes money by buying low and selling high. This is in effect what the BitShares blockchain does. It is the broker that buys the lowest offers and sells to the highest bids while pocketing the change. There is nothing morally wrong with leveraging your knowledge of market demands and taking actions that enable you to profit. People do this every day when they notice an arbitrage opportunity.
Before going any further about front running, I would like to describe BitShares from different perspective. Imagine that no one could see the order book except the broker. The broker's job is to know everyone and what they want. The traders know that the fastest, most convenient way to get their order matched is to go through the broker rather than attempt to find someone on their own. So the broker takes requests from everyone and attempts to meet them without telling the traders how he filled their order. All the clients know is that the broker sold them what they were looking for at the price they agreed to. The broker makes money by buying low and selling high. This is in effect what the BitShares blockchain does. It is the broker that buys the lowest offers and sells to the highest bids. The change is burned and the effect is profit for all shareholders equally. There is nothing morally wrong with leveraging knowledge of market demands and taking actions that enable profit. People do this every day when they notice an arbitrage opportunity.

# Example of Front Running

When Sam places a large order he looks at the order book and sees that he can get 10 coins for $1, 20 coins for $2, and 20 coins for $3. Because he wants to buy 50 coins he knows that it will cost him $10 + $40 + $60 or $110 for 50 coins; therefore, he places an order to buy 50 coins with a maximum price of $3 and fund it at $110. In a traditional exchange the orders execute on a first come, first serve basis so assuming no other orders were placed the order would have been fully filled and Sam would have received 50 coins.
When Sam places a large order he looks at the order book and sees that he can get 10 coins for $1, 20 coins for $2, and 20 coins for $3. Because he wants to buy 50 coins he knows that it will cost him $10 + $40 + $60 or $110 for 50 coins; therefore, he places an order to buy 50 coins with a maximum price of $3 and funds it at $110. In a traditional exchange the orders execute on a first come, first serve basis so assuming no other orders were placed the order would have been fully filled and Sam would have received 50 coins.

If the exchange wanted to it could front run Sam's order by executing an order to buy the cheap coins a $1 and $2 and then turn around and sell them back to Sam at $3. In theory anyone between Sam and the market engine could "front run" him. This means any peer on the P2P network, his ISP, or his wallet provider. Even Sam's coworkers can front run him if they can observe him filling out his order form.
If the exchange wanted to it could front run Sam's order by executing an order to buy the cheap coins at $1 and $2 and then turn around and sell them back to Sam at $3. In theory anyone between Sam and the market engine could "front run" him. This means any peer on the P2P network, his ISP, or his wallet provider. Even Sam's coworkers can front run him if they can observe him filling out his order form.

On the BitShares block chain orders are grouped into blocks every 10 seconds which means all orders are received “at the same time”. This means that a bot could see the new order and simultaneously create another order that will cancel offers for $1 and $2 and move them to $3. Both of these transactions would execute and update the order book before order matching began. The end result would be that the seller would sell 36.7 coins at $3 each for a profit of 13.3 coins and Sam got less than he expected.

# Solutions to Front Running

In our example the average user ended up getting less than they expected and the profits accrued to the advanced user who was able to run a bot or any one that could get their order in first. Their are many ways people have suggested for solving this, but it all boils down to timing. Some people suggest “randomizing” the order in which transactions are processed every block. Others have suggested a two-phase commit and reveal process. All of these strategies have significant shortcomings.
In our example the average user ended up getting less than they expected and the profits accrued to the advanced user who was able to run a bot or any one that could get their order in first. People have suggested solving this in many ways, but it all boils down to timing. Some suggest “randomizing” the order in which transactions are processed every block. Others have suggested a two-phase commit and reveal process. All of these strategies have significant shortcomings.

## Randomizing Orders

Expand Down