mirror of
https://github.com/Rate-Limiting-Nullifier/rln_rs_bellman.git
synced 2026-01-09 15:18:10 -05:00
expose raw vk only
This commit is contained in:
@@ -21,7 +21,7 @@ cargo run --release --example export_test_keys
|
||||
### Build
|
||||
|
||||
```
|
||||
wasm-pack build --release --target=nodejs --out-name=$PACKAGE --out-dir=$PACKAGE_DIR -- --features wasm
|
||||
wasm-pack build --release --target=nodejs --scope=rln --out-name=$PACKAGE --out-dir=$PACKAGE_DIR -- --features wasm
|
||||
```
|
||||
|
||||
### Test
|
||||
|
||||
@@ -180,6 +180,7 @@ where
|
||||
result.prover_time = now.elapsed().as_millis() as f64 / 1000.0;
|
||||
|
||||
let verifing_key = prepare_verifying_key(¶meters.vk);
|
||||
|
||||
assert!(verify_proof(&verifing_key, &proof, &inputs.public_inputs()).unwrap());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,89 +18,6 @@ use rand::{Rand, SeedableRng, XorShiftRng};
|
||||
use std::io::{self, Error, ErrorKind, Read, Write};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use js_sys::Array;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct G1Hex {
|
||||
x: String,
|
||||
y: String,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct G2Hex {
|
||||
x_c0: String,
|
||||
x_c1: String,
|
||||
y_c0: String,
|
||||
y_c1: String,
|
||||
}
|
||||
|
||||
impl G1Hex {
|
||||
pub fn x(&self) -> String {
|
||||
self.x.clone()
|
||||
}
|
||||
|
||||
pub fn y(&self) -> String {
|
||||
self.y.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl G2Hex {
|
||||
pub fn x_c0(&self) -> String {
|
||||
self.x_c0.clone()
|
||||
}
|
||||
|
||||
pub fn x_c1(&self) -> String {
|
||||
self.x_c1.clone()
|
||||
}
|
||||
|
||||
pub fn y_c0(&self) -> String {
|
||||
self.y_c0.clone()
|
||||
}
|
||||
|
||||
pub fn y_c1(&self) -> String {
|
||||
self.y_c1.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn g1_to_hex(point: G1Affine) -> G1Hex {
|
||||
let mut buf_x: Vec<u8> = vec![];
|
||||
let mut buf_y: Vec<u8> = vec![];
|
||||
let point_xy = point.into_xy_unchecked();
|
||||
point_xy.0.into_repr().write_be(&mut buf_x).unwrap();
|
||||
let x = hex::encode(buf_x);
|
||||
point_xy.1.into_repr().write_be(&mut buf_y).unwrap();
|
||||
let y = hex::encode(buf_y);
|
||||
G1Hex { x, y }
|
||||
}
|
||||
|
||||
pub fn g2_to_hex(point: G2Affine) -> G2Hex {
|
||||
let mut buf_x_c0: Vec<u8> = vec![];
|
||||
let mut buf_x_c1: Vec<u8> = vec![];
|
||||
let mut buf_y_c0: Vec<u8> = vec![];
|
||||
let mut buf_y_c1: Vec<u8> = vec![];
|
||||
|
||||
let point_xy = point.into_xy_unchecked();
|
||||
|
||||
point_xy.0.c0.into_repr().write_be(&mut buf_x_c0).unwrap();
|
||||
let x_c0 = hex::encode(buf_x_c0);
|
||||
|
||||
point_xy.0.c1.into_repr().write_be(&mut buf_x_c1).unwrap();
|
||||
let x_c1 = hex::encode(buf_x_c1);
|
||||
|
||||
point_xy.1.c0.into_repr().write_be(&mut buf_y_c0).unwrap();
|
||||
let y_c0 = hex::encode(buf_y_c0);
|
||||
|
||||
point_xy.1.c1.into_repr().write_be(&mut buf_y_c1).unwrap();
|
||||
let y_c1 = hex::encode(buf_y_c1);
|
||||
|
||||
G2Hex {
|
||||
x_c0,
|
||||
x_c1,
|
||||
y_c0,
|
||||
y_c1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_uncompressed_proof<W: Write>(proof: Proof<Bn256>, mut writer: W) -> io::Result<()> {
|
||||
writer.write_all(proof.a.into_uncompressed().as_ref())?;
|
||||
writer.write_all(proof.b.into_uncompressed().as_ref())?;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
use super::utils::{
|
||||
g1_to_hex, g2_to_hex, read_uncompressed_proof, set_panic_hook, write_uncompressed_proof, G1Hex,
|
||||
G2Hex,
|
||||
};
|
||||
use super::utils::{read_uncompressed_proof, set_panic_hook, write_uncompressed_proof};
|
||||
use crate::circuit::poseidon::PoseidonCircuit;
|
||||
use crate::circuit::rln::{RLNCircuit, RLNInputs};
|
||||
use crate::merkle::MerkleTree;
|
||||
@@ -26,32 +23,6 @@ pub struct RLNWasm {
|
||||
merkle_depth: usize,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub struct VerifierKey {
|
||||
alpha_1: G1Hex,
|
||||
beta_2: G2Hex,
|
||||
gamma_2: G2Hex,
|
||||
delta_2: G2Hex,
|
||||
ic_array: Array,
|
||||
}
|
||||
|
||||
impl VerifierKey {
|
||||
pub fn new(circuit_parameters: Parameters<Bn256>) -> VerifierKey {
|
||||
let vk = circuit_parameters.vk;
|
||||
let ic_array: Array = Array::new();
|
||||
for e_ic in vk.ic.iter() {
|
||||
ic_array.push(&wasm_bindgen::JsValue::from(g1_to_hex(e_ic.clone())));
|
||||
}
|
||||
VerifierKey {
|
||||
alpha_1: g1_to_hex(vk.alpha_g1),
|
||||
beta_2: g2_to_hex(vk.beta_g2),
|
||||
gamma_2: g2_to_hex(vk.gamma_g2),
|
||||
delta_2: g2_to_hex(vk.delta_g2),
|
||||
ic_array,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl RLNWasm {
|
||||
fn default_poseidon_params() -> PoseidonParams<Bn256> {
|
||||
@@ -107,7 +78,7 @@ impl RLNWasm {
|
||||
let proof = create_random_proof(circuit, &self.circuit_parameters, &mut rng)
|
||||
.expect("failed to create proof");
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
write_uncompressed_proof(proof, &mut output);
|
||||
write_uncompressed_proof(proof, &mut output).expect("failed to write proof");
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
@@ -123,8 +94,13 @@ impl RLNWasm {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn verifier_key(&self) -> VerifierKey {
|
||||
VerifierKey::new(self.circuit_parameters.clone())
|
||||
pub fn verifier_key(&self) -> Result<Vec<u8>, JsValue> {
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
self.circuit_parameters
|
||||
.vk
|
||||
.write(&mut output)
|
||||
.expect("failed to write verifier key");
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user