Skip to content

Rust adapter for 0xPolygonID/witnesscalc for any circuit

Notifications You must be signed in to change notification settings

zkmopro/witnesscalc_adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Witnesscalc Adapter

Crates.io

This project provides a Rust adapter for compiling and linking Circom circuit witness generator C++ sources into a native library for target platforms (e.g., mobile devices). It includes macros and functions to facilitate the integration of witness generation into Rust codebases.

Usage

Include the crate in your Cargo.toml:

[dependencies]
witnesscalc-adapter = "0.1.0"

[build-dependencies]
witnesscalc-adapter = "0.1.0"

In build.rs, add the following code to compile the witness generator C++ sources into a native library and link to it:

witnesscalc_adapter::build_and_link("../path to directory containing your C++ sources");
// e.g. witnesscalc_adapter::build_and_link("../testdata");

In your main code, use the witness macro to generate a witness for a given input:

witnesscalc_adapter::witness!(<circuit name>);
// e.g. witnesscalc_adapter::witness!(multiplier2);

Calculate the witness by using the witnesscalc_<circuit name> function.

let wtns = <circuit name>_witness(inputs_json_string)
// e.g. let wtns = multiplier2_witness("{\"a\": [\"2\"], \"b\": [\"3\"]}")

It will generate a wtns bytes array like the output of witnesscalc.

Convert the wtns to bigints by using the parse_witness_to_bigints function.

let witness = parse_witness_to_bigints(&wtns).unwrap();

Supported platforms

Linux

  • x86_64 linux
  • arm64 linux

MacOS

  • aarch64-apple-darwin
  • x86_64-apple-darwin

iOS

  • aarch64-apple-ios
  • aarch64-apple-ios-sim
  • x86_64-apple-ios

Android

  • aarch64-linux-android
  • x86_64-linux-android

Acknowledgements

Inspired by https://github.com/chancehudson/rust-witness. This adapter relies on the 0xPolygonID/witnesscalc library fork.