Giter Site home page Giter Site logo

semasaf / hazook-fast-zk-rollup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ycryptx/hazook-fast-zk-rollup

0.0 0.0 0.0 2.17 MB

Hazook is a fast ZK-Rollup built on Mina that parallelizes the accumulation of zk state proofs

License: Apache License 2.0

Shell 1.06% JavaScript 29.44% Python 0.57% TypeScript 46.44% Nix 3.50% Makefile 0.96% HCL 15.47% Dockerfile 2.56%

hazook-fast-zk-rollup's Introduction

Hazook: Fask ZK-Rollup on Mina

Take your Mina (ZkApp) Rollup to the next level by using cloud compute to parallelize the accumulation of ZK Proofs. Hazook comes with a minimal sequencer implementation, the infra code to help you provision a running Hadoop cluster in AWS, and the necessary scripts and logic to leverage cloud-based Map Reduce for computing thousands of rollup proofs in parallel.

Performance

Transactions Duration (minutes) Peak Instance Usage (m5.xlarge) Total # of proofs
8 11 4 14
64 33 22 126
256 40 65 510
1024 48 342 2046

Instances used are AWS EC2 m5.xlarge (or similar sized instances). Refer to here for the full list of potential instances the Hadoop cluster might use. The tests were conducted on a Zk-Rollup which modifies a single MerkleMap.

Usage

You may bring your own ZkApp Rollup implemented in any way you see fit. However, you must implement a few classes that follow the abstractions defined here. Currently the project runs a dummy ZkApp Rollup (reference) that you can use as your reference implementation.

After implementing these abstractions, make sure to use them in the sequencer by updating mapper.ts, reducer.ts compiler.ts and sequencer.ts.

To start the sequencer:

yarn sequencer start

This starts up a grpc server which can be used to run the demos. You can modify the server code to fit your needs here. There are 4 demos (demo1: 8 proofs, demo2: 64 proofs, demo3: 256 proofs, demo4: 1024 proofs).

To run the demo locally:

make run-demo

To run the demo on a deployed sequencer (demo-1):

grpcurl --insecure -d '{"case": 1}' "your_sequencer_host:your_sequencer_port" services.sequencer.v1.SequencerService/Demo

To run the map-reduce on a set of transactions:

const MODE = MODES.EMR
const REGION = 'eu-central-1'
const client = new MapReduceClient<RollupProof>(MODE, REGION);

// First we need to upload your transactions to S3
const txUploader = client.uploader.uploadTransactionsToS3();
const transactions: MyTransaction[] = [/* ...your transactions */]
for (const tx of transactions) {
    txUploader.write(tx.serialize());
}
inputFileUrl = await txUploader.end();

// Then we can initialize a Hadoop cluster and start the map-reduce operation
const accumulatedProof = await client.process(inputFileUrl, transactions.length);

Instance Types

By default the Hadoop Cluster runs on AWS EC2 Spot Instances which are cheaper than normal (i.e. on-demand) instances. You can configure the spot instance bid price (SPOT_BID_PRICE_DOLLARS) in this file. It is currently set to $0.5.

For large transaction batches (>1000 txs), it is more reliable to use on-demand instances though. This is because AWS often does not have enough spot instances to allocate for the job. You can select to use on-demand instances by setting:

const client = new MapReduceClient<RollupProof>(MODE, REGION);
client.onDemandInstances = true;

Acceptable ZkPrograms

Your rollup (which is simply an o1-js ZkProgram) should work with Hazook almost out of the box, but it should be built as a Zk-Rollup as described in Mina's documentation here. To summarize, the ZkProgram should enable two functionalities: (1) a baseFunction which should generate and validate a base zk proof per transaction and (2) a mergeFunction which validates that two baseFunctions form a valid sequence and generates a proof of that.

There's no requirement on the name or the inputs of these two functions; you can even have more than one baseFunction or mergeFunction. You just have to implement these generics, specifically TransactionBase.baseFn() which should call the baseFunction/s of your ZkProgram and RollupProofBase.merge() which should call the mergeFunction/s of your ZkProgram.

Deployment

Please refer to this document for a detailed information of deploying Hazook. In addition to Terraform, the project currenly relies on Github Actions to upload the rollup compilation cache to the Hadoop cluster which speeds up processing. We encourage you to re-use the Github CI script included in this project.

Security

The EMR cluster is in the public subnet for ease of development but for production use cases it should be moved to the private subnet (refer to here).

Components

Architecture Diagram

Simple Rollup Sequencer Service

  • Containarized Node.js service that can be deployable to AWS EC2
  • Terraform provisioning, Github Actions CI/CD
  • Responsible for generating intermediate states and posting them to the MapReduce service

Hadoop Cluster

  • A Hadoop Streaming cluster deployed and managed by AWS EMR, running in the same virtual network as the sequencer
  • Parallelizes the generation of state proofs and reduces them into a single state proof recursively
  • Terraform provisioning, Github Actions CI/CD

We purposefully left out the work of: (1) Posting the accumulated zk proof to Mina L1 and (2) Adding a grpc endpoint to which users can post transactions So that developers can have full freedom to customize Hazook to their liking.

hazook-fast-zk-rollup's People

Contributors

ycryptx avatar picnoir avatar simisimis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.