Grant Results: Marine: Compound Liquidation Keeper with zkGraph


  • Hyper Oracle has successfully implemented **Marine: Compound Liquidation Keeper with zkGraph**.
  • Marine fetches data from 92 different events from 19 different smart contracts, computes for liquidatable accounts, and initiates onchain liquidation call. All these are performed in a trustless and programmable way, leveraging the capabilities of zkOracle and zkGraph.
  • This project is supported by the Compound Grants Program. For further details on the grant, please visit our project page.

0. zkGraph and zkOracle

Hyper Oracle is a programmable zkOracle protocol. We aim to unlock historical data access and complex compute for smart contracts in a trustless and secure way.

A zkOracle expands the computational capabilities of smart contracts. Any DApp that uses a zkOracle in their architecture is a zkDApp that has more potential than a traditional DApp.

To program a zkOracle, you can write code in zkGraph (a piece of code for custom logic) to define your own “API”. Also, we provide zkGraph Standards, including zkAutomation (smart contract automation of zkGraph), so you can use it as a template to power your smart contract to achieve the ability of end-to-end trustless automation.

You can simply understand zkOracle and zkGraph as:

  • zkOracle: the node of Hyper Oracle
  • zkGraph: the program run in a zkOracle node

1. Implementation

Our application Marine is an implementation of a Compound Liquidation Keeper based on a zkOracle. Marine is implemented as a complete zkGraph.

In general, Marine uses the trustless historical data obtained by the zkOracle to determine whether a user’s address needs to be liquidated and, if so, initiate an onchain transaction through zkAutomation to perform the liquidation operation.

In terms of the detailed workflow, Marine achieves the following:

  1. Collect events for a specific contract at any block through zkOracle:
    • Monitor ComptrollerG7 contract to determine if the closeFactor has changed.
    • Monitor cToken contract events to sense changes in user pledge and loan amount.
    • Monitor the onchain price of tokens on Uniswap to get the latest price of underlying assets.
  2. Through a series of compute, count the total value of the collateral and the total value of the debt of the user’s address
  3. Determine if totalValue < totalPrincipal, if true, liquidatable.
  4. If liquidatable, the zkGraph is executed and the zkOracle generates the corresponding zero-knowledge proof.
  5. Once the proof is generated and verified on Ethereum (finished within 12 seconds), an onchain liquidation is triggered.

You can check out the source code here: GitHub - hyperoracle/Marine: Trustless Liquidation Keeper with zkGraph for Compound Protocol.

2. Features

Historical Data Access

zkOracle brings historical data access to Marine.

As a result, Marine can look back at any historical block of data and calculate all the debt and collateral of a user to get the liquidation health of an address.

Expansive Computation

With zkGraph, Marine has unlimited computational power without onchain overhead.

With the programmability of zkGraph and the succinct validity proof of zkOracle, Marine fetches, processes and analyzes large amounts of data. This cannot be done efficiently in an EVM.

Multi-Event & Multi-Source Access

zkOracle supports unlimited multi-source and multi-event data access. These rich data sources can be processed by zkGraph.

Marine’s zkGraph fetches data from 92 different Events from 19 different smart contracts, including but not limited to: Mint() and Borrow() for cToken and Sync() for underlying asset.

3. Other Advantages

Trustless and Secure Compute

The computational validity and security of zkOracle’s data access and computations on zkOracle data in zkGraph are provided by zero-knowledge proofs. These proofs are being verified on Ethereum mainnet.

Therefore, there is no need for any additional trust and therefore Marine is trustless and secure.

Diversity Added to Compound

The liquidation keeper is an important part of the DeFi protocol and ensures the health of the DeFi protocol.

Similar to client diversity, keeper diversity is an important yet often overlooked factor. For example, in MakerDAO MIP-63, MakerDAO runs four different keeper networks to ensure keeper diversity, thus achieving high fault tolerance and decentralization.

As a community-run keeper, Marine has a high level of diversity.

  • Architecture: Uses a zkOracle-based implementation.
  • Technology Stack: Uses Halo2 for ZK system and AssemblyScript as development language, not just a Solidity contract.
  • Operation: Runs with zkAutomation.


With the technology of ZK, it is feasible to add a privacy feature to Marine’s computation.

Another major difference between Marine and a Solidity-based liquidator is the possibility to implement privacy features on the data itself and the data processing strategy. This is similar to how privacy prevents MEV behaviors like copy-tx-then-front-running.

4. Onchain Liquidation Catches

We have deployed Marine into the arena, and by running Marine, we have successfully performed liquidations on mainnet Ethereum:

5. Future Steps

zkML-based Price Prediction

Marine has both rich historical data and unlimited computational power, so it can forecast asset prices through Historical Data + Machine Learning.

Price prediction can predict liquidation before a liquidatable status of account occurs onchain, thus increasing the likelihood of successful liquidation and profit.

Offchain Asset Price Feed

Currently, Marine calculates the asset price based on the onchain price in order to ensure the complete validity and finality of the computation. Compound itself provides asset prices based on Chainlink.

In the future, we can use the offchain data source function to access more price feeds, so that we can determine the asset value without the possibility of price manipulation.

Cross-chain Potential

One of the powers of zkGraph is that it can natively trigger cross-chain calls between data sources and data destinations, so Marine can implement: fetch the data from chainA, and verify the ZKP on chainB to trigger actions.

In the case of liquidation, Marine can obtain the most “accurate” asset prices with more liquidity on Ethereum mainnet, and then perform Compound’s liquidation on the Alt-chain with less liquidity (where price data is not necessarily up-to-date).

6. Contribute to Compound and DeFi

We would like to thank the Compound Grants Program for their help in the development of Marine, and allthecolors as a reviewer for suggestions and insights.

With Marine and the zkOracle and zkGraph technologies underneath it, we hope to make the Compound ecosystem and DeFi as a whole more decentralized with trustless computing.