add g16 wasm supported functions
This commit is contained in:
parent
8c2403ec6a
commit
9a6ddc22ae
4 changed files with 67 additions and 25 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1373,7 +1373,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.0"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"getrandom 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1881,7 +1881,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
dependencies = [
|
||||
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2654,7 +2654,7 @@ dependencies = [
|
|||
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
|
||||
"checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9"
|
||||
"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
|
||||
"checksum rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c"
|
||||
"checksum rand 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "59cea0d944b32347a1863e95942fd6ebdb486afb4f038119494f2860380c1d51"
|
||||
"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
|
||||
"checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
|
||||
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::proof_system::ProofSystem;
|
|||
use bellman::groth16::Parameters;
|
||||
use regex::Regex;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Write};
|
||||
use std::io::{ BufReader, Write, Read, Cursor };
|
||||
use std::path::PathBuf;
|
||||
use zokrates_field::field::FieldPrime;
|
||||
|
||||
|
@ -15,6 +15,7 @@ const G16_WARNING: &str = "WARNING: You are using the G16 scheme which is subjec
|
|||
|
||||
pub struct G16 {}
|
||||
impl ProofSystem for G16 {
|
||||
|
||||
fn setup(&self, program: ir::Prog<FieldPrime>, pk_path: &str, vk_path: &str) {
|
||||
std::env::set_var("BELLMAN_VERBOSE", "0");
|
||||
|
||||
|
@ -22,6 +23,7 @@ impl ProofSystem for G16 {
|
|||
|
||||
let parameters = Computation::without_witness(program).setup();
|
||||
let parameters_file = File::create(PathBuf::from(pk_path)).unwrap();
|
||||
|
||||
parameters.write(parameters_file).unwrap();
|
||||
let mut vk_file = File::create(PathBuf::from(vk_path)).unwrap();
|
||||
vk_file
|
||||
|
@ -29,6 +31,25 @@ impl ProofSystem for G16 {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn setup_c(&self, program: ir::Prog<FieldPrime>) -> (String, Vec<u8>) {
|
||||
std::env::set_var("BELLMAN_VERBOSE", "0");
|
||||
|
||||
println!("{}", G16_WARNING);
|
||||
|
||||
let parameters = Computation::without_witness(program).setup();
|
||||
let mut cursor = Cursor::new(Vec::new());
|
||||
|
||||
parameters.write(&mut cursor).unwrap();
|
||||
cursor.set_position(0);
|
||||
|
||||
let vk: String = serialize::serialize_vk(parameters.vk);
|
||||
|
||||
let mut pk: Vec<u8> = Vec::new();
|
||||
cursor.read_to_end(&mut pk).expect("Could not read cursor buffer");
|
||||
|
||||
(vk, pk)
|
||||
}
|
||||
|
||||
fn generate_proof(
|
||||
&self,
|
||||
program: ir::Prog<FieldPrime>,
|
||||
|
@ -46,7 +67,6 @@ impl ProofSystem for G16 {
|
|||
let params = Parameters::read(parameters_file, true).unwrap();
|
||||
|
||||
let proof = computation.clone().prove(¶ms);
|
||||
|
||||
let mut proof_file = File::create(PathBuf::from(proof_path)).unwrap();
|
||||
write!(
|
||||
proof_file,
|
||||
|
@ -57,7 +77,7 @@ impl ProofSystem for G16 {
|
|||
true
|
||||
}
|
||||
|
||||
fn generate_proof_wasm(
|
||||
fn generate_proof_c(
|
||||
&self,
|
||||
program: ir::Prog<FieldPrime>,
|
||||
witness: ir::Witness<FieldPrime>,
|
||||
|
@ -68,17 +88,21 @@ impl ProofSystem for G16 {
|
|||
println!("{}", G16_WARNING);
|
||||
|
||||
let computation = Computation::with_witness(program, witness);
|
||||
//let parameters_file = File::open(PathBuf::from(pk_path)).unwrap();
|
||||
|
||||
let params = Parameters::read(proving_key, true).unwrap();
|
||||
|
||||
let proof = computation.clone().prove(¶ms);
|
||||
|
||||
serialize::serialize_proof(&proof, &computation.public_inputs_values())
|
||||
}
|
||||
|
||||
fn export_solidity_verifier(&self, reader: BufReader<File>, is_abiv2: bool) -> String {
|
||||
let mut lines = reader.lines();
|
||||
fn export_solidity_verifier(&self, mut reader: BufReader<File>, is_abiv2: bool) -> String {
|
||||
let mut buffer = String::new();
|
||||
reader.read_to_string(&mut buffer).expect("Unable to read from file");
|
||||
|
||||
self.export_solidity_verifier_c(buffer, is_abiv2)
|
||||
}
|
||||
|
||||
fn export_solidity_verifier_c(&self, vk: String, is_abiv2: bool) -> String {
|
||||
let mut lines = vk.lines();
|
||||
|
||||
let (mut template_text, solidity_pairing_lib) = if is_abiv2 {
|
||||
(
|
||||
|
@ -103,10 +127,9 @@ impl ProofSystem for G16 {
|
|||
let vk_input_len_regex = Regex::new(r#"(<%vk_input_length%>)"#).unwrap();
|
||||
|
||||
for _ in 0..4 {
|
||||
let current_line: String = lines
|
||||
let current_line: &str = lines
|
||||
.next()
|
||||
.expect("Unexpected end of file in verification key!")
|
||||
.unwrap();
|
||||
.expect("Unexpected end of file in verification key!");
|
||||
let current_line_split: Vec<&str> = current_line.split("=").collect();
|
||||
assert_eq!(current_line_split.len(), 2);
|
||||
template_text = vk_regex
|
||||
|
@ -114,10 +137,9 @@ impl ProofSystem for G16 {
|
|||
.into_owned();
|
||||
}
|
||||
|
||||
let current_line: String = lines
|
||||
let current_line: &str = lines
|
||||
.next()
|
||||
.expect("Unexpected end of file in verification key!")
|
||||
.unwrap();
|
||||
.expect("Unexpected end of file in verification key!");
|
||||
let current_line_split: Vec<&str> = current_line.split("=").collect();
|
||||
assert_eq!(current_line_split.len(), 2);
|
||||
let gamma_abc_count: i32 = current_line_split[1].trim().parse().unwrap();
|
||||
|
@ -138,10 +160,9 @@ impl ProofSystem for G16 {
|
|||
let mut gamma_abc_repeat_text = String::new();
|
||||
for x in 0..gamma_abc_count {
|
||||
let mut curr_template = gamma_abc_template.clone();
|
||||
let current_line: String = lines
|
||||
let current_line: &str = lines
|
||||
.next()
|
||||
.expect("Unexpected end of file in verification key!")
|
||||
.unwrap();
|
||||
.expect("Unexpected end of file in verification key!");
|
||||
let current_line_split: Vec<&str> = current_line.split("=").collect();
|
||||
assert_eq!(current_line_split.len(), 2);
|
||||
curr_template = vk_gamma_abc_index_regex
|
||||
|
|
|
@ -13,7 +13,18 @@ use crate::ir;
|
|||
use std::io::BufReader;
|
||||
|
||||
pub trait ProofSystem {
|
||||
fn setup(&self, program: ir::Prog<FieldPrime>, pk_path: &str, vk_path: &str);
|
||||
|
||||
fn setup(
|
||||
&self,
|
||||
program: ir::Prog<FieldPrime>,
|
||||
pk_path: &str,
|
||||
vk_path: &str
|
||||
);
|
||||
|
||||
fn setup_c(
|
||||
&self,
|
||||
program: ir::Prog<FieldPrime>
|
||||
) -> (String, Vec<u8>);
|
||||
|
||||
fn generate_proof(
|
||||
&self,
|
||||
|
@ -23,12 +34,22 @@ pub trait ProofSystem {
|
|||
proof_path: &str,
|
||||
) -> bool;
|
||||
|
||||
fn generate_proof_wasm(
|
||||
fn generate_proof_c(
|
||||
&self,
|
||||
program: ir::Prog<FieldPrime>,
|
||||
witness: ir::Witness<FieldPrime>,
|
||||
proving_key: &[u8],
|
||||
) -> String;
|
||||
|
||||
fn export_solidity_verifier(&self, reader: BufReader<File>, is_abiv2: bool) -> String;
|
||||
fn export_solidity_verifier(
|
||||
&self,
|
||||
reader: BufReader<File>,
|
||||
is_abiv2: bool
|
||||
) -> String;
|
||||
|
||||
fn export_solidity_verifier_c(
|
||||
&self,
|
||||
vk: String,
|
||||
is_abiv2: bool
|
||||
) -> String;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ serde_derive = "1.0"
|
|||
lazy_static = "1.4"
|
||||
bincode = "0.8.0"
|
||||
serde_json = "1.0"
|
||||
num-traits = "0.2"
|
||||
num-integer = "0.1"
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
num-integer = { version = "0.1", default-features = false }
|
||||
pairing_ce = "0.18"
|
||||
ff_ce = { features = ["derive"], version = "0.7" }
|
||||
|
||||
|
|
Loading…
Reference in a new issue