Inspiration

Compared to the traditional Push mode for price feed mechanisms, Chainlink introduced the Low Latency Oracle Solution (Data Streams). By adopting Pull mode, this solution allows decentralized applications to access the latest price information more promptly, thereby facilitating smoother business operations. Chainlink's new solution better addresses the needs of on-chain decentralized perpetual exchanges.

With the technological advancement of decentralized derivative exchanges, derivative DEXs based on zk-rollup technology are gradually emerging. Compared to entirely on-chain solutions, zk-rollup technology offers better performance and user experience. However, it also presents new challenges in securely verifying oracle prices.

Especially in high-frequency price reference scenarios, the cost of on-chain signature verification with Chainlink Oracle may surge. To address this issue, we propose a new solution: zk-Oracle. By leveraging zero-knowledge proof technology, the zk-Oracle solution aims to reduce the verification cost in high-frequency price reference scenarios, offering a more efficient and secure oracle solution for decentralized applications and derivative exchanges.

What it does

The zk-Oracle solution offers a new possibility for cost optimization in high-frequency price reference scenarios. By combining off-chain signature verification and on-chain eligibility verification, it retains the transparency of executing verification on widely adopted public chains, significantly reducing the cost of on-chain verification. Moreover, by analyzing the characteristic values of the price sequence, it provides a new perspective for enhancing security constraints and expanding multi-application implementation.

How we built it

The zk-Oracle solution mainly involves three steps:

  1. Obtain price data from the Chainlink Data Streams: With the help of Chainlink Data Streams any dapps that are running on zkLink can easily fetch the real time token price. Once a price info is adopted, they can quickly synchronize with zk-Oracle service to "record" the usage, that means, a dapp needs to ensure the strict transmission of price information to zk-Oracle in the order of transactions, as the subsequent verification process will require the actual price sequence used by this dapp to be a subset of the price sequence received by zk-Oracle.
  2. Off-chain proof generation and signature verification: The zk-Oracle adopts an asynchronous batch processing mode for price information verification, basically by collecting a certain number of price information (possibly hundreds or thousands) off-chain, referred to as a price sequence. We generate the zk proof offchain from circuit, the circuit constraints are defined as following: (1) Increment of timestamp (2) Constraint all signature signing addresses to come from a specific set (in this case, all price singers' addresses form a subset of total valid Chainlink signers) (3) The actual price sequence adopted by dapp is a subset of the price sequence provided by zk-Oracle. (4) All signatures are correct
  3. Verify on-chain: After generating zk proof off-chain, we need to verify the legitimacy of this zk proof onchain. For this, we need to deploy a smart contract on an EVM compatible blockchain (e.g. Ethereum). The smart contract first verifies the correctness of the zero-knowledge proof, then verifies whether all signing addresses participating are from Chainlink official.

Challenges we ran into

Since Data Streams is a cutting age idea, we feel it is too early to use it in full power mode, we tried but unfortunately we did not manage to fully implement step #3. The reason for that is because the Chainlink signer addresses set is a private variable for now, and because of that we can not verify the signers set which we received from our dapps, that is indeed a subset of Chainlink valid singers. So in our smart contract we mocked this verification step. I believe in the future, when Data Streams becomes a mature product, it will be feasible to use this feature.

Accomplishments that we're proud of

We see that with our zk-Oracle solution, we can significantly lower the cost of on-chain verification. With a normal verification workflow the gas cost increases linearly based on the amount of verification times. After compressed with zk proof, the gas cost only increases a little bit while increasing the verification times. E.g. For verifying 16 pieces of data the gas cost is roughly about 1,920,000 but with zk-Oracle the gas cost can be reduced to 554,193

What we learned

As mentioned above, since Data Streams is on an early phase, it is not so straight forward to use its service. Thanks to the help from Chainlink team and finally we understand how to use it and managed to run it properly.

What's next for zk-Oracle

By maintaining such an Oracle datahub, we can not only do verification of price data, but also we will be able to analyze the price data and extract useful information based on that. For example, we can calculate the Spike Detection Indicator (SDI) within a set of time/price sequences to detect the presence of anomalous peaks. We believe, in the future zk-Oracle can significantly save the cost of on-chain verification as well as maintain a high level of token price reliability for our dapps.

Built With

Share this project:

Updates