mirror of https://github.com/zcash/mpc.git
K query in parallel.
This commit is contained in:
parent
1aa90ee32e
commit
8a32e77949
|
@ -200,9 +200,9 @@ impl ConnectionHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Initializing stage3 with stage2");
|
info!("Initializing stage3 with constraint system and stage2");
|
||||||
|
|
||||||
let mut stage3 = Stage3Contents::new(&stage2);
|
let mut stage3 = Stage3Contents::new(&cs, &stage2);
|
||||||
for (pubkey, peerid) in pubkeys.iter().zip(peers.iter()) {
|
for (pubkey, peerid) in pubkeys.iter().zip(peers.iter()) {
|
||||||
info!("Sending stage3 to peerid={}", peerid.to_hex());
|
info!("Sending stage3 to peerid={}", peerid.to_hex());
|
||||||
|
|
||||||
|
|
|
@ -236,20 +236,21 @@ pub struct Stage3Contents {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stage3Contents {
|
impl Stage3Contents {
|
||||||
pub fn new(stage2: &Stage2Contents) -> Self {
|
pub fn new(cs: &CS, stage2: &Stage2Contents) -> Self {
|
||||||
let mut pk_k = Vec::with_capacity(stage2.pk_a.len()+3);
|
assert_eq!(stage2.pk_a.len(), cs.num_vars + 1);
|
||||||
|
assert_eq!(stage2.pk_b_temp.len(), cs.num_vars + 1);
|
||||||
|
assert_eq!(stage2.pk_c.len(), cs.num_vars + 1);
|
||||||
|
|
||||||
for ((a, b), c) in stage2.pk_a.iter().take(stage2.pk_a.len() - 1)
|
let mut pk_k = Vec::with_capacity(cs.num_vars + 3);
|
||||||
.zip(stage2.pk_b_temp.iter().take(stage2.pk_b_temp.len() - 1))
|
|
||||||
.zip(stage2.pk_c.iter().take(stage2.pk_c.len() - 1))
|
|
||||||
{
|
|
||||||
pk_k.push(*a + *b + *c);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform Z extention as libsnark does.
|
// Perform Z extention as libsnark does.
|
||||||
pk_k.push(stage2.pk_a[stage2.pk_a.len() - 1]);
|
pk_k.extend_from_slice(&stage2.pk_a);
|
||||||
pk_k.push(stage2.pk_b_temp[stage2.pk_b_temp.len() - 1]);
|
pk_k.push(stage2.pk_b_temp[cs.num_vars]);
|
||||||
pk_k.push(stage2.pk_c[stage2.pk_c.len() - 1]);
|
pk_k.push(stage2.pk_c[cs.num_vars]);
|
||||||
|
|
||||||
|
// Add B and C
|
||||||
|
add_all_to(&mut pk_k[0..cs.num_vars], &stage2.pk_b_temp[0..cs.num_vars]);
|
||||||
|
add_all_to(&mut pk_k[0..cs.num_vars], &stage2.pk_c[0..cs.num_vars]);
|
||||||
|
|
||||||
Stage3Contents {
|
Stage3Contents {
|
||||||
vk_gamma: G2::one(),
|
vk_gamma: G2::one(),
|
||||||
|
@ -349,7 +350,7 @@ fn compare_to_libsnark_generate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stage 3
|
// Stage 3
|
||||||
let mut stage3 = Stage3Contents::new(&stage2);
|
let mut stage3 = Stage3Contents::new(&cs, &stage2);
|
||||||
for (private, public) in privkeys.iter().zip(pubkeys.iter()) {
|
for (private, public) in privkeys.iter().zip(pubkeys.iter()) {
|
||||||
let prev = stage3.clone();
|
let prev = stage3.clone();
|
||||||
stage3.transform(private);
|
stage3.transform(private);
|
||||||
|
|
|
@ -25,3 +25,14 @@ pub fn mul_all_by<G: Group>(v: &mut [G], c: Fr) {
|
||||||
}
|
}
|
||||||
}, ::THREADS);
|
}, ::THREADS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_all_to<G: Group>(v: &mut [G], other: &[G]) {
|
||||||
|
assert_eq!(v.len(), other.len());
|
||||||
|
|
||||||
|
parallel(v, |mut i, v| {
|
||||||
|
for a in v {
|
||||||
|
*a = *a + other[i];
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}, ::THREADS);
|
||||||
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ fn main() {
|
||||||
stage2 = new_stage;
|
stage2 = new_stage;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut stage3 = Stage3Contents::new(&stage2);
|
let mut stage3 = Stage3Contents::new(&cs, &stage2);
|
||||||
|
|
||||||
for i in 0..num_players {
|
for i in 0..num_players {
|
||||||
let new_stage: Stage3Contents = decode_from(&mut f, Infinite).unwrap();
|
let new_stage: Stage3Contents = decode_from(&mut f, Infinite).unwrap();
|
||||||
|
|
Loading…
Reference in New Issue