What is Layer 2?

FAQ on Layer 2

Written by David Gogel
Updated this week

What is Layer 2?

To significantly scale trading, dYdX and StarkWare have built a Layer 2 protocol for cross-margined perpetuals, based on StarkWare’s StarkEx scalability engine and dYdX’s Perpetual smart contracts. Traders can expect significantly lower gas costs, and in turn, much lower trading fees and minimum trade sizes.

StarkWare zkSTARKS technology is a form of ZK-Rollup technology that significantly increases dYdX’s trade settlement capacity, while still basing its security on the underlying Ethereum blockchain. StarkWare’s dYdX integration combines STARK proofs for data integrity with on-chain data availability to ensure a fully non-custodial protocol. Trades are settled on a Layer 2 system, which publishes Zero-Knowledge Proofs periodically to an Ethereum smart contract in order to prove that state transitions within Layer 2 are valid.

Why is dYdX moving to Layer 2?

Ethereum can process around 15 transactions per second (TPS), which is not enough to support the hypergrowth of DeFi, NFTs, and more. While Ethereum 2.0 will theoretically boost network speeds to 100,000 TPS, base layer scaling is still a while away. In the meantime, Layer 2 scaling solutions — in the forms of Rollups – free up Ethereum's base layer by offloading execution, leading to reduced gas costs and increased throughput without increasing network load. StarkWare’s dYdX integration combines STARK proofs for data integrity with on-chain data availability to ensure a fully non-custodial protocol.

Why did dYdX pick StarkWare as a Layer 2 solution for cross-margined Perpetuals?

In order to address immediate scaling issues, dYdX's engineering team did extensive due diligence on various Layer 2 solutions and other Layer 1s.

Overall, StarkWare was able to provide by far the best trading experience for our users in the shortest amount of time.

Other Layer 1s do not yet have the collateral base and building blocks such as wallets and developer tools that have made Ethereum successful. While other Layer 2 solutions, such as optimistic rollups, are potentially promising, they are not as battle tested, don’t offer quite the same product experience (very long withdrawal times), and cannot offer the same level of decentralization & cryptographic guarantees as ZK-Rollups.

Ultimately, we wanted a solution that could be live on mainnet within months, rather than an undefined period of time. StarkWare has already been running spot-trading exchanges in production, and has a stellar reputation in the industry around security and expertise.

Who is StarkWare?

StarkWare develops software to improve blockchain scalability by allowing any type of computation to move off-chain, using the Ethereum blockchain as a public immutable commitment layer. Focusing on scalability, StarkWare has the fastest in-class technology for asserting computational integrity via succinct, transparent, and post-quantum-secure proofs.

How do ZK-Rollups work?

ZK-Rollups are a type of Layer 2 scaling solution which bundle or “rollup” transactions into a single batch, which is then posted to the Ethereum blockchain alongside a proof attesting to the validity of the bundled transactions. Further, ZK-Rollups allow user balance data on Layer 2 to be available on Layer 1. Scalability benefits in rollups come from moving the expensive computational work off-chain, and only verifying the proof attesting to the validity of the state transition on-chain.

ZK-Rollups offer high throughput, instant finality (no danger of trade rollbacks), self-custody, and trading strategy privacy, and are therefore well suited to the high-value exchange use case. Further, in the event of a system hack, all the data needed to reclaim user's funds on an escape event is right there on the Ethereum blockchain - there are no additional trust assumptions.

Why did dYdX pick ZK-Rollups over Optimistic Rollups?

ZK-Rollups and Optimistic Rollups are both Layer 2 scaling solutions with several design tradeoffs. The critical difference between them is the type of proof each protocol relies on:

  • ZK-Rollups rely on Validity Proofs: a new state will always be presented to the blockchain with proof that it is in fact valid.

  • Optimistic Rollups rely on Fraud Proofs: a new state is assumed to be valid unless a proof of fraud is submitted to the blockchain within some timeframe.

ZK-Rollups have a few important advantages over Optimistic Rollups which are important for dYdX’s use case:

  • Security: In ZK-Rollups, the system is always in a valid state. In Optimistic Rollups, an invalid state may exist, until a fraud proof is submitted, and possibly indefinitely. An Optimistic Rollup system can be susceptible to a 51% attack as the cost of stealing funds is unrelated to the bounty size. Further, Optimistic Rollups can be vulnerable to more attack vectors due to their game theory based security model. In contrast, a ZK-Rollup system cannot be moved to an invalid state and funds cannot be stolen, irrespective of the bounty size.

  • Capital Efficiency: ZK-Rollups are 1000x more capital efficient for withdrawals than Optimistic Rollups.

  • Scalability: For the active trading use case, Optimistic Rollups result in higher costs due to on-chain resource consumption growing linearly with the volume of rollup transactions. In contrast, ZK-Rollups published on-chain data is used only to reflect the current user balances and therefore linear growth is tied to the growth of the positions in the batch.

What Privacy benefits are provided by moving to Layer 2?

StarkEx doesn't publish all transaction details on-chain, but rather just the balance changes. Therefore, privacy is greatly enhanced as traders do not need to worry about proprietary trading strategies being replicated or trading activity being monitored.

How will dYdX change/benefit from Ethereum 2.0?

Rollups today can offer over 100× scaling benefits without ETH 2. According to Vitalik Buterin, “if everyone moves to rollups, we will soon have ~3,000 TPS. Once ETH phase 1 comes along and rollups move to eth2 sharded chains for their data storage, we go up to a theoretical max of ~100,000 TPS. Eventually, phase 2 will come along, bringing eth2 sharded chains with native computations, which give us ~1,000-5,000 TPS.” While Ethereum 2.0 will theoretically boost network speeds to 100,000 TPS, base layer scaling is still a while away. There is increasing competition among various flavors in the rollup space with the trend being towards EVM compatibility and incorporating optionality for dApps depending on their needs.

Other Resources on Layer 2 and Rollups

You can read more about our authors here.

Did this answer your question?