Skip to content

Commit bcf64b4

Browse files
committed
add workflows, todo zkey migr
1 parent 6e376b3 commit bcf64b4

File tree

6 files changed

+185
-1
lines changed

6 files changed

+185
-1
lines changed

.github/workflows/release.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "Release libraries"
2+
3+
on:
4+
release:
5+
types: [published]
6+
# TODO: remove manual dispatch
7+
workflow_dispatch:
8+
9+
jobs:
10+
release:
11+
name: Release - ${{ matrix.platform.os-name }}
12+
strategy:
13+
matrix:
14+
platform:
15+
- os-name: Linux-x86_64
16+
runs-on: ubuntu-20.04
17+
target: x86_64-unknown-linux-musl
18+
19+
- os-name: Linux-aarch64
20+
runs-on: ubuntu-20.04
21+
target: aarch64-unknown-linux-musl
22+
23+
- os-name: macOS-x86_64
24+
runs-on: macOS-latest
25+
target: x86_64-apple-darwin
26+
27+
# more targets here ...
28+
29+
runs-on: ${{ matrix.platform.runs-on }}
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Build binary
35+
uses: houseabsolute/actions-rust-cross@v1
36+
with:
37+
command: ${{ matrix.platform.command }}
38+
target: ${{ matrix.platform.target }}
39+
args: "--locked --release"
40+
strip: true
41+
42+
- name: Publish artifacts and release
43+
uses: houseabsolute/actions-rust-release@v0
44+
with:
45+
executable-name: ubi
46+
target: ${{ matrix.platform.target }}

.github/workflows/test.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Rust Tests
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
test:
12+
name: Run Tests
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Install Rust
19+
uses: dtolnay/rust-toolchain@stable
20+
21+
- name: Cache dependencies
22+
uses: actions/cache@v3
23+
with:
24+
path: |
25+
~/.cargo/bin/
26+
~/.cargo/registry/index/
27+
~/.cargo/registry/cache/
28+
~/.cargo/git/db/
29+
target/
30+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
31+
32+
- name: Build
33+
run: cargo build --verbose
34+
35+
- name: Run tests
36+
run: cargo test --verbose

TODO.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [ ] Add Github Workflows
2+
- [ ] Add zkey reader from LambdaWorks

src/lambdaworks/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub use lambdaworks_groth16::*;
66
use crate::{SnarkjsProof, SnarkjsPublicSignals};
77

88
mod snarkjs;
9+
mod zkey;
910

1011
pub fn prove_with_witness(wtns_path: impl AsRef<Path>, r1cs_path: impl AsRef<Path>) {
1112
let (qap, wtns) = circom_to_lambda(

src/lambdaworks/zkey.rs

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//! Lambdaworks does not have a zkey reader by default, but we can add a converter from Arkworks perhaps.
2+
//!
3+
//!
4+
//! ## ArkWorks
5+
//!
6+
//! ```rs
7+
//! pub struct ProvingKey<E: Pairing> {
8+
//! /// The underlying verification key.
9+
//! pub vk: VerifyingKey<E>,
10+
//! /// The element `beta * G` in `E::G1`.
11+
//! pub beta_g1: E::G1Affine,
12+
//! /// The element `delta * G` in `E::G1`.
13+
//! pub delta_g1: E::G1Affine,
14+
//! /// The elements `a_i * G` in `E::G1`.
15+
//! pub a_query: Vec<E::G1Affine>,
16+
//! /// The elements `b_i * G` in `E::G1`.
17+
//! pub b_g1_query: Vec<E::G1Affine>,
18+
//! /// The elements `b_i * H` in `E::G2`.
19+
//! pub b_g2_query: Vec<E::G2Affine>,
20+
//! /// The elements `h_i * G` in `E::G1`.
21+
//! pub h_query: Vec<E::G1Affine>,
22+
//! /// The elements `l_i * G` in `E::G1`.
23+
//! pub l_query: Vec<E::G1Affine>,
24+
//!}
25+
//! ```
26+
//!
27+
//! ## LambdaWorks
28+
//!
29+
//! ```rs
30+
//! pub struct ProvingKey {
31+
//! pub alpha_g1: G1Point,
32+
//! pub beta_g1: G1Point,
33+
//! pub beta_g2: G2Point,
34+
//! pub delta_g1: G1Point,
35+
//! pub delta_g2: G2Point,
36+
//! // [A_0(τ)]_1, [A_1(τ)]_1, ..., [A_n(τ)]_1
37+
//! pub l_tau_g1: Vec<G1Point>,
38+
//! // [B_0(τ)]_1, [B_1(τ)]_1, ..., [B_n(τ)]_1
39+
//! pub r_tau_g1: Vec<G1Point>,
40+
//! // [B_0(τ)]_2, [B_1(τ)]_2, ..., [B_n(τ)]_2
41+
//! pub r_tau_g2: Vec<G2Point>,
42+
//! // [K_{k+1}(τ)]_1, [K_{k+2}(τ)]_1, ..., [K_n(τ)]_1
43+
//! // where K_i(τ) = ƍ^{-1} * (β*l(τ) + α*r(τ) + o(τ))
44+
//! // and "k" is the number of public inputs
45+
//! pub prover_k_tau_g1: Vec<G1Point>,
46+
//! // [delta^{-1} * t(τ) * tau^0]_1, [delta^{-1} * t(τ) * τ^1]_1, ..., [delta^{-1} * t(τ) * τ^m]_1
47+
//! pub z_powers_of_tau_g1: Vec<G1Point>,
48+
//! }
49+
//! ```
50+
51+
use ark_ec::pairing::Pairing;
52+
use ark_groth16::VerifyingKey;
53+
use lambdaworks_groth16::common::{G1Point, G2Point};
54+
55+
/// The prover key for for the Groth16 zkSNARK.
56+
pub struct ArkworksProvingKey<E: Pairing> {
57+
/// The underlying verification key.
58+
pub vk: VerifyingKey<E>,
59+
/// The element `beta * G` in `E::G1`.
60+
pub beta_g1: E::G1Affine,
61+
/// The element `delta * G` in `E::G1`.
62+
pub delta_g1: E::G1Affine,
63+
/// The elements `a_i * G` in `E::G1`.
64+
pub a_query: Vec<E::G1Affine>,
65+
/// The elements `b_i * G` in `E::G1`.
66+
pub b_g1_query: Vec<E::G1Affine>,
67+
/// The elements `b_i * H` in `E::G2`.
68+
pub b_g2_query: Vec<E::G2Affine>,
69+
/// The elements `h_i * G` in `E::G1`.
70+
pub h_query: Vec<E::G1Affine>,
71+
/// The elements `l_i * G` in `E::G1`.
72+
pub l_query: Vec<E::G1Affine>,
73+
}
74+
75+
/// Converts an Arkworks `ProvingKey` to a Lambdaworks `ProvingKey`.
76+
///
77+
/// Here is how the mapping is done Arkworks to Lambdaworks:
78+
/// - `pk.vb.alpha_g1` -> `alpha_g1`
79+
///
80+
/// - `pk.b_g1_query` -> `beta_g1`
81+
/// - `pk.vk.beta_g2` -> `beta_g2`
82+
///
83+
/// - `pk.delta_g1` -> `delta_g1`
84+
/// - `pk.vk.delta_g2` -> `delta_g2`
85+
///
86+
/// - `pk.l_query` -> `l_tau_g1`
87+
/// - `pk.b_g1_query` -> `r_tau_g1`
88+
/// - `pk.b_g2_query` -> `r_tau_g2`
89+
///
90+
/// - `pk.vk.gamma_abc_g1` -> `prover_k_tau_g1`
91+
///
92+
pub fn convert_zkey<E: Pairing>(
93+
ark_pk: ark_groth16::ProvingKey<E>,
94+
) -> lambdaworks_groth16::ProvingKey {
95+
todo!()
96+
}

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use std::ffi::{c_char, CStr, CString};
88

99
pub use snarkjs::*;
1010

11-
// TODO: !!!
11+
/// Given a string input, returns the same.
12+
///
13+
/// Can be used for testing.
1214
#[no_mangle]
1315
#[allow(improper_ctypes_definitions)]
1416
pub extern "C" fn echo(input: *const c_char) -> CString {
@@ -20,6 +22,7 @@ pub extern "C" fn echo(input: *const c_char) -> CString {
2022
CString::new(input).unwrap()
2123
}
2224

25+
/// Generate an Arkworks proof.
2326
#[no_mangle]
2427
#[allow(improper_ctypes_definitions)]
2528
pub extern "C" fn arkworks_prove(

0 commit comments

Comments
 (0)