Skip to content

Commit

Permalink
Do bad things
Browse files Browse the repository at this point in the history
  • Loading branch information
martinthomson committed Apr 5, 2023
1 parent c8390ab commit bc2e7e1
Show file tree
Hide file tree
Showing 37 changed files with 103 additions and 105 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "raw-ipa"
name = "ipa"
version = "0.1.0"
rust-version = "1.64.0"
edition = "2021"
Expand Down Expand Up @@ -82,7 +82,7 @@ lto = "thin"
debug-assertions = true

[lib]
name = "raw_ipa"
name = "ipa"
path = "src/lib.rs"
bench = false

Expand Down
2 changes: 1 addition & 1 deletion benches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Execute the following command to enable step-level metrics. It is possible to us
`TestWorld` to set up the environment.

```bash
RUST_LOG=raw_ipa=DEBUG cargo bench --bench oneshot_sort --no-default-features --features="enable-benches debug-trace"
RUST_LOG=ipa=DEBUG cargo bench --bench oneshot_sort --no-default-features --features="enable-benches debug-trace"
```

The output would look similar to this:
Expand Down
2 changes: 1 addition & 1 deletion benches/ct/arithmetic_circuit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::{
black_box, criterion_group, criterion_main, BenchmarkId, Criterion, SamplingMode, Throughput,
};
use raw_ipa::{ff::Fp31, test_fixture::circuit};
use ipa::{ff::Fp31, test_fixture::circuit};
use tokio::runtime::Builder;

pub fn criterion_benchmark(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion benches/iai/arithmetic_circuit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iai::black_box;
use raw_ipa::{ff::Fp31, test_fixture::circuit};
use ipa::{ff::Fp31, test_fixture::circuit};
use tokio::runtime::Builder;

pub fn iai_benchmark() {
Expand Down
2 changes: 1 addition & 1 deletion benches/oneshot/arithmetic_circuit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use raw_ipa::{ff::Fp31, secret_sharing::SharedValue, test_fixture::circuit};
use ipa::{ff::Fp31, secret_sharing::SharedValue, test_fixture::circuit};
use std::time::Instant;

#[derive(Debug, Parser)]
Expand Down
4 changes: 2 additions & 2 deletions benches/oneshot/ipa.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use clap::Parser;
use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng};
use raw_ipa::{
use ipa::{
error::Error,
ff::Fp32BitPrime,
helpers::GatewayConfig,
Expand All @@ -9,6 +8,7 @@ use raw_ipa::{
update_expected_output_for_user, IpaSecurityModel, TestWorld, TestWorldConfig,
},
};
use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng};
use std::{num::NonZeroUsize, time::Instant};

/// A benchmark for the full IPA protocol.
Expand Down
7 changes: 3 additions & 4 deletions benches/oneshot/sort.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rand::Rng;
use raw_ipa::{
use ipa::{
error::Error,
ff::{Field, Fp32BitPrime, GaloisField, Gf40Bit},
helpers::GatewayConfig,
Expand All @@ -12,6 +11,7 @@ use raw_ipa::{
secret_sharing::SharedValue,
test_fixture::{join3, Reconstruct, Runner, TestWorld, TestWorldConfig},
};
use rand::Rng;
use std::time::Instant;

#[tokio::main(flavor = "multi_thread", worker_threads = 3)]
Expand All @@ -21,8 +21,7 @@ async fn main() -> Result<(), Error> {
type BenchField = Fp32BitPrime;

let mut config = TestWorldConfig::default();
config.gateway_config =
GatewayConfig::symmetric_buffers::<BenchField>(BATCHSIZE.clamp(4, 1024));
config.gateway_config = GatewayConfig::new(BATCHSIZE.clamp(4, 1024));
let world = TestWorld::new_with(config);
let [ctx0, ctx1, ctx2] = world.contexts();
let mut rng = rand::thread_rng();
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ echo "Generating profiling data"
llvm-profdata merge -sparse -o "$profdata" "$profdir"/*.profraw

echo "Generating HTML report in $profdir"
test_binary="$(ls -td -I '*.*' ./target/debug/deps/raw_ipa-* | head -1)"
test_binary="$(ls -td -I '*.*' ./target/debug/deps/ipa-* | head -1)"
llvm-cov show -Xdemangler=rustfilt "$test_binary" -instr-profile="$profdata" \
-show-line-counts-or-regions -show-instantiations \
-ignore-filename-regex="/\.cargo/registry/" \
Expand Down
2 changes: 1 addition & 1 deletion src/bin/helper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use hyper::http::uri::Scheme;
use raw_ipa::cli::Verbosity;
use ipa::cli::Verbosity;

#[derive(Debug, Parser)]
#[clap(name = "mpc-helper", about = "CLI to start an MPC helper endpoint")]
Expand Down
2 changes: 1 addition & 1 deletion src/bin/ipa_bench/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::sample::Sample;
use super::gen_events::generate_events;

use clap::Parser;
use ipa::cli::Verbosity;
use rand::{rngs::StdRng, SeedableRng};
use raw_ipa::cli::Verbosity;
use std::{
fs::File,
io,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/test_mpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{Parser, Subcommand, ValueEnum};
use raw_ipa::cli::Verbosity;
use ipa::cli::Verbosity;
use std::{fmt::Debug, path::PathBuf};

#[derive(Debug, Parser)]
Expand Down
4 changes: 2 additions & 2 deletions src/cli/playbook/ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
replicated::semi_honest::{AdditiveShare as Replicated, XorShare as XorReplicated},
IntoShares,
},
seq_futures::try_join_all,
seq_join::seq_try_join_all,
test_fixture::input::GenericReportTestInput,
};
use generic_array::GenericArray;
Expand Down Expand Up @@ -54,7 +54,7 @@ where
ByteArrStream::from(r)
});

try_join_all(
seq_try_join_all(
inputs
.into_iter()
.zip(clients)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/playbook/multiply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
net::MpcHelperClient,
protocol::QueryId,
secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, IntoShares},
seq_futures::try_join_all,
};
use futures::future::try_join_all;
use generic_array::{ArrayLength, GenericArray};
use std::{fmt::Debug, ops::Add};
use typenum::Unsigned;
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/buffers/ordering_mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ impl<M: Message> OrderingMpscReceiver<M> {
/// Inserts a new element to the specified position.
///
/// When inserting, `index` needs to be in range. Values that are in range are within `capacity`
/// (as provided to [`new`]) of the last value that was taken with [`take`].
/// (as provided to [`ordering_mpsc`]) of the last value that was taken with [`take`].
///
/// ## Panics
/// Panics if `index` is out of bounds or if something was previously inserted at `index`.
/// Panics only occur in debug builds; otherwise, a bad index will overwrite that location;
/// expect bad things to happen in that case.
/// In all builds, this panics if `msg` fails to serialize properly, which shouldn't happen.
///
/// [`new`]: Self::new
/// [`take`]: Self::take
fn insert(&mut self, index: usize, msg: &M) {
#[cfg(debug_assertions)]
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/buffers/ordering_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl OrderingSender {
/// This occurs when a message cannot reliably be written to the buffer
/// because it would overflow the buffer. The data already in the buffer
/// might not reach the threshold for sending, which means that progress
/// is impossible. Polling the promise returned by [`send`] will panic if
/// is impossible. Polling the promise returned by `send` will panic if
/// the spare capacity is insufficient.
pub fn send<M: Message>(&self, i: usize, m: M) -> Send<'_, M> {
Send { i, m, sender: self }
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/buffers/unordered_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,11 @@ where
/// Wrap a stream for unordered reading.
///
/// The capacity here determines how far ahead a read can be. In most cases,
/// this should be the same as the value given to [`ordering_mpsc`].
/// this should be the same as the value given to `ordering_mpsc`.
///
/// # Panics
///
/// The `capacity` needs to be at least 2.
///
/// [`ordering_mpsc`]: crate::helpers::buffers::ordering_mpsc::ordering_mpsc
pub fn new(stream: Pin<Box<S>>, capacity: NonZeroUsize) -> Self {
// We use `c/2` as a divisor, so `c == 1` would be bad.
assert!(capacity.get() > 1, "a capacity of 1 is too small");
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl GatewayConfig {
}

/// The configured amount of active work.
#[must_use]
pub fn active_work(&self) -> NonZeroUsize {
self.active
}
Expand Down Expand Up @@ -157,14 +158,15 @@ mod tests {
..TestWorldConfig::default()
};
let world = Box::leak(Box::new(TestWorld::new_with(config)));
let world_ptr = world as *mut _;
let contexts = world.contexts();
let sender_ctx = contexts[0].narrow("reordering-test").set_total_records(2);
let recv_ctx = contexts[1].narrow("reordering-test").set_total_records(2);

// send record 1 first and wait for confirmation before sending record 0.
// when gateway received record 0 it triggers flush so it must make sure record 1 is also
// sent (same batch or different does not matter here)
tokio::spawn(async move {
let spawned = tokio::spawn(async move {
let channel = sender_ctx.send_channel(Role::H2);
try_join(
channel.send(RecordId::from(1), Fp31::truncate_from(1_u128)),
Expand All @@ -186,5 +188,7 @@ mod tests {
(Fp31::truncate_from(1u128), Fp31::truncate_from(0u128)),
result
);
spawned.await.unwrap();
let _world = unsafe { Box::from_raw(world_ptr) };
}
}
2 changes: 1 addition & 1 deletion src/helpers/gateway/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<M: Message> SendingEnd<M> {
/// for sending.
///
/// ## Errors
/// If send operation fails or [`record_id`] exceeds the channel limit set by [`set_total_records`]
/// If send operation fails or `record_id` exceeds the channel limit set by [`set_total_records`]
/// call.
///
/// [`set_total_records`]: crate::protocol::context::Context::set_total_records
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/gateway/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use std::io;

/// Transport adapter that resolves [`Role`] -> [`HelperIdentity`] mapping. As gateways created
/// per query, it is not ambiguous.
///
/// [`HelperIdentity`]: crate::helpers::HelperIdentity
#[derive(Clone)]
pub(super) struct RoleResolvingTransport<T> {
pub query_id: QueryId,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub trait Transport: Clone + Send + Sync + 'static {

/// Enum to dispatch calls to various [`Transport`] implementations without the need
/// of dynamic dispatch. DD is not even possible with this trait, so that is the only way to prevent
/// [`Gateway`] to be generic over it. We want to avoid that as it pollutes our protocol code.
/// `Gateway` to be generic over it. We want to avoid that as it pollutes our protocol code.
#[derive(Clone)]
pub enum TransportImpl {
#[cfg(any(test, feature = "test-fixture"))]
Expand Down
5 changes: 3 additions & 2 deletions src/hpke/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ impl From<io::Error> for DecryptionError {
}
}

/// Opens the given ciphertext in place by first obtaining the secret key from [`key_registry`]
/// using epoch and key from [`info`] and then applying [`HPKE decryption`] to the provided ciphertext.
/// Opens the given ciphertext in place by first obtaining the secret key from `key_registry`
/// using epoch and key from the `info` parameter and then applying [`HPKE decryption`]
/// to the provided ciphertext.
///
/// This function mutates the provided ciphertext slice and replaces it with the plaintext obtained
/// after opening the ciphertext. The result will contain a pointer to the plaintext slice.
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/attribution/credit_capping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
BasicProtocols, RecordId, Substep,
},
secret_sharing::Linear as LinearSecretSharing,
seq_join::{seq_join, SeqJoin},
seq_join::seq_join,
};
use futures::{future::try_join_all, stream::once, StreamExt, TryStreamExt};
use std::iter::{repeat, zip};
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/basics/mul/semi_honest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod test {
ff::{Field, Fp31},
protocol::{basics::SecureMul, context::Context, RecordId},
rand::{thread_rng, Rng},
seq_join::seq_try_join_all,
seq_join::SeqJoin,
test_fixture::{Reconstruct, Runner, TestWorld},
};
use rand::distributions::{Distribution, Standard};
Expand Down Expand Up @@ -139,7 +139,7 @@ mod test {
let expected: Vec<_> = zip(a.iter(), b.iter()).map(|(&a, &b)| a * b).collect();
let results = world
.semi_honest((a, b), |ctx, (a_shares, b_shares)| async move {
seq_try_join_all(
ctx.try_join_all(
zip(
repeat(ctx.set_total_records(COUNT)),
zip(a_shares, b_shares),
Expand Down
3 changes: 1 addition & 2 deletions src/protocol/basics/reshare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{
semi_honest::AdditiveShare as Replicated,
ReplicatedSecretSharing,
},
seq_join::seq_try_join_all,
};
use async_trait::async_trait;
use embed_doc_image::embed_doc_image;
Expand Down Expand Up @@ -209,7 +208,7 @@ where
where
C: 'fut,
{
seq_try_join_all(
ctx.try_join_all(
zip(repeat(ctx.set_total_records(self.len())), self.iter())
.enumerate()
.map(|(i, (c, x))| async move { x.reshare(c, RecordId::from(i), to_helper).await }),
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/basics/reveal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{
},
SecretSharing,
},
seq_join::seq_try_join_all,
};
use async_trait::async_trait;
use embed_doc_image::embed_doc_image;
Expand Down Expand Up @@ -138,9 +137,10 @@ where
/// # Panics
/// If we cant convert F to u128
async fn reveal<'fut>(&self, ctx: C, _: NoRecord) -> Result<Vec<u32>, Error> {
let ctx_ref = &ctx;
let ctx = ctx.set_total_records(self.perm.len());
let revealed_permutation =
seq_try_join_all(zip(repeat(ctx), self.perm.iter()).enumerate().map(
let revealed_permutation = ctx_ref
.try_join_all(zip(repeat(ctx), self.perm.iter()).enumerate().map(
|(index, (ctx, value))| async move {
let reveal_value = value.reveal(ctx, RecordId::from(index)).await;

Expand Down
10 changes: 2 additions & 8 deletions src/protocol/boolean/random_bits_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ mod tests {
replicated::{semi_honest::AdditiveShare, ReplicatedSecretSharing},
SharedValue,
},
seq_join::seq_try_join_all,
test_fixture::{join3, Reconstruct, Runner, TestWorld},
test_fixture::{join3, join3v, Reconstruct, Runner, TestWorld},
};
use std::iter::zip;

Expand Down Expand Up @@ -190,12 +189,7 @@ mod tests {
assert_eq!(rbg[0].fallbacks(), rbg[1].fallbacks());
assert_eq!(rbg[0].fallbacks(), rbg[2].fallbacks());

let result = <[_; 3]>::try_from(
seq_try_join_all(zip(validators, m_result).map(|(v, m)| v.validate(m)))
.await
.unwrap(),
)
.unwrap();
let result = join3v(zip(validators, m_result).map(|(v, m)| v.validate(m))).await;
let _: Fp31 = result.reconstruct(); // reconstruct() will validate the value.
}
}
7 changes: 3 additions & 4 deletions src/protocol/boolean/solved_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ mod tests {
ff::{Field, Fp31, Fp32BitPrime, PrimeField},
protocol::{boolean::solved_bits::solved_bits, context::Context, RecordId},
secret_sharing::SharedValue,
seq_join::seq_try_join_all,
seq_join::SeqJoin,
test_fixture::{bits_to_value, Reconstruct, Runner, TestWorld},
};
use rand::{distributions::Standard, prelude::Distribution};
Expand All @@ -168,9 +168,8 @@ mod tests {
let world = TestWorld::default();
let [rv0, rv1, rv2] = world
.semi_honest((), |ctx, ()| async move {
let ctx = ctx.set_total_records(COUNT);
seq_try_join_all(
repeat(ctx)
ctx.try_join_all(
repeat(ctx.set_total_records(COUNT))
.take(COUNT)
.enumerate()
.map(|(i, ctx)| solved_bits(ctx, RecordId::from(i))),
Expand Down
12 changes: 6 additions & 6 deletions src/protocol/context/malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ impl<'a, F: Field + ExtendableField> ContextInner<'a, F> {
/// record ID and the other can use something like a `BitOpStep`.
///
/// ```no_run
/// use raw_ipa::protocol::{context::{UpgradeContext, UpgradeToMalicious}, NoRecord, RecordId};
/// use raw_ipa::ff::Fp32BitPrime;
/// use raw_ipa::secret_sharing::replicated::{
/// use ipa::protocol::{context::{UpgradeContext, UpgradeToMalicious}, NoRecord, RecordId};
/// use ipa::ff::Fp32BitPrime;
/// use ipa::secret_sharing::replicated::{
/// malicious::AdditiveShare as MaliciousReplicated, semi_honest::AdditiveShare as Replicated,
/// };
/// // Note: Unbound upgrades only work when testing.
Expand All @@ -498,9 +498,9 @@ impl<'a, F: Field + ExtendableField> ContextInner<'a, F> {
/// ```
///
/// ```compile_fail
/// use raw_ipa::protocol::{context::{UpgradeContext, UpgradeToMalicious}, NoRecord, RecordId};
/// use raw_ipa::ff::Fp32BitPrime;
/// use raw_ipa::secret_sharing::replicated::{
/// use ipa::protocol::{context::{UpgradeContext, UpgradeToMalicious}, NoRecord, RecordId};
/// use ipa::ff::Fp32BitPrime;
/// use ipa::secret_sharing::replicated::{
/// malicious::AdditiveShare as MaliciousReplicated, semi_honest::AdditiveShare as Replicated,
/// };
/// // This can't be upgraded with a record-bound context because the record ID
Expand Down
Loading

0 comments on commit bc2e7e1

Please sign in to comment.