4 releases

0.1.3 Feb 4, 2025
0.1.2 Jan 16, 2025
0.1.1 Dec 26, 2024
0.1.0 Jul 22, 2024

#363 in Rust patterns

Download history 50/week @ 2024-10-29 15/week @ 2024-11-05 35/week @ 2024-11-19 320/week @ 2024-11-26 137/week @ 2024-12-03 175/week @ 2024-12-10 297/week @ 2024-12-17 141/week @ 2024-12-24 74/week @ 2024-12-31 182/week @ 2025-01-07 419/week @ 2025-01-14 388/week @ 2025-01-21 187/week @ 2025-01-28 574/week @ 2025-02-04 144/week @ 2025-02-11

1,368 downloads per month
Used in 2 crates

Apache-2.0

260KB
364 lines

rust-witness

A crate to natively generate circom witnesses in Rust. This crate transpiles the wasm witness generator to C then provides macros to easily invoke the C functions.

Usage

  1. Add rust-witness as a dependency and a build dependency. Add paste as a dependency.
  2. Write a build.rs that looks like the following:
use rust_witness::transpile::transpile_wasm;

fn main() {
    // This function will recursively search the target directory
    // for any files with the `wasm` extension and compile
    // them to C and link them
    transpile_wasm("my/path/to/wasm/");
}
  1. Compute a witness like the following:
use rust_witness::witness;

// Use this macro to generate a function that can be
// used to build a witness for the target circuit
//
witness!(circuitname);
// The name should be the name of the wasm file all lowercase
// with all special characters removed
//
// e.g. 
// multiplier2 -> multiplier2
// keccak_256_256_main -> keccak256256main
// aadhaar-verifier -> aadhaarverifier
// 

fn build_proof() {
    let inputs: HashMap<String, Vec<BigInt>>;
    // The generated function will be the name of the circuit
    // followed by _witness
    let witness = circuitname_witness(inputs);
}

Setup

Clone the repo then run the following command in the repo directory:

cargo test

Speeding up builds

By default this package will build w2c2 from source if the binary is not in your $PATH. This can be slow when developing and rebuilding frequently. To install w2c2 to your cargo bin run the following:

sh ./install_w2c2.sh

transpile_wasm will automatically use the w2c2 in your $PATH if possible.

Dependencies

~0.8–7MB
~53K SLoC