I have a Merkle

I have a Merkle

In collaboration with DOPP, Pragma is excited to introduce our new product: Merkle Feeds.

To understand the value of Merkle Feeds, it helps to first look at Merkle Trees, a foundational element of blockchain. Merkle Trees play a key role in securing data and maintaining order. They work by organising data into a structure where each piece is hashed, and these hashes combine to form a single, unique hash known as the Merkle root. This design allows for the efficient and secure verification of large amounts of data, without the need to check every piece individually.

This efficiency is invaluable in blockchain applications, where verifying data quickly and securely is crucial. In this article, we’ll dive into something called Merkle Feeds, which is an innovative way of using Merkle Trees. Merkle Feeds make it easier to update and verify complex financial data on-chain. Then we'll explore the first use case of Merkle Feeds with DOPP, the first fully on-chain crypto options exchange.

What are Merkle Feeds?

Merkle Feeds represent a highly efficient method for publishing and verifying extensive amounts of data on a blockchain. At its core, a Merkle Feed utilises the principles of a Merkle Tree, a cryptographic data structure that enables the secure and efficient verification of data integrity.

In the context of Pragma's implementation on Starknet, Merkle Feeds play a pivotal role in handling complex financial instruments, such as options. In fact, we can easily have thousands of different option instruments to cover the range of available strike prices and expiries.

The process begins with the construction of a Merkle Tree, where the leaf nodes represent individual pieces of data—specifically, the mark prices of options on Deribit. The Merkle root, which represents the integrity of the entire tree, is then published on-chain every block.

What sets Merkle Feeds apart is their ability to support a pull oracle model. This model allows users to retrieve data, along with its associated Merkle proof, off-chain through Pragma's API or dedicated rust crate. Developers can fetch the latest option prices and verify their correctness on-chain, thus ensuring the data's accuracy and integrity without the need to store all the data directly on the blockchain. This approach not only enhances efficiency but also significantly reduces on-chain storage requirements, making it a highly scalable solution for data-heavy applications.

The Mechanics of Merkle Feeds

Building on the foundational understanding of Merkle Feeds, let's take a closer look at their mechanics. Merkle Feeds operate through a combination of off-chain and on-chain processes, working together to create a secure and scalable data solution. Below is a detailed breakdown of how these components interact.

1. Creation of the Merkle Tree (Off-chain)

The process begins with the creation of a Merkle tree using options data from Deribit. This tree is constructed off-chain and serves as a hierarchical representation of the data, where each leaf node contains data such as option mark prices.

2. Posting the Merkle Root On-chain

Once the Merkle tree is built, the Merkle root is published on-chain using a transaction (publish_entry). This step involves placing the Merkle root onto Starknet, making it publicly accessible and verifiable. Internally, it leverages the GenericEntry of Pragma's oracle contract which is already audited.

3. Retrieval of Merkle Proof and Data (Off-chain)

To access specific data, protocols query the Pragma API. This API call fetches the necessary call data along with the associated Merkle proof. The proof contains several fields, such as:

  • instrument_name: The name of the financial instrument
  • base_currency: The base currency for the options
  • current_timestamp: The timestamp of the data
  • mark_price: The current market price

4. Verification and Data Update (On-chain)

After retrieving the calldata off-chain, the DeFi protocol uses it in its own transactions (e.g liquidations). Internally their contract will call Pragma's contract which will verify the merkle proofs and update its storage if everything is valid.

You can find a diagram going through these 4 steps below:

Merkle Feeds Flowchart

DOPP: Merkle Feeds for On-Chain Options

DOPP is a fully on-chain options protocol built on Starknet with the mission of creating a composable and transparent options trading platform.

When building an options protocol, it is essential to have access to external key data points such as implied volatility, mark price, and option greeks (Delta, Gamma, Theta, and Vega). These data points are critical for accurately pricing options, managing risk, and ensuring liquidity in the options market. Implied volatility reflects the market's forecast of potential price movements for an option, while the mark price provides an estimate of fair value based on various market factors. Option greeks help traders understand how different variables - such as time, price, and volatility -affect the value of options.

To achieve this, DOPP utilises Merkle Feeds to securely and efficiently bring these data points on-chain. The Merkle Feed model enables DOPP to access latest options data every block without having to bear the cost of updating thousands of data points on-chain which wouldn't be sustainable.

By integrating Merkle Feeds, DOPP aligns with its mission to foster an open and trustworthy financial ecosystem, enabling the seamless and secure trading of complex financial instruments on Starknet.

Conclusion

Merkle feeds are a powerful way for you to have access to heavy amounts of data at a high frequency on Starknet.

If you are building a DeFi protocol or any decentralized application that would require such kind of data, please reach out.

A few resources to go deeper
How it works
Integration Walkthrough
Rust Crate

This is just a taste of what is coming with Pragma X, stay tuned for more


Join the conversation! Follow Pragma on Twitter for updates, and connect with our community on Telegram.

Be part of the DeFi future 🧩