Checkpoints on DerivaDEX

Published by · Jan 24, 2024

test

One of the key challenges for decentralized exchanges, particularly exchanges that seek to support high-volume and high-frequency trading, is to increase transaction throughput without increasing cost (or sacrificing security). Most solutions require compromise on one of these metrics.

DerivaDEX maximizes for the dual goals of security and performance by uniting an off-chain network of operators, secured by Intel SGX, with on-chain Ethereum contracts for deposits, withdrawals, and checkpointing. DerivaDEX checkpoints utilize both cryptographic and hardware security tools to achieve a high degree of security and transparency around the exchange state, without sacrificing performance.

In the DerivaDEX UI, you will see the option to “submit checkpoint” when you open the withdrawal management panel. This article explains what checkpoints are, why they are so important to DerivaDEX, and how they can be submitted.

The second section of this article delves deeper into the technical details of checkpointing.

Checkpointing records exchange state on-chain

Checkpointing is the process by which the exchange state data is stored, in an extremely compressed fashion, on the Ethereum blockchain. This enables the contracts to correctly process certain actions that are dependent on the exchange state, for example, withdrawals.

The DerivaDEX operators agree about the state of the exchange every “epoch” and create “checkpoints”. These checkpoints happen very regularly. Operators achieve a majority consensus on the checkpoint, meaning a majority agree about the exact state of the exchange.

Not every checkpoint is committed to the Ethereum DerivaDEX contracts, but every checkpoint can be comitted. Users can call the checkpointing function anytime from the DerivaDEX exchange UI, and it can also be called directly by interacting with the on-chain contracts.

Checkpointing is required for withdrawals

Withdrawals are a 3-step process. A withdrawal is first initiated, which moves collateral out of a users "free collateral" and puts it into a pending state on the exchange. At this point, it cannot be used to back positions or orders. Then, at least one on-chain checkpoint must occur. After at least one on-chain checkpoint has passed, all users who previously had pending funds for withdrawal are able to withdraw the pending collateral to their externally owned wallet (EOA).

checkpointing Checkpointing overview

Checkpoints in Detail

This section delves into some more technical specifics of the DerivaDEX checkpointing system.

DerivaDEX conducts matching and execution off-chain to enhance efficiency and scalability, enabling faster processing and reduced transaction costs compared to on-chain execution.

Despite the off-chain operations, ensuring that the off-chain state aligns with the on-chain Ethereum data ensures platform integrity, and prevents issues such as users withdrawing more collateral than available. Additionally, verifying the on-chain state allows external applications to gain insight into the off-chain components of DerivaDEX, fostering new product development and enhancing security through increased transparency and monitoring.

DerivaDEX uses both features of Intel SGX as well as cryptographic tools in order to support this required alignment between on and off-chain state.

Intel SGX forms the backbone of what we refer to as expected instant finality in DerivaDEX. This principle revolves around the high assurance that once transactions are validated within DerivaDEX’s localized SGX enclave consensus, they are almost certainly final. Achieving similar levels of finality would typically require a far larger group of unsecured nodes (which would reduce the execution speed for all transactions, increasing system-wide latency). By constraining individual nodes using low-overhead trusted hardware (Intel SGX), DerivaDEX efficiently emulates the strong consistency characteristic of centralized exchanges, rather than the eventual consistency of blockchain systems, without sacrificing performance. The eventual on-chain verification of checkpoints harnesses Ethereum’s security to safeguard DerivaDEX’s streamlined state consensus in disaster scenarios.

State Storage and Updates

The exchange's state, including trading data, account balances, and other key information, is maintained in a Sparse Merkle Tree (SMT). This structure is ideal for efficiently storing and verifying large datasets, which is important for DerivaDEX, which must maintain and rapidly update large amounts of data, such as the position and order data on every single trader across all trading products.

Every transaction impacting the exchange's state (like trades or deposits) results in a state transition, which is then reflected in an updated SMT.

Post- state transition, the SMT's root hash is recalculated to reflect the new state. This root hash, a single hash representing the tree's entire state, changes with every single state alteration. Subsequently, new Merkle branches for the updated state leaves are generated to verify data against the updated root hash. These proofs establish the inclusion (or exclusion) of all exchange-related data, such as a user’s available balance for withdrawal, thus providing succinct, deterministic, and verifiable transitions on any aspect of the exchange state.

Note: This article from Vitalik on rollups has a good description and diagrams detailing how the state root of a merkle tree can be stored on-chain and used to track state transitions.

Consensus and Checkpointing

During each epoch, operators reach a majority consensus on the state by comparing their SMT root hashes. A consensus leads to the creation and signing of a checkpoint, which can then be submitted by anyone to DerivaDEX's Ethereum contracts. The checkpoint is accepted if it meets the smart contracts' criteria, e.g., has correct operator signer addresses and majority consensus.

Withdrawals

Once a checkpoint is validated by the smart contract, it becomes a reliable reference for exchange traders. Traders can execute withdrawals by presenting a Merkle Proof against the certified state root in the checkpoint, affirming the legitimacy and consistency of their withdrawal with the exchange's state.

This approach ensures rapid verifications and updates, improving the platform's security and data integrity.

The content provided in this article is for educational and informational purposes only and does not constitute financial, investment, or trading advice. The information is presented without consideration of the investment objectives, risk tolerance, or financial circumstances of any specific investor and might not be suitable for all investors. Past performance is not indicative of future results. Trading and investing in financial markets carries substantial risk including the possible loss of principal.

Disclaimer DerivaDEX is not available in all jurisdictions, including the US. Users should be aware that there is a risk of financial loss whenever trading derivatives and margin products. Information found in these articles is not financial advice.