9 releases

0.1.7 Oct 11, 2025
0.1.6 Aug 25, 2025
0.1.3 Jun 14, 2025
0.1.2 Mar 7, 2025
0.1.1 Feb 26, 2025

#563 in Rust patterns

Download history 215/week @ 2025-10-19 105/week @ 2025-10-26 138/week @ 2025-11-02 21/week @ 2025-11-09 45/week @ 2025-11-16 3/week @ 2025-11-23 26/week @ 2025-11-30 24/week @ 2025-12-07 78/week @ 2025-12-14 91/week @ 2025-12-21 70/week @ 2025-12-28 159/week @ 2026-01-04 390/week @ 2026-01-11 138/week @ 2026-01-18 84/week @ 2026-01-25 105/week @ 2026-02-01

752 downloads per month
Used in 2 crates (via circom-prover)

MIT/Apache

26KB
390 lines

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.

[!INFO]
This project supports Circom v2.2.0 and above. For details on witness calculation, please see the witnesscalc-v2.2.0 branch.

Requirements

Dependencies

  • Linux:
sudo apt install build-essential cmake m4 nasm libstdc++6
  • MacOS:
brew install nasm

Usage

Include the crate in your Cargo.toml:

[dependencies]
witnesscalc-adapter = "0.1"

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

In build.rs, add the following code to compile the witness generator C++ sources (<circuit name>.cpp and <circuit name>.dat) 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");
// The directory should contain the following files:
// - <circuit name>.cpp
// - <circuit name>.dat

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 <circuit name>_witness 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 or snarkjs.

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

Community

Acknowledgements

Dependencies

~0.8–1.4MB
~29K SLoC