Coin Spotlight: Loopring

An open protocol for building decentralized exchanges

cain larpo
Coinplan Insights
8 min readApr 26, 2019

--

What is Loopring?

Loopring Foundation is a blockchain research organization focused on decentralized trading protocols. The open-source Loopring Protocol provides a fundamental building block for non-custodial, orderbook-based exchanges and other applications that incorporate trustless token trading.

The project consists of two main parts:

1. Loopring Protocol: an open source set of smart contracts that handles trading logic and settlement.

2. Loopring Relayer: an off-chain system of servers for communicating and matching orders that ultimately pass through to the protocol for settlement.

Currently deployed atop Ethereum, Loopring lowers the technical and economic barriers for any person or project building decentralized exchanges (DEXs). Beyond ‘traditional’ token types such as ERC20, Loopring also allows for trading of security tokens, as the protocol supports the ERC1400 standard.

Loopring is blockchain agnostic and can be deployed atop any smart contract-capable platform. Besides Ethereum, there have been versions of the smart contracts deployed on NEO and Wanchain.

How Loopring Works

In previous versions of the protocol (v1 and v2), orders were hosted, communicated, and matched off-chain, with only the actual settlement (swapping of tokens) performed on-chain. This hybrid approach — only using the blockchain for mission-critical tasks — allows for a faster and cost-efficient experience by bypassing Ethereum limitations where it can.

With that view, and to take scalability orders of magnitude higher, the recently released Loopring Protocol 3.0 does even more off-chain — including trade settlement itself — while still remaining non-custodial and trustless.

V3 achieves this by using zero-knowledge proofs (ZKPs); computations which can be certified for correctness without knowledge of the actual data or execution. These proofs are verified on the Ethereum blockchain.

One design decision that is consistent across all 3 versions is that a DEX within Loopring is not necessarily one monolithic ‘thing’, nor necessarily operated by one team. Instead, Loopring makes it possible to divide these duties:

  1. A frontend (referred to as a GUI or Wallet) — where users interact with the exchange and place orders.
  2. A backend (referred to as a Relay or Ring-Miner) — hosts orderbook and matches trades sent to it from a Wallet.
How Wallets and Relays interact to become a DEX

Combined, a Wallet + Relay is effectively a DEX. By allowing these relationships to be configurable, liquidity can be shared at 2 levels: multiple Wallets to a Relay, and between Relays. Wallets and Relays can share trading fees along any lines they see fit and agree on.

Loopring provides an open relay implementation, thus, if desired, a DEX can simply concern itself with building a frontend, acquiring users, etc., while the matching engine is outsourced. This is referred to as Matching-as-a-Service.

Loopring 2.X Mechanics

Protocol 2.0 series works as follows:

  1. A trade order is placed by a user from within her own wallet. The tokens are not locked and do not leave the user’s wallet while the order is being processed.
  2. Loopring smart contracts are authorized by the wallet to access information about the token type and handle the amount specified by the user.
  3. The order is broadcasted to the network with a unique digital signature to one or more Relays.
  4. Relay(s) update their order books with the new order and forward the order to other Relays with whom they share liquidity.
  5. Relays match the order with (multiple) other orders. This is called ring-matching. The order is partially or fully filled by the ring-matcher at the stated exchange rate or better. [See order-rings below].
  6. The order-ring is submitted to the Loopring smart contracts which verify data provided by ring-matchers, settle the order, and transfer tokens between users while paying the ring-matcher and wallet their due fees.

Technologies

Order Rings (Combinatorial matching)

Order rings allow for ring-matching: a process where a series of disparate orders across different trading pairs are linked together to settle.

Order-ring with 3 orders

Loopring orders are based on a model called Unidirectional Order Model or UDOM. UDOM orders are defined by token exchange rate requests. Instead of matching on a single order book, this model can pair up to 16 orders in circular, combinatorial trade. This increases overall liquidity and allows for price improvement.

Dual Authoring (Anti-Front running)

In a decentralized exchange context, front-running is when someone (usually a bot) tries to place trades before other transactions that they’ve seen in the pending transaction pool (mempool). This can be achieved by specifying a higher transaction fee (gas price).

If the front-runner happens to be a miner himself, he can be especially malicious and order pending transactions as he desires. This is a pernicious problem for open DEXs.

Ring-signing Process in Loopring (1.2) using Dual Authoring

Loopring’s solution, Dual Authoring, involves setting up two levels of authorization for orders: one for settlement and one for mining. By inserting an extra dual authoring key, it prevents stealing rings and stealing orders while still ensuring the settlement of rings can be done in a single transaction, and orders can be shared.

Loopring Protocol 3.0

Protocol 3.0 has two main benefits:

  • Much higher throughput & lower costs.
  • Apparent immediate settlement.

In 3.0, data such as account balances and trade history are kept off-chain in Merkle trees. By doing so, trades can be settled between users just by updating the tree off-chain, with no need for slow, expensive token transfers on-chain.

Loopring does not give up security guarantees by doing this. ZKPs assure that what was claimed to be true and executed, is true and executed. The protocol is still 100% non-custodial and fully secure for end users.

With all computations done off-chain, you can speak to the Ethereum chain much less frequently, and with lighter loads. DEXs only submit the aforementioned proof to Ethereum, which certifies everything that a DEX has done off-chain is correct. With zkSNARKs, a proof can be checked efficiently (in milliseconds) by Loopring’s smart contract built to verify proofs.

*Doesn’t include off-chain proof generation cost. Very conservative estimate is $0.005; likely much cheaper.

Throughput can be increased to ~1,000 trades/second without on-chain data availability in the near term.

In 3.0, there is a new ecosystem participant that is introduced to handle the transactions in zero knowledge, the operator. The operator is responsible for creating, committing and proving blocks.

Blocks are not Ethereum blocks in this sense, but chunks of DEX-related ‘work’, such as trade settlements. A block changes the Merkle tree from the existing state to the new state by doing the state changes required by the work in the block. The correctness of a block needs to be proven and submitted to the Ethereum chain. This is done by creating a ZK proof.

LRC Utility

LRC is the Loopring protocol’s utility token. It is an ERC20 token that is used and has benefits within the network.

Fees

While any token can be used to pay trading fees to DEXs built on Loopring, LRC has preferential treatment.

When a trader pays fees to a DEX, a portion of this fee income is captured by the protocol — this is called the burn rate. All captured LRC is burnt, and all non-LRC is converted into LRC then burnt.

Fee model in Loopring protocol 2.0. e.g. Trader paying a 100 BNB fee with 20% burn rate.

Depending on which token is used as a fee, a different portion is captured. LRC has the lowest burn rate, while other tokens may reside in 3 tiers with higher burn rates. Lower burn rates are preferred because that means Wallets + Relays keep more of their income, and can thus charge lower fees to traders to begin with.

Default settings. Eventually will be configurable by LRC holders.

LRC can also be burnt by token projects (or anyone) to move a certain token to preferred tiers. More can be read about the fee model here.

Staking

In protocol 3.0, an exchange can stake LRC. Anyone, not just owner/operators, can add to the stake of an exchange. Withdrawing the stake is only allowed when the exchange is properly shut down and all user balances are withdrawn.

The stake ensures that the exchange behaves correctly. This is done by

  1. burning the stake if a block isn’t proven in time;
  2. only allowing the stake to be withdrawn when the exchange is shut down by automatically returning the funds of all its users.

Exchanges with a large stake have a lot to lose and nothing to gain by breaking the rules because the operator can never steal funds for itself.

Staking is not mandatory because security is there by default, however, staking does guard users against data-availability problems. When data availability isn’t used (not all state transition data is stored on-chain), even if the Merkle tree cannot be rebuilt by anyone but the operator, staking ensures all funds will be returned to users, otherwise the exchange loses its stake.

Near Term Roadmap

  • April 2019 (next week): Lightcone relay open
  • May 2019: LRC token contract upgrade
  • May 2019: Dolomite.io launching
  • May 2019: Oedax implementation
  • June 2019: 3.0 deployed on testnet
  • August 2019: 3.0 deployed to Ethereum mainnet

Coinplan is very excited to feature Loopring because they are building a true open-source protocol that offers open participation and allows anyone to build and operate a DEX. Anyone can join a network to share liquidity, or create and manage their own DEX network. They believe that sharing liquidity greatly improves the competitive landscape.

You can view LRC inside Coinplan’s Alliance Portfolio here.

To learn more about Loopring, please take a look at these helpful links:

Loopring Website
Loopring Medium
Twitter
GitHub
Loopring 3.0 Technical Design

Follow Coinplan on our Website, Twitter, or Medium for the latest updates on our development!

--

--