react-native-dop-prover
v0.0.2
Published
Native ZK witness generator for DOP Protocol - supports all 66 transfer circuits with hardware-accelerated performance
Downloads
106
Maintainers
Readme
react-native-dop-prover
Native ZK witness generator for DOP Protocol. Generates witnesses natively on mobile devices for fast zero-knowledge proof generation.
Features
- 66 transfer circuits - All DOP transfer variants from 1x0 to 13x1
- Native performance - 10-50x faster than JavaScript WASM execution
- Hardware-accelerated - Compiled to native ARM/x86 code
- Proper .wtns format - Compatible with snarkjs and rapidsnark
- TypeScript support - Full type definitions included
Supported Circuits
| Inputs | Outputs 0 | 1 | 2 | 3 | 4 | 5 | 10 | 13 | |--------|-----------|---|---|---|---|---|----|----| | 1 | Y | Y | Y | Y | Y | Y | Y | Y | | 2 | Y | Y | Y | Y | Y | Y | | | | 3 | Y | Y | Y | Y | Y | Y | | | | 4 | Y | Y | Y | Y | Y | Y | | | | 5 | Y | Y | Y | Y | Y | Y | | | | 6 | Y | Y | Y | Y | Y | Y | | | | 7 | Y | Y | Y | Y | Y | Y | | | | 8 | Y | Y | Y | Y | Y | Y | | | | 9 | Y | Y | Y | Y | Y | Y | | | | 10 | Y | Y | Y | Y | Y | | | | | 11 | Y | Y | | | | | | | | 12 | Y | Y | | | | | | | | 13 | | Y | | | | | | |
Total: 66 circuits
Installation
npm install react-native-dop-prover
# or
yarn add react-native-dop-proverDownload Native Libraries
Native libraries (~1GB total) are not included in the git repo. Download from GitHub Releases:
# Build locally (requires Rust + Android NDK):
cd /path/to/mopro-dop
./build_all_android.sh
cp -r jniLibs/* /path/to/react-native-dop-prover/android/src/main/jniLibs/iOS Setup
cd ios && pod installAndroid Setup
Ensure native libraries exist in:
android/src/main/jniLibs/arm64-v8a/libdop_mobile_prover.so(64-bit ARM)armeabi-v7a(32-bit ARM)x86_64(Emulator)
Usage
Basic Example
import DopProver from 'react-native-dop-prover';
// Check supported circuits
const circuits = await DopProver.getSupportedCircuits();
console.log(`Supported: ${circuits.length} circuits`);
// Calculate witness
const witness = await DopProver.calculateWitness('transfer_1x2', inputs);
console.log(`Witness elements: ${witness.length}`);Full Transaction Example
import DopProver from 'react-native-dop-prover';
const inputs = {
merkleRoot: '6222425295742392060788226778694769114506305024317843914902643617290374768963',
boundParamsHash: '5710287756984354871128133611023121898130345951914076394217910154190632022267',
nullifiers: ['2488005839880174281371566850742862351218389849446606448043615745372921337838'],
commitmentsOut: [
'14442913796384197520571496765626647486596829362832619910396444542983171421557',
'19252303434306434500840759223364185816884050656317846745992399487059334764561',
],
token: '546584486846459126461364135121053344201067465379',
publicKey: [
'15684838006997671713939066069845237677934334329285343229142447933587909549584',
'11878614856120328179849762231924033298788609151532558727282528569229552954628',
],
signature: [
'16927417158026668872034053079746879482505341725377973536231219666755150412517',
'4460683417520795250530582144217697783429941348945040786207839936208783640494',
'323943078793744741814096352565656579413445122634109055822579790017960112397',
],
randomIn: ['40419079083657351839989032552519750558'],
valueIn: ['9975062344139650872817'],
pathElements: [
'2051258411002736885948763699317990061539314419500486054347250703186609807356',
// ... 16 elements total (Merkle proof path)
],
leavesIndices: ['0'],
nullifyingKey: '8368299126798249740586535953124199418524409103803955764525436743456763691384',
npkOut: [
'18155422517519710121567557298796336647851001757086572188586973563076356884330',
'14453327337221153863920321130101533812935021152859474978476854443074076494952',
],
valueOut: ['65000000000000000000', '9910062344139650872817'],
};
// Calculate witness (returns decimal string array)
const witness = await DopProver.calculateWitness('transfer_1x2', inputs);
// Or get as .wtns bytes for rapidsnark
const witnessBytes = await DopProver.calculateWitnessAsBytes('transfer_1x2', inputs);Integration with Proof Generation
import DopProver from 'react-native-dop-prover';
import { groth16 } from 'snarkjs';
async function generateProof(circuitName: string, inputs: any, zkeyPath: string) {
// Step 1: Calculate witness natively (10-50x faster than JS)
const startWitness = Date.now();
const witnessBytes = await DopProver.calculateWitnessAsBytes(circuitName, inputs);
console.log(`Witness: ${Date.now() - startWitness}ms`);
// Step 2: Generate proof with rapidsnark/snarkjs
// witnessBytes is in proper .wtns format
const { proof, publicSignals } = await groth16.prove(zkeyPath, witnessBytes);
return { proof, publicSignals };
}API Reference
getSupportedCircuits(): Promise<string[]>
Returns list of all supported circuit names.
calculateWitness(circuit: string, inputs: object): Promise<string[]>
Calculate witness and return as array of decimal strings.
circuit- Circuit name (e.g., 'transfer_1x2')inputs- Circuit inputs as JavaScript object- Returns: Array of witness elements as decimal strings
calculateWitnessAsBytes(circuit: string, inputs: object): Promise<Uint8Array>
Calculate witness and return as .wtns binary format.
circuit- Circuit nameinputs- Circuit inputs- Returns: Witness in snarkjs-compatible .wtns binary format
calculateWitnessJson(circuit: string, inputsJson: string): Promise<string>
Low-level JSON API for witness calculation.
calculateWitnessBytes(circuit: string, inputsJson: string): Promise<string>
Low-level API returning base64-encoded .wtns bytes.
Performance
Typical witness calculation times on modern devices:
| Circuit | iPhone 14 | Pixel 7 | |---------|-----------|---------| | transfer_1x1 | ~15ms | ~20ms | | transfer_1x2 | ~18ms | ~25ms | | transfer_5x5 | ~45ms | ~60ms | | transfer_10x4 | ~80ms | ~100ms |
Compared to JavaScript WASM: 10-50x faster
Error Handling
try {
const witness = await DopProver.calculateWitness('transfer_1x2', inputs);
} catch (error) {
// Possible errors:
// - "Circuit not found: transfer_invalid"
// - "Invalid input format"
// - "Witness calculation failed: constraint not satisfied"
console.error('Prover error:', error.message);
}Building from Source
Requirements
- Rust toolchain (rustup)
- Android NDK 27+
- Xcode 14+ (for iOS)
- cargo-ndk (
cargo install cargo-ndk)
Build Android
cd /path/to/mopro-dop
./build_android.shBuild iOS
cd /path/to/mopro-dop
./build_ios.shArchitecture
react-native-dop-prover/
android/
src/main/
java/.../DopProverModule.java # Android native module
jniLibs/
arm64-v8a/libdop_mobile_prover.so
armeabi-v7a/libdop_mobile_prover.so
x86_64/libdop_mobile_prover.so
ios/
DopProver.swift # iOS native module
libdop_mobile_prover.a # iOS static library
src/
index.ts # TypeScript API
index.d.ts # Type definitionsLicense
MIT
