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
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
circom2 setup --circuit <circut.circom> --pk <proving.key> --verifier <verifier.sol>
circuit.circom
is an input file with themain
component that specifies the circuitproving.key
if a generated output with the key required to generate proofsverifier.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();
circom2 prove --circuit <circuit.circom> --input <input.json> --pk <proving.key> --proof <proof.json>
circuit.circom
is an input file with themain
component that specifies the circuitinput.json
is an input file with the required input signals to generate the full witnessproving.key
if an input file with the key required to generate proofsproof.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
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
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
The code is based on https://github.com/mimirblockchainsolutions/flutter-rust-middleware
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
- Go to
binding/flutter/cargo
and run./build.sh
- Go to
binding/flutter
and runflutter build ios
orflutter build apk
- Go to
binding/flutter
and runflutter run
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 output
s until allsignal 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