Skip to content
Port of circom zk-snarks compiler to rust
Dart Rust Go Java Swift Shell
Branch: master
Clone or download
Latest commit 489bbfa Aug 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bigsnark Feature/solidity (#5) Jul 1, 2019
binding
cli [cli] fix descriptions Aug 2, 2019
compiler [compiler] fix tests Aug 1, 2019
docs Update notes.txt Jul 1, 2019
interop [cli] select test name prefix Jul 27, 2019
parser [parser] decimal output Jul 3, 2019
prover
.dockerignore [build] added Dockerfile Jul 3, 2019
.gitignore initial commit Apr 23, 2019
.travis.yml [build] fix Travis timeout Jul 24, 2019
Cargo.toml [binding] added golang binding Aug 13, 2019
Dockerfile [build] fix dockerfile Jul 25, 2019
LICENSE initial commit Apr 23, 2019
README.md [doc] updated flutter info Jul 26, 2019

README.md

rust-circom-experimental

Build Status

An experimental port of IDEN3 circom compiler to rust.

❗️ This is not the official and supported implementation of IDEN3 circom and circomlib circuits please use official version instead

Building

Install rust

curl https://sh.rustup.rs -sSf | sh

Install additional dependencies, you may need to install the clang build-essentials and openssl-dev

Clone the repo

git clone https://github.com/iden3/rust-circom-experimental.git

Build

cargo build --release

The final binary will be in /target/release/circom2

Usage

Generating trusted setup

circom2 setup --circuit <circut.circom> --pk <proving.key> --verifier <verifier.sol>

  • circuit.circom is an input file with the main component that specifies the circuit
  • proving.key if a generated output with the key required to generate proofs
  • verifier.sol if a generated output with the smartcontract to verify the generated proofs

if you want to do a test, create a file with name circuit.circom with the following contents and run the circom2 setup

template T() {
    signal private input p;
    signal private input q;
    signal output r;

    r <== p*q;
}
component main = T();

Generating a proof

circom2 prove --circuit <circuit.circom> --input <input.json> --pk <proving.key> --proof <proof.json>

  • circuit.circom is an input file with the main component that specifies the circuit
  • input.json is an input file with the required input signals to generate the full witness
  • proving.key if an input file with the key required to generate proofs
  • proof.json the input required to the smartcontract to verify the proof

if you want to do a test, create a file with name input.circom with the following contents and run the circom2 prove

{ a : 2, b: 3 }

then deploy the verifier.sol smartcontract and exec the verifyTx method with the contents of the proof.json

Testing a circuit

In order to test if a circuit is correct is possible to write an embedded test by using the #[test] tag before a template definition (see interop/circomlib/babyjub.circom), to execute the test, run:

  • circom2 test --circuit <circuit.circom>

this will run the tests found in the circuit and all the tests found in the included templates

Javascript bindings

to compile the javascript bindings, go to the binding/js folder and run:

  • npm i
  • npm run install
  • npm test

check the test located in binding/js/test/test.js

Flutter bindings

The code is based on https://github.com/mimirblockchainsolutions/flutter-rust-middleware

Prerequisites

Export vars

  • export ANDROID_HOME=/Users/$USER/Library/Android/sdk
  • export NDK_HOME=$ANDROID_HOME/ndk-bundle

Then, you need to run the ndk script to build your compile targets from the root folder of the project

./ndk.sh

Build

  • Go to binding/flutter/cargo and run ./build.sh
  • Go to binding/flutter and run
    • flutter build ios or
    • flutter build apk

Test

  • Go to binding/flutter and run flutter run

Differences between official circom version

There are few differences between this implementation and the official circom:

  • Precedence of operators rust-like instead C-like:
    • DECNUMBER, HEXNUMBER, "(" exp ")"
    • Unary - !
    • **
    • * / \\ %
    • + -
    • << >>
    • &
    • ^
    • |
    • == != < > <= >=
    • &&
    • ||
  • Removed ++, -- and :?
  • Matrix access is only accessible with [x][y] (not with [x,y])
  • End statement semicolons are mandatory
  • Loops/conditionals statements must be inside blocks { }
  • Added dbg! function to trace variables, signals and components
  • Do now allow to use component signal outputs until all signal input are set
  • Signal input/outputs arrays should be evaluable with template parameters
  • Stamements tagged with #[w] are only evaluated in witness generation
  • #[test] tagged templates are used to verify embeeded tests
You can’t perform that action at this time.