Giter Site home page Giter Site logo

zkriscv's Introduction

zkRiscV

A zero-knowledge VM based on the RV32I Risc-V instruction set with almost full compatibility.

Generate zk-SNARKS proving that N steps of a program where executed correctly.

git clone https://github.com/lucasgleba/zkRiscV.git
cd zkRiscV
npm install
cd circuits
npx mocha # might take up to a minute

You will need circom and snarkjs to compile circuits and generate proofs. Check out the circom introduction.

Check out zkSubleq for a similar project with a way simpler instruction set.

RV32I?

RV32I is a reduced instruction set architecture of the Risc-V family. It has 31 general purpose registers x1-x31 which hold 32-bit integer values and a zero register x0 which is hardwired to 0.

How does it work?

Instruction decoding and logical/arithmetic operations are a bit intricate but straightforward to implement. The trickiest and most costly part is state reading and writing.

The state consists of the program counter, the registers, and memory.

The program counter and registers are always passed as signals as they are very small. The code includes two approaches for handling memory:

  • Flat memory: The entirety of memory is passed as signals from one VM step to the other just like the registers. Reads and writes are done with multiplexers and inverse multiplexers respectively. This is a simple and effective approach when the size of the memory required is very small. The code includes an implementation for 128 byte memory array with half dedicated to program memory.

  • Tree memory: Memory is held in a Merkle tree. Instead of passing the entirety of memory, you pass a Merkle proof for the section of memory being accessed in each step. Validating Merkel proofs is expensive but the size of the proofs scales logarithmically with the memory size. This makes this approach better suited for programs that require lots of memory.

RV32I compatibility

zkRiscV supports all the instructions in the instruction set except for multi-byte memory load/store and environment calls. Transpilation is straightforward (not implemented yet: transpiler/).

See also

One can use more sophisticated zero-knowledge math to make a much more efficient (but complex) zkVM. Most of the efforts in this front are being made by teams working on EVM-compatible zero-knowledge rollups.

Ping me on twitter if you want to learn more.

zkriscv's People

Contributors

lucasgleba avatar

Watchers

 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.