move rng function to proof systems crate
This commit is contained in:
parent
097e707de4
commit
43cb632c4a
12 changed files with 20 additions and 44 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -3211,8 +3211,6 @@ dependencies = [
|
|||
name = "zokrates_js"
|
||||
version = "1.1.4"
|
||||
dependencies = [
|
||||
"blake2 0.8.1",
|
||||
"byteorder",
|
||||
"console_error_panic_hook",
|
||||
"indexmap",
|
||||
"js-sys",
|
||||
|
@ -3262,9 +3260,10 @@ dependencies = [
|
|||
name = "zokrates_proof_systems"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"blake2 0.8.1",
|
||||
"byteorder",
|
||||
"cfg-if 0.1.10",
|
||||
"ethabi",
|
||||
"getrandom",
|
||||
"hex 0.4.3",
|
||||
"primitive-types",
|
||||
"rand 0.8.5",
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
extern crate lazy_static;
|
||||
|
||||
mod cli_constants;
|
||||
mod common;
|
||||
mod ops;
|
||||
|
||||
use clap::{App, AppSettings, Arg};
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::cli_constants;
|
||||
use crate::common::get_seeded_rng;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use rand_0_8::rngs::StdRng;
|
||||
use rand_0_8::SeedableRng;
|
||||
|
@ -15,6 +14,7 @@ use zokrates_bellman::Bellman;
|
|||
use zokrates_common::constants;
|
||||
use zokrates_common::helpers::*;
|
||||
use zokrates_field::Field;
|
||||
use zokrates_proof_systems::rng::get_rng_from_entropy;
|
||||
#[cfg(any(feature = "bellman", feature = "ark"))]
|
||||
use zokrates_proof_systems::*;
|
||||
|
||||
|
@ -179,7 +179,7 @@ fn cli_generate_proof<
|
|||
|
||||
let mut rng = sub_matches
|
||||
.value_of("entropy")
|
||||
.map(get_seeded_rng)
|
||||
.map(get_rng_from_entropy)
|
||||
.unwrap_or_else(StdRng::from_entropy);
|
||||
|
||||
let proof = B::generate_proof(program, witness, pk, &mut rng);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::cli_constants::MPC_DEFAULT_PATH;
|
||||
use crate::common::get_seeded_rng;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use rand_0_8::{rngs::StdRng, SeedableRng};
|
||||
use std::fs::File;
|
||||
|
@ -8,6 +7,7 @@ use std::path::Path;
|
|||
use zokrates_bellman::Bellman;
|
||||
use zokrates_common::constants::{BLS12_381, BN128};
|
||||
use zokrates_field::{BellmanFieldExtensions, Bls12_381Field, Bn128Field, Field};
|
||||
use zokrates_proof_systems::rng::get_rng_from_entropy;
|
||||
use zokrates_proof_systems::{MpcBackend, MpcScheme, G16};
|
||||
|
||||
pub fn subcommand() -> App<'static, 'static> {
|
||||
|
@ -84,7 +84,7 @@ pub fn cli_mpc_contribute<
|
|||
|
||||
let mut rng = sub_matches
|
||||
.value_of("entropy")
|
||||
.map(get_seeded_rng)
|
||||
.map(get_rng_from_entropy)
|
||||
.unwrap_or_else(StdRng::from_entropy);
|
||||
|
||||
let hash = B::contribute(&mut reader, &mut rng, &mut writer)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::cli_constants;
|
||||
use crate::common::get_seeded_rng;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use rand_0_8::rngs::StdRng;
|
||||
use rand_0_8::SeedableRng;
|
||||
|
@ -15,6 +14,7 @@ use zokrates_bellman::Bellman;
|
|||
use zokrates_common::constants;
|
||||
use zokrates_common::helpers::*;
|
||||
use zokrates_field::Field;
|
||||
use zokrates_proof_systems::rng::get_rng_from_entropy;
|
||||
#[cfg(any(feature = "bellman", feature = "ark"))]
|
||||
use zokrates_proof_systems::*;
|
||||
|
||||
|
@ -194,7 +194,7 @@ fn cli_setup_non_universal<
|
|||
|
||||
let mut rng = sub_matches
|
||||
.value_of("entropy")
|
||||
.map(get_seeded_rng)
|
||||
.map(get_rng_from_entropy)
|
||||
.unwrap_or_else(StdRng::from_entropy);
|
||||
|
||||
// run setup phase
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::cli_constants;
|
||||
use crate::common::get_seeded_rng;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use rand_0_8::rngs::StdRng;
|
||||
use rand_0_8::SeedableRng;
|
||||
|
@ -12,6 +11,7 @@ use zokrates_ark::Ark;
|
|||
use zokrates_common::constants;
|
||||
use zokrates_common::helpers::*;
|
||||
use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field};
|
||||
use zokrates_proof_systems::rng::get_rng_from_entropy;
|
||||
#[cfg(any(feature = "bellman", feature = "ark"))]
|
||||
use zokrates_proof_systems::*;
|
||||
|
||||
|
@ -111,7 +111,7 @@ fn cli_universal_setup<T: Field, S: UniversalScheme<T>, B: UniversalBackend<T, S
|
|||
|
||||
let mut rng = sub_matches
|
||||
.value_of("entropy")
|
||||
.map(get_seeded_rng)
|
||||
.map(get_rng_from_entropy)
|
||||
.unwrap_or_else(StdRng::from_entropy);
|
||||
|
||||
// run universal setup phase
|
||||
|
|
|
@ -15,8 +15,6 @@ wasm-bindgen = { version = "0.2.46", features = ["serde-serialize"] }
|
|||
typed-arena = "1.4.1"
|
||||
lazy_static = "1.4.0"
|
||||
rand_0_8 = { version = "0.8", package = "rand" }
|
||||
blake2 = "0.8.1"
|
||||
byteorder = "1"
|
||||
zokrates_core = { path = "../zokrates_core", default-features = false, features = ["ark", "bellman"] }
|
||||
zokrates_ark = { path = "../zokrates_ark", default-features = false}
|
||||
zokrates_bellman = { path = "../zokrates_bellman", default-features = false}
|
||||
|
|
|
@ -3,7 +3,7 @@ mod util;
|
|||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
use crate::util::{get_seeded_rng, normalize_path};
|
||||
use crate::util::normalize_path;
|
||||
use rand_0_8::{rngs::StdRng, SeedableRng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::to_string_pretty;
|
||||
|
@ -28,6 +28,7 @@ use zokrates_core::compile::{
|
|||
use zokrates_core::imports::Error;
|
||||
use zokrates_field::{Bls12_377Field, Bls12_381Field, Bn128Field, Bw6_761Field, Field};
|
||||
use zokrates_proof_systems::groth16::G16;
|
||||
use zokrates_proof_systems::rng::get_rng_from_entropy;
|
||||
use zokrates_proof_systems::{
|
||||
Backend, Marlin, NonUniversalBackend, NonUniversalScheme, Proof, Scheme,
|
||||
SolidityCompatibleField, SolidityCompatibleScheme, TaggedKeypair, TaggedProof,
|
||||
|
@ -544,7 +545,7 @@ pub fn setup(program: &[u8], entropy: JsValue, options: JsValue) -> Result<JsVal
|
|||
|
||||
let mut rng = entropy
|
||||
.as_string()
|
||||
.map(|s| get_seeded_rng(&s))
|
||||
.map(|s| get_rng_from_entropy(&s))
|
||||
.unwrap_or_else(StdRng::from_entropy);
|
||||
|
||||
match (backend, scheme) {
|
||||
|
@ -622,7 +623,7 @@ pub fn universal_setup(curve: JsValue, size: u32, entropy: JsValue) -> Result<Ve
|
|||
|
||||
let mut rng = entropy
|
||||
.as_string()
|
||||
.map(|s| get_seeded_rng(&s))
|
||||
.map(|s| get_rng_from_entropy(&s))
|
||||
.unwrap_or_else(StdRng::from_entropy);
|
||||
|
||||
match curve {
|
||||
|
@ -683,7 +684,7 @@ pub fn generate_proof(
|
|||
|
||||
let mut rng = entropy
|
||||
.as_string()
|
||||
.map(|s| get_seeded_rng(&s))
|
||||
.map(|s| get_rng_from_entropy(&s))
|
||||
.unwrap_or_else(StdRng::from_entropy);
|
||||
|
||||
match (backend, scheme) {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use rand_0_8::rngs::StdRng;
|
||||
use rand_0_8::SeedableRng;
|
||||
use std::path::{Component, PathBuf};
|
||||
|
||||
pub fn normalize_path(path: PathBuf) -> PathBuf {
|
||||
|
@ -28,23 +26,3 @@ pub fn normalize_path(path: PathBuf) -> PathBuf {
|
|||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn get_seeded_rng(entropy: &str) -> StdRng {
|
||||
use blake2::{Blake2b, Digest};
|
||||
use byteorder::ReadBytesExt;
|
||||
|
||||
let h = {
|
||||
let mut h = Blake2b::default();
|
||||
h.input(&entropy.as_bytes());
|
||||
h.result()
|
||||
};
|
||||
|
||||
let mut digest = &h[..];
|
||||
let mut seed = [0u8; 32];
|
||||
|
||||
for e in &mut seed {
|
||||
*e = digest.read_u8().unwrap();
|
||||
}
|
||||
|
||||
StdRng::from_seed(seed)
|
||||
}
|
||||
|
|
|
@ -13,4 +13,5 @@ cfg-if = "0.1"
|
|||
ethabi = "17.0.0"
|
||||
primitive-types = { version = "0.11", features = ["rlp"] }
|
||||
rand_0_8 = { version = "0.8", package = "rand" }
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
blake2 = "0.8.1"
|
||||
byteorder = "1"
|
|
@ -1,3 +1,4 @@
|
|||
pub mod rng;
|
||||
pub mod to_token;
|
||||
|
||||
mod scheme;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use blake2::{Blake2b, Digest};
|
||||
use byteorder::ReadBytesExt;
|
||||
use rand_0_8::rngs::StdRng;
|
||||
use rand_0_8::SeedableRng;
|
||||
use rand_0_8::{rngs::StdRng, SeedableRng};
|
||||
|
||||
pub fn get_seeded_rng(entropy: &str) -> StdRng {
|
||||
pub fn get_rng_from_entropy(entropy: &str) -> StdRng {
|
||||
let h = {
|
||||
let mut h = Blake2b::default();
|
||||
h.input(&entropy.as_bytes());
|
Loading…
Reference in a new issue