Skip to content

cpp witness calculator for mobile and desktop for iden3 circuits

License

Notifications You must be signed in to change notification settings

zkmopro/witnesscalc

 
 

Repository files navigation

About This Fork

This fork turns wintesscalc into a template for building witness generators for arbitrary Circom circuits into native binaries for various platforms. It is supposed to be used by external code that provides the C++ sources and finalizes the template (see witnesscalc_adapter for example).

Changes

Templating

  • The makefile expects the circuit names to be provided as a semicolon-separated list in an environment variable CIRCUIT_NAMES, e.g.,

    export CIRCUIT_NAMES="circuit1;circuit2;circuit3"
  • The circuit files are included into the build script by template.

  • The main entry point into the resulting library is templated and the circuit name is supposed to be replaced by the external code.

  • Please see this code for full circuit templating process illustration.

Compilation

Installation

  • All the targets have the same CMAKE_INSTALL_PREFIX of /package because this fork is meant to be used as a part of the Rust library build process, and the build code expects the same output paths for all the targets. The external code is responsible for later combining the outputs into the final library artifacts.
  • The -GXcode flag was removed because the Rust code needs to link to the binary and the platform-specific artifacts are later generated from the Rust library.

Original Readme

Dependencies

You should have installed gcc and cmake

In ubuntu:

sudo apt install build-essential cmake m4

Compilation

Preparation

git submodule init
git submodule update

Compile witnesscalc for x86_64 host machine

./build_gmp.sh host
make host

Compile witnesscalc for arm64 host machine

./build_gmp.sh host
make arm64_host

Compile witnesscalc for Android

Install Android NDK from https://developer.android.com/ndk or with help of "SDK Manager" in Android Studio.

Set the value of ANDROID_NDK environment variable to the absolute path of Android NDK root directory.

Examples:

export ANDROID_NDK=/home/test/Android/Sdk/ndk/23.1.7779620  # NDK is installed by "SDK Manager" in Android Studio.
export ANDROID_NDK=/home/test/android-ndk-r23b              # NDK is installed as a stand-alone package.

Compilation for arm64:

./build_gmp.sh android
make android

Compilation for x86_64:

./build_gmp.sh android_x86_64
make android_x86_64

Compile witnesscalc for iOS

Requirements: Xcode.

  1. Run:
    ./build_gmp.sh ios
    make ios
  2. Open generated Xcode project.
  3. Add compilation flag -D_LONG_LONG_LIMB to all build targets.
  4. Add compilation flag -DCIRCUIT_NAME=auth, -DCIRCUIT_NAME=sig and -DCIRCUIT_NAME=mtp to the respective targets.
  5. Compile witnesscalc.

Updating circuits

  1. Compile a circuit with compile-circuit.sh script in circuits repo as usual.

  2. Replace existing .cpp and .dat files with generated ones (e.g. auth.cpp & auth.dat).

  3. Enclose all the code inside .cpp file with namespace CIRCUIT_NAME (do not replace CIRCUIT_NAME with the real name, it will be replaced at compilation), like this:

    #include ...
    #include ...
    
    namespace CIRCUIT_NAME {
    
    // millions of code lines here
    
    } // namespace
    
  4. Optional. Remove the #include <assert.h> line and replace all accurances of assert( with check( in .cpp file to switch from asserts to exceptions (more secure).

Alternatively you can patch the .cpp circuit file with a patch_cpp.sh script. Example how to run it:

./patch_cpp.sh ../circuits/build/linkedMultiQuery10/linkedMultiQuery10_cpp/linkedMultiQuery10.cpp > ./src/linkedMultiQuery10.cpp

License

witnesscalc is part of the iden3 project copyright 2022 0KIMS association and published with GPL-3 license. Please check the COPYING file for more details.

About

cpp witness calculator for mobile and desktop for iden3 circuits

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 98.9%
  • Other 1.1%