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

Threading Refactor #165

Merged
merged 34 commits into from
Jun 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a23a095
feat: mpz-common (#107)
sinui0 Mar 7, 2024
7883f37
refactor: cointoss (#108)
sinui0 Mar 7, 2024
272b83d
refactor: mpz-ot (#109)
sinui0 Mar 7, 2024
a4f80dc
refactor: re-organize crates (#110)
sinui0 Mar 7, 2024
61275e8
Adds an ideal ROT functionality to mpz-ot-core (#102)
th4s Mar 7, 2024
13b0cae
refactor(mpz-ot): Normalize OT and ideal functionalities (#122)
sinui0 May 8, 2024
9891192
feat(mpz-common): add try_/join convenience macros (#126)
sinui0 May 13, 2024
9300c94
fix(mpz-ot): Ideal RCOT (#131)
sinui0 May 13, 2024
67564a4
docs: fix typos (#130)
themighty1 May 15, 2024
b35d392
feat(mpz-common): dummy executor (#132)
sinui0 May 15, 2024
3d523ec
feat(mpz-common): simple counter (#133)
sinui0 May 15, 2024
a10810a
refactor(mpz-garble-core): batched garbling (#140)
sinui0 May 28, 2024
b9e5f59
Add crate `mpz-ole-core` (#135)
th4s May 29, 2024
7292063
feat(mpz-common): multi-threaded executor (#136)
sinui0 May 29, 2024
6617c54
Add IO wrapper for OLE (#138)
th4s May 31, 2024
699acff
feat(mpz-common): Context::blocking (#141)
sinui0 May 31, 2024
c50a145
feat(mpz-common): scoped! macro (#143)
sinui0 May 31, 2024
ab82dbf
test(mpz-common): test mt executor concurrency (#145)
sinui0 Jun 4, 2024
81802ea
Add `mpz-share-conversion-core` (#147)
th4s Jun 5, 2024
b858189
refactor(mpz-garble): fix threading breaking changes (#144)
sinui0 Jun 5, 2024
b0f5a90
refactor(mpz-share-conversion): new impl (#146)
sinui0 Jun 5, 2024
6f1ef18
feat(mpz-common): add type alias for test st executor (#154)
sinui0 Jun 7, 2024
5fc90ff
feat(mpz-common): async sync primitives (#152)
sinui0 Jun 11, 2024
801381c
feat(mpz-ot): impl more OT traits on shared KOS (#153)
sinui0 Jun 11, 2024
6c7dec2
feat(mpz-garble): pre-commit inputs (#149)
sinui0 Jun 12, 2024
9c17b38
refactor: KOS and preprocessing traits (#155)
sinui0 Jun 12, 2024
640bda0
refactor(mpz-ot): add accept_reveal for verifiable ot (#158)
sinui0 Jun 14, 2024
1ec8979
fix(mpz-common): flush io in syncer (#157)
sinui0 Jun 14, 2024
34a0663
fix(mpz-ot): fix shared KOS verifiable ot receiver (#161)
sinui0 Jun 20, 2024
3272954
fix(mpz-garble): add thread id to otp ids (#162)
sinui0 Jun 20, 2024
461d3b4
refactor(mpz-common): new thread future (#163)
sinui0 Jun 24, 2024
836ad67
chore: bump serio and uid-mux (#164)
sinui0 Jun 25, 2024
5ad1bea
chore: move workspace manifest
sinui0 Jun 25, 2024
e25d123
fix: clippy --fix
sinui0 Jun 25, 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
Prev Previous commit
Next Next commit
refactor(mpz-garble-core): batched garbling (#140)
* refactor(mpz-garble-core): batched garbling

* Apply suggestions from code review

Co-authored-by: th4s <[email protected]>
Co-authored-by: dan <[email protected]>

* qualify comment

* remove unused msg module

* comments

---------

Co-authored-by: th4s <[email protected]>
Co-authored-by: dan <[email protected]>
3 people committed Jun 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit a10810ac233de9fdeae79759268d2f0e4a8bb18d
1 change: 1 addition & 0 deletions crates/mpz-garble-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ rand_core.workspace = true
rand_chacha.workspace = true
regex = { workspace = true, optional = true }
once_cell.workspace = true
opaque-debug.workspace = true

serde = { workspace = true, features = ["derive"] }
serde_arrays.workspace = true
78 changes: 61 additions & 17 deletions crates/mpz-garble-core/benches/garble.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,83 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use mpz_circuits::circuits::AES128;
use mpz_garble_core::{ChaChaEncoder, Encoder, Generator};
use mpz_garble_core::{ChaChaEncoder, Encoder, Evaluator, Generator};

fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("garble_circuits");
let mut gb_group = c.benchmark_group("garble");

let encoder = ChaChaEncoder::new([0u8; 32]);
let inputs = AES128
let full_inputs = AES128
.inputs()
.iter()
.map(|value| encoder.encode_by_type(0, &value.value_type()))
.collect::<Vec<_>>();
group.bench_function("aes128", |b| {

let active_inputs = vec![
full_inputs[0].clone().select([0u8; 16]).unwrap(),
full_inputs[1].clone().select([0u8; 16]).unwrap(),
];

gb_group.bench_function("aes128", |b| {
let mut gen = Generator::default();
b.iter(|| {
let mut gen = Generator::new(AES128.clone(), encoder.delta(), &inputs).unwrap();
let mut gen_iter = gen
.generate(&AES128, encoder.delta(), full_inputs.clone())
.unwrap();

let mut enc_gates = Vec::with_capacity(AES128.and_count());
for gate in gen.by_ref() {
enc_gates.push(gate);
}
let _: Vec<_> = gen_iter.by_ref().collect();

black_box(gen_iter.finish().unwrap())
})
});

gb_group.bench_function("aes128_batched", |b| {
let mut gen = Generator::default();
b.iter(|| {
let mut gen_iter = gen
.generate_batched(&AES128, encoder.delta(), full_inputs.clone())
.unwrap();

let _: Vec<_> = gen_iter.by_ref().collect();

black_box(gen_iter.finish().unwrap())
})
});

gb_group.bench_function("aes128_with_hash", |b| {
let mut gen = Generator::default();
b.iter(|| {
let mut gen_iter = gen
.generate(&AES128, encoder.delta(), full_inputs.clone())
.unwrap();

gen_iter.enable_hasher();

black_box(gen.outputs().unwrap())
let _: Vec<_> = gen_iter.by_ref().collect();

black_box(gen_iter.finish().unwrap())
})
});
group.bench_function("aes128_with_hash", |b| {

drop(gb_group);

let mut ev_group = c.benchmark_group("evaluate");

ev_group.bench_function("aes128", |b| {
let mut gen = Generator::default();
let mut gen_iter = gen
.generate(&AES128, encoder.delta(), full_inputs.clone())
.unwrap();
let gates: Vec<_> = gen_iter.by_ref().collect();

let mut ev = Evaluator::default();
b.iter(|| {
let mut gen =
Generator::new_with_hasher(AES128.clone(), encoder.delta(), &inputs).unwrap();
let mut ev_consumer = ev.evaluate(&AES128, active_inputs.clone()).unwrap();

let mut enc_gates = Vec::with_capacity(AES128.and_count());
for gate in gen.by_ref() {
enc_gates.push(gate);
for gate in &gates {
ev_consumer.next(*gate);
}

black_box(gen.outputs().unwrap())
black_box(ev_consumer.finish().unwrap());
})
});
}
26 changes: 24 additions & 2 deletions crates/mpz-garble-core/src/circuit.rs
Original file line number Diff line number Diff line change
@@ -3,15 +3,15 @@ use std::ops::Index;
use mpz_core::Block;
use serde::{Deserialize, Serialize};

use crate::EncodingCommitment;
use crate::{EncodingCommitment, DEFAULT_BATCH_SIZE};

/// Encrypted gate truth table
///
/// For the half-gate garbling scheme a truth table will typically have 2 rows, except for in
/// privacy-free garbling mode where it will be reduced to 1.
///
/// We do not yet support privacy-free garbling.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct EncryptedGate(#[serde(with = "serde_arrays")] pub(crate) [Block; 2]);

impl EncryptedGate {
@@ -35,6 +35,28 @@ impl Index<usize> for EncryptedGate {
}
}

/// A batch of encrypted gates.
///
/// # Parameters
///
/// - `N`: The size of a batch.
#[derive(Debug, Serialize, Deserialize)]
pub struct EncryptedGateBatch<const N: usize = DEFAULT_BATCH_SIZE>(
#[serde(with = "serde_arrays")] [EncryptedGate; N],
);

impl<const N: usize> EncryptedGateBatch<N> {
/// Creates a new batch of encrypted gates.
pub fn new(batch: [EncryptedGate; N]) -> Self {
Self(batch)
}

/// Returns the inner array.
pub fn into_array(self) -> [EncryptedGate; N] {
self.0
}
}

/// A garbled circuit
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GarbledCircuit {
11 changes: 10 additions & 1 deletion crates/mpz-garble-core/src/encoding/mod.rs
Original file line number Diff line number Diff line change
@@ -272,7 +272,7 @@ impl<const N: usize, S: LabelState> Index<usize> for Labels<N, S> {
}

/// Encoded bit label.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct Label(Block);

impl Label {
@@ -350,6 +350,15 @@ impl BitXor<Delta> for &Label {
}
}

impl BitXor<&Delta> for Label {
type Output = Label;

#[inline]
fn bitxor(self, rhs: &Delta) -> Self::Output {
Label(self.0 ^ rhs.0)
}
}

impl AsRef<Block> for Label {
fn as_ref(&self) -> &Block {
&self.0
Loading