Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Rep3 compatible garbled circuit implementations and conversion methods for a2y, y2a, b2y, y2b, a2y2b, and b2y2a. #233

Merged
merged 56 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
878437d
start to add yao stuff
rw0x0 Oct 21, 2024
9610ebb
.
rw0x0 Oct 21, 2024
cd4ae8d
.
rw0x0 Oct 21, 2024
e21cc9b
garbler
rw0x0 Oct 21, 2024
a9562c3
evaluator
rw0x0 Oct 21, 2024
8e1bdec
.
rw0x0 Oct 22, 2024
25fb41e
.
rw0x0 Oct 22, 2024
c1b862f
.
rw0x0 Oct 22, 2024
afcb7f0
.
rw0x0 Oct 22, 2024
8d88f50
output function
rw0x0 Oct 22, 2024
fb45acb
first garble test, does not work
rw0x0 Oct 22, 2024
b4dc938
fix test
rw0x0 Oct 22, 2024
43dc088
add function that allows to generate the same value on all parties in…
rw0x0 Oct 22, 2024
1f17737
progress
rw0x0 Oct 22, 2024
e23249f
.
rw0x0 Oct 22, 2024
4c23a66
progress
rw0x0 Oct 22, 2024
b09578a
.
rw0x0 Oct 22, 2024
ceb16ca
a2y untested
rw0x0 Oct 22, 2024
e0fc009
.
rw0x0 Oct 22, 2024
0ed7aee
a2y works
rw0x0 Oct 22, 2024
7db3efe
.
rw0x0 Oct 22, 2024
b09d350
progress
rw0x0 Oct 22, 2024
d50ef56
.
rw0x0 Oct 22, 2024
36a0cdf
y2a test not working
rw0x0 Oct 22, 2024
e14f857
fix y2a
rw0x0 Oct 22, 2024
e43828b
.
rw0x0 Oct 22, 2024
e22526c
.
rw0x0 Oct 22, 2024
2630bce
.
rw0x0 Oct 22, 2024
7f9a796
.
rw0x0 Oct 22, 2024
4e339f8
y2b test
rw0x0 Oct 22, 2024
9506fdb
.
rw0x0 Oct 22, 2024
5e763ae
.
rw0x0 Oct 22, 2024
538d03c
.
rw0x0 Oct 22, 2024
e19514f
.
rw0x0 Oct 22, 2024
ab986cd
.
rw0x0 Oct 22, 2024
c89256c
.
rw0x0 Oct 22, 2024
7d144e2
.
rw0x0 Oct 22, 2024
19ee9f3
.
rw0x0 Oct 22, 2024
9e7fea8
fix docu
rw0x0 Oct 22, 2024
5d0c2cf
remove one dependency
rw0x0 Oct 22, 2024
38ac346
doc comment
rw0x0 Oct 22, 2024
bd1196e
grammar
rw0x0 Oct 22, 2024
c45ab6a
.
rw0x0 Oct 22, 2024
566ced4
.
rw0x0 Oct 22, 2024
85af7e2
make mux explicit circuit
rw0x0 Oct 22, 2024
9a4f708
.
rw0x0 Oct 22, 2024
46efcb8
put garbling/evaluating of and gates into GCUtils
rw0x0 Oct 22, 2024
f56f082
.
rw0x0 Oct 22, 2024
44882e6
.
rw0x0 Oct 22, 2024
153c155
.
rw0x0 Oct 23, 2024
88c973b
remove the consume version of b2a
rw0x0 Oct 23, 2024
56787cc
buffered version of the garbler/evaluator
rw0x0 Oct 23, 2024
eba8032
also send at oncein yao.rs
rw0x0 Oct 23, 2024
75b40aa
add the streaming evaluator/garbler again
rw0x0 Oct 23, 2024
4963971
add conversions for streaming and buffered garbler/evaluator
rw0x0 Oct 23, 2024
10f5547
add ff from galois inc
rw0x0 Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ serde_json = "1.0"
serde_yaml = "0.9.27"
sha2 = "0.10"
sha3 = "0.10.8"
subtle = "2.6"
thiserror = "1.0.59"
tokio = { version = "1.34.0", features = [
"rt",
Expand Down
7 changes: 6 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ unknown-git = "deny"
# if not specified. If it is specified but empty, no registries are allowed.
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
# List of URLs for allowed Git repositories
allow-git = ["https://github.com/noir-lang/noir", "https://github.com/jfecher/chumsky"]
allow-git = [
"https://github.com/noir-lang/noir",
"https://github.com/jfecher/chumsky",
"https://github.com/GaloisInc/swanky",
"https://github.com/GaloisInc/ff",
]

[sources.allow-org]
# 1 or more github.com organizations to allow git sources for
Expand Down
4 changes: 4 additions & 0 deletions mpc-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ ark-ff = { workspace = true }
ark-serialize = { workspace = true }
bytes = { workspace = true }
eyre = { workspace = true }
fancy-garbling = { git = "https://github.com/GaloisInc/swanky", rev = "586a6ba1efdb531542668d6b0afe5cacc302d434" }
itertools = { workspace = true }
mpc-net = { version = "0.1.2", path = "../mpc-net" }
num-bigint = { workspace = true }
num-traits = { workspace = true }
rand = { workspace = true }
rand_chacha = { workspace = true }
rayon = { workspace = true }
scuttlebutt = { git = "https://github.com/GaloisInc/swanky", rev = "586a6ba1efdb531542668d6b0afe5cacc302d434" }
subtle = { workspace = true }
serde = { workspace = true }
sha3 = { workspace = true }
tokio = { workspace = true }
tracing.workspace = true

Expand Down
1 change: 1 addition & 0 deletions mpc-core/src/protocols/rep3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod network;
pub mod pointshare;
pub mod poly;
pub mod rngs;
pub mod yao;

use std::marker::PhantomData;

Expand Down
2 changes: 1 addition & 1 deletion mpc-core/src/protocols/rep3/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn shift_l_public_by_shared<F: PrimeField, N: Rep3Network>(
(shared.a.clone() >> i) & BigUint::one(),
(shared.b.clone() >> i) & BigUint::one(),
);
individual_bit_shares.push(conversion::b2a_consume(bit, context)?);
individual_bit_shares.push(conversion::b2a(&bit, context)?);
}
// v_i = 2^2^i * <b_i> + 1 - <b_i>
let mut vs: Vec<_> = individual_bit_shares
Expand Down
361 changes: 345 additions & 16 deletions mpc-core/src/protocols/rep3/conversion.rs

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions mpc-core/src/protocols/rep3/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,14 @@ fn low_depth_sub_p_cmux<F: PrimeField, N: Rep3Network>(
) -> IoResult<Rep3BigUintShare<F>> {
let original_bitlen = bitlen - 1; // before the potential overflow after an addition
let mask = (BigUint::from(1u64) << original_bitlen) - BigUint::one();
let x_msb = x >> original_bitlen;
let mut y = low_depth_binary_sub_p::<F, N>(x, io_context, bitlen)?;
let x = x & &mask;
let mut y = low_depth_binary_sub_p::<F, N>(&x, io_context, bitlen)?;
let y_msb = &y >> (bitlen);
y &= &mask;

// Spread the ov share to the whole biguint
let ov_a = (x_msb.a.iter_u64_digits().next().unwrap_or_default()
^ y_msb.a.iter_u64_digits().next().unwrap_or_default())
& 1;
let ov_b = (x_msb.b.iter_u64_digits().next().unwrap_or_default()
^ y_msb.b.iter_u64_digits().next().unwrap_or_default())
& 1;
let ov_a = y_msb.a.iter_u64_digits().next().unwrap_or_default() & 1;
let ov_b = y_msb.b.iter_u64_digits().next().unwrap_or_default() & 1;

let ov_a = if ov_a == 1 {
mask.to_owned()
Expand Down
53 changes: 52 additions & 1 deletion mpc-core/src/protocols/rep3/rngs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
//!
//! This module contains implementations of rep3 rngs

use super::{id::PartyID, yao::GCUtils};
use crate::RngType;
use ark_ec::CurveGroup;
use ark_ff::{One, PrimeField};
use fancy_garbling::WireMod2;
use num_bigint::BigUint;
use rand::{Rng, RngCore, SeedableRng};
use rand::{distributions::Standard, prelude::Distribution, Rng, RngCore, SeedableRng};
use rayon::prelude::*;

#[derive(Debug)]
Expand Down Expand Up @@ -38,6 +40,39 @@ impl Rep3CorrelatedRng {
bitcomp2,
}
}

/// Generate a value that is equal on all three parties
pub fn generate_shared<T>(&mut self, id: PartyID) -> T
where
Standard: Distribution<T>,
{
match id {
PartyID::ID0 => self.bitcomp1.rng2.gen(),
PartyID::ID1 => self.bitcomp1.rng2.gen(),
PartyID::ID2 => self.bitcomp1.rng1.gen(),
}
}

/// Generate a value that is equal on all two garbler parties
pub fn generate_garbler_randomness<T>(&mut self, id: PartyID) -> T
where
Standard: Distribution<T>,
{
match id {
PartyID::ID0 => panic!("Garbler should not be PartyID::ID0"),
PartyID::ID1 => self.rand.rng1.gen(),
PartyID::ID2 => self.rand.rng2.gen(),
}
}

/// Generate a random delta that is equal for the two garblers
pub fn generate_random_garbler_delta(&mut self, id: PartyID) -> Option<WireMod2> {
match id {
PartyID::ID0 => None,
PartyID::ID1 => Some(GCUtils::random_delta(&mut self.rand.rng1)),
PartyID::ID2 => Some(GCUtils::random_delta(&mut self.rand.rng2)),
}
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -118,6 +153,22 @@ impl Rep3Rand {
(a & &mask, b & mask)
}

/// Generate a random [`BigUint`] with given `bitlen` from rng1
pub fn random_biguint_rng1(&mut self, bitlen: usize) -> BigUint {
let limbsize = bitlen.div_ceil(8);
let val = BigUint::new((0..limbsize).map(|_| self.rng1.gen()).collect());
let mask = (BigUint::from(1u32) << bitlen) - BigUint::one();
val & &mask
}

/// Generate a random [`BigUint`] with given `bitlen` from rng2
pub fn random_biguint_rng2(&mut self, bitlen: usize) -> BigUint {
let limbsize = bitlen.div_ceil(8);
let val = BigUint::new((0..limbsize).map(|_| self.rng2.gen()).collect());
let mask = (BigUint::from(1u32) << bitlen) - BigUint::one();
val & &mask
}

/// Generate a seed from each rng
pub fn random_seeds(&mut self) -> ([u8; crate::SEED_SIZE], [u8; crate::SEED_SIZE]) {
let seed1 = self.rng1.gen();
Expand Down
Loading