Skip to content

Commit

Permalink
Merge branch 'main' into code-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
akoshelev authored Aug 15, 2023
2 parents 3f5abab + d812293 commit 0ce4111
Show file tree
Hide file tree
Showing 158 changed files with 1,174 additions and 887 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Check formatting
run: cargo fmt --all -- --check --config imports_granularity=Crate
run: cargo fmt --all -- --check --config "imports_granularity=Crate,group_imports=StdExternalCrate"

- name: Clippy
if: ${{ success() || failure() }}
Expand Down
3 changes: 2 additions & 1 deletion benches/oneshot/arithmetic_circuit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Instant;

use clap::Parser;
use ipa::{ff::Fp31, secret_sharing::SharedValue, test_fixture::circuit};
use std::time::Instant;

#[derive(Debug, Parser)]
pub struct CircuitArgs {
Expand Down
10 changes: 6 additions & 4 deletions benches/oneshot/ipa.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use std::{
num::{NonZeroU32, NonZeroUsize},
time::Instant,
};

use clap::Parser;
use ipa::{
error::Error,
Expand All @@ -8,11 +13,8 @@ use ipa::{
EventGenerator, EventGeneratorConfig, TestWorld, TestWorldConfig,
},
};

use rand::{random, rngs::StdRng, SeedableRng};
use std::{
num::{NonZeroU32, NonZeroUsize},
time::Instant,
};
use tokio::runtime::Builder;

#[cfg(all(not(target_env = "msvc"), not(feature = "dhat-heap")))]
Expand Down
3 changes: 2 additions & 1 deletion benches/oneshot/sort.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Instant;

use futures::stream::iter as stream_iter;
use ipa::{
error::Error,
Expand All @@ -14,7 +16,6 @@ use ipa::{
test_fixture::{join3, Reconstruct, TestWorld, TestWorldConfig},
};
use rand::Rng;
use std::time::Instant;

#[tokio::main(flavor = "multi_thread", worker_threads = 3)]
async fn main() -> Result<(), Error> {
Expand Down
3 changes: 2 additions & 1 deletion ipa-macros/src/derive_gate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::parser::{group_by_modules, ipa_state_transition_map, module_string_to_ast};
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};

use crate::parser::{group_by_modules, ipa_state_transition_map, module_string_to_ast};

// Procedural macro to derive the Step and StepNarrow traits and generate a memory-efficient gate.
//
// The goal is to generate a state transition graph and the corresponding `StepNarrow` implementations
Expand Down
6 changes: 4 additions & 2 deletions ipa-macros/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::tree::Node;
use quote::format_ident;
use std::{
collections::{HashMap, VecDeque},
io::Read,
path::PathBuf,
};

use quote::format_ident;

use crate::tree::Node;

const TARGET_CRATE: &str = "ipa";
const STEPS_FILE_PATH: &str = "/../src/protocol/step/";
#[cfg(not(feature = "trybuild"))]
Expand Down
3 changes: 2 additions & 1 deletion ipa-macros/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ impl<T> Deref for InnerNode<T> {

#[cfg(test)]
mod tests {
use crate::tree::Node;
use std::rc::{Rc, Weak};

use crate::tree::Node;

#[derive(Debug)]
struct TestData(u8);

Expand Down
8 changes: 5 additions & 3 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ stashfile=$(mktemp .pre-commit.stashXXXXXX)
trap 'set +e;git stash pop -q; rm -f "$stashfile"; restore_merge_files' EXIT
save_merge_files
git stash push -k -u -q -m "pre-commit stash"
if ! errors=($(cargo fmt -- --check --config imports_granularity=Crate -l)); then

fmtconfig="imports_granularity=Crate,group_imports=StdExternalCrate"
if ! errors=($(cargo fmt --all -- --check --config "$fmtconfig" -l)); then
echo "Formatting errors found."
echo "Run \`cargo fmt -- --config imports_granularity=Crate\` to fix the following files:"
echo "Run \`cargo fmt --all -- --config \"$fmtconfig\"\` to fix the following files:"
for err in "${errors[@]}"; do
echo " $err"
done
Expand Down Expand Up @@ -102,4 +104,4 @@ check "Sort benchmark" \

check "ipa-macros tests" \
pushd ipa-macros && cargo test --features="trybuild" && popd


15 changes: 8 additions & 7 deletions src/bin/helper.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
use std::{
fs,
net::TcpListener,
os::fd::{FromRawFd, RawFd},
path::{Path, PathBuf},
process,
};

use clap::{self, Parser, Subcommand};
use hyper::http::uri::Scheme;
use ipa::{
Expand All @@ -10,13 +18,6 @@ use ipa::{
net::{ClientIdentity, HttpTransport, MpcHelperClient},
AppSetup,
};
use std::{
fs,
net::TcpListener,
os::fd::{FromRawFd, RawFd},
path::{Path, PathBuf},
process,
};
use tracing::{error, info};

#[cfg(not(target_env = "msvc"))]
Expand Down
10 changes: 6 additions & 4 deletions src/bin/ipa_bench/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use crate::{gen_events::generate_events, sample::Sample};
use clap::Parser;
use ipa::cli::Verbosity;
use rand::{rngs::StdRng, SeedableRng};
use std::{
fs::File,
io,
path::{Path, PathBuf},
process,
};

use clap::Parser;
use ipa::cli::Verbosity;
use rand::{rngs::StdRng, SeedableRng};
use tracing::{debug, error, info};

use crate::{gen_events::generate_events, sample::Sample};

const DEFAULT_EVENT_GEN_COUNT: u32 = 100_000;

#[derive(Debug, Parser)]
Expand Down
3 changes: 2 additions & 1 deletion src/bin/ipa_bench/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};
use std::ops::Range;

use serde::{Deserialize, Serialize};

#[cfg(feature = "enable-serde")]
#[derive(Serialize, Deserialize, Debug)]
pub struct WeightedIndex<T> {
Expand Down
20 changes: 12 additions & 8 deletions src/bin/ipa_bench/gen_events.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use crate::{
models::{Epoch, Event, EventTimestamp, GenericReport, MatchKey, Number},
sample::Sample,
};
use std::io;

use bitvec::view::BitViewSized;
use rand::{
distributions::{Bernoulli, Distribution},
CryptoRng, Rng, RngCore,
};
use std::io;
use tracing::{debug, info, trace};

use crate::{
models::{Epoch, Event, EventTimestamp, GenericReport, MatchKey, Number},
sample::Sample,
};

// 0x1E. https://datatracker.ietf.org/doc/html/rfc7464
const RECORD_SEPARATOR: u8 = 30;

Expand Down Expand Up @@ -170,14 +172,16 @@ fn add_event_timestamps(rhs: EventTimestamp, lhs: EventTimestamp) -> EventTimest

#[cfg(all(test, unit_test))]
mod tests {
use super::{gen_reports, generate_events, EventTimestamp, GenericReport};
use crate::{gen_events::add_event_timestamps, models::Epoch, sample::Sample};
use rand::{rngs::StdRng, SeedableRng};
use std::{
cmp::Ordering,
io::{Cursor, Write},
};

use rand::{rngs::StdRng, SeedableRng};

use super::{gen_reports, generate_events, EventTimestamp, GenericReport};
use crate::{gen_events::add_event_timestamps, models::Epoch, sample::Sample};

const DATA: &str = r#"
{
"devices_per_user": [
Expand Down
8 changes: 4 additions & 4 deletions src/bin/ipa_bench/models.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use rand::{CryptoRng, Rng, RngCore};
use serde::{Deserialize, Serialize};
use std::{
fmt::{Debug, Formatter},
io::{Error as IoError, ErrorKind as IoErrorKind},
ops::Range,
};

use rand::{CryptoRng, Rng, RngCore};
use serde::{Deserialize, Serialize};

// Type aliases to indicate whether the parameter should be encrypted, secret shared, etc.
// Underlying types are temporalily assigned for PoC.
pub type CipherText = Vec<u8>;
Expand Down Expand Up @@ -318,9 +319,8 @@ impl Debug for TriggerFanoutQuery {

#[cfg(all(test, unit_test))]
mod tests {
use crate::models::Epoch;

use super::EventTimestamp;
use crate::models::Epoch;

#[test]
fn event_timestamp_new() {
Expand Down
6 changes: 4 additions & 2 deletions src/bin/ipa_bench/sample.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::config::Config;
use std::time::Duration;

use rand::{
distributions::{Distribution, WeightedIndex},
CryptoRng, Rng, RngCore,
};
use std::time::Duration;

use crate::config::Config;

pub struct Sample<'a> {
config: &'a Config,
Expand Down
36 changes: 15 additions & 21 deletions src/bin/report_collector.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
use std::{
borrow::Cow,
error::Error,
fmt::Debug,
fs::{File, OpenOptions},
io,
io::{stdout, Write},
ops::Deref,
path::{Path, PathBuf},
};

use clap::{Parser, Subcommand};
use comfy_table::{Cell, Table};
use hyper::http::uri::Scheme;
use ipa::{
cli::{
noise::{apply, ApplyDpArgs},
playbook::{make_clients, playbook_ipa, validate, InputSource},
Verbosity,
CsvSerializer, IpaQueryResult, Verbosity,
},
config::NetworkConfig,
ff::{FieldType, Fp32BitPrime},
helpers::query::{IpaQueryConfig, QueryConfig, QueryType},
helpers::query::{IpaQueryConfig, QueryConfig, QuerySize, QueryType},
hpke::{KeyRegistry, PublicKeyOnly},
net::MpcHelperClient,
protocol::{BreakdownKey, MatchKey},
Expand All @@ -17,27 +30,8 @@ use ipa::{
EventGenerator, EventGeneratorConfig,
},
};

use comfy_table::{Cell, Table};
use ipa::{
cli::{
noise::{apply, ApplyDpArgs},
CsvSerializer, IpaQueryResult,
},
helpers::query::QuerySize,
};
use rand::{distributions::Alphanumeric, rngs::StdRng, thread_rng, Rng};
use rand_core::SeedableRng;
use std::{
borrow::Cow,
error::Error,
fmt::Debug,
fs::{File, OpenOptions},
io,
io::{stdout, Write},
ops::Deref,
path::{Path, PathBuf},
};

#[derive(Debug, Parser)]
#[clap(name = "rc", about = "Report Collector CLI")]
Expand Down
3 changes: 2 additions & 1 deletion src/bin/test_mpc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{error::Error, fmt::Debug, ops::Add, path::PathBuf};

use clap::{Parser, Subcommand};
use generic_array::ArrayLength;
use hyper::http::uri::Scheme;
Expand All @@ -11,7 +13,6 @@ use ipa::{
net::MpcHelperClient,
secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares},
};
use std::{error::Error, fmt::Debug, ops::Add, path::PathBuf};

#[derive(Debug, Parser)]
#[clap(
Expand Down
8 changes: 5 additions & 3 deletions src/chunkscan.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::error::BoxError;
use futures::{ready, Stream};
use pin_project::pin_project;
use std::{
future::Future,
mem,
pin::Pin,
task::{Context, Poll},
};

use futures::{ready, Stream};
use pin_project::pin_project;
use tracing::error;

use crate::error::BoxError;

/// A variant of stream transform that combines semantic of `StreamExt::chunks` and `StreamExt::scan`.
/// Consumes the input stream and keeps accumulating items in the internal buffer until it reaches
/// `capacity` elements. Then the elements are moved to the `f` function that must produce a future
Expand Down
12 changes: 7 additions & 5 deletions src/cli/clientconf.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::{fs, fs::File, io::Write, iter::zip, path::PathBuf};

use clap::Args;
use config::Map;
use hpke::Serializable as _;
use toml::{Table, Value};

use crate::{
cli::paths::PathExt,
config::{ClientConfig, HpkeClientConfig, NetworkConfig, PeerConfig},
error::BoxError,
};
use clap::Args;
use config::Map;
use hpke::Serializable as _;
use std::{fs, fs::File, io::Write, iter::zip, path::PathBuf};
use toml::{Table, Value};

#[derive(Debug, Args)]
#[clap(about = "Generate client config for 3 MPC helper parties")]
Expand Down
3 changes: 2 additions & 1 deletion src/cli/ipa_output.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::helpers::query::{IpaQueryConfig, QuerySize};
use std::time::Duration;

use crate::helpers::query::{IpaQueryConfig, QuerySize};

#[derive(Debug)]
#[cfg_attr(feature = "enable-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct QueryResult {
Expand Down
Loading

0 comments on commit 0ce4111

Please sign in to comment.