Skip to content

Commit

Permalink
Merge branch 'master' of github.com:QED-it/zkinterface-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
naure committed Jun 20, 2019
2 parents fbe1e18 + d1b0d2d commit d03f875
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 26 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ language: rust
cache: cargo

rust:
- stable
# - stable
- nightly

install:
- rustup component add rustfmt --toolchain stable
- rustup component add clippy --toolchain stable
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- rustup component add rustfmt #--toolchain stable
- rustup component add clippy #--toolchain stable
- cargo install -f wasm-pack

before_script:
- chmod +x ./ci/cargo_check.sh
script:
- ./ci/cargo_check.sh
- make
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ A zkInterface in WebAssembly
live demo: https://qed-it.github.io/zkinterface-wasm-demo (hosted @ https://github.com/QED-it/zkinterface-wasm-demo)

the code for the demo can be found at [/demo](https://github.com/QED-it/zkinterface-wasm/tree/master/demo)

## Progress Tracker:
| System | ZK-Interface support | wasm supports | Demo integration |
|--------------------|-----------------------|--------------------|--------------------|
| :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Bulletproof | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Zokrates | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| | | | |

## How to contribue:

14 changes: 14 additions & 0 deletions ci/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
all: install build-wasm build-web

build-wasm:
wasm-pack build --out-dir ../../demo/pkg/zkif-wasm-zokrates/ ../zkif-wasm-bundles/zkif-wasm-zokrates
wasm-pack build --out-dir ../../demo/pkg/zkif-wasm-bulletproofs/ ../zkif-wasm-bundles/zkif-wasm-bulletproofs

build-web:
cd demo && npm run build

install:
cd demo && npm install

web-dev:
cd demo && npm run start
2 changes: 1 addition & 1 deletion ci/cargo_check.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set +x

echo executing cargo_check.sh

cd ../zkif-wasm-bundles/zkif-wasm-bulletproofs/
cd ./zkif-wasm-bundles/zkif-wasm-bulletproofs/
cargo fmt -- --check
cargo clippy -- -D warnings
cargo test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use bulletproofs::r1cs::{zkinterface_backend, R1CSProof};
use wasm_bindgen::prelude::wasm_bindgen;
use zkinterface::reading::Messages;
use bulletproofs::r1cs::{
R1CSProof,
zkinterface_backend,
};


/// Prove using the circuit and the witness.
#[wasm_bindgen]
Expand All @@ -18,7 +14,6 @@ pub fn prove(circuit: &[u8], witness: &[u8]) -> Vec<u8> {
bincode::serialize(&proof).unwrap()
}


/// Verify using the circuit and the proof.
#[wasm_bindgen]
pub fn verify(circuit: &[u8], inputs: &[u8], proof_ser: &[u8]) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions zkif-wasm-bundles/zkif-wasm-bulletproofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use wasm_bindgen::prelude::*;
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
extern {
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn error(msg: String);
#[wasm_bindgen(js_namespace = console)]
Expand All @@ -19,5 +19,5 @@ extern {
#[wasm_bindgen(start)]
pub fn start() {
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
console_error_panic_hook::set_once();
}
5 changes: 2 additions & 3 deletions zkif-wasm-bundles/zkif-wasm-example/src/frontend.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use wasm_bindgen::prelude::wasm_bindgen;
use zkinterface::{
examples::{example_circuit_inputs, write_example_constraints, write_example_witness_inputs},
use zkinterface::examples::{
example_circuit_inputs, write_example_constraints, write_example_witness_inputs,
};

/// Generate a test circuit constraints.
Expand All @@ -15,7 +15,6 @@ pub fn make_circuit(x: u32, y: u32, zz: u32) -> Vec<u8> {
msg
}


/// Generate a witness.
#[wasm_bindgen]
pub fn make_witness(x: u32, y: u32) -> Vec<u8> {
Expand Down
4 changes: 2 additions & 2 deletions zkif-wasm-bundles/zkif-wasm-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use wasm_bindgen::prelude::*;
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
extern {
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn error(msg: String);
#[wasm_bindgen(js_namespace = console)]
Expand All @@ -19,5 +19,5 @@ extern {
#[wasm_bindgen(start)]
pub fn start() {
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
console_error_panic_hook::set_once();
}
14 changes: 8 additions & 6 deletions zkif-wasm-bundles/zkif-wasm-zokrates/src/frontend.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use wasm_bindgen::prelude::{JsValue, wasm_bindgen};
use wasm_bindgen::prelude::{wasm_bindgen, JsValue};
use zkinterface::{
reading::{Messages, split_messages},
reading::{split_messages, Messages},
zkinterface_generated::zkinterface::get_size_prefixed_root_as_root,
};
use zokrates_core::{
Expand All @@ -11,10 +11,8 @@ use zokrates_core::{
};
use zokrates_field::field::FieldPrime;


fn compile_prog(code: &str) -> Prog<FieldPrime> {
compile::<FieldPrime, &[u8], &[u8], std::io::Error>(
&mut code.as_bytes(), None, None).unwrap()
compile::<FieldPrime, &[u8], &[u8], std::io::Error>(&mut code.as_bytes(), None, None).unwrap()
}

/// Generate a constraint system.
Expand Down Expand Up @@ -42,7 +40,11 @@ pub fn make_witness(code: &str, x: u32, y: u32) -> JsValue /* Instance */ {

let verifier_msg = get_verifier_msg(&prover_msg).unwrap();

JsValue::from_serde(&Instance { prover_msg, verifier_msg }).unwrap()
JsValue::from_serde(&Instance {
prover_msg,
verifier_msg,
})
.unwrap()
}

#[derive(Serialize)]
Expand Down
4 changes: 2 additions & 2 deletions zkif-wasm-bundles/zkif-wasm-zokrates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern crate serde_derive;
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
extern {
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn error(msg: String);
#[wasm_bindgen(js_namespace = console)]
Expand All @@ -22,5 +22,5 @@ extern {
#[wasm_bindgen(start)]
pub fn start() {
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
console_error_panic_hook::set_once();
}

0 comments on commit d03f875

Please sign in to comment.