dYdX Now on Mainnet

StarkEx for Perpetual Trading

Published in
4 min readApr 6, 2021



Eight months ago we announced our cooperation with dYdX. Following the announcement, we worked closely with the dYdX team to port their perpetual contracts trading platform to run over StarkEx, our L2 scalability engine.

Supporting perpetual contracts is a major enhancement of StarkEx, as up until now it proved computational integrity only for spot trading. StarkEx will continue to evolve, to support lending, futures trading, and — imminently — NFTs. This is also the first time that StarkEx provides scalability in a ZK-Rollup mode (on-chain data) in production.

Feature Velocity thanks to Cairo

This system was developed using Cairo, our Turing-complete language scaling applications using STARKs. Cairo has been our platform of choice on Ethereum Mainnet starting with our Reddit Scaling Bakeoff (July 2020), and following with the upgrade of DeversiFi’s V3 a couple of months ago.

We considered the dYdX project to be an important test of Cairo’s maturity and expressiveness. We were delighted with the result and in particular with the feature velocity Cairo offers: complex business logic can be written with speed, and proofs of integrity can then be generated for it.

Benefits to dYdX Users

What does dYdX’s perpetual trading platform gain from StarkEx? What do its users gain?

High Scalability & Low Fees

We partnered with dYdX to simultaneously scale up their trading volume and decrease gas costs for their users. dYdX was spending a considerable amount on gas. This, in turn, meant that users had to pay high fees and trade subject to a minimum trade policy ($10K for limit orders), in order to pay for this gas.

StarkEx now gives dYdX the ability to build a sustainable business that can scale. Less money spent on gas → Less money that users need to pay → Lower fees and lower minimum trade size.

But scale and low gas costs are far from being the end of the story. As we built the system together with dYdX, we realized that StarkEx will give dYdX and its customers several other important benefits.

Instant Trading

When using StarkEx, dYdX considers a transaction settled once it enters the StarkEx transaction queue. This means that users can instantly submit subsequent transactions; no need to await the actual settlement of the transaction on-chain!

Cross-Margin Trading

Previously, dYdX offered trading in pairs: a collateral asset vs. a synthetic asset (for example: USDC-BTC, or USDC-ETH). This was for good reason: having a position that includes more than one synthetic asset makes the on-chain logic much more expensive to execute. The cost of executing a position scales roughly linearly with the number of synthetic assets in it.

However, with StarkEx as a scaling solution, such gas concerns belong to the past. This means traders can create positions that combine multiple synthetic assets, potentially putting all of their longs/shorts into a single position. This is merely another demonstration of the profound implications of L2 scalability: It not only makes executing your existing logic cheaper, it allows you to define better logic that was entirely infeasible to execute on-chain.

Real-time Oracle Prices

Perpetual trading requires a price feed for every synthetic asset. Prices are verified by oracles using STARK-compatible signatures, allowing prices to be used as soon as they are signed, rather than waiting for a transaction to be mined. This significantly reduces the latency of oracle price updates from minutes on Ethereum’s Layer 1 chain to fractions of a second on StarkEx. Furthermore, the price feed never has to appear on-chain (a commitment to the quorum of public keys being used suffices), thereby saving gas.

We’re currently using Chainlink’s oracle network to power secure price feeds for Layer 2. Chainlink has integrated with StarkWare to extend the Chainlink Network’s oracle functions to high-performance Layer 2 solutions. Shortly, other oracle providers such as MakerDAO may be used for some markets.

As more and more dApps adopt the benefits of L2 scaling, we hope that this is just the first of many projects to be powered by oracles.

Better Leveraging

Up until now, perpetual trading and lending platforms came in two flavors:

  • A centralized exchange, with real time off-chain oracle prices, which is able to support a high leverage ratio because rapid price changes will be detected sooner. The downside? The exchange took custody of the assets.
  • A dApp with trustless execution of trades on the blockchain, but — due to high gas prices — without real-time price feeds (and the high leverage enabled by those).

The StarkEx scalability engine can now offer the best of both worlds: continuous, real-time price feeds off-chain (once again, thus enabling higher leverage), and self-custody.


dYdX’s perpetual trading platform is now powered by StarkEx, which will allow them to scale and grow their business. Within roughly six months, we were able to support a business logic which is as complex as any executed on blockchains. In the process we learned that relying on trustless off-chain computation offers the ability to build not merely a more scalable system, but rather a better, richer and more complex trading platform.

Ohad Barta




STARK-Based Scaling Solutions