Skip to content

druiz0992/za

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •