Skip to content

Commit

Permalink
Initial version.
Browse files Browse the repository at this point in the history
  • Loading branch information
5eeman committed Jun 26, 2024
1 parent 836f05a commit d305757
Show file tree
Hide file tree
Showing 99 changed files with 2,142 additions and 3,759 deletions.
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion LICENSE

This file was deleted.

118 changes: 108 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,113 @@
# flutter_rapidsnark
# flutter-rapidsnark

A new Flutter project.
---

## Getting Started
This library is Flutter wrapper for the [Rapidsnark](https://github.com/iden3/rapidsnark). It enables the
generation of proofs for specified circuits within a Flutter environment.

This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.
## Platform Support

For help getting started with Flutter development, view the
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
**iOS**: Compatible with any iOS device with 64 bit architecture.
> Version for emulator built without assembly optimizations, resulting in slower performance.
**Android**: Compatible with arm64-v8a, x86_64 architectures.

## Installation

```sh
flutter pub add flutter_rapidsnark
```

## Usage

#### groth16ProveWithZKeyFilePath

Function takes path to .zkey file and witness file as [Uint8List] and returns proof and public signals as record.

Reads .zkey file directly from filesystem.


```dart
import 'package:flutter_rapidsnark/flutter_rapidsnark.dart';
// ...
final zkeyPath = "path/to/zkey";
final wtns = await File("path/to/wtns").readAsBytes();
final proof = await groth16ProveWithZKeyFilePath(zkeyPath, wtns);
```

#### groth16Verify

Verifies proof and public signals against zkey.

```dart
import 'package:flutter_rapidsnark/flutter_rapidsnark.dart';
// ...
final zkey = await File("path/to/zkey").readAsBytes();
final wtns = await File("path/to/wtns").readAsBytes();
final verificationKey = await File("path/to/verification_key").readAsBytes();
final proof = await groth16Prove(zkey, wtns);
final proofValid = await groth16Verify(proof.proof, proof.publicSignals, verificationKey);
```

#### groth16Prove

Function that takes zkey and witness files as bytes.

`proof` and `pub_signals` are JSON encoded strings.

>Large circuits might cause OOM. Use with caution.
```dart
import 'package:flutter_rapidsnark/flutter_rapidsnark.dart';
// ...
final zkey = await File("path/to/zkey").readAsBytes();
final wtns = await File("path/to/wtns").readAsBytes();
final proof = await groth16Prove(zkey, wtns);
```
#### groth16PublicSizeForZkeyFile

Calculates public buffer size for specified zkey.

```dart
import 'package:flutter_rapidsnark/flutter_rapidsnark.dart';
// ...
final publicBufferSize = await groth16PublicSizeForZkeyFile("path/to/zkey");
```

### Public buffer size

Both `groth16Prove` and `groth16ProveWithZKeyFilePath` has an optional `proofBufferSize`, `publicBufferSize` and `errorBufferSize` parameters. If publicBufferSize is too small it will be recalculated automatically by library.

These parameters are used to set the size of the buffers used to store the proof, public signals and error.

If you have embedded circuit in the app, it is recommended to calculate the size of the public buffer once and reuse it.
To calculate the size of public buffer call `groth16ProveWithZKeyFilePath`.

## Troubleshooting

### Errors

#### Invalid witness length.

If you're getting invalid witness length error - check that your witness file is not corrupted and is generated for the same circuit as zkey.

## Example App

Check out the [example app](./example) and [example README](./example/README.md) for a working example.

## License

flutter-rapidsnark is part of the iden3 project 0KIMS association. Please check the [COPYING](./COPYING) file for
more details.
12 changes: 7 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group 'com.rapidsnark.flutter_rapidsnark'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.9.0'
repositories {
google()
mavenCentral()
Expand Down Expand Up @@ -46,10 +46,12 @@ android {
}

defaultConfig {
minSdkVersion 19
minSdkVersion 24
}

dependencies {
implementation "io.iden3:rapidsnark:0.0.1-alpha.1"

testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.mockito:mockito-core:5.0.0'
}
Expand All @@ -59,9 +61,9 @@ android {
useJUnitPlatform()

testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen { false }
showStandardStreams = true
}
}
}
Expand Down
Binary file added android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit d305757

Please sign in to comment.