mirror of https://github.com/zcash/mpc.git
Improve performance of verification.
This commit is contained in:
parent
b06d48c728
commit
983af331b2
|
@ -3,7 +3,7 @@ name = "mpc"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bn 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bn 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crossbeam 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -22,7 +22,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bn"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -77,7 +77,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
name = "snark"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"bn 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bn 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -11,7 +11,7 @@ readme = "README.md"
|
|||
|
||||
[dependencies]
|
||||
snark = { path = "./snark/" }
|
||||
bn = "0.2.2"
|
||||
bn = "0.2.3"
|
||||
crossbeam = "0.2.9"
|
||||
rand = "0.3.14"
|
||||
rustc-serialize = "~0.3.19"
|
||||
|
|
|
@ -16,4 +16,4 @@ gcc = "0.3.*"
|
|||
[dependencies]
|
||||
libc = "0.2.*"
|
||||
lazy_static = "0.1.*"
|
||||
bn = "0.2.2"
|
||||
bn = "0.2.3"
|
||||
|
|
|
@ -6,7 +6,6 @@ extern crate rustc_serialize;
|
|||
|
||||
mod taupowers;
|
||||
mod multicore;
|
||||
mod sequences;
|
||||
mod qap;
|
||||
mod spairs;
|
||||
mod transcript;
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
pub struct Sequences<'a, T: 'a, I: Iterator<Item=&'a T>> {
|
||||
v: I,
|
||||
last: Option<&'a T>
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, I: Iterator<Item=&'a T>> Sequences<'a, T, I> {
|
||||
pub fn new(v: I) -> Self {
|
||||
Sequences { v: v, last: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, I: Iterator<Item=&'a T>> Iterator for Sequences<'a, T, I> {
|
||||
type Item = (&'a T, &'a T);
|
||||
|
||||
fn next(&mut self) -> Option<(&'a T, &'a T)> {
|
||||
match (self.last, self.v.next()) {
|
||||
(Some(a), Some(b)) => {
|
||||
self.last = Some(b);
|
||||
Some((a, b))
|
||||
},
|
||||
(None, Some(b)) => {
|
||||
self.last = Some(b);
|
||||
self.next()
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sequences() {
|
||||
let a = vec![10, 57, 34, 12];
|
||||
let b: Vec<(&usize, &usize)> = Sequences::new(a.iter()).collect();
|
||||
let expected = vec![(&a[0], &a[1]), (&a[1], &a[2]), (&a[2], &a[3])];
|
||||
assert_eq!(b, expected);
|
||||
}
|
|
@ -2,7 +2,6 @@ use bn::*;
|
|||
use rand::Rng;
|
||||
use snark::*;
|
||||
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
|
||||
use sequences::*;
|
||||
use multicore::*;
|
||||
use crossbeam;
|
||||
|
||||
|
@ -394,18 +393,34 @@ pub fn checkvec<R: Rng, Group1: Group, Group2: Group>(
|
|||
where Group1: Pairing<Group2>
|
||||
{
|
||||
assert!(v1.len() == v2.len());
|
||||
let mut p = Group1::zero();
|
||||
let mut q = Group1::zero();
|
||||
|
||||
for i in v1.iter().zip(v2.iter()) {
|
||||
let alpha = Fr::random(rng);
|
||||
p = p + *i.0 * alpha;
|
||||
q = q + *i.1 * alpha;
|
||||
}
|
||||
crossbeam::scope(|scope| {
|
||||
let window_size = v1.len() / THREADS;
|
||||
let mut tasks = vec![];
|
||||
for i in v1.chunks(window_size).zip(v2.chunks(window_size)) {
|
||||
tasks.push(scope.spawn(move || {
|
||||
let rng = &mut ::rand::thread_rng();
|
||||
let mut p = Group1::zero();
|
||||
let mut q = Group1::zero();
|
||||
|
||||
if p.is_zero() || q.is_zero() { return false; }
|
||||
for (a, b) in i.0.iter().zip(i.1.iter()) {
|
||||
let alpha = Fr::random(rng);
|
||||
p = p + (*a * alpha);
|
||||
q = q + (*b * alpha);
|
||||
}
|
||||
|
||||
same_power(&Spair::new(p, q).unwrap(), &a)
|
||||
if p.is_zero() || q.is_zero() {
|
||||
false
|
||||
} else {
|
||||
same_power(&Spair::new(p, q).unwrap(), a)
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
assert!(tasks.len() >= THREADS);
|
||||
|
||||
tasks.into_iter().map(|t| t.join()).all(|r| r)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn checkseq<R: Rng, Group1: Group, Group2: Group>(
|
||||
|
|
Loading…
Reference in New Issue