diff --git a/ipa-core/Cargo.toml b/ipa-core/Cargo.toml index 73e33cd54..c53b6df8c 100644 --- a/ipa-core/Cargo.toml +++ b/ipa-core/Cargo.toml @@ -7,7 +7,7 @@ version = "0.1.0" # 2. Update the rust version used for draft in # https://github.com/private-attribution/draft/blob/main/sidecar/ansible/provision.yaml. rust-version = "1.85.0" -edition = "2021" +edition = "2024" build = "build.rs" [features] diff --git a/ipa-core/benches/ct/arithmetic_circuit.rs b/ipa-core/benches/ct/arithmetic_circuit.rs index d3b19c7f3..9078b4b45 100644 --- a/ipa-core/benches/ct/arithmetic_circuit.rs +++ b/ipa-core/benches/ct/arithmetic_circuit.rs @@ -1,11 +1,11 @@ use criterion::{ - black_box, criterion_group, criterion_main, measurement::Measurement, BatchSize, - BenchmarkGroup, BenchmarkId, Criterion, SamplingMode, Throughput, + BatchSize, BenchmarkGroup, BenchmarkId, Criterion, SamplingMode, Throughput, black_box, + criterion_group, criterion_main, measurement::Measurement, }; use ipa_core::{ ff::{Field, Fp31, Fp32BitPrime, U128Conversions}, protocol::{basics::SecureMul, context::SemiHonestContext}, - secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, FieldSimd, IntoShares}, + secret_sharing::{FieldSimd, IntoShares, replicated::semi_honest::AdditiveShare as Replicated}, test_fixture::circuit, }; use rand::distributions::{Distribution, Standard}; diff --git a/ipa-core/benches/ct/dzkp.rs b/ipa-core/benches/ct/dzkp.rs index 962bcbcab..2e5b87997 100644 --- a/ipa-core/benches/ct/dzkp.rs +++ b/ipa-core/benches/ct/dzkp.rs @@ -2,26 +2,26 @@ use std::iter::{repeat_with, zip}; -use criterion::{criterion_group, criterion_main, BatchSize, Criterion, SamplingMode}; -use futures::{stream::iter, TryStreamExt}; +use criterion::{BatchSize, Criterion, SamplingMode, criterion_group, criterion_main}; +use futures::{TryStreamExt, stream::iter}; use ipa_core::{ ff::boolean_array::BA256, helpers::TotalRecords, protocol::{ + RecordId, basics::BooleanArrayMul, context::{ + Context, DZKPUpgradedMaliciousContext, UpgradableContext, dzkp_validator::{DZKPValidator, MultiplicationInputsBlock, TARGET_PROOF_SIZE}, malicious::TEST_DZKP_STEPS, - Context, DZKPUpgradedMaliciousContext, UpgradableContext, }, - RecordId, }, - secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, SharedValue}, + secret_sharing::{SharedValue, replicated::semi_honest::AdditiveShare as Replicated}, sharding::NotSharded, test_fixture::{Runner, TestWorld}, utils::non_zero_prev_power_of_two, }; -use rand::{thread_rng, Rng}; +use rand::{Rng, random, thread_rng}; use tokio::runtime::Builder; /// Benchmark for the table_indices_prover function in dzkp_field.rs. @@ -29,7 +29,7 @@ fn benchmark_table_indices_prover(c: &mut Criterion) { let mut group = c.benchmark_group("benches"); group.bench_function("table_indices_prover", |b| { b.iter_batched_ref( - || thread_rng().gen(), + || random(), |input: &mut MultiplicationInputsBlock| input.table_indices_prover(), BatchSize::SmallInput, ) @@ -60,8 +60,8 @@ fn benchmark_proof(c: &mut Criterion) { || { let mut rng = thread_rng(); - let a = repeat_with(|| rng.gen()).take(COUNT).collect::>(); - let b = repeat_with(|| rng.gen()).take(COUNT).collect::>(); + let a = repeat_with(|| rng.r#gen()).take(COUNT).collect::>(); + let b = repeat_with(|| rng.r#gen()).take(COUNT).collect::>(); (a, b) }, diff --git a/ipa-core/benches/ct/prss.rs b/ipa-core/benches/ct/prss.rs index 4e14a485d..9d6356381 100644 --- a/ipa-core/benches/ct/prss.rs +++ b/ipa-core/benches/ct/prss.rs @@ -1,11 +1,11 @@ use std::sync::Arc; -use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; +use criterion::{Criterion, Throughput, black_box, criterion_group, criterion_main}; use ipa_core::{ - ff::boolean_array::{BA256, BA64, BA8}, + ff::boolean_array::{BA8, BA64, BA256}, protocol::{ - prss::{Endpoint, IndexedSharedRandomness, KeyExchange, SharedRandomness}, Gate, + prss::{Endpoint, IndexedSharedRandomness, KeyExchange, SharedRandomness}, }, }; use rand::thread_rng; diff --git a/ipa-core/benches/oneshot/arithmetic_circuit.rs b/ipa-core/benches/oneshot/arithmetic_circuit.rs index 459bd2e58..bd8dfa4e9 100644 --- a/ipa-core/benches/oneshot/arithmetic_circuit.rs +++ b/ipa-core/benches/oneshot/arithmetic_circuit.rs @@ -30,7 +30,9 @@ pub async fn main() { let field_size = Fp31::BITS; let width = args.width; let depth = args.depth; - println!("benchmark parameters: Field size: {field_size} bits, circuit width: {width}, depth: {depth}"); + println!( + "benchmark parameters: Field size: {field_size} bits, circuit width: {width}, depth: {depth}" + ); } let input = circuit::arithmetic_setup(args.width, args.depth); diff --git a/ipa-core/benches/transpose.rs b/ipa-core/benches/transpose.rs index e0b872e93..d8b768d1c 100644 --- a/ipa-core/benches/transpose.rs +++ b/ipa-core/benches/transpose.rs @@ -14,18 +14,19 @@ use std::{array, iter::repeat_with, time::Duration}; -use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput}; +use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; use ipa_core::{ error::UnwrapInfallible, ff::boolean_array::BA64, secret_sharing::{ - vector::{transpose_16x16, transpose_8x8}, SharedValue, TransposeFrom, + vector::{transpose_8x8, transpose_16x16}, }, }; use rand::{ + Rng, distributions::{Distribution, Standard}, - thread_rng, Rng, + thread_rng, }; fn random_array() -> [T; N] @@ -33,7 +34,7 @@ where Standard: Distribution, { let mut rng = thread_rng(); - array::from_fn(|_| rng.gen()) + array::from_fn(|_| rng.r#gen()) } struct Params { diff --git a/ipa-core/src/app.rs b/ipa-core/src/app.rs index a87c253a0..36ea28e91 100644 --- a/ipa-core/src/app.rs +++ b/ipa-core/src/app.rs @@ -6,10 +6,10 @@ use crate::{ cli::LoggingHandle, executor::IpaRuntime, helpers::{ - query::{CompareStatusRequest, PrepareQuery, QueryConfig, QueryInput}, - routing::{Addr, RouteId}, ApiError, BodyStream, HandlerBox, HandlerRef, HelperIdentity, HelperResponse, MpcTransportImpl, RequestHandler, ShardTransportImpl, Transport, TransportIdentity, + query::{CompareStatusRequest, PrepareQuery, QueryConfig, QueryInput}, + routing::{Addr, RouteId}, }, hpke::{KeyRegistry, PrivateKeyOnly}, protocol::QueryId, @@ -222,7 +222,7 @@ impl RequestHandler for Inner { return Err(ApiError::BadRequest( format!("{r:?} request must not be handled by shard query processing flow") .into(), - )) + )); } }) } @@ -241,7 +241,7 @@ impl RequestHandler for Inner { return Err(ApiError::BadRequest( format!("{r:?} request must not be handled by MPC query processing flow") .into(), - )) + )); } RouteId::ReceiveQuery => { let req = req.into::()?; diff --git a/ipa-core/src/bin/crypto_util.rs b/ipa-core/src/bin/crypto_util.rs index 2ac02e0f5..bd71b79a5 100644 --- a/ipa-core/src/bin/crypto_util.rs +++ b/ipa-core/src/bin/crypto_util.rs @@ -3,8 +3,8 @@ use std::fmt::Debug; use clap::{Parser, Subcommand}; use ipa_core::{ cli::{ - crypto::{HybridDecryptArgs, HybridEncryptArgs}, Verbosity, + crypto::{HybridDecryptArgs, HybridEncryptArgs}, }, error::BoxError, }; diff --git a/ipa-core/src/bin/helper.rs b/ipa-core/src/bin/helper.rs index 3b62653a4..e82598dec 100644 --- a/ipa-core/src/bin/helper.rs +++ b/ipa-core/src/bin/helper.rs @@ -11,12 +11,13 @@ use clap::{self, Parser, Subcommand}; use futures::future::join; use hyper::http::uri::Scheme; use ipa_core::{ + AppConfig, AppSetup, NonZeroU32PowerOfTwo, cli::{ + ConfGenArgs, KeygenArgs, LoggingHandle, ShardedConfGenArgs, TestSetupArgs, Verbosity, client_config_setup, keygen, sharded_client_config_setup, sharded_server_from_toml_str, - test_setup, ConfGenArgs, KeygenArgs, LoggingHandle, ShardedConfGenArgs, TestSetupArgs, - Verbosity, + test_setup, }, - config::{hpke_registry, HpkeServerConfig, ServerConfig, TlsConfig}, + config::{HpkeServerConfig, ServerConfig, TlsConfig, hpke_registry}, error::BoxError, executor::IpaRuntime, helpers::HelperIdentity, @@ -25,7 +26,6 @@ use ipa_core::{ ShardHttpTransport, }, sharding::ShardIndex, - AppConfig, AppSetup, NonZeroU32PowerOfTwo, }; use tokio::runtime::Runtime; use tracing::{error, info}; diff --git a/ipa-core/src/bin/in_the_clear.rs b/ipa-core/src/bin/in_the_clear.rs index af6cb380d..010242bf6 100644 --- a/ipa-core/src/bin/in_the_clear.rs +++ b/ipa-core/src/bin/in_the_clear.rs @@ -2,8 +2,8 @@ use std::{error::Error, fs::File, io::Write, num::NonZeroU32, path::PathBuf}; use clap::Parser; use ipa_core::{ - cli::{playbook::InputSource, Verbosity}, - test_fixture::hybrid::{hybrid_in_the_clear, TestHybridRecord}, + cli::{Verbosity, playbook::InputSource}, + test_fixture::hybrid::{TestHybridRecord, hybrid_in_the_clear}, }; #[derive(Debug, Parser)] diff --git a/ipa-core/src/bin/ipa_bench/cmd.rs b/ipa-core/src/bin/ipa_bench/cmd.rs index aeb4785ca..4229427b1 100644 --- a/ipa-core/src/bin/ipa_bench/cmd.rs +++ b/ipa-core/src/bin/ipa_bench/cmd.rs @@ -7,7 +7,7 @@ use std::{ use clap::Parser; use ipa_core::cli::Verbosity; -use rand::{rngs::StdRng, SeedableRng}; +use rand::{SeedableRng, rngs::StdRng}; use tracing::{debug, error, info}; use crate::{gen_events::generate_events, sample::Sample}; @@ -159,7 +159,7 @@ impl Command { fn get_input(path: &Option) -> Result, io::Error> { match path { - Some(ref path) => File::open(path).map(|f| Box::new(f) as Box), + Some(path) => File::open(path).map(|f| Box::new(f) as Box), None => Ok(Box::new(io::stdin())), } } diff --git a/ipa-core/src/bin/ipa_bench/gen_events.rs b/ipa-core/src/bin/ipa_bench/gen_events.rs index 0af9ef8e4..a699aeff3 100644 --- a/ipa-core/src/bin/ipa_bench/gen_events.rs +++ b/ipa-core/src/bin/ipa_bench/gen_events.rs @@ -2,8 +2,8 @@ use std::io; use bitvec::view::BitViewSized; use rand::{ - distributions::{Bernoulli, Distribution}, CryptoRng, Rng, RngCore, + distributions::{Bernoulli, Distribution}, }; use tracing::{debug, info, trace}; @@ -38,7 +38,7 @@ pub fn generate_events( debug!("ad: {}", ad_count); // For now, we'll do 1 ad = 1 breakdown key - let ad_id: u32 = rng.gen(); + let ad_id: u32 = rng.r#gen(); // Number of unique people who saw the ad let reach = sample.reach_per_ad(rng); @@ -93,7 +93,7 @@ fn gen_reports( ) -> Vec { let mut reports: Vec = Vec::new(); - let matchkey = rng.gen::(); + let matchkey = rng.r#gen::(); // Randomly choose a datetime (plus the given base timestamp) as the first impression let mut last_impression = @@ -177,9 +177,9 @@ mod tests { io::{Cursor, Write}, }; - use rand::{rngs::StdRng, SeedableRng}; + use rand::{SeedableRng, rngs::StdRng}; - use super::{gen_reports, generate_events, EventTimestamp, GenericReport}; + use super::{EventTimestamp, GenericReport, gen_reports, generate_events}; use crate::{gen_events::add_event_timestamps, models::Epoch, sample::Sample}; const DATA: &str = r#" diff --git a/ipa-core/src/bin/ipa_bench/sample.rs b/ipa-core/src/bin/ipa_bench/sample.rs index 8024ebe2d..6f14864e1 100644 --- a/ipa-core/src/bin/ipa_bench/sample.rs +++ b/ipa-core/src/bin/ipa_bench/sample.rs @@ -1,8 +1,8 @@ use std::time::Duration; use rand::{ - distributions::{Distribution, WeightedIndex}, CryptoRng, Rng, RngCore, + distributions::{Distribution, WeightedIndex}, }; use crate::config::Config; diff --git a/ipa-core/src/bin/report_collector.rs b/ipa-core/src/bin/report_collector.rs index 20a1724e1..1d39fa22d 100644 --- a/ipa-core/src/bin/report_collector.rs +++ b/ipa-core/src/bin/report_collector.rs @@ -4,32 +4,32 @@ use std::{ fmt::Debug, fs::{File, OpenOptions}, io, - io::{stdout, BufRead, BufReader, Write}, + io::{BufRead, BufReader, Write, stdout}, iter::zip, ops::Deref, path::{Path, PathBuf}, }; use clap::{Parser, Subcommand}; -use hyper::{http::uri::Scheme, Uri}; +use hyper::{Uri, http::uri::Scheme}; use ipa_core::{ cli::{ + CsvSerializer, Verbosity, playbook::{ - make_clients, make_sharded_clients, run_hybrid_query_and_validate, BufferedRoundRobinSubmission, HybridQueryResult, InputSource, StreamingSubmission, + make_clients, make_sharded_clients, run_hybrid_query_and_validate, }, - CsvSerializer, Verbosity, }, - ff::{boolean_array::BA32, FieldType}, + ff::{FieldType, boolean_array::BA32}, helpers::{ - query::{HybridQueryParams, QueryConfig, QueryInput, QuerySize, QueryType}, BodyStream, + query::{HybridQueryParams, QueryConfig, QueryInput, QuerySize, QueryType}, }, net::{Helper, IpaHttpClient}, protocol::QueryId, test_fixture::{HybridEventGenerator, HybridGeneratorConfig}, }; -use rand::{distributions::Alphanumeric, rngs::StdRng, thread_rng, Rng}; +use rand::{Rng, distributions::Alphanumeric, rngs::StdRng, thread_rng}; use rand_core::SeedableRng; #[derive(Debug, Parser)] @@ -181,9 +181,9 @@ async fn main() -> Result<(), Box> { hybrid_query_config, clients, |query_id| { - if let Some(ref url_file_list) = url_file_list { + if let Some(url_file_list) = url_file_list { inputs_from_url_file(url_file_list, query_id, args.shard_count) - } else if let Some(ref encrypted_inputs) = encrypted_inputs { + } else if let Some(encrypted_inputs) = encrypted_inputs { Ok(inputs_from_encrypted_inputs( encrypted_inputs, query_id, diff --git a/ipa-core/src/bin/test_mpc.rs b/ipa-core/src/bin/test_mpc.rs index 3735c4c18..b6ce4a659 100644 --- a/ipa-core/src/bin/test_mpc.rs +++ b/ipa-core/src/bin/test_mpc.rs @@ -14,21 +14,21 @@ use generic_array::ArrayLength; use hyper::http::uri::Scheme; use ipa_core::{ cli::{ + Verbosity, playbook::{ - make_clients, make_sharded_clients, secure_add, secure_mul, secure_shuffle, validate, - InputSource, + InputSource, make_clients, make_sharded_clients, secure_add, secure_mul, + secure_shuffle, validate, }, - Verbosity, }, ff::{ - boolean_array::BA64, Field, FieldType, Fp31, Fp32BitPrime, Serializable, U128Conversions, + Field, FieldType, Fp31, Fp32BitPrime, Serializable, U128Conversions, boolean_array::BA64, }, helpers::query::{ QueryConfig, QueryType::{TestAddInPrimeField, TestMultiply, TestShardedShuffle}, }, net::{Helper, IpaHttpClient}, - secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares}, + secret_sharing::{IntoShares, replicated::semi_honest::AdditiveShare}, }; use tiny_http::{Response, ResponseBox, Server, StatusCode}; use tracing::{error, info}; diff --git a/ipa-core/src/cli/clientconf.rs b/ipa-core/src/cli/clientconf.rs index 8d50a6337..453eb2f09 100644 --- a/ipa-core/src/cli/clientconf.rs +++ b/ipa-core/src/cli/clientconf.rs @@ -4,7 +4,7 @@ use clap::Args; use crate::{ cli::{ - config_parse::{gen_client_config, HelperClientConf}, + config_parse::{HelperClientConf, gen_client_config}, paths::PathExt, }, error::BoxError, diff --git a/ipa-core/src/cli/config_parse.rs b/ipa-core/src/cli/config_parse.rs index f282a3a9f..1efdf0e67 100644 --- a/ipa-core/src/cli/config_parse.rs +++ b/ipa-core/src/cli/config_parse.rs @@ -380,11 +380,11 @@ pub fn sharded_server_from_toml_str( #[cfg(test)] mod tests { - use once_cell::sync::Lazy; + use std::sync::LazyLock; use crate::{ cli::{ - config_parse::{parse_sharded_network_toml, Error}, + config_parse::{Error, parse_sharded_network_toml}, sharded_server_from_toml_str, }, config::HttpClientConfigurator, @@ -564,11 +564,11 @@ mod tests { // Following are some large &str const used for tests /// Valid: A non-sharded network toml, just how they used to be - static NON_SHARDED_COMPAT: Lazy = Lazy::new(|| format!("{CLIENT}{P1}{REST}")); + static NON_SHARDED_COMPAT: LazyLock = LazyLock::new(|| format!("{CLIENT}{P1}{REST}")); /// Invalid: Same as [`NON_SHARDED_COMPAT`] but with a single `shard_port` set. - static SHARDED_COMPAT_ONE_URL: Lazy = - Lazy::new(|| format!("{CLIENT}{P1}\nshard_url = \"helper1.org:777\"\n{REST}")); + static SHARDED_COMPAT_ONE_URL: LazyLock = + LazyLock::new(|| format!("{CLIENT}{P1}\nshard_url = \"helper1.org:777\"\n{REST}")); /// Helper const used to create client configs const CLIENT: &str = r#"[client.http_config] @@ -704,7 +704,7 @@ public_key = "55f87a8794b4de9a60f8ede9ed000f5f10c028e22390922efc4fb63bc6be0a61" "#; /// Valid: Three sharded configs together for 9 - static SHARDED_OK_REPEAT: Lazy = Lazy::new(|| { + static SHARDED_OK_REPEAT: LazyLock = LazyLock::new(|| { format!( "{}{}{}", SHARDED_OK, @@ -714,13 +714,13 @@ public_key = "55f87a8794b4de9a60f8ede9ed000f5f10c028e22390922efc4fb63bc6be0a61" }); /// Invalid: A network toml with 8 entries - static SHARDED_8: Lazy = Lazy::new(|| { + static SHARDED_8: LazyLock = LazyLock::new(|| { let last_peers_index = SHARDED_OK_REPEAT.rfind("[[peers]]").unwrap(); SHARDED_OK_REPEAT[..last_peers_index].to_string() }); /// Invalid: Same as [`SHARDED_OK_REPEAT`] but without the expected ports - static SHARDED_MISSING_URLS_REPEAT: Lazy = Lazy::new(|| { + static SHARDED_MISSING_URLS_REPEAT: LazyLock = LazyLock::new(|| { let lines: Vec<&str> = SHARDED_OK_REPEAT.lines().collect(); let new_lines: Vec = lines .iter() diff --git a/ipa-core/src/cli/crypto/hybrid_decrypt.rs b/ipa-core/src/cli/crypto/hybrid_decrypt.rs index 285df9e7e..39bf00bd4 100644 --- a/ipa-core/src/cli/crypto/hybrid_decrypt.rs +++ b/ipa-core/src/cli/crypto/hybrid_decrypt.rs @@ -7,11 +7,11 @@ use std::{ use clap::Parser; use crate::{ - config::{hpke_registry, HpkeServerConfig}, + config::{HpkeServerConfig, hpke_registry}, error::BoxError, ff::{ - boolean_array::{BA3, BA8}, U128Conversions, + boolean_array::{BA3, BA8}, }, hpke::{KeyRegistry, PrivateKeyOnly}, report::hybrid::{EncryptedHybridReport, HybridReport}, @@ -154,7 +154,10 @@ impl HybridDecryptArgs { let timestamp = conversion_report1.info.timestamp; let epsilon = conversion_report1.info.epsilon; let sensitivity = conversion_report1.info.sensitivity; - writeln!(writer, "c,{match_key},{value},{key_id},{conversion_site_domain},{timestamp},{epsilon},{sensitivity}")?; + writeln!( + writer, + "c,{match_key},{value},{key_id},{conversion_site_domain},{timestamp},{epsilon},{sensitivity}" + )?; } _ => { panic!("Reports are not all the same type"); @@ -192,7 +195,7 @@ impl Iterator for DecryptedHybridReports { impl DecryptedHybridReports { fn new(filename: &PathBuf, key_registry: KeyRegistry) -> Self { let file = File::open(filename) - .unwrap_or_else(|e| panic!("unable to open file {filename:?}. {e}")); + .unwrap_or_else(|e| panic!("unable to open file {}. {e}", filename.display())); let reader = BufReader::new(file); Self { reader, diff --git a/ipa-core/src/cli/crypto/hybrid_encrypt.rs b/ipa-core/src/cli/crypto/hybrid_encrypt.rs index ac33fceef..3f401242f 100644 --- a/ipa-core/src/cli/crypto/hybrid_encrypt.rs +++ b/ipa-core/src/cli/crypto/hybrid_encrypt.rs @@ -1,7 +1,7 @@ use std::{ array, collections::BTreeMap, - fs::{read_to_string, File, OpenOptions}, + fs::{File, OpenOptions, read_to_string}, io::{BufWriter, Write}, path::{Path, PathBuf}, sync::mpsc::SyncSender, @@ -21,7 +21,7 @@ use crate::{ config::{KeyRegistries, NetworkConfig}, error::BoxError, hpke::{KeyRegistry, PublicKeyOnly}, - report::hybrid::{HybridReport, DEFAULT_KEY_ID}, + report::hybrid::{DEFAULT_KEY_ID, HybridReport}, secret_sharing::IntoShares, test_fixture::hybrid::TestHybridRecord, }; @@ -98,16 +98,22 @@ impl HybridEncryptArgs { let key_registries = KeyRegistries::default(); - let network = - NetworkConfig::from_toml_str_sharded(&read_to_string(&self.network).unwrap_or_else( - |e| panic!("Failed to open network file: {:?}. {}", &self.network, e), - )) - .unwrap_or_else(|e| { + let network = NetworkConfig::from_toml_str_sharded( + &read_to_string(&self.network).unwrap_or_else(|e| { panic!( - "Failed to parse network file into toml: {:?}. {}", - &self.network, e + "Failed to open network file: {}. {}", + &self.network.display(), + e ) - }); + }), + ) + .unwrap_or_else(|e| { + panic!( + "Failed to parse network file into toml: {}. {}", + &self.network.display(), + e + ) + }); let Some(key_registries) = key_registries.init_from(&network[0]) else { panic!("could not load network file") }; @@ -356,12 +362,12 @@ impl FileWriteWorker { mod tests { use std::io::Write; - use tempfile::{tempdir, NamedTempFile}; + use tempfile::{NamedTempFile, tempdir}; use crate::{ cli::{ - crypto::{hybrid_encrypt::HybridEncryptArgs, hybrid_sample_data}, CsvSerializer, + crypto::{hybrid_encrypt::HybridEncryptArgs, hybrid_sample_data}, }, test_fixture::hybrid::TestHybridRecord, }; diff --git a/ipa-core/src/cli/crypto/mod.rs b/ipa-core/src/cli/crypto/mod.rs index d57d23cb4..4b8acca5e 100644 --- a/ipa-core/src/cli/crypto/mod.rs +++ b/ipa-core/src/cli/crypto/mod.rs @@ -16,8 +16,8 @@ mod hybrid_sample_data { cli::CsvSerializer, hpke::{IpaPrivateKey, IpaPublicKey}, test_fixture::{ - hybrid::TestHybridRecord, hybrid_event_gen::ConversionDistribution, - HybridEventGenerator, HybridGeneratorConfig, + HybridEventGenerator, HybridGeneratorConfig, hybrid::TestHybridRecord, + hybrid_event_gen::ConversionDistribution, }, }; diff --git a/ipa-core/src/cli/csv.rs b/ipa-core/src/cli/csv.rs index 53d4b1002..fea660f79 100644 --- a/ipa-core/src/cli/csv.rs +++ b/ipa-core/src/cli/csv.rs @@ -27,7 +27,10 @@ impl Serializer for crate::test_fixture::hybrid::TestHybridRecord { epsilon, sensitivity, } => { - write!(buf, "c,{match_key},{value},{key_id},{conversion_site_domain},{timestamp},{epsilon},{sensitivity}")?; + write!( + buf, + "c,{match_key},{value},{key_id},{conversion_site_domain},{timestamp},{epsilon},{sensitivity}" + )?; } } diff --git a/ipa-core/src/cli/keygen.rs b/ipa-core/src/cli/keygen.rs index adaa0c046..a0ddec88f 100644 --- a/ipa-core/src/cli/keygen.rs +++ b/ipa-core/src/cli/keygen.rs @@ -5,11 +5,11 @@ use std::{ }; use clap::Args; -use rand::{thread_rng, Rng}; +use rand::{Rng, thread_rng}; use rand_core::CryptoRng; use rcgen::{ CertificateParams, DistinguishedName, ExtendedKeyUsagePurpose, Ia5String, IsCa, - KeyUsagePurpose, SanType, SerialNumber, PKCS_ECDSA_P256_SHA256, + KeyUsagePurpose, PKCS_ECDSA_P256_SHA256, SanType, SerialNumber, }; use time::{Duration, OffsetDateTime}; @@ -101,7 +101,7 @@ pub fn keygen_tls(args: &KeygenArgs, rng: &mut R) -> Result< /// Generates public and private key used for encrypting and decrypting match keys. fn keygen_matchkey(args: &KeygenArgs, mut rng: &mut R) -> Result<(), BoxError> { - let keypair = crate::hpke::KeyPair::gen(&mut rng); + let keypair = crate::hpke::KeyPair::r#gen(&mut rng); if args.mk_public_key.is_some() && args.mk_private_key.is_some() { create_new(args.mk_public_key.as_ref().unwrap())? diff --git a/ipa-core/src/cli/metric_collector.rs b/ipa-core/src/cli/metric_collector.rs index 5b8f07b27..2cf678f6c 100644 --- a/ipa-core/src/cli/metric_collector.rs +++ b/ipa-core/src/cli/metric_collector.rs @@ -36,7 +36,7 @@ impl Drop for CollectorHandle { fn drop(&mut self) { if !thread::panicking() && !self.thread_handle.is_finished() { tracing::warn!("Metrics thread is still running"); - }; + } } } diff --git a/ipa-core/src/cli/mod.rs b/ipa-core/src/cli/mod.rs index b675128f1..914728c00 100644 --- a/ipa-core/src/cli/mod.rs +++ b/ipa-core/src/cli/mod.rs @@ -17,17 +17,17 @@ mod test_setup; mod verbosity; #[cfg(feature = "web-app")] pub use clientconf::{ - setup as client_config_setup, sharded_setup as sharded_client_config_setup, ConfGenArgs, - ShardedConfGenArgs, + ConfGenArgs, ShardedConfGenArgs, setup as client_config_setup, + sharded_setup as sharded_client_config_setup, }; #[cfg(feature = "web-app")] pub use config_parse::sharded_server_from_toml_str; pub use csv::Serializer as CsvSerializer; pub use ipa_output::QueryResult as IpaQueryResult; #[cfg(feature = "web-app")] -pub use keygen::{keygen, KeygenArgs}; -pub use metric_collector::{install_collector, CollectorHandle}; +pub use keygen::{KeygenArgs, keygen}; +pub use metric_collector::{CollectorHandle, install_collector}; pub use paths::PathExt as CliPaths; #[cfg(feature = "web-app")] -pub use test_setup::{test_setup, TestSetupArgs}; +pub use test_setup::{TestSetupArgs, test_setup}; pub use verbosity::{LoggingHandle, Verbosity}; diff --git a/ipa-core/src/cli/playbook/add.rs b/ipa-core/src/cli/playbook/add.rs index 5c785bd1b..69a1e7645 100644 --- a/ipa-core/src/cli/playbook/add.rs +++ b/ipa-core/src/cli/playbook/add.rs @@ -8,10 +8,10 @@ use typenum::Unsigned; use crate::{ ff::{Field, Serializable}, - helpers::{query::QueryInput, BodyStream}, + helpers::{BodyStream, query::QueryInput}, net::{Helper, IpaHttpClient}, protocol::QueryId, - secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, IntoShares}, + secret_sharing::{IntoShares, replicated::semi_honest::AdditiveShare as Replicated}, test_fixture::Reconstruct, }; diff --git a/ipa-core/src/cli/playbook/hybrid.rs b/ipa-core/src/cli/playbook/hybrid.rs index ff6f7d3a4..73c35fb6d 100644 --- a/ipa-core/src/cli/playbook/hybrid.rs +++ b/ipa-core/src/cli/playbook/hybrid.rs @@ -14,7 +14,7 @@ use crate::{ helpers::query::{HybridQueryParams, QueryInput, QuerySize}, net::{Helper, IpaHttpClient}, query::QueryStatus, - secret_sharing::{replicated::semi_honest::AdditiveShare, SharedValue}, + secret_sharing::{SharedValue, replicated::semi_honest::AdditiveShare}, test_fixture::Reconstruct, }; diff --git a/ipa-core/src/cli/playbook/input.rs b/ipa-core/src/cli/playbook/input.rs index a78d7a72c..0305f995f 100644 --- a/ipa-core/src/cli/playbook/input.rs +++ b/ipa-core/src/cli/playbook/input.rs @@ -2,7 +2,7 @@ use std::{ any::type_name, fs::File, io, - io::{stdin, BufRead, BufReader, Read}, + io::{BufRead, BufReader, Read, stdin}, path::PathBuf, }; @@ -66,8 +66,16 @@ impl InputItem for TestHybridRecord { } 'c' => { - if let [_, match_key, number, key_id, conversion_site_domain, timestamp, epsilon, sensitivity] = - s.splitn(8, ',').collect::>()[..] + if let [ + _, + match_key, + number, + key_id, + conversion_site_domain, + timestamp, + epsilon, + sensitivity, + ] = s.splitn(8, ',').collect::>()[..] { let match_key: u64 = match_key .parse() diff --git a/ipa-core/src/cli/playbook/mod.rs b/ipa-core/src/cli/playbook/mod.rs index 2acef7589..513a91cc9 100644 --- a/ipa-core/src/cli/playbook/mod.rs +++ b/ipa-core/src/cli/playbook/mod.rs @@ -19,14 +19,14 @@ pub use sharded_shuffle::secure_shuffle; use tokio::time::sleep; pub use self::{ - hybrid::{run_hybrid_query_and_validate, HybridQueryResult}, + hybrid::{HybridQueryResult, run_hybrid_query_and_validate}, streaming::{BufferedRoundRobinSubmission, StreamingSubmission}, }; use crate::{ cli::config_parse::HelperNetworkConfigParseExt, config::{ClientConfig, NetworkConfig, PeerConfig}, executor::IpaRuntime, - ff::boolean_array::{BA20, BA3, BA8}, + ff::boolean_array::{BA3, BA8, BA20}, helpers::query::DpMechanism, net::{ClientIdentity, Helper, IpaHttpClient}, protocol::{dp::NoiseParams, ipa_prf::oprf_padding::insecure::OPRFPaddingDp}, @@ -158,7 +158,7 @@ pub fn validate_dp( let (_, std) = truncated_discrete_laplace.mean_and_std(); let tolerance_factor = 20.0; // set so this fails randomly with small probability - // println!("mean = {mean}, std = {std}, tolerance_factor * std = {}",tolerance_factor * std); + // println!("mean = {mean}, std = {std}, tolerance_factor * std = {}",tolerance_factor * std); (next_actual_f64_shifted - next_expected_f64).abs() < tolerance_factor * 3.0 * std } DpMechanism::NoDp => next_expected == next_actual, @@ -189,8 +189,10 @@ pub fn validate_dp( // make sure DP noise actually changed the results. For large epsilon and few breakdowns keys // we might end up not adding any noise if epsilon <= 1.0 { - assert!(!all_equal, - "Expected and actual results match exactly...probably DP noise is not being added when it should be"); + assert!( + !all_equal, + "Expected and actual results match exactly...probably DP noise is not being added when it should be" + ); } } diff --git a/ipa-core/src/cli/playbook/multiply.rs b/ipa-core/src/cli/playbook/multiply.rs index 265659c85..1459968af 100644 --- a/ipa-core/src/cli/playbook/multiply.rs +++ b/ipa-core/src/cli/playbook/multiply.rs @@ -8,10 +8,10 @@ use typenum::Unsigned; use crate::{ ff::{Field, Serializable}, - helpers::{query::QueryInput, BodyStream}, + helpers::{BodyStream, query::QueryInput}, net::{Helper, IpaHttpClient}, protocol::QueryId, - secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, IntoShares}, + secret_sharing::{IntoShares, replicated::semi_honest::AdditiveShare as Replicated}, test_fixture::Reconstruct, }; diff --git a/ipa-core/src/cli/playbook/sharded_shuffle.rs b/ipa-core/src/cli/playbook/sharded_shuffle.rs index fceb1f4e4..2ec4b1343 100644 --- a/ipa-core/src/cli/playbook/sharded_shuffle.rs +++ b/ipa-core/src/cli/playbook/sharded_shuffle.rs @@ -8,12 +8,12 @@ use futures_util::future::try_join_all; use generic_array::ArrayLength; use crate::{ - ff::{boolean_array::BooleanArray, Serializable}, - helpers::{query::QueryInput, BodyStream}, + ff::{Serializable, boolean_array::BooleanArray}, + helpers::{BodyStream, query::QueryInput}, net::{Helper, IpaHttpClient}, protocol::QueryId, query::QueryStatus, - secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares}, + secret_sharing::{IntoShares, replicated::semi_honest::AdditiveShare}, test_fixture::Reconstruct, }; diff --git a/ipa-core/src/cli/playbook/streaming.rs b/ipa-core/src/cli/playbook/streaming.rs index 7ee743aa4..e528475f6 100644 --- a/ipa-core/src/cli/playbook/streaming.rs +++ b/ipa-core/src/cli/playbook/streaming.rs @@ -194,7 +194,7 @@ mod tests { iter, }; - use futures_util::{stream::FuturesOrdered, TryStreamExt}; + use futures_util::{TryStreamExt, stream::FuturesOrdered}; use proptest::proptest; use tempfile::TempDir; @@ -236,9 +236,7 @@ mod tests { pending_len = 0; r } else if chunk.len() > 1 { - let len = - u16::from_le_bytes(chunk.split_to(2).as_ref().try_into().unwrap()); - len + u16::from_le_bytes(chunk.split_to(2).as_ref().try_into().unwrap()) } else { pending_len = u8::from_le_bytes(chunk.split_to(1).as_ref().try_into().unwrap()); diff --git a/ipa-core/src/cli/test_setup.rs b/ipa-core/src/cli/test_setup.rs index 00ee95645..b6ef5cdeb 100644 --- a/ipa-core/src/cli/test_setup.rs +++ b/ipa-core/src/cli/test_setup.rs @@ -9,10 +9,10 @@ use clap::Args; use super::clientconf::shard_conf_folder; use crate::{ cli::{ - config_parse::{gen_client_config, HelperClientConf}, + KeygenArgs, + config_parse::{HelperClientConf, gen_client_config}, keygen, paths::PathExt, - KeygenArgs, }, error::BoxError, sharding::ShardIndex, @@ -191,7 +191,7 @@ mod tests { use tempfile::TempDir; use crate::{ - cli::{sharded_server_from_toml_str, test_setup, TestSetupArgs}, + cli::{TestSetupArgs, sharded_server_from_toml_str, test_setup}, helpers::HelperIdentity, sharding::ShardIndex, }; diff --git a/ipa-core/src/cli/verbosity.rs b/ipa-core/src/cli/verbosity.rs index 339626228..6a76f45f9 100644 --- a/ipa-core/src/cli/verbosity.rs +++ b/ipa-core/src/cli/verbosity.rs @@ -1,13 +1,13 @@ use std::{ fs::OpenOptions, - io::{stderr, IsTerminal}, + io::{IsTerminal, stderr}, path::PathBuf, }; use clap::Parser; -use tracing::{info, metadata::LevelFilter, Level}; +use tracing::{Level, info, metadata::LevelFilter}; use tracing_subscriber::{ - fmt, fmt::format::FmtSpan, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, + EnvFilter, fmt, fmt::format::FmtSpan, layer::SubscriberExt, util::SubscriberInitExt, }; use crate::{ @@ -57,7 +57,7 @@ impl Verbosity { .append(true) .create(true) .open(path) - .unwrap_or_else(|e| panic!("failed to open log file {path:?}: {e}")); + .unwrap_or_else(|e| panic!("failed to open log file {}: {e}", path.display())); let file_writer = fmt::layer() .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) .with_ansi(false) diff --git a/ipa-core/src/config.rs b/ipa-core/src/config.rs index 2060320ac..188a10728 100644 --- a/ipa-core/src/config.rs +++ b/ipa-core/src/config.rs @@ -6,8 +6,8 @@ use std::{ time::Duration, }; -use base64::{engine::general_purpose::STANDARD as BASE64, Engine as _}; -use hyper::{http::uri::Scheme, Uri}; +use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; +use hyper::{Uri, http::uri::Scheme}; use hyper_util::client::legacy::Builder; use rustls_pemfile::Item; use rustls_pki_types::{CertificateDer, PrivateKeyDer}; @@ -503,7 +503,7 @@ impl KeyRegistries { mod tests { use std::time::Duration; - use hpke::{kem::X25519HkdfSha256, Kem}; + use hpke::{Kem, kem::X25519HkdfSha256}; use hyper::Uri; use rand::rngs::StdRng; use rand_core::SeedableRng; @@ -577,14 +577,16 @@ mod tests { "http config is not the same: {:?} vs {:?}", expected.http_config, actual.http_config ), - }; + } } - assert!(serde_json::from_str::( - r#"{ "http_config": { "version": "http1", "ping_interval_secs": 132 } }"#, - ) - .unwrap_err() - .is_data()); + assert!( + serde_json::from_str::( + r#"{ "http_config": { "version": "http1", "ping_interval_secs": 132 } }"#, + ) + .unwrap_err() + .is_data() + ); assert_config_eq( r#"{ "http_config": { "version": "http2" } }"#, diff --git a/ipa-core/src/ff/accumulator.rs b/ipa-core/src/ff/accumulator.rs index 6edf5390a..995b03bb0 100644 --- a/ipa-core/src/ff/accumulator.rs +++ b/ipa-core/src/ff/accumulator.rs @@ -346,6 +346,7 @@ mod test { ($field:ty) => { mod accum_tests { use std::iter::zip; + use rand::Rng; use proptest::prelude::*; @@ -360,10 +361,10 @@ mod test { #[test] fn accum_simple() { run_random(|mut rng| async move { - let a = rng.gen(); - let b = rng.gen(); - let c = rng.gen(); - let d = rng.gen(); + let a = rng.r#gen(); + let b = rng.r#gen(); + let c = rng.r#gen(); + let d = rng.r#gen(); let mut acc = <$field as MultiplyAccumulate>::Accumulator::new(); acc.multiply_accumulate(a, b); diff --git a/ipa-core/src/ff/boolean.rs b/ipa-core/src/ff/boolean.rs index b76699587..75ec1b58a 100644 --- a/ipa-core/src/ff/boolean.rs +++ b/ipa-core/src/ff/boolean.rs @@ -36,11 +36,7 @@ impl ArrayAccess for Boolean { type Iter<'a> = Once; fn get(&self, index: usize) -> Option { - if index < 1 { - Some(*self) - } else { - None - } + if index < 1 { Some(*self) } else { None } } fn set(&mut self, index: usize, e: Self::Output) { @@ -111,7 +107,7 @@ impl Serializable for Boolean { ///generate random bool impl rand::distributions::Distribution for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> Boolean { - Boolean(rng.gen::()) + Boolean(rng.r#gen::()) } } @@ -237,12 +233,12 @@ impl DZKPCompatibleField for Boolean { #[cfg(all(test, unit_test))] mod test { use generic_array::GenericArray; - use proptest::prelude::{prop, Arbitrary, Strategy}; - use rand::{thread_rng, Rng}; + use proptest::prelude::{Arbitrary, Strategy, prop}; + use rand::{Rng, thread_rng}; use typenum::U1; use crate::{ - ff::{boolean::Boolean, ArrayAccess, Field, Serializable}, + ff::{ArrayAccess, Field, Serializable, boolean::Boolean}, protocol::context::dzkp_field::DZKPCompatibleField, secret_sharing::{SharedValue, Vectorizable}, }; @@ -260,7 +256,7 @@ mod test { #[test] fn serde_boolean() { let mut rng = thread_rng(); - let input = rng.gen::(); + let input = rng.r#gen::(); let mut a: GenericArray = [0u8; 1].into(); input.serialize(&mut a); let output = Boolean::deserialize(&a).unwrap(); @@ -271,10 +267,10 @@ mod test { #[test] fn simple_arithmetics_boolean() { let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); - let c = rng.gen::(); - let d = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); + let c = rng.r#gen::(); + let d = rng.r#gen::(); assert_eq!((a + b) * (c + d), a * c + a * d + b * c + b * d); } @@ -282,7 +278,7 @@ mod test { #[test] fn not_boolean() { let mut rng = thread_rng(); - let a = rng.gen::(); + let a = rng.r#gen::(); assert_ne!(a, !a); } diff --git a/ipa-core/src/ff/boolean_array.rs b/ipa-core/src/ff/boolean_array.rs index 3c394b5a3..b97392094 100644 --- a/ipa-core/src/ff/boolean_array.rs +++ b/ipa-core/src/ff/boolean_array.rs @@ -8,11 +8,11 @@ use bitvec::{ slice::Iter, }; use generic_array::GenericArray; -use typenum::{Unsigned, U12, U14, U18, U2, U32, U8}; +use typenum::{U2, U8, U12, U14, U18, U32, Unsigned}; use crate::{ error::LengthError, - ff::{boolean::Boolean, ArrayAccess, Expand, Field, Gf32Bit, Serializable, U128Conversions}, + ff::{ArrayAccess, Expand, Field, Gf32Bit, Serializable, U128Conversions, boolean::Boolean}, protocol::prss::{FromRandom, FromRandomU128}, secret_sharing::{Block, SharedValue, StdArray, Vectorizable}, }; @@ -218,7 +218,7 @@ macro_rules! boolean_array_impl_small { impl rand::distributions::Distribution<$name> for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> $name { - <$name>::from_random_u128(rng.gen::()) + <$name>::from_random_u128(rng.r#gen::()) } } @@ -602,8 +602,7 @@ macro_rules! boolean_array_impl { fn try_from(value: $name) -> Result { // len() returns bits, so divide by 8 // further divide by 4 since Gf32Bit has 4 byte - // add 31 to round up - let length = (value.0.len() + 31) / 32; + let length = value.0.len().div_ceil(32); let mut chunks = Vec::::with_capacity(length); let last_chunk_start = length-1; for i in 0..last_chunk_start { @@ -787,9 +786,9 @@ macro_rules! boolean_array_impl { #[test] fn set_boolean_array() { let mut rng = thread_rng(); - let i = rng.gen::() % usize::try_from(<$name>::BITS).unwrap(); - let a = rng.gen::(); - let mut ba = rng.gen::<$name>(); + let i = rng.r#gen::() % usize::try_from(<$name>::BITS).unwrap(); + let a = rng.r#gen::(); + let mut ba = rng.r#gen::<$name>(); ba.set(i, a); assert_eq!(ba.get(i), Some(a)); } @@ -797,7 +796,7 @@ macro_rules! boolean_array_impl { #[test] fn convert_to_galois_field() { let mut rng = thread_rng(); - let ba = rng.gen::<$name>(); + let ba = rng.r#gen::<$name>(); let mut vec = ba.as_raw_slice().to_vec(); // append with zeros when necessary for _ in 0..(4-vec.len()%4)%4 { @@ -862,7 +861,7 @@ macro_rules! boolean_array_impl { #[test] fn serde() { - let ba = thread_rng().gen::<$name>(); + let ba = thread_rng().r#gen::<$name>(); let mut buf = GenericArray::default(); ba.serialize(&mut buf); assert_eq!( @@ -882,7 +881,7 @@ macro_rules! boolean_array_impl { #[test] fn bitslice() { let zero = $name::ZERO; - let random = thread_rng().gen::<$name>(); + let random = thread_rng().r#gen::<$name>(); // generate slices let slice_zero = zero.as_bitslice(); @@ -944,7 +943,7 @@ macro_rules! boolean_array_impl_large { impl rand::distributions::Distribution<$name> for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> $name { <$name>::from_random( - repeat_with(|| rng.gen()) + repeat_with(|| rng.r#gen()) .take(<$wordlength>::USIZE) .collect(), ) diff --git a/ipa-core/src/ff/curve_points.rs b/ipa-core/src/ff/curve_points.rs index 7a95c4832..0e19c34b7 100644 --- a/ipa-core/src/ff/curve_points.rs +++ b/ipa-core/src/ff/curve_points.rs @@ -1,14 +1,14 @@ use std::sync::OnceLock; use curve25519_dalek::{ - ristretto::{CompressedRistretto, RistrettoPoint}, Scalar, + ristretto::{CompressedRistretto, RistrettoPoint}, }; use generic_array::GenericArray; -use typenum::{U128, U32}; +use typenum::{U32, U128}; use crate::{ - ff::{ec_prime_field::Fp25519, Serializable}, + ff::{Serializable, ec_prime_field::Fp25519}, impl_shared_value_common, protocol::ipa_prf::PRF_CHUNK, secret_sharing::{Block, SharedValue, StdArray, Vectorizable}, @@ -261,11 +261,11 @@ impl From for RistrettoRepr { mod test { use curve25519_dalek::{constants, scalar::Scalar}; use generic_array::GenericArray; - use rand::{thread_rng, Rng}; + use rand::{Rng, thread_rng}; use typenum::U32; use crate::{ - ff::{curve_points::RP25519, ec_prime_field::Fp25519, Serializable}, + ff::{Serializable, curve_points::RP25519, ec_prime_field::Fp25519}, secret_sharing::SharedValue, }; @@ -275,7 +275,7 @@ mod test { #[test] fn serde_25519() { let mut rng = thread_rng(); - let input = rng.gen::(); + let input = rng.r#gen::(); let mut a: GenericArray = [0u8; 32].into(); input.serialize(&mut a); let output = RP25519::deserialize(&a).unwrap(); @@ -297,14 +297,14 @@ mod test { #[test] fn curve_arithmetics() { let mut rng = thread_rng(); - let fp_a = rng.gen::(); - let fp_b = rng.gen::(); + let fp_a = rng.r#gen::(); + let fp_b = rng.r#gen::(); let fp_c = fp_a + fp_b; let fp_d = RP25519::from(fp_a) + RP25519::from(fp_b); assert_eq!(fp_d, RP25519::from(fp_c)); assert_ne!(fp_d, RP25519::from(constants::RISTRETTO_BASEPOINT_POINT)); - let fp_e = rng.gen::(); - let fp_f = rng.gen::(); + let fp_e = rng.r#gen::(); + let fp_f = rng.r#gen::(); let fp_g = fp_e * fp_f; let fp_h = RP25519::from(fp_e) * fp_f; assert_eq!(fp_h, RP25519::from(fp_g)); @@ -317,7 +317,7 @@ mod test { #[test] fn curve_point_to_hash() { let mut rng = thread_rng(); - let fp_a = rng.gen::(); + let fp_a = rng.r#gen::(); assert_ne!(0u64, u64::from(fp_a)); assert_ne!(0u32, u32::from(fp_a)); } diff --git a/ipa-core/src/ff/ec_prime_field.rs b/ipa-core/src/ff/ec_prime_field.rs index a2e565ac0..e46c977bf 100644 --- a/ipa-core/src/ff/ec_prime_field.rs +++ b/ipa-core/src/ff/ec_prime_field.rs @@ -6,15 +6,15 @@ use subtle::{Choice, ConstantTimeEq}; use typenum::{U2, U32}; use crate::{ - ff::{boolean_array::BA256, Field, MultiplyAccumulate, Serializable}, + ff::{Field, MultiplyAccumulate, Serializable, boolean_array::BA256}, impl_shared_value_common, protocol::{ ipa_prf::PRF_CHUNK, prss::{FromPrss, FromRandom, PrssIndex, SharedRandomness}, }, secret_sharing::{ - replicated::{malicious::ExtendableField, semi_honest::AdditiveShare}, Block, FieldVectorizable, SharedValue, SharedValueArray, StdArray, Vectorizable, + replicated::{malicious::ExtendableField, semi_honest::AdditiveShare}, }, }; @@ -295,11 +295,11 @@ where mod test { use curve25519_dalek::scalar::Scalar; use generic_array::GenericArray; - use rand::{thread_rng, Rng}; + use rand::{Rng, thread_rng}; use typenum::U32; use crate::{ - ff::{ec_prime_field::Fp25519, Serializable}, + ff::{Serializable, ec_prime_field::Fp25519}, secret_sharing::SharedValue, }; @@ -314,7 +314,7 @@ mod test { #[test] fn serde_25519() { let mut rng = thread_rng(); - let input = rng.gen::(); + let input = rng.r#gen::(); let mut a: GenericArray = [0u8; 32].into(); input.serialize(&mut a); let output = Fp25519::deserialize_infallible(&a); @@ -356,14 +356,14 @@ mod test { #[test] fn simple_random_25519() { let mut rng = thread_rng(); - assert_ne!(Fp25519::ZERO, rng.gen::()); + assert_ne!(Fp25519::ZERO, rng.r#gen::()); } ///test inversion for field elements #[test] fn invert_25519() { let mut rng = thread_rng(); - let a = rng.gen::(); + let a = rng.r#gen::(); let ia = a.invert(); assert_eq!(a * ia, Fp25519(Scalar::ONE)); } diff --git a/ipa-core/src/ff/galois_field.rs b/ipa-core/src/ff/galois_field.rs index aa12f2c7a..69c1917b3 100644 --- a/ipa-core/src/ff/galois_field.rs +++ b/ipa-core/src/ff/galois_field.rs @@ -5,15 +5,15 @@ use std::{ use bitvec::{ array::BitArray, - prelude::{bitarr, BitArr, Lsb0}, + prelude::{BitArr, Lsb0, bitarr}, }; use generic_array::GenericArray; use subtle::{Choice, ConstantTimeEq}; -use typenum::{Unsigned, U1, U2, U3, U4, U5}; +use typenum::{U1, U2, U3, U4, U5, Unsigned}; use crate::{ error::LengthError, - ff::{boolean_array::NonZeroPadding, Field, MultiplyAccumulate, Serializable, U128Conversions}, + ff::{Field, MultiplyAccumulate, Serializable, U128Conversions, boolean_array::NonZeroPadding}, impl_serializable_trait, impl_shared_value_common, protocol::prss::FromRandomU128, secret_sharing::{Block, FieldVectorizable, SharedValue, StdArray, Vectorizable}, @@ -72,29 +72,31 @@ mod clmul_x86_64 { unsafe fn clmul(a: u64, b: u64) -> __m128i { #[allow(clippy::cast_possible_wrap)] // Thanks Intel. unsafe fn to_m128i(v: u64) -> __m128i { - _mm_set_epi64x(0, v as i64) + unsafe { _mm_set_epi64x(0, v as i64) } } - _mm_clmulepi64_si128(to_m128i(a), to_m128i(b), 0) + unsafe { _mm_clmulepi64_si128(to_m128i(a), to_m128i(b), 0) } } #[allow(clippy::cast_sign_loss)] // Thanks Intel. #[inline] unsafe fn extract(v: __m128i) -> u128 { // Note: watch for sign extension that you get from casting i64 to u128 directly. - u128::from(_mm_extract_epi64(v, I) as u64) + unsafe { u128::from(_mm_extract_epi64(v, I) as u64) } } /// clmul with 32-bit inputs (and a 64-bit answer). #[inline] pub unsafe fn clmul32(a: u64, b: u64) -> u128 { - extract::<0>(clmul(a, b)) + unsafe { extract::<0>(clmul(a, b)) } } /// clmul with 64-bit inputs (and a 128-bit answer). #[inline] pub unsafe fn clmul64(a: u64, b: u64) -> u128 { - let product = clmul(a, b); - extract::<1>(product) << 64 | extract::<0>(product) + unsafe { + let product = clmul(a, b); + extract::<1>(product) << 64 | extract::<0>(product) + } } } @@ -211,6 +213,8 @@ macro_rules! bit_array_impl { type Error = LengthError; fn try_from(value: &[u8]) -> Result { + // compiler cannot derive the integer type and make it easy to use + #[allow(clippy::manual_div_ceil)] if value.len()<=usize::try_from(Self::BITS/8).unwrap() { let mut bitarray = [0u8;{($bits+7)/8}]; bitarray[0..value.len()].copy_from_slice(value); @@ -248,7 +252,7 @@ macro_rules! bit_array_impl { impl rand::distributions::Distribution<$name> for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> $name { - <$name>::truncate_from(rng.gen::()) + <$name>::truncate_from(rng.r#gen::()) } } @@ -545,8 +549,8 @@ macro_rules! bit_array_impl { #[test] pub fn basic_ops() { let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let xor = $name::truncate_from(a ^ b); @@ -568,9 +572,9 @@ macro_rules! bit_array_impl { #[test] pub fn distributive_property_of_multiplication() { let mut rng = thread_rng(); - let a = $name::truncate_from(rng.gen::()); - let b = $name::truncate_from(rng.gen::()); - let r = $name::truncate_from(rng.gen::()); + let a = $name::truncate_from(rng.r#gen::()); + let b = $name::truncate_from(rng.r#gen::()); + let r = $name::truncate_from(rng.r#gen::()); let a_plus_b = a + b; let r_a_plus_b = r * a_plus_b; assert_eq!(r_a_plus_b, r * a + r * b, "distributive {r:?}*({a:?}+{b:?})"); @@ -579,8 +583,8 @@ macro_rules! bit_array_impl { #[test] pub fn commutative_property_of_multiplication() { let mut rng = thread_rng(); - let a = $name::truncate_from(rng.gen::()); - let b = $name::truncate_from(rng.gen::()); + let a = $name::truncate_from(rng.r#gen::()); + let b = $name::truncate_from(rng.r#gen::()); let ab = a * b; // This stupid hack is here to FORCE the compiler to not just optimize this away and really run the test let b_copy = $name::truncate_from(b.as_u128()); @@ -591,9 +595,9 @@ macro_rules! bit_array_impl { #[test] pub fn associative_property_of_multiplication() { let mut rng = thread_rng(); - let a = $name::truncate_from(rng.gen::()); - let b = $name::truncate_from(rng.gen::()); - let c = $name::truncate_from(rng.gen::()); + let a = $name::truncate_from(rng.r#gen::()); + let b = $name::truncate_from(rng.r#gen::()); + let c = $name::truncate_from(rng.r#gen::()); let bc = b * c; let ab = a * b; assert_eq!(a * bc, ab * c, "associative {a:?}*{b:?}*{c:?}"); @@ -612,8 +616,8 @@ macro_rules! bit_array_impl { #[test] pub fn ordering() { let mut rng = thread_rng(); - let a = rng.gen::() & MASK; - let b = rng.gen::() & MASK; + let a = rng.r#gen::() & MASK; + let b = rng.r#gen::() & MASK; println!("a: {a}"); println!("b: {b}"); @@ -624,7 +628,7 @@ macro_rules! bit_array_impl { #[test] pub fn serde() { let mut rng = thread_rng(); - let a = rng.gen::() & MASK; + let a = rng.r#gen::() & MASK; let a = $name::truncate_from(a); let mut buf = GenericArray::default(); @@ -636,13 +640,13 @@ macro_rules! bit_array_impl { #[test] fn slice_to_galois_err() { let mut rng = thread_rng(); - let vec = (0..{(<$name>::BITS+7)/8+1}).map(|_| rng.gen::()).collect::>(); + let vec = (0..{<$name>::BITS.div_ceil(8)+1}).map(|_| rng.r#gen::()).collect::>(); let element = <$name>::try_from(vec.as_slice()); assert_eq!( element.unwrap_err(), LengthError { expected: <$name>::BITS as usize, - actual: ((<$name>::BITS + 7) / 8 + 1) as usize, + actual: (<$name>::BITS.div_ceil(8) + 1) as usize, }, ); } diff --git a/ipa-core/src/ff/mod.rs b/ipa-core/src/ff/mod.rs index 3d2ffb187..7f067f63f 100644 --- a/ipa-core/src/ff/mod.rs +++ b/ipa-core/src/ff/mod.rs @@ -18,11 +18,11 @@ use std::{ pub use accumulator::{MultiplyAccumulate, MultiplyAccumulator, MultiplyAccumulatorArray}; pub use field::{Field, FieldType}; -pub use galois_field::{GaloisField, Gf2, Gf20Bit, Gf32Bit, Gf3Bit, Gf40Bit, Gf8Bit, Gf9Bit}; +pub use galois_field::{GaloisField, Gf2, Gf3Bit, Gf8Bit, Gf9Bit, Gf20Bit, Gf32Bit, Gf40Bit}; use generic_array::{ArrayLength, GenericArray}; #[cfg(any(test, feature = "weak-field"))] pub use prime_field::Fp31; -pub use prime_field::{batch_invert, Fp32BitPrime, Fp61BitPrime, PrimeField}; +pub use prime_field::{Fp32BitPrime, Fp61BitPrime, PrimeField, batch_invert}; use crate::{ error::UnwrapInfallible, protocol::prss::FromRandomU128, secret_sharing::BitDecomposed, diff --git a/ipa-core/src/ff/prime_field.rs b/ipa-core/src/ff/prime_field.rs index de07710b7..049d97113 100644 --- a/ipa-core/src/ff/prime_field.rs +++ b/ipa-core/src/ff/prime_field.rs @@ -7,8 +7,8 @@ use super::Field; use crate::{ const_assert, ff::{ - accumulator::{Accumulator, MultiplyAccumulate}, Serializable, U128Conversions, + accumulator::{Accumulator, MultiplyAccumulate}, }, impl_shared_value_common, protocol::prss::FromRandomU128, @@ -280,7 +280,7 @@ macro_rules! field_impl { impl rand::distributions::Distribution<$field> for rand::distributions::Standard { fn sample(&self, rng: &mut R) -> $field { - <$field>::truncate_from(rng.gen::()) + <$field>::truncate_from(rng.r#gen::()) } } @@ -350,14 +350,14 @@ macro_rules! field_impl { use generic_array::GenericArray; use proptest::{ - prelude::{prop, Arbitrary, Strategy}, + prelude::{Arbitrary, Strategy, prop}, proptest, }; use super::*; use crate::{ ff::Serializable, - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, }; impl Arbitrary for $field { @@ -391,9 +391,9 @@ macro_rules! field_impl { fn batch_invert_test() { let mut rng = thread_rng(); let mut elements: [$field; 100] = from_fn(|_| { - let mut element = $field::truncate_from(rng.gen::()); + let mut element = $field::truncate_from(rng.r#gen::()); while (element == $field::ZERO) { - element = $field::truncate_from(rng.gen::()); + element = $field::truncate_from(rng.r#gen::()); } element }); diff --git a/ipa-core/src/helpers/buffers/circular.rs b/ipa-core/src/helpers/buffers/circular.rs index 3e166c436..1b09f1b42 100644 --- a/ipa-core/src/helpers/buffers/circular.rs +++ b/ipa-core/src/helpers/buffers/circular.rs @@ -90,8 +90,10 @@ impl CircularBuf { /// * `read_size` is smaller than `write_size` /// * `read_size` is larger than `capacity` pub fn new(capacity: usize, write_size: usize, read_size: usize) -> Self { - debug_assert!(capacity > 0 && write_size > 0 && read_size > 0, - "Capacity \"{capacity}\", write \"{write_size}\" and read size \"{read_size}\" must all be greater than zero"); // enforced at the level above, so debug_assert is fine + debug_assert!( + capacity > 0 && write_size > 0 && read_size > 0, + "Capacity \"{capacity}\", write \"{write_size}\" and read size \"{read_size}\" must all be greater than zero" + ); // enforced at the level above, so debug_assert is fine debug_assert!( capacity % write_size == 0, "\"{write_size}\" write size must divide capacity \"{capacity}\"" @@ -132,10 +134,11 @@ impl CircularBuf { /// [`can_write`]: Self::can_write pub fn next(&mut self) -> Next<'_> { debug_assert!(!self.closed, "Writing to a closed buffer"); - debug_assert!(self.can_write(), - "Not enough space for the next write: only {av} bytes available, but at least {req} is required", - av = self.remaining(), - req = self.write_size + debug_assert!( + self.can_write(), + "Not enough space for the next write: only {av} bytes available, but at least {req} is required", + av = self.remaining(), + req = self.write_size ); Next { @@ -311,7 +314,7 @@ mod test { use generic_array::GenericArray; use serde::Serializer; - use typenum::{Unsigned, U1, U2}; + use typenum::{U1, U2, Unsigned}; use super::CircularBuf; use crate::ff::Serializable; @@ -543,7 +546,9 @@ mod test { #[test] fn panic_on_zero() { fn check_panic(capacity: usize, write_size: usize, read_size: usize) { - let err = format!("Capacity \"{capacity}\", write \"{write_size}\" and read size \"{read_size}\" must all be greater than zero"); + let err = format!( + "Capacity \"{capacity}\", write \"{write_size}\" and read size \"{read_size}\" must all be greater than zero" + ); assert_eq!( err, @@ -697,9 +702,9 @@ mod test { use proptest::{arbitrary::any, prop_compose, proptest, strategy::Just}; use rand::{ + Rng, distributions::{Distribution, Standard}, rngs::StdRng, - Rng, }; use rand_core::SeedableRng; @@ -739,7 +744,7 @@ mod test { impl Distribution for Standard { fn sample(&self, rng: &mut R) -> Decision { - if rng.gen() { + if rng.r#gen() { Decision::Read } else { Decision::Write @@ -771,7 +776,7 @@ mod test { let write_size = buf.write_size; for _ in 0..ops { - if rng.gen::() == Decision::Write && buf.can_write() { + if rng.r#gen::() == Decision::Write && buf.can_write() { buf.next().write(pack(cnt.0, write_size).as_slice()); written.push(cnt.0); cnt += 1; diff --git a/ipa-core/src/helpers/buffers/ordering_sender.rs b/ipa-core/src/helpers/buffers/ordering_sender.rs index 37bb044cf..f69288a49 100644 --- a/ipa-core/src/helpers/buffers/ordering_sender.rs +++ b/ipa-core/src/helpers/buffers/ordering_sender.rs @@ -9,16 +9,16 @@ use std::{ task::{Context, Poll}, }; -use futures::{task::Waker, Future, Stream}; +use futures::{Future, Stream, task::Waker}; use crate::{ - helpers::{buffers::circular::CircularBuf, Message}, + helpers::{Message, buffers::circular::CircularBuf}, sync::{ + Mutex, MutexGuard, atomic::{ AtomicUsize, Ordering::{AcqRel, Acquire}, }, - Mutex, MutexGuard, }, }; @@ -207,7 +207,7 @@ impl Waiting { /// Find a shard. This ensures that sequential values pick the same shard /// in a contiguous block. - fn shard(&self, i: usize) -> MutexGuard { + fn shard(&self, i: usize) -> MutexGuard<'_, WaitingShard> { let idx = (i >> Self::CONTIGUOUS_BITS) % Self::SHARDS; self.shards[idx].lock().unwrap() } @@ -511,18 +511,18 @@ mod test { future::poll_fn, iter::zip, num::NonZeroUsize, - pin::{pin, Pin}, + pin::{Pin, pin}, }; use ::tokio::sync::Barrier; use futures::{ - future::{join, join3, join_all, poll_immediate, try_join_all}, - stream::StreamExt, Future, FutureExt, + future::{join, join_all, join3, poll_immediate, try_join_all}, + stream::StreamExt, }; use futures_util::future::try_join; use generic_array::GenericArray; - use rand::{seq::SliceRandom, Rng}; + use rand::{Rng, seq::SliceRandom}; #[cfg(feature = "shuttle")] use shuttle::future as tokio; use typenum::Unsigned; @@ -738,7 +738,7 @@ mod test { run_random(|mut rng| async move { let mut values = Vec::with_capacity(COUNT); - values.resize_with(COUNT, || rng.gen::()); + values.resize_with(COUNT, || rng.r#gen::()); let indices = shuffle_indices(COUNT, &mut rng); let sender = sender::(); @@ -834,7 +834,7 @@ mod test { use std::{cmp::min, iter::zip}; use futures::{ - future::{join3, join_all}, + future::{join_all, join3}, stream::StreamExt, }; use generic_array::GenericArray; @@ -844,17 +844,17 @@ mod test { strategy::{Just, Strategy}, }; use rand::{ + Rng, distributions::{Distribution, Standard}, rngs::StdRng, - Rng, }; use rand_core::SeedableRng; use typenum::Unsigned; use crate::{ ff::{ - boolean_array::{BA112, BA256, BA7}, Fp31, Fp32BitPrime, Serializable, + boolean_array::{BA7, BA112, BA256}, }, helpers::OrderingSender, secret_sharing::SharedValue, @@ -877,7 +877,7 @@ mod test { let mut rng = StdRng::seed_from_u64(seed); let mut values = Vec::with_capacity(count); - values.resize_with(count, || rng.gen::()); + values.resize_with(count, || rng.r#gen::()); let sender = OrderingSender::new( (sz * capacity_units).try_into().unwrap(), @@ -897,8 +897,10 @@ mod test { let lengths = output.iter().map(Vec::len).collect::>(); let read_size_bytes = min(read_size_bytes, sz * count); assert!(lengths.len() <= 2); - assert!(lengths.iter().any(|l| read_size_bytes == *l), - "read size {read_size_bytes} chunks never read from OrderingSender. Actual chunks read: {lengths:?}"); + assert!( + lengths.contains(&read_size_bytes), + "read size {read_size_bytes} chunks never read from OrderingSender. Actual chunks read: {lengths:?}" + ); let buf = output.into_iter().flatten().collect::>(); for (&v, b) in zip(values.iter(), buf.chunks(sz)) { assert_eq!(v, V::deserialize(GenericArray::from_slice(b)).unwrap()); diff --git a/ipa-core/src/helpers/buffers/unordered_receiver.rs b/ipa-core/src/helpers/buffers/unordered_receiver.rs index fdeb754f1..8e2ed535f 100644 --- a/ipa-core/src/helpers/buffers/unordered_receiver.rs +++ b/ipa-core/src/helpers/buffers/unordered_receiver.rs @@ -6,7 +6,7 @@ use std::{ task::{Context, Poll}, }; -use futures::{task::Waker, Future, Stream}; +use futures::{Future, Stream, task::Waker}; use generic_array::GenericArray; use typenum::Unsigned; @@ -193,7 +193,8 @@ where fn add_waker(&mut self, i: usize, waker: &Waker) { assert!( i > self.next, - "Awaiting a read (record = {i}) that has already been fulfilled. Read cursor is currently at {}", self.next + "Awaiting a read (record = {i}) that has already been fulfilled. Read cursor is currently at {}", + self.next ); // We don't save a waker at `self.next`, so `>` and not `>=`. if i > self.next + self.wakers.len() { @@ -257,7 +258,7 @@ where } } Poll::Ready(None) => { - return Poll::Ready(Err(EndOfStreamError(RecordId::from(self.next)).into())) + return Poll::Ready(Err(EndOfStreamError(RecordId::from(self.next)).into())); } } } @@ -374,9 +375,9 @@ mod test { use std::num::NonZeroUsize; use futures::{ + Future, Stream, future::{try_join, try_join_all}, stream::iter, - Future, Stream, }; use generic_array::GenericArray; use rand::Rng; @@ -500,7 +501,7 @@ mod test { run(|| { let mut rng = crate::rand::thread_rng(); let mut values = Vec::with_capacity(COUNT); - values.resize_with(COUNT, || rng.gen::()); + values.resize_with(COUNT, || rng.r#gen::()); let mut encoded = vec![0; ENCODED_LEN]; for (i, v) in values.iter().enumerate() { diff --git a/ipa-core/src/helpers/cross_shard_prss.rs b/ipa-core/src/helpers/cross_shard_prss.rs index 53ebf5f45..14d34f323 100644 --- a/ipa-core/src/helpers/cross_shard_prss.rs +++ b/ipa-core/src/helpers/cross_shard_prss.rs @@ -1,10 +1,10 @@ -use futures::{stream::FuturesUnordered, TryStreamExt}; +use futures::{TryStreamExt, stream::FuturesUnordered}; use crate::{ - helpers::{buffers::EndOfStreamError, ChannelId, Error, Gateway, TotalRecords}, + helpers::{ChannelId, Error, Gateway, TotalRecords, buffers::EndOfStreamError}, protocol::{ - prss::{Endpoint as PrssEndpoint, Seed, SeededEndpointSetup, SharedRandomness}, Gate, RecordId, + prss::{Endpoint as PrssEndpoint, Seed, SeededEndpointSetup, SharedRandomness}, }, sharding::ShardConfiguration, }; @@ -66,8 +66,8 @@ mod tests { use crate::{ ff::boolean_array::BA64, helpers::cross_shard_prss::gen_and_distribute, - protocol::{context::Context, prss::SharedRandomness, Gate, RecordId}, - secret_sharing::{replicated::semi_honest::AdditiveShare, SharedValue}, + protocol::{Gate, RecordId, context::Context, prss::SharedRandomness}, + secret_sharing::{SharedValue, replicated::semi_honest::AdditiveShare}, sharding::ShardConfiguration, test_executor::run, test_fixture::{Reconstruct, Runner, TestWorld, TestWorldConfig, WithShards}, diff --git a/ipa-core/src/helpers/error.rs b/ipa-core/src/helpers/error.rs index 22451c1b1..161271d50 100644 --- a/ipa-core/src/helpers/error.rs +++ b/ipa-core/src/helpers/error.rs @@ -2,8 +2,8 @@ use thiserror::Error; use crate::{ helpers::{ - buffers::{DeserializeError, EndOfStreamError}, ChannelId, TotalRecords, TransportIdentity, + buffers::{DeserializeError, EndOfStreamError}, }, protocol::RecordId, }; @@ -21,7 +21,9 @@ pub enum Error { channel_id: ChannelId, inner: DeserializeError, }, - #[error("record ID {record_id:?} is out of range for {channel_id:?} (expected {total_records:?} records)")] + #[error( + "record ID {record_id:?} is out of range for {channel_id:?} (expected {total_records:?} records)" + )] TooManyRecords { record_id: RecordId, channel_id: ChannelId, diff --git a/ipa-core/src/helpers/gateway/mod.rs b/ipa-core/src/helpers/gateway/mod.rs index c14bfb0fd..7aa3af35b 100644 --- a/ipa-core/src/helpers/gateway/mod.rs +++ b/ipa-core/src/helpers/gateway/mod.rs @@ -17,6 +17,8 @@ pub use transport::RoleResolvingTransport; use crate::{ helpers::{ + HelperChannelId, LogErrors, Message, MpcMessage, RecordsStream, Role, RoleAssignment, + ShardChannelId, TotalRecords, Transport, buffers::UnorderedReceiver, gateway::{ receive::{GatewayReceivers, ShardReceiveStream, UR}, @@ -24,8 +26,6 @@ use crate::{ transport::Transports, }, query::QueryConfig, - HelperChannelId, LogErrors, Message, MpcMessage, RecordsStream, Role, RoleAssignment, - ShardChannelId, TotalRecords, Transport, }, protocol::QueryId, sharding::{ShardConfiguration, ShardIndex}, @@ -351,21 +351,21 @@ mod tests { use crate::{ ff::{ - boolean_array::{BA20, BA256, BA3, BA4, BA5, BA6, BA7, BA8}, FieldType, Fp31, Fp32BitPrime, Gf2, U128Conversions, + boolean_array::{BA3, BA4, BA5, BA6, BA7, BA8, BA20, BA256}, }, helpers::{ - gateway::QueryConfig, - query::{QuerySize, QueryType}, ChannelId, Direction, GatewayConfig, MpcMessage, MpcReceivingEnd, Role, SendingEnd, TotalRecords, + gateway::QueryConfig, + query::{QuerySize, QueryType}, }, protocol::{ - context::{Context, ShardedContext}, Gate, RecordId, + context::{Context, ShardedContext}, }, secret_sharing::{ - replicated::semi_honest::AdditiveShare, SharedValue, SharedValueArray, StdArray, + SharedValue, SharedValueArray, StdArray, replicated::semi_honest::AdditiveShare, }, seq_join::seq_join, sharding::ShardConfiguration, @@ -792,7 +792,7 @@ mod tests { // futures pending and unblock them all at the same time seq_join( active_work.try_into().unwrap(), - stream::iter(std::iter::repeat(msg).take(total_records).enumerate()).map( + stream::iter(std::iter::repeat_n(msg, total_records).enumerate()).map( |(record_id, msg)| { let send_channel = &send_channel; let recv_channel = &recv_channel; diff --git a/ipa-core/src/helpers/gateway/receive.rs b/ipa-core/src/helpers/gateway/receive.rs index 3744792ca..8ccb34822 100644 --- a/ipa-core/src/helpers/gateway/receive.rs +++ b/ipa-core/src/helpers/gateway/receive.rs @@ -5,18 +5,18 @@ use std::{ }; use bytes::Bytes; -use dashmap::{mapref::entry::Entry, DashMap}; +use dashmap::{DashMap, mapref::entry::Entry}; use futures::Stream; use pin_project::pin_project; use crate::{ error::BoxError, helpers::{ + ChannelId, Error, HelperChannelId, LogErrors, Message, MpcMessage, Role, ShardChannelId, + ShardTransportImpl, Transport, TransportIdentity, buffers::{UnorderedReceiver, UnorderedReceiverError}, gateway::transport::RoleResolvingTransport, transport::SingleRecordStream, - ChannelId, Error, HelperChannelId, LogErrors, Message, MpcMessage, Role, ShardChannelId, - ShardTransportImpl, Transport, TransportIdentity, }, protocol::RecordId, sync::{Arc, Mutex}, diff --git a/ipa-core/src/helpers/gateway/send.rs b/ipa-core/src/helpers/gateway/send.rs index bbd913031..0fd9cd6ff 100644 --- a/ipa-core/src/helpers/gateway/send.rs +++ b/ipa-core/src/helpers/gateway/send.rs @@ -7,7 +7,7 @@ use std::{ task::{Context, Poll}, }; -use dashmap::{mapref::entry::Entry, DashMap}; +use dashmap::{DashMap, mapref::entry::Entry}; use futures::Stream; use ipa_metrics::counter; #[cfg(all(test, feature = "shuttle"))] @@ -16,8 +16,8 @@ use typenum::Unsigned; use crate::{ helpers::{ - buffers::OrderingSender, routing::RouteId, ChannelId, Error, GatewayConfig, Message, - TotalRecords, Transport, TransportIdentity, + ChannelId, Error, GatewayConfig, Message, TotalRecords, Transport, TransportIdentity, + buffers::OrderingSender, routing::RouteId, }, protocol::{QueryId, RecordId}, sync::Arc, @@ -304,10 +304,10 @@ mod test { use crate::{ ff::{ - boolean_array::{BA16, BA20, BA256, BA3, BA32, BA7}, Serializable, + boolean_array::{BA3, BA7, BA16, BA20, BA32, BA256}, }, - helpers::{gateway::send::SendChannelConfig, GatewayConfig, TotalRecords}, + helpers::{GatewayConfig, TotalRecords, gateway::send::SendChannelConfig}, secret_sharing::SharedValue, }; diff --git a/ipa-core/src/helpers/gateway/stall_detection.rs b/ipa-core/src/helpers/gateway/stall_detection.rs index 30d641a4b..e62ac82ce 100644 --- a/ipa-core/src/helpers/gateway/stall_detection.rs +++ b/ipa-core/src/helpers/gateway/stall_detection.rs @@ -6,8 +6,8 @@ use std::{ pub use gateway::InstrumentedGateway; use crate::sync::{ - atomic::{AtomicUsize, Ordering}, Weak, + atomic::{AtomicUsize, Ordering}, }; /// Trait for structs that can report their current state. @@ -70,12 +70,12 @@ mod gateway { use delegate::delegate; - use super::{receive, send, AtomicUsize, Debug, Formatter, ObserveState, Observed, Weak}; + use super::{AtomicUsize, Debug, Formatter, ObserveState, Observed, Weak, receive, send}; use crate::{ helpers::{ - gateway::{Gateway, ShardTransportImpl, State}, GatewayConfig, HelperChannelId, Message, MpcMessage, MpcReceivingEnd, MpcTransportImpl, Role, RoleAssignment, SendingEnd, ShardChannelId, ShardReceivingEnd, TotalRecords, + gateway::{Gateway, ShardTransportImpl, State}, }, protocol::QueryId, sharding::{ShardConfiguration, ShardIndex}, @@ -285,12 +285,12 @@ mod receive { use super::{ObserveState, Observed}; use crate::{ helpers::{ + ChannelId, Message, MpcMessage, Role, TransportIdentity, error::Error, gateway::{ - receive::{GatewayReceivers, ShardReceiveStream, ShardReceivingEnd, UR}, MpcReceivingEnd, + receive::{GatewayReceivers, ShardReceiveStream, ShardReceivingEnd, UR}, }, - ChannelId, Message, MpcMessage, Role, TransportIdentity, }, protocol::RecordId, sharding::ShardIndex, @@ -374,9 +374,9 @@ mod send { use super::{ObserveState, Observed}; use crate::{ helpers::{ + ChannelId, Message, TotalRecords, TransportIdentity, error::Error, gateway::send::{GatewaySender, GatewaySenders}, - ChannelId, Message, TotalRecords, TransportIdentity, }, protocol::RecordId, }; diff --git a/ipa-core/src/helpers/gateway/transport.rs b/ipa-core/src/helpers/gateway/transport.rs index 09a1053cb..26ae85830 100644 --- a/ipa-core/src/helpers/gateway/transport.rs +++ b/ipa-core/src/helpers/gateway/transport.rs @@ -3,8 +3,8 @@ use futures::Stream; use crate::{ helpers::{ - transport::routing::RouteId, MpcTransportImpl, NoResourceIdentifier, QueryIdBinding, Role, - RoleAssignment, RouteParams, StepBinding, Transport, + MpcTransportImpl, NoResourceIdentifier, QueryIdBinding, Role, RoleAssignment, RouteParams, + StepBinding, Transport, transport::routing::RouteId, }, protocol::{Gate, QueryId}, sharding::ShardIndex, diff --git a/ipa-core/src/helpers/hashing.rs b/ipa-core/src/helpers/hashing.rs index d083eaf8b..4980b6c48 100644 --- a/ipa-core/src/helpers/hashing.rs +++ b/ipa-core/src/helpers/hashing.rs @@ -2,8 +2,8 @@ use std::convert::Infallible; use generic_array::GenericArray; use sha2::{ - digest::{Output, OutputSizeUser}, Digest, Sha256, + digest::{Output, OutputSizeUser}, }; use subtle::{Choice, ConstantTimeEq}; @@ -161,11 +161,11 @@ where mod test { use std::iter; - use generic_array::{sequence::GenericSequence, GenericArray}; - use rand::{thread_rng, Rng}; + use generic_array::{GenericArray, sequence::GenericSequence}; + use rand::{Rng, thread_rng}; use typenum::U8; - use super::{compute_hash, compute_possibly_empty_hash, Hash}; + use super::{Hash, compute_hash, compute_possibly_empty_hash}; use crate::{ ff::{Fp31, Fp32BitPrime, Serializable}, helpers::hashing::hash_to_field, @@ -175,7 +175,7 @@ mod test { fn can_serialize_and_deserialize() { let mut rng = thread_rng(); let list: GenericArray = - GenericArray::generate(|_| rng.gen::()); + GenericArray::generate(|_| rng.r#gen::()); let hash: Hash = compute_hash(list); let mut buf: GenericArray = GenericArray::default(); hash.serialize(&mut buf); @@ -191,15 +191,15 @@ mod test { let mut list: Vec = Vec::with_capacity(LIST_LENGTH); for _ in 0..LIST_LENGTH { - list.push(rng.gen::()); + list.push(rng.r#gen::()); } let hash_1 = compute_hash(&list); // modify one, randomly selected element in the list - let random_index = rng.gen::() % LIST_LENGTH; + let random_index = rng.r#gen::() % LIST_LENGTH; let mut different_field_element = list[random_index]; while different_field_element == list[random_index] { - different_field_element = rng.gen::(); + different_field_element = rng.r#gen::(); } list[random_index] = different_field_element; @@ -243,16 +243,16 @@ mod test { let mut left = Vec::with_capacity(LIST_LENGTH); let mut right = Vec::with_capacity(LIST_LENGTH); for _ in 0..LIST_LENGTH { - left.push(rng.gen::()); - right.push(rng.gen::()); + left.push(rng.r#gen::()); + right.push(rng.r#gen::()); } let r1: Fp32BitPrime = hash_to_field(&compute_hash(&left), &compute_hash(&right), EXCLUDE); // modify one, randomly selected element in the list - let random_index = rng.gen::() % LIST_LENGTH; + let random_index = rng.r#gen::() % LIST_LENGTH; // There is a 1 in 2^32 chance that we generate exactly the same value and the test fails. - let modified_value = rng.gen::(); - if rng.gen::() { + let modified_value = rng.r#gen::(); + if rng.r#gen::() { left[random_index] = modified_value; } else { right[random_index] = modified_value; @@ -269,7 +269,7 @@ mod test { #[test] fn check_hash_from_owned_values() { let mut rng = thread_rng(); - let vec = (0..100).map(|_| rng.gen::()).collect::>(); + let vec = (0..100).map(|_| rng.r#gen::()).collect::>(); assert_eq!(compute_hash(&vec), compute_hash(vec)); } diff --git a/ipa-core/src/helpers/mod.rs b/ipa-core/src/helpers/mod.rs index eae6d8439..4bd4a1c76 100644 --- a/ipa-core/src/helpers/mod.rs +++ b/ipa-core/src/helpers/mod.rs @@ -36,7 +36,7 @@ mod gateway_exports { use crate::helpers::{ gateway, - gateway::{stall_detection::Observed, InstrumentedGateway}, + gateway::{InstrumentedGateway, stall_detection::Observed}, }; pub type Gateway = Observed; @@ -69,19 +69,19 @@ use ipa_metrics::LabelValue; pub use prss_protocol::negotiate as negotiate_prss; #[cfg(feature = "web-app")] pub use transport::WrappedAxumBodyStream; -#[cfg(feature = "in-memory-infra")] pub use transport::{ - config as in_memory_config, InMemoryMpcNetwork, InMemoryShardNetwork, InMemoryTransport, - InMemoryTransportError, + ApiError, BodyStream, BroadcastError, BufferedBytesStream, BytesStream, HandlerBox, HandlerRef, + HelperResponse, Identity as TransportIdentity, LengthDelimitedStream, LogErrors, NoQueryId, + NoResourceIdentifier, NoStep, QueryIdBinding, ReceiveRecords, RecordsStream, RequestHandler, + RouteParams, SingleRecordStream, StepBinding, StreamCollection, StreamKey, Transport, + WrappedBoxBodyStream, make_owned_handler, query, routing, }; +#[cfg(feature = "in-memory-infra")] pub use transport::{ - make_owned_handler, query, routing, ApiError, BodyStream, BroadcastError, BufferedBytesStream, - BytesStream, HandlerBox, HandlerRef, HelperResponse, Identity as TransportIdentity, - LengthDelimitedStream, LogErrors, NoQueryId, NoResourceIdentifier, NoStep, QueryIdBinding, - ReceiveRecords, RecordsStream, RequestHandler, RouteParams, SingleRecordStream, StepBinding, - StreamCollection, StreamKey, Transport, WrappedBoxBodyStream, + InMemoryMpcNetwork, InMemoryShardNetwork, InMemoryTransport, InMemoryTransportError, + config as in_memory_config, }; -use typenum::{Const, ToUInt, Unsigned, U8}; +use typenum::{Const, ToUInt, U8, Unsigned}; use x25519_dalek::PublicKey; use crate::{ @@ -738,8 +738,8 @@ mod tests { use crate::{ ff::Fp31, helpers::{HelperIdentity, Role, RoleAssignment}, - protocol::{basics::SecureMul, context::Context, RecordId}, - rand::{thread_rng, Rng}, + protocol::{RecordId, basics::SecureMul, context::Context}, + rand::{Rng, thread_rng}, test_fixture::{Reconstruct, Runner, TestWorld, TestWorldConfig}, }; @@ -811,8 +811,8 @@ mod tests { let world = TestWorld::new_with(config); let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let res = world .semi_honest((a, b), |ctx, (a, b)| async move { @@ -837,12 +837,12 @@ mod concurrency_tests { use crate::{ ff::{FieldType, Fp31, Fp32BitPrime, U128Conversions}, helpers::{ - query::{QueryConfig, QueryType::TestMultiply}, Direction, GatewayConfig, + query::{QueryConfig, QueryType::TestMultiply}, }, - protocol::{context::Context, RecordId}, + protocol::{RecordId, context::Context}, secret_sharing::replicated::{ - semi_honest, semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing, + ReplicatedSecretSharing, semi_honest, semi_honest::AdditiveShare as Replicated, }, seq_join::SeqJoin, test_fixture::{Reconstruct, Runner, TestApp, TestWorld, TestWorldConfig}, diff --git a/ipa-core/src/helpers/prss_protocol.rs b/ipa-core/src/helpers/prss_protocol.rs index 850d6c733..d58b8788a 100644 --- a/ipa-core/src/helpers/prss_protocol.rs +++ b/ipa-core/src/helpers/prss_protocol.rs @@ -4,7 +4,7 @@ use x25519_dalek::PublicKey; use crate::{ helpers::{ChannelId, Direction, Error, Gateway, Role, TotalRecords}, - protocol::{prss, Gate, RecordId}, + protocol::{Gate, RecordId, prss}, }; /// Establish the prss endpoint by exchanging public keys with the other helpers. diff --git a/ipa-core/src/helpers/stream/chunks.rs b/ipa-core/src/helpers/stream/chunks.rs index 85653e94d..4f7d150ee 100644 --- a/ipa-core/src/helpers/stream/chunks.rs +++ b/ipa-core/src/helpers/stream/chunks.rs @@ -5,10 +5,10 @@ use std::{ mem, ops::{Deref, RangeInclusive}, pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; -use futures::{stream::FusedStream, Stream, TryStream}; +use futures::{Stream, TryStream, stream::FusedStream}; use pin_project::pin_project; use typenum::{Const, ToUInt, Unsigned}; @@ -584,9 +584,9 @@ mod tests { }; use futures::{ + SinkExt, StreamExt, TryStreamExt, channel::mpsc::channel, stream::{self, poll_immediate}, - SinkExt, StreamExt, TryStreamExt, }; use super::*; diff --git a/ipa-core/src/helpers/stream/mod.rs b/ipa-core/src/helpers/stream/mod.rs index 26410f4b2..c907f2296 100644 --- a/ipa-core/src/helpers/stream/mod.rs +++ b/ipa-core/src/helpers/stream/mod.rs @@ -2,7 +2,7 @@ mod chunks; mod exact; pub use chunks::{ - div_round_up, process_slice_by_chunks, process_stream_by_chunks, Chunk, ChunkBuffer, ChunkData, - ChunkType, TryFlattenItersExt, + Chunk, ChunkBuffer, ChunkData, ChunkType, TryFlattenItersExt, div_round_up, + process_slice_by_chunks, process_stream_by_chunks, }; pub use exact::{ExactSizeStream, FixedLength}; diff --git a/ipa-core/src/helpers/transport/handler.rs b/ipa-core/src/helpers/transport/handler.rs index 9a1f1b457..b36a1e3b4 100644 --- a/ipa-core/src/helpers/transport/handler.rs +++ b/ipa-core/src/helpers/transport/handler.rs @@ -7,8 +7,8 @@ use serde_json::json; use crate::{ error::BoxError, helpers::{ - query::PrepareQuery, transport::routing::Addr, BodyStream, HelperIdentity, - TransportIdentity, + BodyStream, HelperIdentity, TransportIdentity, query::PrepareQuery, + transport::routing::Addr, }, query::{ NewQueryError, PrepareQueryError, ProtocolResult, QueryCompletionError, QueryInputError, diff --git a/ipa-core/src/helpers/transport/in_memory/mod.rs b/ipa-core/src/helpers/transport/in_memory/mod.rs index 1f23eb278..066787d8a 100644 --- a/ipa-core/src/helpers/transport/in_memory/mod.rs +++ b/ipa-core/src/helpers/transport/in_memory/mod.rs @@ -8,8 +8,8 @@ pub use transport::{Error as InMemoryTransportError, Setup}; use crate::{ helpers::{ - in_memory_config::DynStreamInterceptor, transport::in_memory::config::passthrough, - HandlerRef, HelperIdentity, + HandlerRef, HelperIdentity, in_memory_config::DynStreamInterceptor, + transport::in_memory::config::passthrough, }, sharding::ShardIndex, sync::{Arc, Weak}, diff --git a/ipa-core/src/helpers/transport/in_memory/sharding.rs b/ipa-core/src/helpers/transport/in_memory/sharding.rs index 053a41c28..81e0622c0 100644 --- a/ipa-core/src/helpers/transport/in_memory/sharding.rs +++ b/ipa-core/src/helpers/transport/in_memory/sharding.rs @@ -1,8 +1,8 @@ use crate::{ helpers::{ - in_memory_config::{passthrough, DynStreamInterceptor}, - transport::in_memory::transport::{InMemoryTransport, Setup, TransportConfigBuilder}, HandlerBox, HelperIdentity, RequestHandler, + in_memory_config::{DynStreamInterceptor, passthrough}, + transport::in_memory::transport::{InMemoryTransport, Setup, TransportConfigBuilder}, }, sharding::ShardIndex, sync::{Arc, Weak}, @@ -134,8 +134,8 @@ mod tests { use crate::{ helpers::{ - transport::{in_memory::InMemoryShardNetwork, routing::RouteId}, HelperIdentity, Transport, + transport::{in_memory::InMemoryShardNetwork, routing::RouteId}, }, protocol::{Gate, QueryId}, sharding::ShardIndex, diff --git a/ipa-core/src/helpers/transport/in_memory/transport.rs b/ipa-core/src/helpers/transport/in_memory/transport.rs index 504921eb5..0763d48eb 100644 --- a/ipa-core/src/helpers/transport/in_memory/transport.rs +++ b/ipa-core/src/helpers/transport/in_memory/transport.rs @@ -7,7 +7,7 @@ use std::{ }; use ::tokio::sync::{ - mpsc::{channel, Receiver, Sender}, + mpsc::{Receiver, Sender, channel}, oneshot, }; use async_trait::async_trait; @@ -21,11 +21,11 @@ use tracing::Instrument; use crate::{ error::BoxError, helpers::{ - in_memory_config::{self, DynStreamInterceptor}, - transport::routing::{Addr, RouteId}, ApiError, BodyStream, HandlerRef, HelperIdentity, HelperResponse, NoResourceIdentifier, QueryIdBinding, ReceiveRecords, RequestHandler, RouteParams, StepBinding, StreamCollection, Transport, TransportIdentity, + in_memory_config::{self, DynStreamInterceptor}, + transport::routing::{Addr, RouteId}, }, protocol::{Gate, QueryId}, sharding::ShardIndex, @@ -314,14 +314,17 @@ impl Setup { /// ## Panics /// Panics if there is a link already. pub fn connect(&mut self, other: &mut Self) { - assert!(self - .connections - .insert(other.identity, other.tx.clone()) - .is_none()); - assert!(other - .connections - .insert(self.identity, self.tx.clone()) - .is_none()); + assert!( + self.connections + .insert(other.identity, other.tx.clone()) + .is_none() + ); + assert!( + other + .connections + .insert(self.identity, self.tx.clone()) + .is_none() + ); } pub(crate) fn start(self, handler: Option>) -> Arc> { @@ -356,8 +359,8 @@ mod tests { }; use bytes::Bytes; - use futures::{stream, Stream}; - use futures_util::{stream::poll_immediate, FutureExt, StreamExt}; + use futures::{Stream, stream}; + use futures_util::{FutureExt, StreamExt, stream::poll_immediate}; use tokio::sync::{mpsc::channel, oneshot}; use tokio_stream::wrappers::ReceiverStream; use typenum::Unsigned; @@ -365,17 +368,16 @@ mod tests { use crate::{ ff::{FieldType, Fp31, Serializable}, helpers::{ - make_owned_handler, + HandlerBox, HelperIdentity, HelperResponse, InMemoryShardNetwork, OrderingSender, Role, + RoleAssignment, Transport, TransportIdentity, make_owned_handler, query::{PrepareQuery, QueryConfig, QueryType::TestMultiply}, transport::{ in_memory::{ - transport::{Addr, ConnectionTx, Error, InMemoryStream, InMemoryTransport}, InMemoryMpcNetwork, Setup, + transport::{Addr, ConnectionTx, Error, InMemoryStream, InMemoryTransport}, }, routing::RouteId, }, - HandlerBox, HelperIdentity, HelperResponse, InMemoryShardNetwork, OrderingSender, Role, - RoleAssignment, Transport, TransportIdentity, }, protocol::{Gate, QueryId}, sharding::ShardIndex, diff --git a/ipa-core/src/helpers/transport/mod.rs b/ipa-core/src/helpers/transport/mod.rs index 84289d946..f93b6d3db 100644 --- a/ipa-core/src/helpers/transport/mod.rs +++ b/ipa-core/src/helpers/transport/mod.rs @@ -5,12 +5,12 @@ use std::{ }; use async_trait::async_trait; -use futures::{stream::FuturesUnordered, FutureExt, Stream, StreamExt}; +use futures::{FutureExt, Stream, StreamExt, stream::FuturesUnordered}; #[cfg(feature = "in-memory-infra")] use crate::helpers::in_memory_config::InspectContext; use crate::{ - helpers::{transport::routing::RouteId, HelperIdentity, Role, TransportIdentity}, + helpers::{HelperIdentity, Role, TransportIdentity, transport::routing::RouteId}, protocol::{Gate, QueryId}, sharding::ShardIndex, }; @@ -24,11 +24,11 @@ pub mod routing; mod stream; pub use handler::{ - make_owned_handler, Error as ApiError, HandlerBox, HandlerRef, HelperResponse, RequestHandler, + Error as ApiError, HandlerBox, HandlerRef, HelperResponse, RequestHandler, make_owned_handler, }; #[cfg(feature = "in-memory-infra")] pub use in_memory::{ - config, InMemoryMpcNetwork, InMemoryShardNetwork, InMemoryTransport, InMemoryTransportError, + InMemoryMpcNetwork, InMemoryShardNetwork, InMemoryTransport, InMemoryTransportError, config, }; use ipa_metrics::LabelValue; pub use receive::{LogErrors, ReceiveRecords}; diff --git a/ipa-core/src/helpers/transport/query/mod.rs b/ipa-core/src/helpers/transport/query/mod.rs index 906dde4f6..c9b728440 100644 --- a/ipa-core/src/helpers/transport/query/mod.rs +++ b/ipa-core/src/helpers/transport/query/mod.rs @@ -11,8 +11,8 @@ use serde::{Deserialize, Deserializer, Serialize}; use crate::{ ff::FieldType, helpers::{ - transport::{routing::RouteId, BodyStream, NoQueryId, NoStep}, RoleAssignment, RouteParams, + transport::{BodyStream, NoQueryId, NoStep, routing::RouteId}, }, protocol::QueryId, query::QueryStatus, diff --git a/ipa-core/src/helpers/transport/receive.rs b/ipa-core/src/helpers/transport/receive.rs index 4a5411f98..299433a1c 100644 --- a/ipa-core/src/helpers/transport/receive.rs +++ b/ipa-core/src/helpers/transport/receive.rs @@ -1,5 +1,5 @@ use std::{ - pin::{pin, Pin}, + pin::{Pin, pin}, task::{Context, Poll}, }; @@ -11,8 +11,8 @@ use tracing::error; use crate::{ error::BoxError, helpers::{ - transport::stream::{StreamCollection, StreamKey}, TransportIdentity, + transport::stream::{StreamCollection, StreamKey}, }, }; diff --git a/ipa-core/src/helpers/transport/stream/box_body.rs b/ipa-core/src/helpers/transport/stream/box_body.rs index 731addb22..e00df5e91 100644 --- a/ipa-core/src/helpers/transport/stream/box_body.rs +++ b/ipa-core/src/helpers/transport/stream/box_body.rs @@ -4,9 +4,9 @@ use std::{ }; use bytes::Bytes; -use futures::{stream::StreamExt, Stream}; +use futures::{Stream, stream::StreamExt}; -use crate::helpers::{transport::stream::BoxBytesStream, BytesStream}; +use crate::helpers::{BytesStream, transport::stream::BoxBytesStream}; pub struct WrappedBoxBodyStream(BoxBytesStream); diff --git a/ipa-core/src/helpers/transport/stream/buffered.rs b/ipa-core/src/helpers/transport/stream/buffered.rs index b0b332fb1..076ed4807 100644 --- a/ipa-core/src/helpers/transport/stream/buffered.rs +++ b/ipa-core/src/helpers/transport/stream/buffered.rs @@ -6,7 +6,7 @@ use std::{ }; use bytes::Bytes; -use futures::{stream::Fuse, Stream, StreamExt}; +use futures::{Stream, StreamExt, stream::Fuse}; use pin_project::pin_project; use crate::helpers::BytesStream; @@ -104,7 +104,7 @@ mod tests { }; use bytes::Bytes; - use futures::{stream::TryStreamExt, FutureExt, Stream, StreamExt}; + use futures::{FutureExt, Stream, StreamExt, stream::TryStreamExt}; use pin_project::pin_project; use proptest::{ prop_compose, proptest, diff --git a/ipa-core/src/helpers/transport/stream/collection.rs b/ipa-core/src/helpers/transport/stream/collection.rs index f19fd7ce5..43946e396 100644 --- a/ipa-core/src/helpers/transport/stream/collection.rs +++ b/ipa-core/src/helpers/transport/stream/collection.rs @@ -1,5 +1,5 @@ use std::{ - collections::{hash_map::Entry, HashMap}, + collections::{HashMap, hash_map::Entry}, fmt::{Debug, Formatter}, task::Waker, }; diff --git a/ipa-core/src/helpers/transport/stream/input.rs b/ipa-core/src/helpers/transport/stream/input.rs index 02b312795..bd4240036 100644 --- a/ipa-core/src/helpers/transport/stream/input.rs +++ b/ipa-core/src/helpers/transport/stream/input.rs @@ -12,12 +12,12 @@ use std::{ use bytes::Bytes; use futures::{ - stream::{iter, once, Fuse, FusedStream, Iter, Map, Once}, Stream, StreamExt, + stream::{Fuse, FusedStream, Iter, Map, Once, iter, once}, }; use generic_array::GenericArray; use pin_project::pin_project; -use typenum::{Unsigned, U2}; +use typenum::{U2, Unsigned}; use crate::{error::BoxError, ff::Serializable, helpers::BytesStream}; @@ -416,7 +416,7 @@ where return Poll::Ready(Some(Err(io::Error::new( io::ErrorKind::InvalidData, err, - )))) + )))); } } } @@ -657,7 +657,7 @@ mod test { use crate::{ ff::{Fp31, Fp32BitPrime}, - helpers::{transport::stream::input::Single, RecordsStream}, + helpers::{RecordsStream, transport::stream::input::Single}, secret_sharing::SharedValue, }; @@ -782,7 +782,7 @@ mod test { mod prop_test { use futures::TryStreamExt; use proptest::prelude::*; - use rand::{rngs::StdRng, SeedableRng}; + use rand::{SeedableRng, rngs::StdRng}; use super::*; @@ -841,7 +841,7 @@ mod test { use bytes::BufMut; use futures::TryStreamExt; use proptest::prelude::*; - use rand::{rngs::StdRng, SeedableRng}; + use rand::{SeedableRng, rngs::StdRng}; use super::*; diff --git a/ipa-core/src/helpers/transport/stream/mod.rs b/ipa-core/src/helpers/transport/stream/mod.rs index 9e6e32a63..05d71656f 100644 --- a/ipa-core/src/helpers/transport/stream/mod.rs +++ b/ipa-core/src/helpers/transport/stream/mod.rs @@ -16,7 +16,7 @@ pub use box_body::WrappedBoxBodyStream; pub use buffered::BufferedBytesStream; use bytes::Bytes; pub use collection::{StreamCollection, StreamKey}; -use futures::{stream::iter, Stream}; +use futures::{Stream, stream::iter}; use futures_util::StreamExt; use generic_array::GenericArray; pub use input::{LengthDelimitedStream, RecordsStream, SingleRecordStream}; @@ -109,7 +109,7 @@ impl Stream for BodyStream { "Chunk size {} is greater than maximum allowed {MAX_HTTP_CHUNK_SIZE_BYTES} bytes", v.len() ); - }; + } next } @@ -179,7 +179,7 @@ mod tests { use futures::{future, stream, stream::TryStreamExt}; use crate::{ - helpers::{transport::stream::MAX_HTTP_CHUNK_SIZE_BYTES, BodyStream}, + helpers::{BodyStream, transport::stream::MAX_HTTP_CHUNK_SIZE_BYTES}, test_executor::run, }; diff --git a/ipa-core/src/hpke/mod.rs b/ipa-core/src/hpke/mod.rs index 9c8e3dfb2..89f2a6c43 100644 --- a/ipa-core/src/hpke/mod.rs +++ b/ipa-core/src/hpke/mod.rs @@ -6,8 +6,8 @@ use std::{fmt::Debug, io, ops::Add}; use generic_array::ArrayLength; use hpke::{ - aead::AeadTag, single_shot_open_in_place_detached, single_shot_seal_in_place_detached, OpModeR, - OpModeS, + OpModeR, OpModeS, aead::AeadTag, single_shot_open_in_place_detached, + single_shot_seal_in_place_detached, }; use rand_core::{CryptoRng, RngCore}; use typenum::U16; diff --git a/ipa-core/src/hpke/registry.rs b/ipa-core/src/hpke/registry.rs index ae97ae9f6..554fd37ac 100644 --- a/ipa-core/src/hpke/registry.rs +++ b/ipa-core/src/hpke/registry.rs @@ -22,7 +22,7 @@ impl From<(IpaPrivateKey, IpaPublicKey)> for KeyPair { } impl KeyPair { - pub fn gen(mut r: &mut R) -> Self { + pub fn r#gen(mut r: &mut R) -> Self { ::gen_keypair(&mut r).into() } @@ -120,7 +120,9 @@ impl KeyRegistry { impl KeyRegistry { #[cfg(any(test, feature = "test-fixture"))] pub fn random(keys_count: usize, r: &mut R) -> Self { - let keys = (0..keys_count).map(|_| KeyPair::gen(r)).collect::>(); + let keys = (0..keys_count) + .map(|_| KeyPair::r#gen(r)) + .collect::>(); Self { keys: keys.into_boxed_slice(), @@ -200,8 +202,8 @@ mod tests { #[test] fn encrypt_decrypt() { let mut rng = StdRng::seed_from_u64(42); - let keypair1 = KeyPair::gen(&mut rng); - let keypair2 = KeyPair::gen(&mut rng); + let keypair1 = KeyPair::r#gen(&mut rng); + let keypair2 = KeyPair::r#gen(&mut rng); let registry = KeyRegistry::::from_keys([keypair1, keypair2]); let pt = b"This is a plaintext."; @@ -216,7 +218,7 @@ mod tests { decrypt(registry.private_key(1).unwrap(), &ct_payload).unwrap_err() ); - let keypair3 = KeyPair::gen(&mut rng); + let keypair3 = KeyPair::r#gen(&mut rng); let private_registry = KeyRegistry::::from_keys([PrivateKeyOnly(keypair3.sk)]); diff --git a/ipa-core/src/lib.rs b/ipa-core/src/lib.rs index 188f8154b..9345de3c1 100644 --- a/ipa-core/src/lib.rs +++ b/ipa-core/src/lib.rs @@ -61,12 +61,12 @@ pub(crate) mod rand { /// TODO: shuttle does not re-export `CryptoRng`. The only reason it works is because IPA uses /// the same version of `rand`. pub use rand::CryptoRng; - pub use shuttle::rand::{thread_rng, Rng, RngCore}; + pub use shuttle::rand::{Rng, RngCore, thread_rng}; } #[cfg(not(all(feature = "shuttle", test)))] pub(crate) mod rand { - pub use rand::{thread_rng, CryptoRng, Rng, RngCore}; + pub use rand::{CryptoRng, Rng, RngCore, thread_rng}; } #[cfg(all(feature = "shuttle", test))] @@ -198,7 +198,7 @@ pub(crate) mod executor { task::{Context, Poll}, }; - use shuttle_crate::future::{spawn, JoinHandle}; + use shuttle_crate::future::{JoinHandle, spawn}; use crate::shim::Tokio; @@ -294,7 +294,7 @@ pub(crate) mod test_executor { pub(crate) mod test_executor { use std::future::Future; - use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng}; + use rand::{SeedableRng, random, rngs::StdRng}; // These routines use `FnOnce` because it is easier than dealing with lifetimes of // `&mut rng` borrows in futures. If there were a need to support multiple @@ -342,7 +342,7 @@ pub(crate) mod test_executor { F: FnOnce(StdRng) -> Fut + Send + Sync + 'static, Fut: Future, { - let seed = thread_rng().gen(); + let seed = random(); run_with_seed(seed, f); } } diff --git a/ipa-core/src/net/client/mod.rs b/ipa-core/src/net/client/mod.rs index 42d7c1377..b1ae064f7 100644 --- a/ipa-core/src/net/client/mod.rs +++ b/ipa-core/src/net/client/mod.rs @@ -5,7 +5,7 @@ use std::{ marker::PhantomData, pin::Pin, sync::Arc, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; use axum::{ @@ -13,12 +13,12 @@ use axum::{ http::uri::{self, Parts, Scheme}, }; use bytes::Bytes; -use futures::{stream::StreamExt, Stream}; +use futures::{Stream, stream::StreamExt}; use http_body_util::BodyExt; -use hyper::{header::HeaderName, http::HeaderValue, Request, Response, StatusCode, Uri}; +use hyper::{Request, Response, StatusCode, Uri, header::HeaderName, http::HeaderValue}; use hyper_rustls::{ConfigBuilderExt, HttpsConnector, HttpsConnectorBuilder}; use hyper_util::{ - client::legacy::{connect::HttpConnector, Client}, + client::legacy::{Client, connect::HttpConnector}, rt::TokioTimer, }; use pin_project::pin_project; @@ -33,10 +33,10 @@ use crate::{ }, executor::IpaRuntime, helpers::{ - query::{CompareStatusRequest, PrepareQuery, QueryConfig, QueryInput}, TransportIdentity, + query::{CompareStatusRequest, PrepareQuery, QueryConfig, QueryInput}, }, - net::{error::ShardQueryStatusMismatchError, http_serde, Error, CRYPTO_PROVIDER}, + net::{CRYPTO_PROVIDER, Error, error::ShardQueryStatusMismatchError, http_serde}, protocol::{Gate, QueryId}, }; @@ -549,7 +549,7 @@ fn make_http_connector() -> HttpConnector { pub(crate) mod tests { use std::{ fmt::Debug, - future::{ready, Future}, + future::{Future, ready}, iter::zip, task::Poll, }; @@ -561,8 +561,8 @@ pub(crate) mod tests { use crate::{ ff::{FieldType, Fp31}, helpers::{ - make_owned_handler, query::QueryType::TestMultiply, BytesStream, HelperIdentity, - HelperResponse, RequestHandler, RoleAssignment, MESSAGE_PAYLOAD_SIZE_BYTES, + BytesStream, HelperIdentity, HelperResponse, MESSAGE_PAYLOAD_SIZE_BYTES, + RequestHandler, RoleAssignment, make_owned_handler, query::QueryType::TestMultiply, }, net::test::TestServer, protocol::step::TestExecutionStep, diff --git a/ipa-core/src/net/http_serde.rs b/ipa-core/src/net/http_serde.rs index e9f189051..2777cf7cb 100644 --- a/ipa-core/src/net/http_serde.rs +++ b/ipa-core/src/net/http_serde.rs @@ -83,9 +83,9 @@ pub mod query { use async_trait::async_trait; use axum::{ + RequestPartsExt, extract::{FromRequestParts, Query}, http::request::Parts, - RequestPartsExt, }; use serde::Deserialize; @@ -188,8 +188,8 @@ pub mod query { use serde::{Deserialize, Serialize}; use crate::{ - helpers::{query::QueryConfig, HelperResponse}, - net::http_serde::query::{QueryConfigQueryParams, BASE_AXUM_PATH}, + helpers::{HelperResponse, query::QueryConfig}, + net::http_serde::query::{BASE_AXUM_PATH, QueryConfigQueryParams}, protocol::QueryId, }; @@ -243,10 +243,10 @@ pub mod query { use serde::{Deserialize, Serialize}; use crate::{ - helpers::{query::PrepareQuery, RoleAssignment}, + helpers::{RoleAssignment, query::PrepareQuery}, net::{ - http_serde::query::{QueryConfigQueryParams, BASE_AXUM_PATH}, APPLICATION_JSON, + http_serde::query::{BASE_AXUM_PATH, QueryConfigQueryParams}, }, }; @@ -301,15 +301,15 @@ pub mod query { http::{request::Parts, uri}, }; use hyper::{ - header::{HeaderValue, CONTENT_TYPE}, Uri, + header::{CONTENT_TYPE, HeaderValue}, }; use crate::{ helpers::query::QueryInput, net::{ - http_serde::query::BASE_AXUM_PATH, Error, APPLICATION_OCTET_STREAM, - HTTP_QUERY_INPUT_URL_HEADER, + APPLICATION_OCTET_STREAM, Error, HTTP_QUERY_INPUT_URL_HEADER, + http_serde::query::BASE_AXUM_PATH, }, }; @@ -388,7 +388,7 @@ pub mod query { use axum::{body::Body, http::uri}; use crate::{ - net::{http_serde::query::BASE_AXUM_PATH, Error}, + net::{Error, http_serde::query::BASE_AXUM_PATH}, protocol::{Gate, QueryId}, }; @@ -439,7 +439,7 @@ pub mod query { use serde::{Deserialize, Serialize}; use crate::{ - helpers::{routing::RouteId, HelperResponse, NoStep, RouteParams}, + helpers::{HelperResponse, NoStep, RouteParams, routing::RouteId}, protocol::QueryId, query::QueryStatus, }; @@ -510,7 +510,7 @@ pub mod query { pub mod results { use crate::{ - helpers::{routing::RouteId, NoStep, RouteParams}, + helpers::{NoStep, RouteParams, routing::RouteId}, protocol::QueryId, }; @@ -569,7 +569,7 @@ pub mod query { use serde::{Deserialize, Serialize}; use crate::{ - helpers::{routing::RouteId, HelperResponse, NoStep, RouteParams}, + helpers::{HelperResponse, NoStep, RouteParams, routing::RouteId}, protocol::QueryId, }; diff --git a/ipa-core/src/net/mod.rs b/ipa-core/src/net/mod.rs index 5bce44553..2d8c47c5a 100644 --- a/ipa-core/src/net/mod.rs +++ b/ipa-core/src/net/mod.rs @@ -1,11 +1,10 @@ use std::{ fmt::Debug, io::{self, BufRead}, - sync::Arc, + sync::{Arc, LazyLock}, }; use hyper::header::HeaderName; -use once_cell::sync::Lazy; use rustls::crypto::CryptoProvider; use rustls_pki_types::CertificateDer; @@ -45,8 +44,8 @@ pub(crate) const MAX_HTTP2_WINDOW_SIZE: u32 = (1 << 31) - 1; pub(crate) const MAX_HTTP2_CONCURRENT_STREAMS: u32 = 5000; /// Provides access to IPAs Crypto Provider (AWS Libcrypto). -static CRYPTO_PROVIDER: Lazy> = - Lazy::new(|| Arc::new(rustls::crypto::aws_lc_rs::default_provider())); +static CRYPTO_PROVIDER: LazyLock> = + LazyLock::new(|| Arc::new(rustls::crypto::aws_lc_rs::default_provider())); /// This simple trait is used to make aware on what transport dimnsion one is running. Structs like /// [`MpcHelperClient`] use it to know whether they are talking to other servers as Shards diff --git a/ipa-core/src/net/query_input.rs b/ipa-core/src/net/query_input.rs index 7a71b6f77..d4c4eac39 100644 --- a/ipa-core/src/net/query_input.rs +++ b/ipa-core/src/net/query_input.rs @@ -1,4 +1,4 @@ -use axum::{body::Body, BoxError}; +use axum::{BoxError, body::Body}; use http_body_util::BodyExt; use hyper::Uri; use hyper_rustls::HttpsConnectorBuilder; diff --git a/ipa-core/src/net/server/handlers/echo.rs b/ipa-core/src/net/server/handlers/echo.rs index cb067c749..290eb90eb 100644 --- a/ipa-core/src/net/server/handlers/echo.rs +++ b/ipa-core/src/net/server/handlers/echo.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use axum::{extract::Query, routing::get, Json, Router}; +use axum::{Json, Router, extract::Query, routing::get}; use hyper::HeaderMap; use crate::net::{ @@ -38,7 +38,7 @@ mod tests { use bytes::Buf; use http_body_util::BodyExt; use hyper::{Request, StatusCode}; - use serde_json::{json, Value}; + use serde_json::{Value, json}; use tower::ServiceExt; use super::*; diff --git a/ipa-core/src/net/server/handlers/metrics.rs b/ipa-core/src/net/server/handlers/metrics.rs index 1c7d859b6..4d8b02d7c 100644 --- a/ipa-core/src/net/server/handlers/metrics.rs +++ b/ipa-core/src/net/server/handlers/metrics.rs @@ -1,11 +1,11 @@ -use axum::{routing::get, Extension, Router}; +use axum::{Extension, Router, routing::get}; use hyper::StatusCode; use crate::{ - helpers::{routing::RouteId, BodyStream}, + helpers::{BodyStream, routing::RouteId}, net::{ - http_serde::{self}, Error, MpcHttpTransport, + http_serde::{self}, }, }; @@ -36,7 +36,7 @@ mod tests { use super::*; use crate::{ - helpers::{make_owned_handler, routing::Addr, HelperIdentity, HelperResponse}, + helpers::{HelperIdentity, HelperResponse, make_owned_handler, routing::Addr}, net::server::handlers::query::test_helpers::assert_success_with, }; diff --git a/ipa-core/src/net/server/handlers/mod.rs b/ipa-core/src/net/server/handlers/mod.rs index 2571a2be0..4b379b4fd 100644 --- a/ipa-core/src/net/server/handlers/mod.rs +++ b/ipa-core/src/net/server/handlers/mod.rs @@ -5,7 +5,7 @@ mod query; use axum::Router; use crate::{ - net::{http_serde, transport::MpcHttpTransport, HttpTransport, Shard}, + net::{HttpTransport, Shard, http_serde, transport::MpcHttpTransport}, sync::Arc, }; diff --git a/ipa-core/src/net/server/handlers/query/create.rs b/ipa-core/src/net/server/handlers/query/create.rs index 4eb63aa7f..577e2b3cc 100644 --- a/ipa-core/src/net/server/handlers/query/create.rs +++ b/ipa-core/src/net/server/handlers/query/create.rs @@ -1,12 +1,12 @@ -use axum::{routing::post, Extension, Json, Router}; +use axum::{Extension, Json, Router, routing::post}; use hyper::StatusCode; use crate::{ helpers::{ApiError, BodyStream}, net::{ + Error, http_serde::{self, query::QueryConfigQueryParams}, transport::MpcHttpTransport, - Error, }, query::NewQueryError, }; @@ -37,17 +37,16 @@ mod tests { use axum::body::Body; use hyper::{ - http::uri::{Authority, Scheme}, StatusCode, + http::uri::{Authority, Scheme}, }; use crate::{ ff::FieldType, helpers::{ - make_owned_handler, + HelperResponse, Role, RoleAssignment, make_owned_handler, query::{PrepareQuery, QueryConfig, QueryType}, routing::RouteId, - HelperResponse, Role, RoleAssignment, }, net::{ http_serde, @@ -164,6 +163,7 @@ mod tests { val.epsilon, ); + #[allow(clippy::format_push_string)] if let Some(window) = val.attribution_window_seconds { query.push_str(&format!("&attribution_window_seconds={window}")); } diff --git a/ipa-core/src/net/server/handlers/query/input.rs b/ipa-core/src/net/server/handlers/query/input.rs index fa97b124b..ef206f54d 100644 --- a/ipa-core/src/net/server/handlers/query/input.rs +++ b/ipa-core/src/net/server/handlers/query/input.rs @@ -1,13 +1,13 @@ -use axum::{extract::Path, routing::post, Extension, Router}; +use axum::{Extension, Router, extract::Path, routing::post}; use hyper::StatusCode; use crate::{ - helpers::{routing::RouteId, BodyStream}, + helpers::{BodyStream, routing::RouteId}, net::{ + Error, http_serde::{self, query::input::QueryInputUrl}, query_input::stream_query_input_from_url, transport::MpcHttpTransport, - Error, }, protocol::QueryId, }; @@ -53,7 +53,7 @@ mod tests { use crate::{ helpers::{ - make_owned_handler, query::QueryInput, routing::RouteId, BytesStream, HelperResponse, + BytesStream, HelperResponse, make_owned_handler, query::QueryInput, routing::RouteId, }, net::{ http_serde, diff --git a/ipa-core/src/net/server/handlers/query/kill.rs b/ipa-core/src/net/server/handlers/query/kill.rs index f97fa1657..0c959e631 100644 --- a/ipa-core/src/net/server/handlers/query/kill.rs +++ b/ipa-core/src/net/server/handlers/query/kill.rs @@ -1,13 +1,13 @@ -use axum::{extract::Path, routing::post, Extension, Json, Router}; +use axum::{Extension, Json, Router, extract::Path, routing::post}; use hyper::StatusCode; use crate::{ helpers::{ApiError, BodyStream}, net::{ + Error::QueryIdNotFound, http_serde::query::kill::{self, Request}, server::Error, transport::MpcHttpTransport, - Error::QueryIdNotFound, }, protocol::QueryId, query::QueryKillStatus, @@ -43,9 +43,8 @@ mod tests { use crate::{ helpers::{ - make_owned_handler, + ApiError, BodyStream, HelperIdentity, HelperResponse, make_owned_handler, routing::{Addr, RouteId}, - ApiError, BodyStream, HelperIdentity, HelperResponse, }, net::{ http_serde, diff --git a/ipa-core/src/net/server/handlers/query/mod.rs b/ipa-core/src/net/server/handlers/query/mod.rs index 8a9881bb7..13cf67d03 100644 --- a/ipa-core/src/net/server/handlers/query/mod.rs +++ b/ipa-core/src/net/server/handlers/query/mod.rs @@ -10,20 +10,20 @@ mod step; use std::marker::PhantomData; use axum::{ - response::{IntoResponse, Response}, Router, + response::{IntoResponse, Response}, }; use futures_util::{ - future::{ready, Either, Ready}, FutureExt, + future::{Either, Ready, ready}, }; use hyper::{Request, StatusCode}; -use tower::{layer::layer_fn, Service}; +use tower::{Service, layer::layer_fn}; use crate::{ net::{ - server::ClientIdentity, transport::MpcHttpTransport, ConnectionFlavor, Helper, - HttpTransport, Shard, + ConnectionFlavor, Helper, HttpTransport, Shard, server::ClientIdentity, + transport::MpcHttpTransport, }, sync::Arc, }; @@ -127,11 +127,11 @@ pub mod test_helpers { use std::{any::Any, sync::Arc}; use axum::body::Body; - use hyper::{http::request, StatusCode}; + use hyper::{StatusCode, http::request}; use crate::{ helpers::{HelperIdentity, RequestHandler}, - net::{test::TestServer, Helper}, + net::{Helper, test::TestServer}, }; /// Helper trait for optionally adding an extension to a request. diff --git a/ipa-core/src/net/server/handlers/query/prepare.rs b/ipa-core/src/net/server/handlers/query/prepare.rs index a86dbb87e..e6bc7921f 100644 --- a/ipa-core/src/net/server/handlers/query/prepare.rs +++ b/ipa-core/src/net/server/handlers/query/prepare.rs @@ -1,18 +1,18 @@ use std::sync::Arc; -use axum::{extract::Path, response::IntoResponse, routing::post, Extension, Json, Router}; +use axum::{Extension, Json, Router, extract::Path, response::IntoResponse, routing::post}; use hyper::StatusCode; use crate::{ - helpers::{query::PrepareQuery, BodyStream}, + helpers::{BodyStream, query::PrepareQuery}, net::{ + ConnectionFlavor, Error, http_serde::{ self, - query::{prepare::RequestBody, QueryConfigQueryParams}, + query::{QueryConfigQueryParams, prepare::RequestBody}, }, server::ClientIdentity, transport::HttpTransport, - ConnectionFlavor, Error, }, protocol::QueryId, query::PrepareQueryError, @@ -55,26 +55,24 @@ pub fn router(transport: Arc>) -> Router { #[cfg(all(test, unit_test))] mod tests { use axum::body::Body; - use hyper::{header::CONTENT_TYPE, StatusCode}; + use hyper::{StatusCode, header::CONTENT_TYPE}; use serde::Serialize; use crate::{ ff::FieldType, helpers::{ - make_owned_handler, + HelperIdentity, HelperResponse, RoleAssignment, make_owned_handler, query::{PrepareQuery, QueryConfig, QueryType::TestMultiply}, routing::RouteId, - HelperIdentity, HelperResponse, RoleAssignment, }, net::{ - http_serde, + APPLICATION_JSON, http_serde, server::{ + ClientIdentity, handlers::query::test_helpers::{ - assert_fails_with, assert_success_with, MaybeExtensionExt, + MaybeExtensionExt, assert_fails_with, assert_success_with, }, - ClientIdentity, }, - APPLICATION_JSON, }, protocol::QueryId, }; diff --git a/ipa-core/src/net/server/handlers/query/results.rs b/ipa-core/src/net/server/handlers/query/results.rs index 2f2a59f5e..917be7aef 100644 --- a/ipa-core/src/net/server/handlers/query/results.rs +++ b/ipa-core/src/net/server/handlers/query/results.rs @@ -1,14 +1,14 @@ use std::sync::Arc; -use axum::{extract::Path, routing::get, Extension, Router}; +use axum::{Extension, Router, extract::Path, routing::get}; use hyper::StatusCode; use crate::{ helpers::BodyStream, net::{ + ConnectionFlavor, HttpTransport, http_serde::{self, query::results::Request}, server::Error, - ConnectionFlavor, HttpTransport, }, protocol::QueryId, }; @@ -47,9 +47,8 @@ mod tests { use crate::{ ff::Fp31, helpers::{ - make_owned_handler, + BodyStream, HelperIdentity, HelperResponse, make_owned_handler, routing::{Addr, RouteId}, - BodyStream, HelperIdentity, HelperResponse, }, net::{ http_serde, diff --git a/ipa-core/src/net/server/handlers/query/status.rs b/ipa-core/src/net/server/handlers/query/status.rs index 0056b76d0..3d6872ea3 100644 --- a/ipa-core/src/net/server/handlers/query/status.rs +++ b/ipa-core/src/net/server/handlers/query/status.rs @@ -1,4 +1,4 @@ -use axum::{extract::Path, routing::get, Extension, Json, Router}; +use axum::{Extension, Json, Router, extract::Path, routing::get}; use hyper::StatusCode; use crate::{ @@ -38,9 +38,8 @@ mod tests { use crate::{ helpers::{ - make_owned_handler, + BodyStream, HelperIdentity, HelperResponse, make_owned_handler, routing::{Addr, RouteId}, - BodyStream, HelperIdentity, HelperResponse, }, net::{ http_serde, diff --git a/ipa-core/src/net/server/handlers/query/status_match.rs b/ipa-core/src/net/server/handlers/query/status_match.rs index 5b2081c5e..3374b8a1f 100644 --- a/ipa-core/src/net/server/handlers/query/status_match.rs +++ b/ipa-core/src/net/server/handlers/query/status_match.rs @@ -1,18 +1,18 @@ use axum::{ + Extension, Router, extract::{Path, Query}, routing::get, - Extension, Router, }; use hyper::StatusCode; use crate::{ - helpers::{query::CompareStatusRequest, ApiError, BodyStream}, + helpers::{ApiError, BodyStream, query::CompareStatusRequest}, net::{ + HttpTransport, Shard, http_serde::query::status_match::{ StatusQueryString, {self}, }, server::Error, - HttpTransport, Shard, }, protocol::QueryId, query::QueryStatusError, @@ -55,17 +55,16 @@ mod tests { use crate::{ helpers::{ - make_owned_handler, + ApiError, BodyStream, HelperResponse, RequestHandler, make_owned_handler, query::CompareStatusRequest, routing::{Addr, RouteId}, - ApiError, BodyStream, HelperResponse, RequestHandler, }, net::{ + Error, Shard, error::ShardQueryStatusMismatchError, http_serde::query::status_match::try_into_http_request, server::ClientIdentity, test::{TestServer, TestServerBuilder}, - Error, Shard, }, protocol::QueryId, query::{QueryStatus, QueryStatusError}, diff --git a/ipa-core/src/net/server/handlers/query/step.rs b/ipa-core/src/net/server/handlers/query/step.rs index 4128e933a..4a345ca4a 100644 --- a/ipa-core/src/net/server/handlers/query/step.rs +++ b/ipa-core/src/net/server/handlers/query/step.rs @@ -1,11 +1,10 @@ -use axum::{extract::Path, routing::post, Extension, Router}; +use axum::{Extension, Router, extract::Path, routing::post}; use crate::{ helpers::BodyStream, net::{ - http_serde, + ConnectionFlavor, HttpTransport, http_serde, server::{ClientIdentity, Error}, - ConnectionFlavor, HttpTransport, }, protocol::{Gate, QueryId}, sync::Arc, @@ -34,7 +33,7 @@ mod tests { use std::task::Poll; use axum::body::Body; - use futures::{stream::poll_immediate, StreamExt}; + use futures::{StreamExt, stream::poll_immediate}; use hyper::StatusCode; use ipa_step::StepNarrow; @@ -42,7 +41,7 @@ mod tests { use crate::{ helpers::{HelperIdentity, MESSAGE_PAYLOAD_SIZE_BYTES}, net::{ - server::handlers::query::test_helpers::{assert_fails_with, MaybeExtensionExt}, + server::handlers::query::test_helpers::{MaybeExtensionExt, assert_fails_with}, test::TestServer, }, protocol::{Gate, QueryId}, diff --git a/ipa-core/src/net/server/mod.rs b/ipa-core/src/net/server/mod.rs index bcf855d5e..6e4a538df 100644 --- a/ipa-core/src/net/server/mod.rs +++ b/ipa-core/src/net/server/mod.rs @@ -16,30 +16,30 @@ use ::tokio::{ net::TcpStream, }; use axum::{ + Router, http::HeaderValue, response::{IntoResponse, Response}, routing::IntoMakeService, - Router, }; use axum_server::{ + Handle, Server, accept::Accept, service::SendService, tls_rustls::{RustlsAcceptor, RustlsConfig}, - Handle, Server, }; use futures::{ - future::{ready, BoxFuture, Either, Ready}, FutureExt, + future::{BoxFuture, Either, Ready, ready}, }; -use hyper::{body::Incoming, Request}; +use hyper::{Request, body::Incoming}; use ipa_metrics::counter; -use rustls::{server::WebPkiClientVerifier, RootCertStore}; +use rustls::{RootCertStore, server::WebPkiClientVerifier}; use tokio_rustls::server::TlsStream; -use tower::{layer::layer_fn, Service}; +use tower::{Service, layer::layer_fn}; use tower_http::trace::TraceLayer; -use tracing::{error, Span}; +use tracing::{Span, error}; -use super::{transport::MpcHttpTransport, HttpTransport, Shard}; +use super::{HttpTransport, Shard, transport::MpcHttpTransport}; use crate::{ config::{ NetworkConfig, OwnedCertificate, OwnedPrivateKey, PeerConfig, ServerConfig, TlsConfig, @@ -48,11 +48,11 @@ use crate::{ executor::{IpaJoinHandle, IpaRuntime}, helpers::TransportIdentity, net::{ - parse_certificate_and_private_key_bytes, server::config::HttpServerConfig, - ConnectionFlavor, Error, Helper, CRYPTO_PROVIDER, + CRYPTO_PROVIDER, ConnectionFlavor, Error, Helper, parse_certificate_and_private_key_bytes, + server::config::HttpServerConfig, }, sync::Arc, - telemetry::metrics::{web::RequestProtocolVersion, REQUESTS_RECEIVED}, + telemetry::metrics::{REQUESTS_RECEIVED, web::RequestProtocolVersion}, }; pub trait TracingSpanMaker: Send + Sync + Clone + 'static { @@ -523,12 +523,12 @@ mod e2e_tests { use bytes::Buf; use http_body_util::BodyExt; - use hyper::{http::uri, StatusCode, Version}; + use hyper::{StatusCode, Version, http::uri}; use hyper_rustls::HttpsConnector; use hyper_util::{ client::legacy::{ - connect::{Connect, HttpConnector}, Client, + connect::{Connect, HttpConnector}, }, rt::{TokioExecutor, TokioTimer}, }; diff --git a/ipa-core/src/net/test.rs b/ipa-core/src/net/test.rs index 12330f67a..8f76b3991 100644 --- a/ipa-core/src/net/test.rs +++ b/ipa-core/src/net/test.rs @@ -13,18 +13,18 @@ use std::{ iter::zip, net::{SocketAddr, TcpListener}, ops::Index, + sync::LazyLock, }; #[cfg(all(test, unit_test))] use http_body_util::BodyExt; #[cfg(all(test, unit_test))] use hyper::StatusCode; -use once_cell::sync::Lazy; use rustls_pki_types::CertificateDer; use super::{ConnectionFlavor, HttpTransport, Shard}; #[cfg(all(test, web_test, descriptive_gate))] -use crate::cli::{install_collector, LoggingHandle}; +use crate::cli::{LoggingHandle, install_collector}; use crate::{ config::{ ClientConfig, HpkeClientConfig, HpkeServerConfig, NetworkConfig, PeerConfig, ServerConfig, @@ -797,7 +797,7 @@ impl Index for [&'static [u8]; S] { } } -impl Index for Lazy<[CertificateDer<'static>; S]> { +impl Index for LazyLock<[CertificateDer<'static>; S]> { type Output = CertificateDer<'static>; fn index(&self, index: ShardedHelperIdentity) -> &Self::Output { @@ -899,7 +899,7 @@ xYxSeDvd5vt4ROlqgvLMcOOUjbFF7YAT6g== ", ]; -static TEST_CERTS_DER: Lazy<[CertificateDer; 6]> = Lazy::new(|| { +static TEST_CERTS_DER: LazyLock<[CertificateDer; 6]> = LazyLock::new(|| { TEST_CERTS.map(|mut pem| rustls_pemfile::certs(&mut pem).flatten().next().unwrap()) }); @@ -960,13 +960,13 @@ a0778c3e9960576cbef4312a3b7ca34137880fd588c11047bd8b6a8b70b5a151 #[cfg(all(test, unit_test))] mod tests { - use super::{get_test_certificate_and_key, TestConfigBuilder}; + use super::{TestConfigBuilder, get_test_certificate_and_key}; use crate::{ config::NetworkConfig, helpers::HelperIdentity, net::{ - test::{Ports, TEST_CERTS, TEST_KEYS}, ConnectionFlavor, + test::{Ports, TEST_CERTS, TEST_KEYS}, }, sharding::{ShardIndex, ShardedHelperIdentity}, }; diff --git a/ipa-core/src/net/transport.rs b/ipa-core/src/net/transport.rs index 599024271..58b8a742d 100644 --- a/ipa-core/src/net/transport.rs +++ b/ipa-core/src/net/transport.rs @@ -9,18 +9,18 @@ use async_trait::async_trait; use futures::{Stream, TryFutureExt}; use pin_project::{pin_project, pinned_drop}; -use super::{client::resp_ok, error::ShardError, ConnectionFlavor, Helper, Shard}; +use super::{ConnectionFlavor, Helper, Shard, client::resp_ok, error::ShardError}; use crate::{ config::{NetworkConfig, ServerConfig}, executor::IpaRuntime, helpers::{ - query::QueryConfig, - routing::{Addr, RouteId}, ApiError, BodyStream, HandlerRef, HelperIdentity, HelperResponse, NoQueryId, NoResourceIdentifier, NoStep, QueryIdBinding, ReceiveRecords, RequestHandler, RouteParams, StepBinding, StreamCollection, Transport, TransportIdentity, + query::QueryConfig, + routing::{Addr, RouteId}, }, - net::{client::IpaHttpClient, error::Error, IpaHttpServer}, + net::{IpaHttpServer, client::IpaHttpClient, error::Error}, protocol::{Gate, QueryId}, sharding::ShardIndex, sync::Arc, @@ -405,7 +405,7 @@ mod tests { use std::{iter::repeat, task::Poll}; use bytes::Bytes; - use futures::stream::{poll_immediate, StreamExt}; + use futures::stream::{StreamExt, poll_immediate}; use futures_util::future::{join_all, try_join_all}; use generic_array::GenericArray; use once_cell::sync::Lazy; @@ -415,7 +415,8 @@ mod tests { use super::*; use crate::{ - ff::{boolean_array::BA64, FieldType, Fp31, Serializable}, + HelperApp, + ff::{FieldType, Fp31, Serializable, boolean_array::BA64}, helpers::{ make_owned_handler, query::{ @@ -427,20 +428,15 @@ mod tests { client::ClientIdentity, test::{TestConfig, TestConfigBuilder, TestServer}, }, - secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares}, + secret_sharing::{IntoShares, replicated::semi_honest::AdditiveShare}, test_fixture::Reconstruct, - HelperApp, }; static STEP: Lazy = Lazy::new(|| Gate::from("http-transport")); #[tokio::test] async fn clean_on_kill() { - let noop_handler = make_owned_handler(|_, _| async move { - { - Ok(HelperResponse::ok()) - } - }); + let noop_handler = make_owned_handler(|_, _| async move { Ok(HelperResponse::ok()) }); let TestServer { transport, .. } = TestServer::builder() .with_request_handler(Arc::clone(&noop_handler)) .build() diff --git a/ipa-core/src/protocol/basics/check_zero.rs b/ipa-core/src/protocol/basics/check_zero.rs index 7cbe8b8b3..b4bb87dc8 100644 --- a/ipa-core/src/protocol/basics/check_zero.rs +++ b/ipa-core/src/protocol/basics/check_zero.rs @@ -4,10 +4,10 @@ use crate::{ error::Error, ff::Field, protocol::{ + RecordId, basics::{malicious_reveal, mul::semi_honest_multiply, step::CheckZeroStep as Step}, context::Context, prss::{FromRandom, SharedRandomness}, - RecordId, }, secret_sharing::replicated::semi_honest::AdditiveShare as Replicated, }; @@ -74,7 +74,7 @@ mod tests { use crate::{ error::Error, ff::{Fp31, PrimeField, U128Conversions}, - protocol::{context::Context, RecordId}, + protocol::{RecordId, context::Context}, rand::thread_rng, secret_sharing::{IntoShares, SharedValue}, test_fixture::TestWorld, diff --git a/ipa-core/src/protocol/basics/if_else.rs b/ipa-core/src/protocol/basics/if_else.rs index 9905d1274..e5c5ab374 100644 --- a/ipa-core/src/protocol/basics/if_else.rs +++ b/ipa-core/src/protocol/basics/if_else.rs @@ -2,9 +2,9 @@ use crate::{ error::Error, ff::boolean::Boolean, protocol::{ - basics::mul::{boolean_array_multiply, BooleanArrayMul}, - context::Context, RecordId, + basics::mul::{BooleanArrayMul, boolean_array_multiply}, + context::Context, }, secret_sharing::replicated::semi_honest::AdditiveShare, }; diff --git a/ipa-core/src/protocol/basics/mod.rs b/ipa-core/src/protocol/basics/mod.rs index 1182ea618..132498398 100644 --- a/ipa-core/src/protocol/basics/mod.rs +++ b/ipa-core/src/protocol/basics/mod.rs @@ -14,7 +14,7 @@ pub use if_else::select; pub use mul::{BooleanArrayMul, SecureMul}; pub use reshare::Reshare; pub use reveal::{ - malicious_reveal, partial_reveal, reveal, semi_honest_reveal, validated_partial_reveal, Reveal, + Reveal, malicious_reveal, partial_reveal, reveal, semi_honest_reveal, validated_partial_reveal, }; pub use shard_fin::{FinalizerContext, ShardAssembledResult}; pub use share_known_value::ShareKnownValue; @@ -31,8 +31,8 @@ use crate::{ prss::FromPrss, }, secret_sharing::{ - replicated::{malicious, semi_honest::AdditiveShare}, FieldSimd, SecretSharing, SharedValue, Vectorizable, + replicated::{malicious, semi_honest::AdditiveShare}, }, sharding::ShardBinding, }; diff --git a/ipa-core/src/protocol/basics/mul/dzkp_malicious.rs b/ipa-core/src/protocol/basics/mul/dzkp_malicious.rs index 87e987920..70ac51b5b 100644 --- a/ipa-core/src/protocol/basics/mul/dzkp_malicious.rs +++ b/ipa-core/src/protocol/basics/mul/dzkp_malicious.rs @@ -4,15 +4,15 @@ use crate::{ error::Error, ff::Field, protocol::{ - basics::{mul::semi_honest::multiplication_protocol, SecureMul}, + RecordId, + basics::{SecureMul, mul::semi_honest::multiplication_protocol}, context::{ - dzkp_field::DZKPCompatibleField, dzkp_validator::Segment, Context, - DZKPUpgradedMaliciousContext, + Context, DZKPUpgradedMaliciousContext, dzkp_field::DZKPCompatibleField, + dzkp_validator::Segment, }, prss::SharedRandomness, - RecordId, }, - secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, Vectorizable}, + secret_sharing::{Vectorizable, replicated::semi_honest::AdditiveShare as Replicated}, sharding::{NotSharded, ShardBinding}, }; @@ -85,11 +85,11 @@ mod test { use crate::{ ff::boolean::Boolean, protocol::{ - basics::SecureMul, - context::{dzkp_validator::DZKPValidator, Context, UpgradableContext, TEST_DZKP_STEPS}, RecordId, + basics::SecureMul, + context::{Context, TEST_DZKP_STEPS, UpgradableContext, dzkp_validator::DZKPValidator}, }, - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, test_fixture::{Reconstruct, Runner, TestWorld}, }; @@ -98,8 +98,8 @@ mod test { let world = TestWorld::default(); let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let res = world .malicious((a, b), |ctx, (a, b)| async move { diff --git a/ipa-core/src/protocol/basics/mul/malicious.rs b/ipa-core/src/protocol/basics/mul/malicious.rs index 3ee72f467..3bca3474b 100644 --- a/ipa-core/src/protocol/basics/mul/malicious.rs +++ b/ipa-core/src/protocol/basics/mul/malicious.rs @@ -4,13 +4,13 @@ use futures::future::try_join; use crate::{ error::Error, protocol::{ + RecordId, basics::{ - mul::{semi_honest_multiply, step::MaliciousMultiplyStep}, SecureMul, + mul::{semi_honest_multiply, step::MaliciousMultiplyStep}, }, context::{Context, UpgradedMaliciousContext}, prss::FromPrss, - RecordId, }, secret_sharing::replicated::{ malicious::{AdditiveShare as MaliciousReplicated, ExtendableFieldSimd}, @@ -131,7 +131,7 @@ mod test { use crate::{ ff::Fp31, protocol::basics::SecureMul, - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, test_fixture::{Reconstruct, Runner, TestWorld}, }; @@ -140,8 +140,8 @@ mod test { let world = TestWorld::default(); let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let res = world diff --git a/ipa-core/src/protocol/basics/mul/mod.rs b/ipa-core/src/protocol/basics/mul/mod.rs index a69b7faf4..8cb992745 100644 --- a/ipa-core/src/protocol/basics/mul/mod.rs +++ b/ipa-core/src/protocol/basics/mul/mod.rs @@ -8,16 +8,16 @@ use async_trait::async_trait; use crate::{ error::Error, ff::{ - boolean::Boolean, - boolean_array::{BA16, BA20, BA256, BA3, BA32, BA5, BA64, BA8}, Expand, + boolean::Boolean, + boolean_array::{BA3, BA5, BA8, BA16, BA20, BA32, BA64, BA256}, }, protocol::{ + RecordId, context::{ - dzkp_semi_honest::DZKPUpgraded as SemiHonestDZKPUpgraded, Context, - DZKPUpgradedMaliciousContext, + Context, DZKPUpgradedMaliciousContext, + dzkp_semi_honest::DZKPUpgraded as SemiHonestDZKPUpgraded, }, - RecordId, }, secret_sharing::replicated::semi_honest::AdditiveShare as Replicated, sharding, diff --git a/ipa-core/src/protocol/basics/mul/semi_honest.rs b/ipa-core/src/protocol/basics/mul/semi_honest.rs index 3986056d9..b22fe5ae5 100644 --- a/ipa-core/src/protocol/basics/mul/semi_honest.rs +++ b/ipa-core/src/protocol/basics/mul/semi_honest.rs @@ -5,17 +5,17 @@ use crate::{ ff::Field, helpers::Direction, protocol::{ + RecordId, context::{ + Context, dzkp_semi_honest::DZKPUpgraded as SemiHonestDZKPUpgraded, semi_honest::{Context as SemiHonestContext, Upgraded as UpgradedSemiHonestContext}, - Context, }, prss::SharedRandomness, - RecordId, }, secret_sharing::{ - replicated::{malicious::ExtendableField, semi_honest::AdditiveShare as Replicated}, FieldSimd, Vectorizable, + replicated::{malicious::ExtendableField, semi_honest::AdditiveShare as Replicated}, }, sharding, }; @@ -190,8 +190,8 @@ mod test { use crate::{ ff::{Field, Fp31, Fp32BitPrime, U128Conversions}, helpers::TotalRecords, - protocol::{basics::SecureMul, context::Context, RecordId}, - rand::{thread_rng, Rng}, + protocol::{RecordId, basics::SecureMul, context::Context}, + rand::{Rng, thread_rng}, secret_sharing::replicated::semi_honest::AdditiveShare, seq_join::SeqJoin, test_fixture::{Reconstruct, ReconstructArr, Runner, TestWorld}, @@ -215,8 +215,8 @@ mod test { let world = TestWorld::default(); let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let res = world .semi_honest((a, b), |ctx, (a, b)| async move { @@ -239,8 +239,8 @@ mod test { let world = TestWorld::default(); let mut rng = thread_rng(); - let a = (0..COUNT).map(|_| rng.gen::()).collect::>(); - let b = (0..COUNT).map(|_| rng.gen::()).collect::>(); + let a = (0..COUNT).map(|_| rng.r#gen::()).collect::>(); + let b = (0..COUNT).map(|_| rng.r#gen::()).collect::>(); let expected: Vec<_> = zip(a.iter(), b.iter()).map(|(&a, &b)| a * b).collect(); let results = world .semi_honest( @@ -291,8 +291,8 @@ mod test { let world = TestWorld::default(); let mut rng = thread_rng(); - let a: [Fp32BitPrime; COUNT] = array::from_fn(|_| rng.gen()); - let b: [Fp32BitPrime; COUNT] = array::from_fn(|_| rng.gen()); + let a: [Fp32BitPrime; COUNT] = array::from_fn(|_| rng.r#gen()); + let b: [Fp32BitPrime; COUNT] = array::from_fn(|_| rng.r#gen()); let expected: [Fp32BitPrime; COUNT] = zip(a.iter(), b.iter()) .map(|(&a, &b)| a * b) .collect::>() @@ -376,7 +376,7 @@ mod test { let mut rng = thread_rng(); let mut inputs = Vec::<[Fp32BitPrime; MANYMULT_WIDTH]>::new(); for _ in 0..MANYMULT_ITERS { - inputs.push(array::from_fn(|_| rng.gen())); + inputs.push(array::from_fn(|_| rng.r#gen())); } let expected = inputs .iter() diff --git a/ipa-core/src/protocol/basics/reshare.rs b/ipa-core/src/protocol/basics/reshare.rs index cb33a8146..57a14c3d0 100644 --- a/ipa-core/src/protocol/basics/reshare.rs +++ b/ipa-core/src/protocol/basics/reshare.rs @@ -6,18 +6,18 @@ use crate::{ ff::Field, helpers::{Direction, Role}, protocol::{ + RecordId, basics::mul::step::MaliciousMultiplyStep::{RandomnessForValidation, ReshareRx}, context::{Context, SpecialAccessToUpgradedContext, UpgradedMaliciousContext}, prss::SharedRandomness, - RecordId, }, secret_sharing::replicated::{ + ReplicatedSecretSharing, malicious::{ AdditiveShare as MaliciousReplicated, ExtendableField, ThisCodeIsAuthorizedToDowngradeFromMalicious, }, semi_honest::AdditiveShare as Replicated, - ReplicatedSecretSharing, }, }; @@ -135,11 +135,12 @@ impl<'a, F: ExtendableField> Reshare> for Malici #[cfg(all(test, unit_test))] mod tests { mod semi_honest { + use rand::random; + use crate::{ ff::Fp32BitPrime, helpers::Role, - protocol::{basics::Reshare, context::Context, prss::SharedRandomness, RecordId}, - rand::{thread_rng, Rng}, + protocol::{RecordId, basics::Reshare, context::Context, prss::SharedRandomness}, test_fixture::{Reconstruct, Runner, TestWorld}, }; @@ -149,7 +150,7 @@ mod tests { let world = TestWorld::default(); for &target in Role::all() { - let secret = thread_rng().gen::(); + let secret = random::(); let shares = world .semi_honest(secret, |ctx, share| async move { let record_id = RecordId::from(0); @@ -183,7 +184,7 @@ mod tests { let world = TestWorld::default(); for &role in Role::all() { - let secret = thread_rng().gen::(); + let secret = random::(); let new_shares = world .semi_honest(secret, |ctx, share| async move { share @@ -200,21 +201,21 @@ mod tests { mod malicious { - use rand::{distributions::Standard, prelude::Distribution}; + use rand::{distributions::Standard, prelude::Distribution, random}; use crate::{ error::Error, ff::{Field, Fp32BitPrime, Gf2, Gf32Bit}, - helpers::{in_memory_config::MaliciousHelper, Role}, + helpers::{Role, in_memory_config::MaliciousHelper}, protocol::{ + RecordId, basics::Reshare, context::{ - upgrade::Upgradable, Context, UpgradableContext, UpgradedContext, Validator, + Context, UpgradableContext, UpgradedContext, Validator, upgrade::Upgradable, }, - RecordId, }, - rand::{thread_rng, Rng}, - secret_sharing::{replicated::malicious::ExtendableField, SharedValue}, + rand::{Rng, thread_rng}, + secret_sharing::{SharedValue, replicated::malicious::ExtendableField}, test_fixture::{Reconstruct, Runner, TestWorld, TestWorldConfig}, }; @@ -229,7 +230,7 @@ mod tests { let world = TestWorld::default(); for &role in Role::all() { - let secret = thread_rng().gen::(); + let secret = random::(); let new_shares = world .upgraded_malicious( vec![secret].into_iter(), @@ -296,7 +297,7 @@ mod tests { ); let world = TestWorld::new_with(&config); let mut rng = thread_rng(); - let a = rng.gen::(); + let a = rng.r#gen::(); let to_helper = Role::H1; world diff --git a/ipa-core/src/protocol/basics/reveal.rs b/ipa-core/src/protocol/basics/reveal.rs index e38d31500..aefd7853e 100644 --- a/ipa-core/src/protocol/basics/reveal.rs +++ b/ipa-core/src/protocol/basics/reveal.rs @@ -34,21 +34,21 @@ use crate::{ error::Error, helpers::{Direction, MaybeFuture, Role}, protocol::{ + RecordId, boolean::step::TwoHundredFiftySixBitOpStep, context::{ Context, DZKPContext, DZKPUpgradedMaliciousContext, DZKPUpgradedSemiHonestContext, ShardedUpgradedMaliciousContext, UpgradedMaliciousContext, UpgradedSemiHonestContext, }, - RecordId, }, secret_sharing::{ + BitDecomposed, SharedValue, Vectorizable, replicated::{ malicious::{ AdditiveShare as MaliciousReplicated, ExtendableField, ExtendableFieldSimd, }, semi_honest::AdditiveShare as Replicated, }, - BitDecomposed, SharedValue, Vectorizable, }, sharding::ShardBinding, }; @@ -159,6 +159,9 @@ where /// ![Reveal steps][reveal] /// Each helper sends their left share to the right helper. The helper then reconstructs their secret by adding the three shares /// i.e. their own shares and received share. +/// +/// ## Errors +/// Returns an error if network send or receive operation fails. #[embed_doc_image("reveal", "images/reveal.png")] pub async fn semi_honest_reveal<'fut, C, V, const N: usize>( ctx: C, @@ -239,6 +242,9 @@ where /// It works similarly to semi-honest reveal, the key difference is that each helper sends its share /// to both helpers (right and left) and upon receiving 2 shares from peers it validates that they /// indeed match. +/// +/// ## Errors +/// Returns an error if network send or receive operation fails. pub async fn malicious_reveal<'fut, C, V, const N: usize>( ctx: C, record_id: RecordId, @@ -438,6 +444,9 @@ where S::generic_reveal(v, ctx, record_id, excluded) } +/// +/// ## Errors +/// Returns an error if network send or receive operation fails. pub async fn validated_partial_reveal<'fut, C, S>( ctx: C, record_id: RecordId, @@ -460,26 +469,26 @@ mod tests { use crate::{ error::Error, - ff::{boolean::Boolean, Field, Fp31, Fp32BitPrime}, + ff::{Field, Fp31, Fp32BitPrime, boolean::Boolean}, helpers::{ - in_memory_config::{MaliciousHelper, MaliciousHelperContext}, Role, + in_memory_config::{MaliciousHelper, MaliciousHelperContext}, }, protocol::{ - basics::{partial_reveal, reveal, Reveal}, + RecordId, + basics::{Reveal, partial_reveal, reveal}, context::{ - upgrade::Upgradable, validator::BatchValidator, Context, UpgradableContext, - Validator, + Context, UpgradableContext, Validator, upgrade::Upgradable, + validator::BatchValidator, }, - RecordId, }, - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, secret_sharing::{ - replicated::semi_honest::AdditiveShare, BitDecomposed, IntoShares, SecretSharing, - SharedValue, Vectorizable, + BitDecomposed, IntoShares, SecretSharing, SharedValue, Vectorizable, + replicated::semi_honest::AdditiveShare, }, test_executor::run, - test_fixture::{join3v, Runner, TestWorld, TestWorldConfig}, + test_fixture::{Runner, TestWorld, TestWorldConfig, join3v}, }; #[tokio::test] @@ -489,7 +498,7 @@ mod tests { let mut rng = thread_rng(); let world = TestWorld::default(); - let input = rng.gen::(); + let input = rng.r#gen::(); let results = world .dzkp_semi_honest(input, |ctx, share| async move { TestField::from_array( @@ -516,7 +525,7 @@ mod tests { let world = TestWorld::default(); for &excluded in Role::all() { - let input = rng.gen::(); + let input = rng.r#gen::(); let results = world .dzkp_semi_honest(input, |ctx, share| async move { share @@ -547,7 +556,7 @@ mod tests { let mut rng = thread_rng(); let world = TestWorld::default(); - let input = rng.gen::(); + let input = rng.r#gen::(); let results = world .dzkp_semi_honest( input, @@ -581,7 +590,7 @@ mod tests { let m_ctx = v.each_ref().map(BatchValidator::context); let record_id = RecordId::from(0); - let input: TestField = rng.gen(); + let input: TestField = rng.r#gen(); let m_shares = join3v( zip(m_ctx.iter(), input.share_with(&mut rng)).map(|(m_ctx, share)| async { @@ -620,7 +629,7 @@ mod tests { let m_ctx = v.each_ref().map(BatchValidator::context); let record_id = RecordId::from(0); - let input: TestField = rng.gen(); + let input: TestField = rng.r#gen(); let m_shares = join3v(zip(m_ctx.iter(), input.share_with(&mut rng)).map( |(m_ctx, share)| async { share.upgrade(m_ctx.clone(), RecordId::FIRST).await }, @@ -695,7 +704,7 @@ mod tests { MaliciousHelper::new(Role::H3, config.role_assignment(), interceptor::); let world = TestWorld::new_with(config); - let input: Fp31 = rng.gen(); + let input: Fp31 = rng.r#gen(); world .upgraded_malicious( vec![input].into_iter(), @@ -715,7 +724,7 @@ mod tests { MaliciousHelper::new(Role::H3, config.role_assignment(), interceptor::); let world = TestWorld::new_with(config); - let input: Fp31 = rng.gen(); + let input: Fp31 = rng.r#gen(); world .upgraded_malicious( vec![input].into_iter(), @@ -735,7 +744,7 @@ mod tests { MaliciousHelper::new(Role::H3, config.role_assignment(), interceptor::); let world = TestWorld::new_with(config); - let input: Boolean = rng.gen(); + let input: Boolean = rng.r#gen(); // ZKP malicious does not set the total records as `upgraded_malicious` // something to think about how to bring them closer together. world @@ -756,7 +765,7 @@ mod tests { MaliciousHelper::new(Role::H3, config.role_assignment(), interceptor::); let world = TestWorld::new_with(config); - let input: Boolean = rng.gen(); + let input: Boolean = rng.r#gen(); world .dzkp_malicious(input, |ctx, share| { do_malicious_reveal(ctx.set_total_records(1), partial, share) diff --git a/ipa-core/src/protocol/basics/shard_fin.rs b/ipa-core/src/protocol/basics/shard_fin.rs index ce817c13a..a3129a09f 100644 --- a/ipa-core/src/protocol/basics/shard_fin.rs +++ b/ipa-core/src/protocol/basics/shard_fin.rs @@ -6,20 +6,20 @@ use ipa_step::{Step, StepNarrow}; use crate::{ error::{Error, LengthError}, - ff::{boolean::Boolean, boolean_array::BooleanArray, Serializable}, + ff::{Serializable, boolean::Boolean, boolean_array::BooleanArray}, helpers::{Message, TotalRecords}, protocol::{ + BooleanProtocols, Gate, RecordId, boolean::step::ThirtyTwoBitStep, context::{ - dzkp_validator::DZKPValidator, DZKPContext, DZKPUpgradedMaliciousContext, - DZKPUpgradedSemiHonestContext, MaliciousProtocolSteps, ShardedContext, - ShardedMaliciousContext, ShardedSemiHonestContext, UpgradableContext, + DZKPContext, DZKPUpgradedMaliciousContext, DZKPUpgradedSemiHonestContext, + MaliciousProtocolSteps, ShardedContext, ShardedMaliciousContext, + ShardedSemiHonestContext, UpgradableContext, dzkp_validator::DZKPValidator, }, ipa_prf::boolean_ops::addition_sequential::integer_sat_add, - BooleanProtocols, Gate, RecordId, }, secret_sharing::{ - replicated::semi_honest::AdditiveShare, BitDecomposed, FieldSimd, TransposeFrom, + BitDecomposed, FieldSimd, TransposeFrom, replicated::semi_honest::AdditiveShare, }, seq_join::{assert_send, seq_join}, sharding::Sharded, @@ -315,11 +315,10 @@ where #[cfg(all(test, unit_test))] mod tests { - use std::iter::repeat; use crate::{ - ff::{boolean_array::BA8, U128Conversions}, - helpers::{in_memory_config::MaliciousHelper, Role}, + ff::{U128Conversions, boolean_array::BA8}, + helpers::{Role, in_memory_config::MaliciousHelper}, protocol::{ basics::shard_fin::{FinalizerContext, Histogram}, context::TEST_DZKP_STEPS, @@ -330,7 +329,7 @@ mod tests { }; /// generate some data to validate the integer addition finalizer - fn gen(values: [BA8; SHARDS]) -> impl Iterator + Clone { + fn gen_data(values: [BA8; SHARDS]) -> impl Iterator + Clone { let mut cnt = 0; // each shard receive the same value std::iter::from_fn(move || { @@ -346,7 +345,7 @@ mod tests { let world: TestWorld> = TestWorld::with_shards(TestWorldConfig::default()); - let input = gen::([ + let input = gen_data::([ BA8::truncate_from(10_u128), BA8::truncate_from(21_u128), BA8::truncate_from(3_u128), @@ -362,9 +361,7 @@ mod tests { // leader aggregates everything let leader_shares = results[0].reconstruct(); assert_eq!( - repeat(BA8::truncate_from(34_u128)) - .take(16) - .collect::>(), + std::iter::repeat_n(BA8::truncate_from(34_u128), 16).collect::>(), leader_shares ); @@ -383,7 +380,7 @@ mod tests { let world: TestWorld> = TestWorld::with_shards(TestWorldConfig::default()); - let input = gen::([ + let input = gen_data::([ BA8::truncate_from(1_u128), BA8::truncate_from(3_u128), BA8::truncate_from(5_u128), @@ -399,9 +396,7 @@ mod tests { // leader aggregates everything let leader_shares = results[0].reconstruct(); assert_eq!( - repeat(BA8::truncate_from(9_u128)) - .take(16) - .collect::>(), + std::iter::repeat_n(BA8::truncate_from(9_u128), 16).collect::>(), leader_shares ); @@ -433,7 +428,7 @@ mod tests { }); let world: TestWorld> = TestWorld::with_shards(config); - let input = gen::([ + let input = gen_data::([ BA8::truncate_from(1_u128), BA8::truncate_from(3_u128), BA8::truncate_from(5_u128), diff --git a/ipa-core/src/protocol/basics/share_known_value.rs b/ipa-core/src/protocol/basics/share_known_value.rs index 052356e4f..9a694e0d2 100644 --- a/ipa-core/src/protocol/basics/share_known_value.rs +++ b/ipa-core/src/protocol/basics/share_known_value.rs @@ -2,8 +2,8 @@ use crate::{ helpers::Role, protocol::context::Context, secret_sharing::{ - replicated::{semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing}, SharedValue, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare as Replicated}, }, }; @@ -46,7 +46,7 @@ mod tests { let world = TestWorld::default(); let mut rng = rand::thread_rng(); - let a = rng.gen::(); + let a = rng.r#gen::(); let result = world .semi_honest((), |ctx, ()| async move { diff --git a/ipa-core/src/protocol/basics/share_validation.rs b/ipa-core/src/protocol/basics/share_validation.rs index 492b99973..86959e9dc 100644 --- a/ipa-core/src/protocol/basics/share_validation.rs +++ b/ipa-core/src/protocol/basics/share_validation.rs @@ -4,10 +4,10 @@ use subtle::ConstantTimeEq; use crate::{ error::Error, helpers::{ - hashing::{compute_hash, Hash}, Direction, TotalRecords, + hashing::{Hash, compute_hash}, }, - protocol::{context::Context, RecordId}, + protocol::{RecordId, context::Context}, secret_sharing::SharedValue, }; @@ -93,7 +93,7 @@ where mod test { use std::ops::Neg; - use rand::{thread_rng, Rng}; + use rand::{Rng, thread_rng}; use crate::{ error::Error, @@ -120,7 +120,7 @@ mod test { let len: usize = rng.gen_range(50..100); let r = (0..len) - .map(|_| rng.gen::()) + .map(|_| rng.r#gen::()) .collect::>(); let _ = world diff --git a/ipa-core/src/protocol/boolean/and.rs b/ipa-core/src/protocol/boolean/and.rs index 9afbfd9af..c40cb6ba5 100644 --- a/ipa-core/src/protocol/boolean/and.rs +++ b/ipa-core/src/protocol/boolean/and.rs @@ -4,12 +4,12 @@ use crate::{ error::Error, ff::boolean::Boolean, protocol::{ + RecordId, basics::SecureMul, - boolean::{step::EightBitStep, NBitStep}, + boolean::{NBitStep, step::EightBitStep}, context::Context, - RecordId, }, - secret_sharing::{replicated::semi_honest::AdditiveShare, BitDecomposed, FieldSimd}, + secret_sharing::{BitDecomposed, FieldSimd, replicated::semi_honest::AdditiveShare}, }; /// Matrix bitwise AND for use with vectors of bit-decomposed values. Supports up to 8 bits of input diff --git a/ipa-core/src/protocol/boolean/or.rs b/ipa-core/src/protocol/boolean/or.rs index da07c35cd..55e797d61 100644 --- a/ipa-core/src/protocol/boolean/or.rs +++ b/ipa-core/src/protocol/boolean/or.rs @@ -4,11 +4,11 @@ use ipa_step::StepNarrow; use crate::{ error::Error, - ff::{boolean::Boolean, Field}, - protocol::{basics::SecureMul, boolean::NBitStep, context::Context, Gate, RecordId}, + ff::{Field, boolean::Boolean}, + protocol::{Gate, RecordId, basics::SecureMul, boolean::NBitStep, context::Context}, secret_sharing::{ - replicated::semi_honest::AdditiveShare, BitDecomposed, FieldSimd, - Linear as LinearSecretSharing, + BitDecomposed, FieldSimd, Linear as LinearSecretSharing, + replicated::semi_honest::AdditiveShare, }, }; @@ -73,8 +73,8 @@ mod tests { use super::or; use crate::{ ff::{Field, Fp31}, - protocol::{context::Context, RecordId}, - secret_sharing::{replicated::malicious::ExtendableField, SharedValue}, + protocol::{RecordId, context::Context}, + secret_sharing::{SharedValue, replicated::malicious::ExtendableField}, test_fixture::{Reconstruct, Runner, TestWorld}, }; diff --git a/ipa-core/src/protocol/context/batcher.rs b/ipa-core/src/protocol/context/batcher.rs index 974968bcf..77ab0deee 100644 --- a/ipa-core/src/protocol/context/batcher.rs +++ b/ipa-core/src/protocol/context/batcher.rs @@ -6,7 +6,7 @@ use tokio::sync::watch; use crate::{ error::Error, helpers::TotalRecords, - protocol::{context::dzkp_validator::TARGET_PROOF_SIZE, RecordId}, + protocol::{RecordId, context::dzkp_validator::TARGET_PROOF_SIZE}, sync::Mutex, }; @@ -208,7 +208,7 @@ impl<'a, B> Batcher<'a, B> { &mut self, record_id: RecordId, validate_batch: VF, - ) -> impl Future> + ) -> impl Future> + use where VF: FnOnce(usize, B) -> Fut, Fut: Future>, @@ -286,8 +286,8 @@ mod tests { use std::{future::ready, pin::pin}; use futures::{ - future::{join_all, poll_immediate, try_join, try_join3, try_join4}, FutureExt, + future::{join_all, poll_immediate, try_join, try_join3, try_join4}, }; use super::*; @@ -413,28 +413,36 @@ mod tests { .push(i); } - let mut fut0 = pin!(batcher - .lock() - .unwrap() - .validate_record(RecordId::from(0), |_i, _b| async { unreachable!() })); - let fut1 = pin!(batcher - .lock() - .unwrap() - .validate_record(RecordId::from(1), |i, b| { - assert!(i == 0 && b.as_slice() == [0, 1]); - ready(Ok(())) - })); - let mut fut2 = pin!(batcher - .lock() - .unwrap() - .validate_record(RecordId::from(2), |_i, _b| async { unreachable!() })); - let fut3 = pin!(batcher - .lock() - .unwrap() - .validate_record(RecordId::from(3), |i, b| { - assert!(i == 1 && b.as_slice() == [2, 3]); - ready(Ok(())) - })); + let mut fut0 = pin!( + batcher + .lock() + .unwrap() + .validate_record(RecordId::from(0), |_i, _b| async { unreachable!() }) + ); + let fut1 = pin!( + batcher + .lock() + .unwrap() + .validate_record(RecordId::from(1), |i, b| { + assert!(i == 0 && b.as_slice() == [0, 1]); + ready(Ok(())) + }) + ); + let mut fut2 = pin!( + batcher + .lock() + .unwrap() + .validate_record(RecordId::from(2), |_i, _b| async { unreachable!() }) + ); + let fut3 = pin!( + batcher + .lock() + .unwrap() + .validate_record(RecordId::from(3), |i, b| { + assert!(i == 1 && b.as_slice() == [2, 3]); + ready(Ok(())) + }) + ); assert!(poll_immediate(&mut fut0).await.is_none()); assert!(poll_immediate(&mut fut2).await.is_none()); @@ -462,28 +470,36 @@ mod tests { .push(i); } - let mut fut0 = pin!(batcher - .lock() - .unwrap() - .validate_record(RecordId::from(0), |_i, _b| async { unreachable!() })); - let fut1 = pin!(batcher - .lock() - .unwrap() - .validate_record(RecordId::from(1), |i, b| { - assert!(i == 0 && b.as_slice() == [0, 1]); - ready(Err(Error::DZKPValidationFailed)) - })); - let mut fut2 = pin!(batcher - .lock() - .unwrap() - .validate_record(RecordId::from(2), |_i, _b| async { unreachable!() })); - let fut3 = pin!(batcher - .lock() - .unwrap() - .validate_record(RecordId::from(3), |i, b| { - assert!(i == 1 && b.as_slice() == [2, 3]); - ready(Ok(())) - })); + let mut fut0 = pin!( + batcher + .lock() + .unwrap() + .validate_record(RecordId::from(0), |_i, _b| async { unreachable!() }) + ); + let fut1 = pin!( + batcher + .lock() + .unwrap() + .validate_record(RecordId::from(1), |i, b| { + assert!(i == 0 && b.as_slice() == [0, 1]); + ready(Err(Error::DZKPValidationFailed)) + }) + ); + let mut fut2 = pin!( + batcher + .lock() + .unwrap() + .validate_record(RecordId::from(2), |_i, _b| async { unreachable!() }) + ); + let fut3 = pin!( + batcher + .lock() + .unwrap() + .validate_record(RecordId::from(3), |i, b| { + assert!(i == 1 && b.as_slice() == [2, 3]); + ready(Ok(())) + }) + ); assert!(poll_immediate(&mut fut0).await.is_none()); assert!(poll_immediate(&mut fut2).await.is_none()); diff --git a/ipa-core/src/protocol/context/dzkp_field.rs b/ipa-core/src/protocol/context/dzkp_field.rs index 38babdb27..36aa155c1 100644 --- a/ipa-core/src/protocol/context/dzkp_field.rs +++ b/ipa-core/src/protocol/context/dzkp_field.rs @@ -370,12 +370,12 @@ pub mod tests { use bitvec::{array::BitArray, macros::internal::funty::Fundamental}; use proptest::proptest; - use rand::{thread_rng, Rng}; + use rand::{Rng, thread_rng}; use crate::{ ff::{Field, Fp61BitPrime, U128Conversions}, protocol::context::{ - dzkp_field::{bits_to_table_indices, DZKPBaseField, TABLE_U, TABLE_V}, + dzkp_field::{DZKPBaseField, TABLE_U, TABLE_V, bits_to_table_indices}, dzkp_validator::MultiplicationInputsBlock, }, secret_sharing::SharedValue, @@ -394,9 +394,9 @@ pub mod tests { assert_eq!(z3, 0x73_u128); let mut rng = thread_rng(); - let b0 = rng.gen(); - let b1 = rng.gen(); - let b2 = rng.gen(); + let b0 = rng.r#gen(); + let b1 = rng.r#gen(); + let b2 = rng.r#gen(); let [z0, z1, z2, z3] = bits_to_table_indices(b0, b1, b2); for i in (0..128).step_by(4) { @@ -463,7 +463,7 @@ pub mod tests { #[test] fn batch_convert() { run_random(|mut rng| async move { - let block = rng.gen::(); + let block = rng.r#gen::(); // When verifying, we rotate the intermediates to match what each prover // would have. `rotate_right` also calculates z_right from the others. diff --git a/ipa-core/src/protocol/context/dzkp_malicious.rs b/ipa-core/src/protocol/context/dzkp_malicious.rs index 577d209a1..fc8fce940 100644 --- a/ipa-core/src/protocol/context/dzkp_malicious.rs +++ b/ipa-core/src/protocol/context/dzkp_malicious.rs @@ -12,13 +12,13 @@ use crate::{ Message, MpcMessage, MpcReceivingEnd, Role, SendingEnd, ShardReceivingEnd, TotalRecords, }, protocol::{ + Gate, RecordId, context::{ - dzkp_validator::{Batch, MaliciousDZKPValidatorInner, Segment}, - prss::InstrumentedIndexedSharedRandomness, Context as ContextTrait, DZKPContext, InstrumentedSequentialSharedRandomness, MaliciousContext, ShardedContext, + dzkp_validator::{Batch, MaliciousDZKPValidatorInner, Segment}, + prss::InstrumentedIndexedSharedRandomness, }, - Gate, RecordId, }, seq_join::SeqJoin, sharding::{ShardBinding, ShardConfiguration, ShardIndex, Sharded}, diff --git a/ipa-core/src/protocol/context/dzkp_semi_honest.rs b/ipa-core/src/protocol/context/dzkp_semi_honest.rs index 24925970d..73d59ff79 100644 --- a/ipa-core/src/protocol/context/dzkp_semi_honest.rs +++ b/ipa-core/src/protocol/context/dzkp_semi_honest.rs @@ -13,11 +13,11 @@ use crate::{ Message, MpcMessage, MpcReceivingEnd, Role, SendingEnd, ShardReceivingEnd, TotalRecords, }, protocol::{ + Gate, RecordId, context::{ Base, DZKPContext, InstrumentedIndexedSharedRandomness, InstrumentedSequentialSharedRandomness, }, - Gate, RecordId, }, seq_join::SeqJoin, sharding::{ShardBinding, ShardConfiguration, ShardIndex, Sharded}, @@ -89,8 +89,8 @@ impl super::Context for DZKPUpgraded<'_, B> { fn prss_rng( &self, ) -> ( - InstrumentedSequentialSharedRandomness, - InstrumentedSequentialSharedRandomness, + InstrumentedSequentialSharedRandomness<'_>, + InstrumentedSequentialSharedRandomness<'_>, ) { self.inner.prss_rng() } diff --git a/ipa-core/src/protocol/context/dzkp_validator.rs b/ipa-core/src/protocol/context/dzkp_validator.rs index b5386997c..4ede763c0 100644 --- a/ipa-core/src/protocol/context/dzkp_validator.rs +++ b/ipa-core/src/protocol/context/dzkp_validator.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, fmt::Debug, future::ready}; use async_trait::async_trait; use bitvec::prelude::{BitArray, BitSlice, Lsb0}; -use futures::{stream, Future, FutureExt, Stream, StreamExt}; +use futures::{Future, FutureExt, Stream, StreamExt, stream}; use ipa_step::StepNarrow; use crate::{ @@ -10,22 +10,22 @@ use crate::{ ff::{Fp61BitPrime, U128Conversions}, helpers::TotalRecords, protocol::{ + Gate, RecordId, RecordIdRange, context::{ + Base, Context, DZKPContext, MaliciousContext, MaliciousProtocolSteps, batcher::Batcher, dzkp_field::{DZKPBaseField, TABLE_U, TABLE_V}, dzkp_malicious::DZKPUpgraded as MaliciousDZKPUpgraded, dzkp_semi_honest::DZKPUpgraded as SemiHonestDZKPUpgraded, step::DzkpValidationProtocolStep as Step, - Base, Context, DZKPContext, MaliciousContext, MaliciousProtocolSteps, }, ipa_prf::{ - validation_protocol::{proof_generation::ProofBatch, validation::BatchToVerify}, CompressedProofGenerator, FirstProofGenerator, ProverTableIndices, VerifierTableIndices, + validation_protocol::{proof_generation::ProofBatch, validation::BatchToVerify}, }, - Gate, RecordId, RecordIdRange, }, - seq_join::{seq_join, SeqJoin}, + seq_join::{SeqJoin, seq_join}, sharding::ShardBinding, sync::{Arc, Mutex}, }; @@ -938,7 +938,7 @@ mod tests { }; use bitvec::{order::Lsb0, prelude::BitArray, vec::BitVec}; - use futures::{stream, StreamExt, TryStreamExt}; + use futures::{StreamExt, TryStreamExt, stream}; use futures_util::stream::iter; use proptest::{ prelude::{Just, Strategy}, @@ -950,30 +950,30 @@ mod tests { error::Error, ff::{ boolean::Boolean, - boolean_array::{BooleanArray, BA16, BA20, BA256, BA3, BA32, BA64, BA8}, + boolean_array::{BA3, BA8, BA16, BA20, BA32, BA64, BA256, BooleanArray}, }, protocol::{ - basics::{select, BooleanArrayMul, SecureMul}, + Gate, RecordId, + basics::{BooleanArrayMul, SecureMul, select}, context::{ + Context, DZKPUpgradedMaliciousContext, DZKPUpgradedSemiHonestContext, + TEST_DZKP_STEPS, UpgradableContext, dzkp_field::DZKPCompatibleField, dzkp_validator::{ - Batch, DZKPValidator, Segment, SegmentEntry, BIT_ARRAY_LEN, TARGET_PROOF_SIZE, + BIT_ARRAY_LEN, Batch, DZKPValidator, Segment, SegmentEntry, TARGET_PROOF_SIZE, }, - Context, DZKPUpgradedMaliciousContext, DZKPUpgradedSemiHonestContext, - UpgradableContext, TEST_DZKP_STEPS, }, - Gate, RecordId, }, - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, secret_sharing::{ - replicated::semi_honest::AdditiveShare as Replicated, IntoShares, SharedValue, - Vectorizable, + IntoShares, SharedValue, Vectorizable, + replicated::semi_honest::AdditiveShare as Replicated, }, - seq_join::{seq_join, SeqJoin}, + seq_join::{SeqJoin, seq_join}, sharding::NotSharded, test_executor::run_random, test_fixture::{ - join3v, mpc_proptest_config, Reconstruct, Runner, TestWorld, TestWorldConfig, + Reconstruct, Runner, TestWorld, TestWorldConfig, join3v, mpc_proptest_config, }, }; @@ -987,9 +987,9 @@ mod tests { let context = world.contexts(); let mut rng = thread_rng(); - let bit = rng.gen::(); - let a = rng.gen::(); - let b = rng.gen::(); + let bit = rng.r#gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let bit_shares = bit.share_with(&mut rng); let a_shares = a.share_with(&mut rng); @@ -1043,9 +1043,9 @@ mod tests { let context = world.malicious_contexts(); let mut rng = thread_rng(); - let bit = rng.gen::(); - let a = rng.gen::(); - let b = rng.gen::(); + let bit = rng.r#gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let bit_shares = bit.share_with(&mut rng); let a_shares = a.share_with(&mut rng); @@ -1094,7 +1094,7 @@ mod tests { const COUNT: usize = 32; let mut rng = thread_rng(); - let original_inputs = repeat_with(|| rng.gen()) + let original_inputs = repeat_with(|| rng.r#gen()) .take(COUNT) .collect::>(); @@ -1159,9 +1159,9 @@ mod tests { { let mut rng = thread_rng(); - let bit: Vec = repeat_with(|| rng.gen::()).take(count).collect(); - let a: Vec = repeat_with(|| rng.gen()).take(count).collect(); - let b: Vec = repeat_with(|| rng.gen()).take(count).collect(); + let bit: Vec = repeat_with(|| rng.r#gen::()).take(count).collect(); + let a: Vec = repeat_with(|| rng.r#gen()).take(count).collect(); + let b: Vec = repeat_with(|| rng.r#gen()).take(count).collect(); // Timeout is 10 seconds plus count * (3 ms). let config = TestWorldConfig::default() @@ -1211,7 +1211,7 @@ mod tests { let mut rng = thread_rng(); let original_inputs = (0..count) - .map(|_| rng.gen::()) + .map(|_| rng.r#gen::()) .collect::>(); let shared_inputs: Vec<[Replicated; 3]> = original_inputs @@ -1369,9 +1369,9 @@ mod tests { let count: usize = TARGET_PROOF_SIZE + 1; let mut rng = thread_rng(); - let bit: Vec = repeat_with(|| rng.gen::()).take(count).collect(); - let a: Vec = repeat_with(|| rng.gen()).take(count).collect(); - let b: Vec = repeat_with(|| rng.gen()).take(count).collect(); + let bit: Vec = repeat_with(|| rng.r#gen::()).take(count).collect(); + let a: Vec = repeat_with(|| rng.r#gen()).take(count).collect(); + let b: Vec = repeat_with(|| rng.r#gen()).take(count).collect(); let config = TestWorldConfig::default().with_timeout_secs(60); let world = TestWorld::::with_config(&config); @@ -1420,8 +1420,8 @@ mod tests { async fn missing_validate() { let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); TestWorld::default() .malicious((a, b), |ctx, (a, b)| async move { @@ -1441,8 +1441,8 @@ mod tests { async fn missing_validate_panic() { let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); TestWorld::default() .malicious((a, b), |ctx, (a, b)| async move { @@ -1531,9 +1531,9 @@ mod tests { fn batch_fill_out_of_order() { run_random(|mut rng| async move { let mut batch = Batch::with_implicit_first_record(3); - let ba0 = rng.gen::(); - let ba1 = rng.gen::(); - let ba2 = rng.gen::(); + let ba0 = rng.r#gen::(); + let ba1 = rng.r#gen::(); + let ba2 = rng.r#gen::(); let segment = segment_from_entry( >::as_segment_entry(&ba0), ); @@ -1567,9 +1567,9 @@ mod tests { run_random(|mut rng| async move { const SIZE: usize = 3; let mut batch = Batch::with_implicit_first_record(SIZE); - let ba0 = rng.gen::(); - let ba1 = rng.gen::(); - let ba2 = rng.gen::(); + let ba0 = rng.r#gen::(); + let ba1 = rng.r#gen::(); + let ba2 = rng.r#gen::(); let segment = segment_from_entry( >::as_segment_entry(&ba0), ); @@ -1603,7 +1603,7 @@ mod tests { run_random(|mut rng| async move { const SIZE: usize = 3; let mut batch = Batch::new(Some(RecordId::from(4)), SIZE); - let ba6 = rng.gen::(); + let ba6 = rng.r#gen::(); let segment = segment_from_entry( >::as_segment_entry(&ba6), ); @@ -1672,12 +1672,12 @@ mod tests { let mut rng = thread_rng(); // vec for segments - let vec_x_left = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_x_right = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_y_left = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_y_right = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_prss_left = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_prss_right = (0..1024).map(|_| rng.gen::()).collect::>(); + let vec_x_left = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_x_right = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_y_left = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_y_right = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_prss_left = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_prss_right = (0..1024).map(|_| rng.r#gen::()).collect::>(); // compute z let vec_z_left = vec_x_left.clone() & vec_y_left.clone() @@ -1689,11 +1689,11 @@ mod tests { // vector for unchecked elements // i.e. these are used to fill the segments of the verifier and prover that are not part // of this povers proof - let vec_x_3rd_share = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_y_3rd_share = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_z_right = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_prss_3rd_share = (0..1024).map(|_| rng.gen::()).collect::>(); - let vec_z_3rd_share = (0..1024).map(|_| rng.gen::()).collect::>(); + let vec_x_3rd_share = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_y_3rd_share = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_z_right = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_prss_3rd_share = (0..1024).map(|_| rng.r#gen::()).collect::>(); + let vec_z_3rd_share = (0..1024).map(|_| rng.r#gen::()).collect::>(); // generate and push segments for i in 0..1024 / segment_size { @@ -1857,8 +1857,8 @@ mod tests { let world = TestWorld::default(); let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let [h1_batch, h2_batch, h3_batch] = world .malicious((a, b), |ctx, (a, b)| async move { diff --git a/ipa-core/src/protocol/context/malicious.rs b/ipa-core/src/protocol/context/malicious.rs index 609e4a518..a985ca368 100644 --- a/ipa-core/src/protocol/context/malicious.rs +++ b/ipa-core/src/protocol/context/malicious.rs @@ -14,19 +14,19 @@ use crate::{ TotalRecords, }, protocol::{ + Gate, RecordId, basics::mul::{semi_honest_multiply, step::MaliciousMultiplyStep::RandomnessForValidation}, context::{ + Base, Context as ContextTrait, InstrumentedSequentialSharedRandomness, ShardedContext, + SpecialAccessToUpgradedContext, UpgradableContext, UpgradedContext, batcher::Batcher, dzkp_validator::MaliciousDZKPValidator, prss::InstrumentedIndexedSharedRandomness, step::UpgradeStep, upgrade::Upgradable, validator::{self, BatchValidator}, - Base, Context as ContextTrait, InstrumentedSequentialSharedRandomness, ShardedContext, - SpecialAccessToUpgradedContext, UpgradableContext, UpgradedContext, }, prss::{Endpoint as PrssEndpoint, FromPrss}, - Gate, RecordId, }, secret_sharing::replicated::{ malicious::{AdditiveShare as MaliciousReplicated, ExtendableField, ExtendableFieldSimd}, @@ -148,8 +148,8 @@ impl super::Context for Context<'_, B> { fn prss_rng( &self, ) -> ( - InstrumentedSequentialSharedRandomness, - InstrumentedSequentialSharedRandomness, + InstrumentedSequentialSharedRandomness<'_>, + InstrumentedSequentialSharedRandomness<'_>, ) { self.inner.prss_rng() } diff --git a/ipa-core/src/protocol/context/mod.rs b/ipa-core/src/protocol/context/mod.rs index f0f906969..14f78d35a 100644 --- a/ipa-core/src/protocol/context/mod.rs +++ b/ipa-core/src/protocol/context/mod.rs @@ -16,7 +16,7 @@ use std::{collections::HashMap, num::NonZeroUsize, pin::pin}; use async_trait::async_trait; pub use dzkp_malicious::DZKPUpgraded as DZKPUpgradedMaliciousContext; pub use dzkp_semi_honest::DZKPUpgraded as DZKPUpgradedSemiHonestContext; -use futures::{stream, Stream, StreamExt, TryStreamExt}; +use futures::{Stream, StreamExt, TryStreamExt, stream}; use ipa_step::{Step, StepNarrow}; pub use malicious::MaliciousProtocolSteps; use prss::{InstrumentedIndexedSharedRandomness, InstrumentedSequentialSharedRandomness}; @@ -36,13 +36,13 @@ pub(crate) use malicious::TEST_DZKP_STEPS; use crate::{ error::Error, helpers::{ - stream::ExactSizeStream, ChannelId, Direction, Gateway, Message, MpcMessage, - MpcReceivingEnd, Role, SendingEnd, ShardReceivingEnd, TotalRecords, + ChannelId, Direction, Gateway, Message, MpcMessage, MpcReceivingEnd, Role, SendingEnd, + ShardReceivingEnd, TotalRecords, stream::ExactSizeStream, }, protocol::{ + Gate, RecordId, context::dzkp_validator::DZKPValidator, prss::{Endpoint as PrssEndpoint, SharedRandomness}, - Gate, RecordId, }, secret_sharing::replicated::malicious::ExtendableField, seq_join::SeqJoin, @@ -95,8 +95,8 @@ pub trait Context: Clone + Send + Sync + SeqJoin { fn prss_rng( &self, ) -> ( - InstrumentedSequentialSharedRandomness, - InstrumentedSequentialSharedRandomness, + InstrumentedSequentialSharedRandomness<'_>, + InstrumentedSequentialSharedRandomness<'_>, ); /// Open a communication channel to an MPC peer. This channel can be requested multiple times @@ -258,7 +258,7 @@ impl Context for Base<'_, B> { self.total_records } - fn prss(&self) -> InstrumentedIndexedSharedRandomness { + fn prss(&self) -> InstrumentedIndexedSharedRandomness<'_> { let prss = self.inner.prss.indexed(self.gate()); InstrumentedIndexedSharedRandomness::new(prss, &self.gate, self.role()) @@ -620,38 +620,38 @@ pub trait DZKPContext: Context { mod tests { use std::{iter, iter::repeat, pin::Pin, task::Poll}; - use futures::{future::join_all, ready, stream, stream::StreamExt, try_join, Stream}; + use futures::{Stream, future::join_all, ready, stream, stream::StreamExt, try_join}; use ipa_step::StepNarrow; use pin_project::pin_project; use rand::{ - distributions::{Distribution, Standard}, Rng, + distributions::{Distribution, Standard}, }; use typenum::Unsigned; use crate::{ ff::{ - boolean_array::{BA3, BA64, BA8}, Field, Fp31, Serializable, U128Conversions, + boolean_array::{BA3, BA8, BA64}, }, helpers::{Direction, Role}, protocol::{ + RecordId, basics::ShareKnownValue, context::{ - reshard_iter, reshard_stream, reshard_try_stream, - step::MaliciousProtocolStep::MaliciousProtocol, upgrade::Upgradable, Context, - ShardedContext, UpgradableContext, Validator, + Context, ShardedContext, UpgradableContext, Validator, reshard_iter, + reshard_stream, reshard_try_stream, step::MaliciousProtocolStep::MaliciousProtocol, + upgrade::Upgradable, }, prss::SharedRandomness, - RecordId, }, secret_sharing::{ + SharedValue, replicated::{ + ReplicatedSecretSharing, malicious::{AdditiveShare as MaliciousReplicated, ExtendableField}, semi_honest::AdditiveShare as Replicated, - ReplicatedSecretSharing, }, - SharedValue, }, sharding::{ShardConfiguration, ShardIndex}, telemetry::metrics::{ @@ -710,8 +710,8 @@ mod tests { // have special constructor method for them: `next_u32`. Sequential randomness must // record metrics for both calls. ( - left_rng.gen::() + F::truncate_from(left_rng.gen::()), - right_rng.gen::() + F::truncate_from(right_rng.gen::()), + left_rng.r#gen::() + F::truncate_from(left_rng.r#gen::()), + right_rng.r#gen::() + F::truncate_from(right_rng.r#gen::()), ) }; diff --git a/ipa-core/src/protocol/context/prss.rs b/ipa-core/src/protocol/context/prss.rs index a2427da1c..424fe9736 100644 --- a/ipa-core/src/protocol/context/prss.rs +++ b/ipa-core/src/protocol/context/prss.rs @@ -7,8 +7,8 @@ use rand_core::{CryptoRng, Error, RngCore}; use crate::{ helpers::{Direction, Role}, protocol::{ - prss::{IndexedSharedRandomness, PrssIndex, SequentialSharedRandomness, SharedRandomness}, Gate, + prss::{IndexedSharedRandomness, PrssIndex, SequentialSharedRandomness, SharedRandomness}, }, sync::Arc, telemetry::{ diff --git a/ipa-core/src/protocol/context/semi_honest.rs b/ipa-core/src/protocol/context/semi_honest.rs index 5c75aec4b..35d64a47f 100644 --- a/ipa-core/src/protocol/context/semi_honest.rs +++ b/ipa-core/src/protocol/context/semi_honest.rs @@ -15,19 +15,19 @@ use crate::{ TotalRecords, }, protocol::{ + Gate, RecordId, context::{ + Base, Context as _, InstrumentedIndexedSharedRandomness, + InstrumentedSequentialSharedRandomness, MaliciousProtocolSteps, ShardedContext, + SpecialAccessToUpgradedContext, UpgradableContext, UpgradedContext, dzkp_validator::SemiHonestDZKPValidator, step::MaliciousProtocolStep, - upgrade::Upgradable, validator::SemiHonest as Validator, Base, Context as _, - InstrumentedIndexedSharedRandomness, InstrumentedSequentialSharedRandomness, - MaliciousProtocolSteps, ShardedContext, SpecialAccessToUpgradedContext, - UpgradableContext, UpgradedContext, + upgrade::Upgradable, validator::SemiHonest as Validator, }, prss::Endpoint as PrssEndpoint, - Gate, RecordId, }, secret_sharing::{ - replicated::{malicious::ExtendableField, semi_honest::AdditiveShare as Replicated}, Vectorizable, + replicated::{malicious::ExtendableField, semi_honest::AdditiveShare as Replicated}, }, seq_join::SeqJoin, sharding::{NotSharded, ShardBinding, ShardConfiguration, ShardIndex, Sharded}, @@ -81,7 +81,7 @@ impl<'a> Context<'a, Sharded> { } } -#[allow(clippy::needless_lifetimes)] // Lifetime may not live long enough, if lifetime is dropped +#[allow(clippy::needless_lifetimes, clippy::elidable_lifetime_names)] // Lifetime may not live long enough, if lifetime is dropped impl<'a, B: ShardBinding> Context<'a, B> { #[cfg(test)] #[must_use] @@ -139,8 +139,8 @@ impl super::Context for Context<'_, B> { fn prss_rng( &self, ) -> ( - InstrumentedSequentialSharedRandomness, - InstrumentedSequentialSharedRandomness, + InstrumentedSequentialSharedRandomness<'_>, + InstrumentedSequentialSharedRandomness<'_>, ) { self.inner.prss_rng() } @@ -260,8 +260,8 @@ impl super::Context for Upgraded<'_, B, F> fn prss_rng( &self, ) -> ( - InstrumentedSequentialSharedRandomness, - InstrumentedSequentialSharedRandomness, + InstrumentedSequentialSharedRandomness<'_>, + InstrumentedSequentialSharedRandomness<'_>, ) { self.inner.prss_rng() } diff --git a/ipa-core/src/protocol/context/upgrade.rs b/ipa-core/src/protocol/context/upgrade.rs index bd70a1d7b..075a26766 100644 --- a/ipa-core/src/protocol/context/upgrade.rs +++ b/ipa-core/src/protocol/context/upgrade.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use crate::{ error::Error, - protocol::{context::UpgradedContext, RecordId}, + protocol::{RecordId, context::UpgradedContext}, }; /// This trait is implemented by secret sharing types that can be upgraded. diff --git a/ipa-core/src/protocol/context/validator.rs b/ipa-core/src/protocol/context/validator.rs index a71b395c3..ff5c7b7c7 100644 --- a/ipa-core/src/protocol/context/validator.rs +++ b/ipa-core/src/protocol/context/validator.rs @@ -9,26 +9,26 @@ use crate::{ ff::Field, helpers::{Direction, TotalRecords}, protocol::{ + RecordId, basics::{check_zero::malicious_check_zero, malicious_reveal}, context::{ + Base, Context, MaliciousContext, UpgradedContext, UpgradedMaliciousContext, + UpgradedSemiHonestContext, batcher::Batcher, malicious::MacBatcher, step::{MaliciousProtocolStep as Step, ValidateStep}, - Base, Context, MaliciousContext, UpgradedContext, UpgradedMaliciousContext, - UpgradedSemiHonestContext, }, prss::{FromPrss, SharedRandomness}, - RecordId, }, secret_sharing::{ + FieldSimd, SharedValue, replicated::{ + ReplicatedSecretSharing, malicious::{ AdditiveShare as MaliciousReplicated, ExtendableField, ExtendableFieldSimd, }, semi_honest::AdditiveShare as Replicated, - ReplicatedSecretSharing, }, - FieldSimd, SharedValue, }, seq_join::SeqJoin, sharding::ShardBinding, @@ -401,23 +401,23 @@ mod tests { ff::{Field, Fp31, Fp32BitPrime}, helpers::Role, protocol::{ + RecordId, basics::SecureMul, context::{ - upgrade::Upgradable, validator::Validator, Context, UpgradableContext, - UpgradedContext, + Context, UpgradableContext, UpgradedContext, upgrade::Upgradable, + validator::Validator, }, - RecordId, }, - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, secret_sharing::{ + IntoShares, replicated::{ - malicious::ThisCodeIsAuthorizedToDowngradeFromMalicious, - semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing, + ReplicatedSecretSharing, malicious::ThisCodeIsAuthorizedToDowngradeFromMalicious, + semi_honest::AdditiveShare as Replicated, }, - IntoShares, }, seq_join::SeqJoin, - test_fixture::{join3v, Reconstruct, Runner, TestWorld}, + test_fixture::{Reconstruct, Runner, TestWorld, join3v}, }; /// This is the simplest arithmetic circuit that allows us to test all of the pieces of this validator @@ -440,8 +440,8 @@ mod tests { let context = world.malicious_contexts(); let mut rng = thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); let a_shares = a.share_with(&mut rng); let b_shares = b.share_with(&mut rng); @@ -488,7 +488,7 @@ mod tests { let world = TestWorld::default(); let mut rng = thread_rng(); - let a = rng.gen::(); + let a = rng.r#gen::(); let result = world .malicious(a, |ctx, a| async move { @@ -508,7 +508,7 @@ mod tests { let world = TestWorld::default(); let mut rng = thread_rng(); - let a = rng.gen::(); + let a = rng.r#gen::(); for malicious_actor in Role::all() { world @@ -560,7 +560,7 @@ mod tests { let mut original_inputs = Vec::with_capacity(COUNT); for _ in 0..COUNT { - let x = rng.gen::(); + let x = rng.r#gen::(); original_inputs.push(x); } let shared_inputs: Vec<[Replicated; 3]> = original_inputs diff --git a/ipa-core/src/protocol/dp/mod.rs b/ipa-core/src/protocol/dp/mod.rs index b40a81d96..bd0cbd9a7 100644 --- a/ipa-core/src/protocol/dp/mod.rs +++ b/ipa-core/src/protocol/dp/mod.rs @@ -3,7 +3,7 @@ pub mod step; use std::{convert::Infallible, f64}; -use futures_util::{stream, StreamExt}; +use futures_util::{StreamExt, stream}; use rand_core::{CryptoRng, RngCore}; use crate::{ @@ -11,13 +11,14 @@ use crate::{ Error::{self, EpsilonOutOfBounds}, LengthError, }, - ff::{boolean::Boolean, boolean_array::BooleanArray, U128Conversions}, - helpers::{query::DpMechanism, Direction, Role, TotalRecords}, + ff::{U128Conversions, boolean::Boolean, boolean_array::BooleanArray}, + helpers::{Direction, Role, TotalRecords, query::DpMechanism}, protocol::{ + BooleanProtocols, RecordId, boolean::step::ThirtyTwoBitStep, context::{ - dzkp_validator::DZKPValidator, Context, DZKPUpgraded, MaliciousProtocolSteps, - UpgradableContext, + Context, DZKPUpgraded, MaliciousProtocolSteps, UpgradableContext, + dzkp_validator::DZKPValidator, }, dp::step::{ApplyDpNoise, DPStep}, hybrid::step::HybridStep, @@ -27,11 +28,10 @@ use crate::{ oprf_padding::insecure::OPRFPaddingDp, }, prss::{FromPrss, SharedRandomness}, - BooleanProtocols, RecordId, }, secret_sharing::{ - replicated::{semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing}, BitDecomposed, FieldSimd, TransposeFrom, Vectorizable, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare as Replicated}, }, }; @@ -599,25 +599,25 @@ mod test { use crate::{ ff::{ + U128Conversions, boolean::Boolean, boolean_array::{ - BooleanArray, BA112, BA16, BA20, BA3, BA32, BA4, BA5, BA6, BA64, BA7, BA8, + BA3, BA4, BA5, BA6, BA7, BA8, BA16, BA20, BA32, BA64, BA112, BooleanArray, }, - U128Conversions, }, - helpers::{query::DpMechanism, Direction}, + helpers::{Direction, query::DpMechanism}, protocol::{ dp::{ - apply_dp_noise, delta_constraint, dp_for_histogram, epsilon_constraint, error, - find_smallest_num_bernoulli, gen_binomial_noise, NoiseParams, - ShiftedTruncatedDiscreteLaplace, + NoiseParams, ShiftedTruncatedDiscreteLaplace, apply_dp_noise, delta_constraint, + dp_for_histogram, epsilon_constraint, error, find_smallest_num_bernoulli, + gen_binomial_noise, }, ipa_prf::oprf_padding::insecure::OPRFPaddingDp, }, rand::thread_rng, secret_sharing::{ - replicated::{semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing}, BitDecomposed, SharedValue, TransposeFrom, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare as Replicated}, }, sharding::NotSharded, telemetry::metrics::BYTES_SENT, @@ -758,9 +758,9 @@ mod test { result_u32[i], ); assert!( - (next_result_f64_shifted - f64::from(input_values[i])).abs() < - tolerance_factor * three_std - , "test failed because noised result is more than {tolerance_factor} standard deviations of the noise distribution \ + (next_result_f64_shifted - f64::from(input_values[i])).abs() + < tolerance_factor * three_std, + "test failed because noised result is more than {tolerance_factor} standard deviations of the noise distribution \ from the original input values. This will fail with a small chance of failure" ); } @@ -848,8 +848,8 @@ mod test { f64::from(result_u32[i]) - f64::from(input_values[i]) > mean - 5.0 * standard_deviation && f64::from(result_u32[i]) - f64::from(input_values[i]) - < mean + 5.0 * standard_deviation - , "test failed because noised result is more than 5 standard deviations of the noise distribution \ + < mean + 5.0 * standard_deviation, + "test failed because noised result is more than 5 standard deviations of the noise distribution \ from the original input values. This will fail with a small chance of failure" ); } diff --git a/ipa-core/src/protocol/hybrid/agg.rs b/ipa-core/src/protocol/hybrid/agg.rs index d03461058..2e9bb1d56 100644 --- a/ipa-core/src/protocol/hybrid/agg.rs +++ b/ipa-core/src/protocol/hybrid/agg.rs @@ -1,20 +1,20 @@ use std::collections::BTreeMap; -use futures::{stream, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt, stream}; use crate::{ error::Error, - ff::{boolean::Boolean, boolean_array::BooleanArray, ArrayAccess}, + ff::{ArrayAccess, boolean::Boolean, boolean_array::BooleanArray}, helpers::TotalRecords, protocol::{ + BooleanProtocols, boolean::step::EightBitStep, context::{ - dzkp_validator::{validated_seq_join, DZKPValidator, TARGET_PROOF_SIZE}, Context, DZKPUpgraded, MaliciousProtocolSteps, ShardedContext, UpgradableContext, + dzkp_validator::{DZKPValidator, TARGET_PROOF_SIZE, validated_seq_join}, }, hybrid::step::{AggregateReportsStep, HybridStep}, ipa_prf::boolean_ops::addition_sequential::integer_add, - BooleanProtocols, }, report::hybrid::{AggregateableHybridReport, PrfHybridReport}, secret_sharing::replicated::semi_honest::AdditiveShare as Replicated, @@ -167,8 +167,8 @@ pub mod test { use super::{aggregate_reports, group_report_pairs_ordered}; use crate::{ ff::{ - boolean_array::{BA3, BA8}, U128Conversions, + boolean_array::{BA3, BA8}, }, helpers::Role, protocol::hybrid::step::AggregateReportsStep, @@ -176,13 +176,13 @@ pub mod test { AggregateableHybridReport, IndistinguishableHybridReport, PrfHybridReport, }, secret_sharing::replicated::{ - semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing, + ReplicatedSecretSharing, semi_honest::AdditiveShare as Replicated, }, sharding::{ShardConfiguration, ShardIndex}, test_executor::{run, run_random}, test_fixture::{ - hybrid::{TestAggregateableHybridReport, TestHybridRecord}, Reconstruct, Runner, TestWorld, TestWorldConfig, WithShards, + hybrid::{TestAggregateableHybridReport, TestHybridRecord}, }, }; diff --git a/ipa-core/src/protocol/hybrid/breakdown_reveal.rs b/ipa-core/src/protocol/hybrid/breakdown_reveal.rs index 8c1215f63..1fd9e0b03 100644 --- a/ipa-core/src/protocol/hybrid/breakdown_reveal.rs +++ b/ipa-core/src/protocol/hybrid/breakdown_reveal.rs @@ -1,31 +1,31 @@ -use std::{convert::Infallible, iter::repeat, pin::pin}; +use std::{convert::Infallible, pin::pin}; use futures::stream; use futures_util::{StreamExt, TryStreamExt}; -use tracing::{info_span, Instrument}; +use tracing::{Instrument, info_span}; use crate::{ error::{Error, UnwrapInfallible}, - ff::{boolean::Boolean, boolean_array::BooleanArray, U128Conversions}, + ff::{U128Conversions, boolean::Boolean, boolean_array::BooleanArray}, helpers::TotalRecords, protocol::{ - basics::{reveal, Reveal}, + BooleanProtocols, RecordId, + basics::{Reveal, reveal}, context::{ - dzkp_validator::DZKPValidator, Context, DZKPUpgraded, MaliciousProtocolSteps, - ShardedContext, UpgradableContext, + Context, DZKPUpgraded, MaliciousProtocolSteps, ShardedContext, UpgradableContext, + dzkp_validator::DZKPValidator, }, hybrid::step::AggregationStep as Step, ipa_prf::{ - aggregation::{aggregate_values, aggregate_values_proof_chunk, AGGREGATE_DEPTH}, - oprf_padding::{apply_dp_padding, PaddingParameters}, + aggregation::{AGGREGATE_DEPTH, aggregate_values, aggregate_values_proof_chunk}, + oprf_padding::{PaddingParameters, apply_dp_padding}, shuffle::ShardedShuffle, }, - BooleanProtocols, RecordId, }, report::hybrid::AggregateableHybridReport, secret_sharing::{ - replicated::semi_honest::AdditiveShare as Replicated, BitDecomposed, FieldSimd, - TransposeFrom, Vectorizable, + BitDecomposed, FieldSimd, TransposeFrom, Vectorizable, + replicated::semi_honest::AdditiveShare as Replicated, }, seq_join::seq_join, }; @@ -77,9 +77,10 @@ where // This was checked early in the protocol, but we need to check again here, in case // there were no matching pairs of reports. if attributed_values.is_empty() { - return Ok(BitDecomposed::new( - repeat(Replicated::::ZERO).take(usize::try_from(HV::BITS).unwrap()), - )); + return Ok(BitDecomposed::new(std::iter::repeat_n( + Replicated::::ZERO, + usize::try_from(HV::BITS).unwrap(), + ))); } // Apply DP padding for Breakdown Reveal Aggregation @@ -249,21 +250,21 @@ pub mod tests { use crate::{ff::boolean_array::BA16, test_executor::run}; use crate::{ ff::{ + U128Conversions, boolean::Boolean, boolean_array::{BA3, BA5, BA8}, - U128Conversions, }, protocol::{ hybrid::breakdown_reveal_aggregation, ipa_prf::oprf_padding::PaddingParameters, }, rand::Rng, secret_sharing::{ - replicated::semi_honest::AdditiveShare as Replicated, BitDecomposed, TransposeFrom, + BitDecomposed, TransposeFrom, replicated::semi_honest::AdditiveShare as Replicated, }, test_executor::run_with, test_fixture::{ - hybrid::TestAggregateableHybridReport, Reconstruct, Runner, TestWorld, TestWorldConfig, - WithShards, + Reconstruct, Runner, TestWorld, TestWorldConfig, WithShards, + hybrid::TestAggregateableHybridReport, }, }; @@ -522,22 +523,22 @@ mod proptests { use crate::{ const_assert, ff::{ - boolean::Boolean, - boolean_array::{BA3, BA32, BA5, BA8}, U128Conversions, + boolean::Boolean, + boolean_array::{BA3, BA5, BA8, BA32}, }, protocol::{ hybrid::breakdown_reveal::breakdown_reveal_aggregation, ipa_prf::oprf_padding::PaddingParameters, }, secret_sharing::{ - replicated::semi_honest::AdditiveShare as Replicated, BitDecomposed, SharedValue, - TransposeFrom, + BitDecomposed, SharedValue, TransposeFrom, + replicated::semi_honest::AdditiveShare as Replicated, }, test_fixture::{ + Reconstruct, Runner, TestWorld, TestWorldConfig, WithShards, hybrid::{TestAggregateableHybridReport, TestIndistinguishableHybridReport}, - mpc_proptest_config_with_cases, Reconstruct, Runner, TestWorld, TestWorldConfig, - WithShards, + mpc_proptest_config_with_cases, }, }; diff --git a/ipa-core/src/protocol/hybrid/mod.rs b/ipa-core/src/protocol/hybrid/mod.rs index b6de81fc6..f4effdfeb 100644 --- a/ipa-core/src/protocol/hybrid/mod.rs +++ b/ipa-core/src/protocol/hybrid/mod.rs @@ -6,19 +6,20 @@ pub(crate) mod step; use std::{convert::Infallible, ops::Add}; use generic_array::ArrayLength; -use tracing::{info_span, Instrument}; +use tracing::{Instrument, info_span}; use crate::{ error::{Error, LengthError}, ff::{ - boolean::Boolean, boolean_array::BooleanArray, curve_points::RP25519, - ec_prime_field::Fp25519, Serializable, U128Conversions, + Serializable, U128Conversions, boolean::Boolean, boolean_array::BooleanArray, + curve_points::RP25519, ec_prime_field::Fp25519, }, helpers::query::DpMechanism, protocol::{ + BooleanProtocols, basics::{ - shard_fin::{FinalizerContext, Histogram}, BooleanArrayMul, Reveal, + shard_fin::{FinalizerContext, Histogram}, }, context::{ DZKPUpgraded, MacUpgraded, MaliciousProtocolSteps, ShardedContext, UpgradableContext, @@ -27,21 +28,20 @@ use crate::{ hybrid::{ agg::aggregate_reports, breakdown_reveal::breakdown_reveal_aggregation, - oprf::{compute_prf_and_reshard, BreakdownKey, CONV_CHUNK, PRF_CHUNK}, + oprf::{BreakdownKey, CONV_CHUNK, PRF_CHUNK, compute_prf_and_reshard}, step::{FinalizeSteps, HybridStep as Step}, }, ipa_prf::{ - oprf_padding::{apply_dp_padding, PaddingParameters}, + oprf_padding::{PaddingParameters, apply_dp_padding}, prf_eval::PrfSharing, shuffle::ShardedShuffle, }, prss::FromPrss, - BooleanProtocols, }, report::hybrid::{IndistinguishableHybridReport, PrfHybridReport}, secret_sharing::{ - replicated::semi_honest::AdditiveShare as Replicated, BitDecomposed, FieldSimd, - TransposeFrom, Vectorizable, + BitDecomposed, FieldSimd, TransposeFrom, Vectorizable, + replicated::semi_honest::AdditiveShare as Replicated, }, }; diff --git a/ipa-core/src/protocol/hybrid/oprf.rs b/ipa-core/src/protocol/hybrid/oprf.rs index 08160bfce..d4135720c 100644 --- a/ipa-core/src/protocol/hybrid/oprf.rs +++ b/ipa-core/src/protocol/hybrid/oprf.rs @@ -1,43 +1,44 @@ use std::cmp::max; -use futures::{stream, StreamExt, TryStreamExt}; +use futures::{StreamExt, TryStreamExt, stream}; use typenum::Const; use crate::{ error::{Error, UnwrapInfallible}, ff::{ + Serializable, U128Conversions, boolean::Boolean, - boolean_array::{BooleanArray, BA5, BA64, BA8}, + boolean_array::{BA5, BA8, BA64, BooleanArray}, curve_points::RP25519, ec_prime_field::Fp25519, - Serializable, U128Conversions, }, helpers::{ - stream::{div_round_up, process_slice_by_chunks, Chunk, ChunkData, TryFlattenItersExt}, TotalRecords, + stream::{Chunk, ChunkData, TryFlattenItersExt, div_round_up, process_slice_by_chunks}, }, protocol::{ + BasicProtocols, RecordId, basics::{BooleanProtocols, Reveal}, context::{ - dzkp_validator::{DZKPValidator, TARGET_PROOF_SIZE}, - reshard_try_stream, DZKPUpgraded, MacUpgraded, MaliciousProtocolSteps, ShardedContext, + DZKPUpgraded, MacUpgraded, MaliciousProtocolSteps, ShardedContext, ShardedUpgradedMaliciousContext, UpgradableContext, UpgradedMaliciousContext, Validator, + dzkp_validator::{DZKPValidator, TARGET_PROOF_SIZE}, + reshard_try_stream, }, hybrid::step::HybridStep, ipa_prf::{ boolean_ops::convert_to_fp25519, - prf_eval::{eval_dy_prf, PrfSharing}, + prf_eval::{PrfSharing, eval_dy_prf}, }, prss::{FromPrss, SharedRandomness}, - BasicProtocols, RecordId, }, report::hybrid::{IndistinguishableHybridReport, PrfHybridReport}, secret_sharing::{ - replicated::{malicious, semi_honest::AdditiveShare as Replicated}, BitDecomposed, FieldSimd, TransposeFrom, Vectorizable, + replicated::{malicious, semi_honest::AdditiveShare as Replicated}, }, - seq_join::{seq_join, SeqJoin}, + seq_join::{SeqJoin, seq_join}, utils::non_zero_prev_power_of_two, }; @@ -211,10 +212,10 @@ mod test { use crate::{ ff::boolean_array::{BA3, BA8}, - protocol::{hybrid::oprf::compute_prf_and_reshard, step::ProtocolStep, Gate}, + protocol::{Gate, hybrid::oprf::compute_prf_and_reshard, step::ProtocolStep}, report::hybrid::{IndistinguishableHybridReport, PrfHybridReport}, test_executor::run, - test_fixture::{hybrid::TestHybridRecord, Runner, TestWorld, TestWorldConfig, WithShards}, + test_fixture::{Runner, TestWorld, TestWorldConfig, WithShards, hybrid::TestHybridRecord}, }; #[test] diff --git a/ipa-core/src/protocol/ipa_prf/aggregation/mod.rs b/ipa-core/src/protocol/ipa_prf/aggregation/mod.rs index 288693722..a802d8fa2 100644 --- a/ipa-core/src/protocol/ipa_prf/aggregation/mod.rs +++ b/ipa-core/src/protocol/ipa_prf/aggregation/mod.rs @@ -5,20 +5,20 @@ use tracing::Instrument; use crate::{ error::Error, - ff::{boolean::Boolean, boolean_array::BooleanArray, U128Conversions}, - helpers::{stream::FixedLength, TotalRecords}, + ff::{U128Conversions, boolean::Boolean, boolean_array::BooleanArray}, + helpers::{TotalRecords, stream::FixedLength}, protocol::{ + RecordId, basics::BooleanProtocols, - boolean::{step::ThirtyTwoBitStep, NBitStep}, - context::{dzkp_validator::TARGET_PROOF_SIZE, Context}, + boolean::{NBitStep, step::ThirtyTwoBitStep}, + context::{Context, dzkp_validator::TARGET_PROOF_SIZE}, ipa_prf::{ aggregation::step::{AggregateChunkStep, AggregateValuesStep}, boolean_ops::addition_sequential::{integer_add, integer_sat_add}, }, - RecordId, }, secret_sharing::{ - replicated::semi_honest::AdditiveShare as Replicated, BitDecomposed, FieldSimd, + BitDecomposed, FieldSimd, replicated::semi_honest::AdditiveShare as Replicated, }, utils::non_zero_prev_power_of_two, }; @@ -106,7 +106,7 @@ where let par_agg_ctx = ctx .narrow(&AggregateChunkStep::from(depth)) .set_total_records(TotalRecords::Indeterminate); - let next_num_rows = (num_rows + 1) / 2; + let next_num_rows = num_rows.div_ceil(2); let base_record_id = record_ids[depth]; record_ids[depth] += num_rows / 2; aggregated_stream = Box::pin( @@ -187,7 +187,7 @@ where pub mod tests { use std::cmp::min; - use futures::{stream, StreamExt}; + use futures::{StreamExt, stream}; use proptest::prelude::*; use super::aggregate_values; @@ -198,7 +198,7 @@ pub mod tests { helpers::Role, secret_sharing::{BitDecomposed, SharedValue}, test_executor::run, - test_fixture::{mpc_proptest_config, ReconstructArr, Runner, TestWorld}, + test_fixture::{ReconstructArr, Runner, TestWorld, mpc_proptest_config}, }; fn input_row(tv_bits: usize, values: &[u32]) -> BitDecomposed<[Boolean; B]> { diff --git a/ipa-core/src/protocol/ipa_prf/boolean_ops/addition_sequential.rs b/ipa-core/src/protocol/ipa_prf/boolean_ops/addition_sequential.rs index 981ec9770..40c328956 100644 --- a/ipa-core/src/protocol/ipa_prf/boolean_ops/addition_sequential.rs +++ b/ipa-core/src/protocol/ipa_prf/boolean_ops/addition_sequential.rs @@ -6,12 +6,12 @@ use crate::{ error::Error, ff::boolean::Boolean, protocol::{ + Gate, RecordId, basics::{BooleanProtocols, SecureMul}, - boolean::{or::bool_or, NBitStep}, + boolean::{NBitStep, or::bool_or}, context::Context, - Gate, RecordId, }, - secret_sharing::{replicated::semi_honest::AdditiveShare, BitDecomposed, FieldSimd}, + secret_sharing::{BitDecomposed, FieldSimd, replicated::semi_honest::AdditiveShare}, }; /// Non-saturated unsigned integer addition @@ -160,14 +160,14 @@ mod test { use crate::{ ff::{ - boolean_array::{BA16, BA32, BA64}, ArrayAccess, U128Conversions, + boolean_array::{BA16, BA32, BA64}, }, protocol::{ + RecordId, boolean::step::DefaultBitStep, context::Context, ipa_prf::boolean_ops::addition_sequential::{integer_add, integer_sat_add}, - RecordId, }, rand::thread_rng, secret_sharing::BitDecomposed, @@ -183,8 +183,8 @@ mod test { let mut rng = thread_rng(); - let x_ba64 = rng.gen::(); - let y_ba64 = rng.gen::(); + let x_ba64 = rng.r#gen::(); + let y_ba64 = rng.r#gen::(); let x = x_ba64.as_u128(); let y = y_ba64.as_u128(); @@ -221,8 +221,8 @@ mod test { let mut rng = thread_rng(); - let x_ba = rng.gen::(); - let y_ba = rng.gen::(); + let x_ba = rng.r#gen::(); + let y_ba = rng.r#gen::(); let x = x_ba.as_u128(); let y = y_ba.as_u128(); let z = 1_u128 << BITS; @@ -260,8 +260,8 @@ mod test { let mut rng = thread_rng(); - let x_ba64 = rng.gen::(); - let y_ba32 = rng.gen::(); + let x_ba64 = rng.r#gen::(); + let y_ba32 = rng.r#gen::(); let x = x_ba64.as_u128(); let y = y_ba32.as_u128(); diff --git a/ipa-core/src/protocol/ipa_prf/boolean_ops/comparison_and_subtraction_sequential.rs b/ipa-core/src/protocol/ipa_prf/boolean_ops/comparison_and_subtraction_sequential.rs index b02c41bad..5df9ca0f2 100644 --- a/ipa-core/src/protocol/ipa_prf/boolean_ops/comparison_and_subtraction_sequential.rs +++ b/ipa-core/src/protocol/ipa_prf/boolean_ops/comparison_and_subtraction_sequential.rs @@ -10,14 +10,14 @@ use ipa_step::StepNarrow; use crate::{ error::Error, - ff::{boolean::Boolean, boolean_array::BooleanArray, Field}, + ff::{Field, boolean::Boolean, boolean_array::BooleanArray}, protocol::{ - basics::{select, BooleanArrayMul, BooleanProtocols, SecureMul, ShareKnownValue}, + Gate, RecordId, + basics::{BooleanArrayMul, BooleanProtocols, SecureMul, ShareKnownValue, select}, boolean::NBitStep, context::Context, - Gate, RecordId, }, - secret_sharing::{replicated::semi_honest::AdditiveShare, BitDecomposed, FieldSimd}, + secret_sharing::{BitDecomposed, FieldSimd, replicated::semi_honest::AdditiveShare}, }; /// Comparison operation @@ -222,25 +222,24 @@ mod test { use crate::{ ff::{ - boolean::Boolean, - boolean_array::{BA3, BA32, BA5, BA64}, ArrayAccess, Expand, Field, U128Conversions, + boolean::Boolean, + boolean_array::{BA3, BA5, BA32, BA64}, }, protocol::{ - self, + self, RecordId, boolean::step::DefaultBitStep, context::Context, ipa_prf::boolean_ops::comparison_and_subtraction_sequential::{ compare_geq, compare_gt, integer_sat_sub, integer_sub, }, - RecordId, }, rand::thread_rng, secret_sharing::{ - replicated::{semi_honest::AdditiveShare, ReplicatedSecretSharing}, BitDecomposed, SharedValue, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare}, }, - seq_join::{seq_join, SeqJoin}, + seq_join::{SeqJoin, seq_join}, test_executor::run, test_fixture::{Reconstruct, ReconstructArr, Runner, TestWorld}, }; @@ -285,7 +284,7 @@ mod test { let mut rng = thread_rng(); - let records: Vec = vec![rng.gen::(), rng.gen::()]; + let records: Vec = vec![rng.r#gen::(), rng.r#gen::()]; let x = records[0].as_u128(); let y = records[1].as_u128(); @@ -332,7 +331,7 @@ mod test { let mut rng = thread_rng(); - let records: Vec = vec![rng.gen::(), rng.gen::()]; + let records: Vec = vec![rng.r#gen::(), rng.r#gen::()]; let x = records[0].as_u128(); let y = records[1].as_u128(); @@ -384,11 +383,11 @@ mod test { let mut rng = thread_rng(); - let x = repeat_with(|| rng.gen()) + let x = repeat_with(|| rng.r#gen()) .take(BENCH_COUNT) .collect::>(); let x_int = x.iter().map(U128Conversions::as_u128).collect::>(); - let y: BA64 = rng.gen::(); + let y: BA64 = rng.r#gen::(); let y_int = y.as_u128(); let expected = x_int.iter().map(|x| *x > y_int).collect::>(); @@ -442,14 +441,14 @@ mod test { let mut rng = thread_rng(); - let x = repeat_with(|| rng.gen()) + let x = repeat_with(|| rng.r#gen()) .take(BENCH_COUNT) .collect::>(); let x_int: Vec = x .iter() .map(|x| x.as_u128().try_into().unwrap()) .collect::>(); - let y: BA64 = rng.gen::(); + let y: BA64 = rng.r#gen::(); let y_int: u64 = y.as_u128().try_into().unwrap(); let xa: Vec> = x_int .chunks(N) @@ -520,7 +519,7 @@ mod test { let mut rng = thread_rng(); - let records: Vec = vec![rng.gen::(), rng.gen::()]; + let records: Vec = vec![rng.r#gen::(), rng.r#gen::()]; let x = records[0].as_u128(); let y = records[1].as_u128(); let z = 1_u128 << 64; @@ -552,7 +551,7 @@ mod test { let mut rng = thread_rng(); - let records: Vec = vec![rng.gen::(), rng.gen::()]; + let records: Vec = vec![rng.r#gen::(), rng.r#gen::()]; let x = records[0].as_u128(); let y = records[1].as_u128(); @@ -610,7 +609,7 @@ mod test { let mut rng = thread_rng(); - let records = (rng.gen::(), rng.gen::()); + let records = (rng.r#gen::(), rng.r#gen::()); let x = records.0.as_u128(); let y = records.1.as_u128(); let z = 1_u128 << 64; diff --git a/ipa-core/src/protocol/ipa_prf/boolean_ops/multiplication.rs b/ipa-core/src/protocol/ipa_prf/boolean_ops/multiplication.rs index 6977407b3..f413c6721 100644 --- a/ipa-core/src/protocol/ipa_prf/boolean_ops/multiplication.rs +++ b/ipa-core/src/protocol/ipa_prf/boolean_ops/multiplication.rs @@ -4,10 +4,10 @@ use crate::{ error::Error, ff::boolean::Boolean, protocol::{ - basics::mul::SecureMul, boolean::NBitStep, context::Context, - ipa_prf::boolean_ops::addition_sequential::integer_add, BooleanProtocols, Gate, RecordId, + BooleanProtocols, Gate, RecordId, basics::mul::SecureMul, boolean::NBitStep, + context::Context, ipa_prf::boolean_ops::addition_sequential::integer_add, }, - secret_sharing::{replicated::semi_honest::AdditiveShare, BitDecomposed, FieldSimd}, + secret_sharing::{BitDecomposed, FieldSimd, replicated::semi_honest::AdditiveShare}, }; /// This function multiplies x by y in these steps: @@ -77,19 +77,19 @@ where mod test { use std::iter; - use rand::{thread_rng, Rng}; + use rand::{Rng, thread_rng}; use crate::{ ff::{ - boolean::Boolean, - boolean_array::{BooleanArray, BA16, BA8}, U128Conversions, + boolean::Boolean, + boolean_array::{BA8, BA16, BooleanArray}, }, protocol::{ - boolean::step::DefaultBitStep, context::Context, - ipa_prf::boolean_ops::multiplication::integer_mul, RecordId, + RecordId, boolean::step::DefaultBitStep, context::Context, + ipa_prf::boolean_ops::multiplication::integer_mul, }, - secret_sharing::{replicated::semi_honest::AdditiveShare, BitDecomposed, TransposeFrom}, + secret_sharing::{BitDecomposed, TransposeFrom, replicated::semi_honest::AdditiveShare}, test_executor::run, test_fixture::{Reconstruct, Runner, TestWorld}, }; @@ -115,7 +115,7 @@ mod test { let all_x_values = (0..256) .map(|i| BA8::truncate_from(u128::try_from(i).unwrap())) .collect::>(); - let random_y_values = (0..256).map(|_| rng.gen::()).collect::>(); + let random_y_values = (0..256).map(|_| rng.r#gen::()).collect::>(); let result: Vec = world .dzkp_semi_honest( diff --git a/ipa-core/src/protocol/ipa_prf/boolean_ops/share_conversion_aby.rs b/ipa-core/src/protocol/ipa_prf/boolean_ops/share_conversion_aby.rs index 00f60cb33..afe1ca17c 100644 --- a/ipa-core/src/protocol/ipa_prf/boolean_ops/share_conversion_aby.rs +++ b/ipa-core/src/protocol/ipa_prf/boolean_ops/share_conversion_aby.rs @@ -3,25 +3,25 @@ use std::{convert::Infallible, iter::zip, ops::Neg}; use crate::{ error::{Error, UnwrapInfallible}, ff::{ + ArrayAccess, boolean::Boolean, - boolean_array::{BooleanArray, BA256}, + boolean_array::{BA256, BooleanArray}, ec_prime_field::Fp25519, - ArrayAccess, }, helpers::Role, protocol::{ - basics::{validated_partial_reveal, BooleanProtocols}, + RecordId, + basics::{BooleanProtocols, validated_partial_reveal}, boolean::step::TwoHundredFiftySixBitOpStep, context::{Context, DZKPContext}, ipa_prf::boolean_ops::{ addition_sequential::integer_add, step::Fp25519ConversionStep as Step, }, prss::{FromPrss, SharedRandomness}, - RecordId, }, secret_sharing::{ - replicated::{semi_honest::AdditiveShare, ReplicatedSecretSharing}, BitDecomposed, FieldSimd, SharedValueArray, TransposeFrom, Vectorizable, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare}, }, }; @@ -361,16 +361,16 @@ mod tests { use super::*; use crate::{ - ff::{boolean_array::BA64, Serializable}, + ff::{Serializable, boolean_array::BA64}, helpers::stream::process_slice_by_chunks, protocol::{ - context::{dzkp_validator::DZKPValidator, UpgradableContext, TEST_DZKP_STEPS}, + context::{TEST_DZKP_STEPS, UpgradableContext, dzkp_validator::DZKPValidator}, hybrid::oprf::conv_proof_chunk, ipa_prf::{CONV_CHUNK, PRF_CHUNK}, }, rand::thread_rng, secret_sharing::SharedValue, - seq_join::{seq_join, SeqJoin}, + seq_join::{SeqJoin, seq_join}, sharding::NotSharded, test_executor::run, test_fixture::{ReconstructArr, Runner, TestWorld, TestWorldConfig}, @@ -385,7 +385,7 @@ mod tests { let mut rng = thread_rng(); - let records = repeat_with(|| rng.gen::()) + let records = repeat_with(|| rng.r#gen::()) .take(COUNT) .collect::>(); @@ -448,7 +448,7 @@ mod tests { let mut rng = thread_rng(); - let records = repeat_with(|| rng.gen::()) + let records = repeat_with(|| rng.r#gen::()) .take(COUNT) .collect::>(); @@ -527,7 +527,7 @@ mod tests { fn test_expand() { let mut rng = thread_rng(); - let a = rng.gen::(); + let a = rng.r#gen::(); let b = expand_array::<_, BA256>(&a, None); diff --git a/ipa-core/src/protocol/ipa_prf/boolean_ops/sigmoid.rs b/ipa-core/src/protocol/ipa_prf/boolean_ops/sigmoid.rs index c01f023ee..2786950ed 100644 --- a/ipa-core/src/protocol/ipa_prf/boolean_ops/sigmoid.rs +++ b/ipa-core/src/protocol/ipa_prf/boolean_ops/sigmoid.rs @@ -6,10 +6,10 @@ use crate::{ error::Error, ff::boolean::Boolean, protocol::{ - basics::mul::SecureMul, boolean::step::ThirtyTwoBitStep, context::Context, - BooleanProtocols, RecordId, + BooleanProtocols, RecordId, basics::mul::SecureMul, boolean::step::ThirtyTwoBitStep, + context::Context, }, - secret_sharing::{replicated::semi_honest::AdditiveShare, BitDecomposed, FieldSimd}, + secret_sharing::{BitDecomposed, FieldSimd, replicated::semi_honest::AdditiveShare}, }; async fn a_times_b_and_not_b( @@ -163,8 +163,8 @@ mod test { use std::num::TryFromIntError; use crate::{ - ff::{boolean_array::BA8, U128Conversions}, - protocol::{context::Context, ipa_prf::boolean_ops::sigmoid::sigmoid, RecordId}, + ff::{U128Conversions, boolean_array::BA8}, + protocol::{RecordId, context::Context, ipa_prf::boolean_ops::sigmoid::sigmoid}, secret_sharing::{BitDecomposed, SharedValue, TransposeFrom}, test_executor::run, test_fixture::{Reconstruct, Runner, TestWorld}, @@ -233,7 +233,10 @@ mod test { let y_f64 = (res.as_u128() as f64) / 256_f64; let exact_sigmoid = 1.0_f64 / (1.0_f64 + f64::exp(-x_f64)); let delta_from_exact = f64::abs(exact_sigmoid - y_f64); - assert!(delta_from_exact < 0.0197_f64, "At x={x_f64} the delta from an exact sigmoid is {delta_from_exact}. Exact value: {exact_sigmoid}, approximate value: {y_f64}"); + assert!( + delta_from_exact < 0.0197_f64, + "At x={x_f64} the delta from an exact sigmoid is {delta_from_exact}. Exact value: {exact_sigmoid}, approximate value: {y_f64}" + ); } }); } diff --git a/ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs b/ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs index 1f598cb31..9a1730f31 100644 --- a/ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs +++ b/ipa-core/src/protocol/ipa_prf/malicious_security/lagrange.rs @@ -3,7 +3,7 @@ use std::{array::from_fn, fmt::Debug}; use typenum::Unsigned; use crate::ff::{ - batch_invert, Field, MultiplyAccumulate, MultiplyAccumulator, PrimeField, Serializable, + Field, MultiplyAccumulate, MultiplyAccumulator, PrimeField, Serializable, batch_invert, }; /// The Canonical Lagrange denominator is defined as the denominator of the Lagrange base polynomials diff --git a/ipa-core/src/protocol/ipa_prf/malicious_security/prover.rs b/ipa-core/src/protocol/ipa_prf/malicious_security/prover.rs index 6ecb33c6d..41abb0ecf 100644 --- a/ipa-core/src/protocol/ipa_prf/malicious_security/prover.rs +++ b/ipa-core/src/protocol/ipa_prf/malicious_security/prover.rs @@ -5,19 +5,19 @@ use crate::{ ff::{Fp61BitPrime, MultiplyAccumulate, MultiplyAccumulatorArray, PrimeField}, helpers::hashing::{compute_hash, hash_to_field}, protocol::{ + RecordId, RecordIdRange, context::{ - dzkp_field::{TABLE_U, TABLE_V}, Context, + dzkp_field::{TABLE_U, TABLE_V}, }, ipa_prf::{ + CompressedProofGenerator, malicious_security::{ - lagrange::{CanonicalLagrangeDenominator, LagrangeTable}, FIRST_RECURSION_FACTOR as FRF, + lagrange::{CanonicalLagrangeDenominator, LagrangeTable}, }, - CompressedProofGenerator, }, prss::SharedRandomness, - RecordId, RecordIdRange, }, secret_sharing::SharedValue, }; @@ -229,12 +229,12 @@ struct ValuesExtrapolateIterator< } impl< - F: PrimeField, - const L: usize, - const P: usize, - const M: usize, - I: Iterator, - > Iterator for ValuesExtrapolateIterator<'_, F, L, P, M, I> + F: PrimeField, + const L: usize, + const P: usize, + const M: usize, + I: Iterator, +> Iterator for ValuesExtrapolateIterator<'_, F, L, P, M, I> { type Item = ([F; P], [F; P]); @@ -466,16 +466,16 @@ mod test { ff::{Fp31, Fp61BitPrime, PrimeField, U128Conversions}, helpers::{Direction, Role}, protocol::{ + RecordId, RecordIdRange, context::{ - dzkp_field::tests::reference_convert, - dzkp_validator::{MultiplicationInputsBlock, BIT_ARRAY_LEN}, Context, + dzkp_field::tests::reference_convert, + dzkp_validator::{BIT_ARRAY_LEN, MultiplicationInputsBlock}, }, ipa_prf::{ - malicious_security::lagrange::{CanonicalLagrangeDenominator, LagrangeTable}, FirstProofGenerator, + malicious_security::lagrange::{CanonicalLagrangeDenominator, LagrangeTable}, }, - RecordId, RecordIdRange, }, seq_join::SeqJoin, test_executor::{run, run_random}, @@ -759,49 +759,50 @@ mod test { const PROOF_2: [u128; 7] = [18, 13, 26, 29, 1, 0, 4]; const PROOF_3: [u128; 7] = [19, 25, 20, 9, 2, 15, 5]; let world = TestWorld::default(); - let [(h1_proof_left, h1_proof_right), (h2_proof_left, h2_proof_right), (h3_proof_left, h3_proof_right)] = - world - .semi_honest((), |ctx, ()| async move { - let mut record_ids = RecordIdRange::ALL; - let (proof_share_left, my_share_of_right) = - TestProofGenerator::gen_proof_shares_from_prss(&ctx, &mut record_ids); - let proof_u128 = match ctx.role() { - Role::H1 => PROOF_1, - Role::H2 => PROOF_2, - Role::H3 => PROOF_3, - }; - let proof = proof_u128.map(Fp31::truncate_from); - let proof_share_right = - TestProofGenerator::gen_other_proof_share(proof, proof_share_left); - - // set up context - let c = ctx - .narrow("send_proof_share") - .set_total_records(proof_share_right.len()); - - // set up channels - let send_channel_right = - &c.send_channel::(ctx.role().peer(Direction::Right)); - let recv_channel_left = - &c.recv_channel::(ctx.role().peer(Direction::Left)); - - // send share - let (my_share_of_left_vec, _) = try_join( - c.parallel_join((0..proof_share_right.len()).map(|i| async move { - recv_channel_left.receive(RecordId::from(i)).await - })), - c.parallel_join(proof_share_right.iter().enumerate().map( - |(i, elem)| async move { - send_channel_right.send(RecordId::from(i), elem).await - }, - )), - ) - .await - .unwrap(); - - (my_share_of_left_vec.try_into().unwrap(), my_share_of_right) - }) - .await; + let [ + (h1_proof_left, h1_proof_right), + (h2_proof_left, h2_proof_right), + (h3_proof_left, h3_proof_right), + ] = world + .semi_honest((), |ctx, ()| async move { + let mut record_ids = RecordIdRange::ALL; + let (proof_share_left, my_share_of_right) = + TestProofGenerator::gen_proof_shares_from_prss(&ctx, &mut record_ids); + let proof_u128 = match ctx.role() { + Role::H1 => PROOF_1, + Role::H2 => PROOF_2, + Role::H3 => PROOF_3, + }; + let proof = proof_u128.map(Fp31::truncate_from); + let proof_share_right = + TestProofGenerator::gen_other_proof_share(proof, proof_share_left); + + // set up context + let c = ctx + .narrow("send_proof_share") + .set_total_records(proof_share_right.len()); + + // set up channels + let send_channel_right = &c.send_channel::(ctx.role().peer(Direction::Right)); + let recv_channel_left = &c.recv_channel::(ctx.role().peer(Direction::Left)); + + // send share + let (my_share_of_left_vec, _) = try_join( + c.parallel_join((0..proof_share_right.len()).map(|i| async move { + recv_channel_left.receive(RecordId::from(i)).await + })), + c.parallel_join(proof_share_right.iter().enumerate().map( + |(i, elem)| async move { + send_channel_right.send(RecordId::from(i), elem).await + }, + )), + ) + .await + .unwrap(); + + (my_share_of_left_vec.try_into().unwrap(), my_share_of_right) + }) + .await; assert_two_part_secret_sharing(PROOF_1, h3_proof_right, h2_proof_left); assert_two_part_secret_sharing(PROOF_2, h1_proof_right, h3_proof_left); @@ -814,44 +815,48 @@ mod test { const FPL: usize = FirstProofGenerator::PROOF_LENGTH; const FLL: usize = FirstProofGenerator::LAGRANGE_LENGTH; - let block = rng.gen::(); + let block = rng.r#gen::(); // Test equivalence for extrapolate_y_values let denominator = CanonicalLagrangeDenominator::new(); let lagrange_table = LagrangeTable::from(denominator); - assert!(ProverTableIndices(block.table_indices_prover().into_iter()) - .extrapolate_y_values::(&lagrange_table) - .eq(ProverValues((0..BIT_ARRAY_LEN).map(|i| { - reference_convert( - block.x_left[i], - block.x_right[i], - block.y_left[i], - block.y_right[i], - block.prss_left[i], - block.prss_right[i], - ) - })) - .extrapolate_y_values::(&lagrange_table))); + assert!( + ProverTableIndices(block.table_indices_prover().into_iter()) + .extrapolate_y_values::(&lagrange_table) + .eq(ProverValues((0..BIT_ARRAY_LEN).map(|i| { + reference_convert( + block.x_left[i], + block.x_right[i], + block.y_left[i], + block.y_right[i], + block.prss_left[i], + block.prss_right[i], + ) + })) + .extrapolate_y_values::(&lagrange_table)) + ); // Test equivalence for eval_at_r let denominator = CanonicalLagrangeDenominator::new(); - let r = rng.gen(); + let r = rng.r#gen(); let lagrange_table_r = LagrangeTable::new(&denominator, &r); - assert!(ProverTableIndices(block.table_indices_prover().into_iter()) - .eval_at_r(&lagrange_table_r) - .eq(ProverValues((0..BIT_ARRAY_LEN).map(|i| { - reference_convert( - block.x_left[i], - block.x_right[i], - block.y_left[i], - block.y_right[i], - block.prss_left[i], - block.prss_right[i], - ) - })) - .eval_at_r(&lagrange_table_r))); + assert!( + ProverTableIndices(block.table_indices_prover().into_iter()) + .eval_at_r(&lagrange_table_r) + .eq(ProverValues((0..BIT_ARRAY_LEN).map(|i| { + reference_convert( + block.x_left[i], + block.x_right[i], + block.y_left[i], + block.y_right[i], + block.prss_left[i], + block.prss_right[i], + ) + })) + .eval_at_r(&lagrange_table_r)) + ); }); } } diff --git a/ipa-core/src/protocol/ipa_prf/malicious_security/verifier.rs b/ipa-core/src/protocol/ipa_prf/malicious_security/verifier.rs index 8a49849f0..79747a266 100644 --- a/ipa-core/src/protocol/ipa_prf/malicious_security/verifier.rs +++ b/ipa-core/src/protocol/ipa_prf/malicious_security/verifier.rs @@ -11,7 +11,7 @@ use crate::{ dzkp_validator::{MAX_PROOF_RECURSION, MIN_PROOF_RECURSION}, }, ipa_prf::malicious_security::{ - CanonicalLagrangeDenominator, LagrangeTable, FIRST_RECURSION_FACTOR as FRF, + CanonicalLagrangeDenominator, FIRST_RECURSION_FACTOR as FRF, LagrangeTable, }, }, utils::arraychunks::ArrayChunkIterator, @@ -278,8 +278,8 @@ mod test { ff::{Fp31, U128Conversions}, protocol::{ context::{ - dzkp_field::{tests::reference_convert, TABLE_U, TABLE_V}, - dzkp_validator::{MultiplicationInputsBlock, BIT_ARRAY_LEN}, + dzkp_field::{TABLE_U, TABLE_V, tests::reference_convert}, + dzkp_validator::{BIT_ARRAY_LEN, MultiplicationInputsBlock}, }, ipa_prf::malicious_security::lagrange::{CanonicalLagrangeDenominator, LagrangeTable}, }, @@ -562,55 +562,59 @@ mod test { #[test] fn verifier_table_indices_equivalence() { run_random(|mut rng| async move { - let block = rng.gen::(); + let block = rng.r#gen::(); let denominator = CanonicalLagrangeDenominator::new(); - let r = rng.gen(); + let r = rng.r#gen(); let lagrange_table_r = LagrangeTable::new(&denominator, &r); // Test equivalence for _u_ values - assert!(VerifierTableIndices { - input: block - .rotate_right() - .table_indices_from_right_prover() - .into_iter(), - table: &TABLE_U, - } - .eval_at_r(&lagrange_table_r) - .eq(VerifierValues((0..BIT_ARRAY_LEN).map(|i| { - reference_convert( - block.x_left[i], - block.x_right[i], - block.y_left[i], - block.y_right[i], - block.prss_left[i], - block.prss_right[i], - ) - .0 - })) - .eval_at_r(&lagrange_table_r))); + assert!( + VerifierTableIndices { + input: block + .rotate_right() + .table_indices_from_right_prover() + .into_iter(), + table: &TABLE_U, + } + .eval_at_r(&lagrange_table_r) + .eq(VerifierValues((0..BIT_ARRAY_LEN).map(|i| { + reference_convert( + block.x_left[i], + block.x_right[i], + block.y_left[i], + block.y_right[i], + block.prss_left[i], + block.prss_right[i], + ) + .0 + })) + .eval_at_r(&lagrange_table_r)) + ); // Test equivalence for _v_ values - assert!(VerifierTableIndices { - input: block - .rotate_left() - .table_indices_from_left_prover() - .into_iter(), - table: &TABLE_V, - } - .eval_at_r(&lagrange_table_r) - .eq(VerifierValues((0..BIT_ARRAY_LEN).map(|i| { - reference_convert( - block.x_left[i], - block.x_right[i], - block.y_left[i], - block.y_right[i], - block.prss_left[i], - block.prss_right[i], - ) - .1 - })) - .eval_at_r(&lagrange_table_r))); + assert!( + VerifierTableIndices { + input: block + .rotate_left() + .table_indices_from_left_prover() + .into_iter(), + table: &TABLE_V, + } + .eval_at_r(&lagrange_table_r) + .eq(VerifierValues((0..BIT_ARRAY_LEN).map(|i| { + reference_convert( + block.x_left[i], + block.x_right[i], + block.y_left[i], + block.y_right[i], + block.prss_left[i], + block.prss_right[i], + ) + .1 + })) + .eval_at_r(&lagrange_table_r)) + ); }); } } diff --git a/ipa-core/src/protocol/ipa_prf/mod.rs b/ipa-core/src/protocol/ipa_prf/mod.rs index ace2918c7..ab42e7b1b 100644 --- a/ipa-core/src/protocol/ipa_prf/mod.rs +++ b/ipa-core/src/protocol/ipa_prf/mod.rs @@ -15,8 +15,8 @@ pub use malicious_security::{ use crate::{ ff::{ - boolean_array::{BooleanArray, BA5, BA64, BA8}, U128Conversions, + boolean_array::{BA5, BA8, BA64, BooleanArray}, }, secret_sharing::SharedValue, }; diff --git a/ipa-core/src/protocol/ipa_prf/oprf_padding/distributions.rs b/ipa-core/src/protocol/ipa_prf/oprf_padding/distributions.rs index 4ef26323f..5dace464a 100644 --- a/ipa-core/src/protocol/ipa_prf/oprf_padding/distributions.rs +++ b/ipa-core/src/protocol/ipa_prf/oprf_padding/distributions.rs @@ -4,8 +4,8 @@ use std::{ }; use rand::{ - distributions::{Bernoulli, Distribution, Uniform}, Rng, + distributions::{Bernoulli, Distribution, Uniform}, }; use crate::protocol::ipa_prf::oprf_padding::insecure::Error; @@ -175,12 +175,12 @@ impl Distribution for TruncatedDoubleGeometric { mod tests { use std::{collections::HashMap, f64::consts::E, iter::repeat_with}; - use rand::{distributions::Distribution, thread_rng, Rng}; + use rand::{Rng, distributions::Distribution, thread_rng}; use rand_core::RngCore; use crate::protocol::ipa_prf::oprf_padding::{ distributions::{ - is_close, BoxMuller, DoubleGeometric, Geometric, TruncatedDoubleGeometric, + BoxMuller, DoubleGeometric, Geometric, TruncatedDoubleGeometric, is_close, }, insecure::Error, }; @@ -198,8 +198,8 @@ mod tests { fn dp_normal_distribution_sample_random() { let mut rng = thread_rng(); let nd = BoxMuller { - mean: rng.gen(), - std: rng.gen::().abs().sqrt(), + mean: rng.r#gen(), + std: rng.r#gen::().abs().sqrt(), }; check(&nd, &mut rng, 2_u8); } @@ -220,8 +220,8 @@ mod tests { fn dp_rounded_normal_distribution_sample_random() { let mut rng = thread_rng(); let nd = BoxMuller { - mean: rng.gen(), - std: rng.gen::().abs().sqrt(), + mean: rng.r#gen(), + std: rng.r#gen::().abs().sqrt(), }; check(&nd, &mut rng, 1_u8); } @@ -255,7 +255,9 @@ mod tests { .get(&x) .map_or(0.0, |count| f64::from(*count) / f64::from(num_samples)); let expected_probability = (1.0 - p).powf(f64::from(x)) * p; - println!("x = {x}, Observed Probability = {observed_probability}, Expected Probability = {expected_probability}"); + println!( + "x = {x}, Observed Probability = {observed_probability}, Expected Probability = {expected_probability}" + ); assert!((observed_probability - expected_probability) <= TOLERANCE); } } @@ -332,7 +334,9 @@ mod tests { samples_truncated_double_geometric.push(sample); } // Print the samples to the console - println!("Samples from generate_truncated_geometric with s={s}, n={n}: {samples_truncated_double_geometric:?}"); + println!( + "Samples from generate_truncated_geometric with s={s}, n={n}: {samples_truncated_double_geometric:?}" + ); } #[test] fn test_truncated_double_geometric_hoffding() { diff --git a/ipa-core/src/protocol/ipa_prf/oprf_padding/insecure.rs b/ipa-core/src/protocol/ipa_prf/oprf_padding/insecure.rs index cddb3e720..96ebdceb1 100644 --- a/ipa-core/src/protocol/ipa_prf/oprf_padding/insecure.rs +++ b/ipa-core/src/protocol/ipa_prf/oprf_padding/insecure.rs @@ -319,7 +319,7 @@ mod test { use std::collections::BTreeMap; use proptest::{prelude::ProptestConfig, proptest}; - use rand::{rngs::StdRng, thread_rng, Rng}; + use rand::{Rng, rngs::StdRng, thread_rng}; use rand_core::SeedableRng; use super::*; @@ -350,7 +350,7 @@ mod test { #[test] fn dp_normal_distribution_generation_random() { let mut rng = thread_rng(); - let cap: u32 = rng.gen(); + let cap: u32 = rng.r#gen(); let delta: f64 = rng.gen_range(1e-9..1e-6); let epsilon = f64::from(rng.gen_range(1..255_u8)); let sensitivity = f64::from(cap); @@ -549,7 +549,9 @@ mod test { let (_, std) = truncated_discrete_laplace.mean_and_std(); let (first_moment, second_moment) = truncated_discrete_laplace .first_second_moments_discrete_truncated_laplace(); - println!("std = {std}, std_bound = {std_bound}, first_moment = {first_moment}, second_moment = {second_moment}"); + println!( + "std = {std}, std_bound = {std_bound}, first_moment = {first_moment}, second_moment = {second_moment}" + ); if std_bound > 1.0 { // otherwise the bound is not valid assert!(std < std_bound + 0.00001); diff --git a/ipa-core/src/protocol/ipa_prf/oprf_padding/mod.rs b/ipa-core/src/protocol/ipa_prf/oprf_padding/mod.rs index 925bec51e..bbe092b70 100644 --- a/ipa-core/src/protocol/ipa_prf/oprf_padding/mod.rs +++ b/ipa-core/src/protocol/ipa_prf/oprf_padding/mod.rs @@ -2,7 +2,7 @@ pub(crate) mod distributions; pub mod insecure; pub mod step; -use std::iter::{repeat, repeat_with}; +use std::iter::repeat_with; #[cfg(any(test, feature = "test-fixture", feature = "cli"))] pub use insecure::DiscreteDp as InsecureDiscreteDp; @@ -13,20 +13,20 @@ use crate::{ error, error::Error, ff::{ - boolean_array::{BooleanArray, BA32, BA64}, U128Conversions, + boolean_array::{BA32, BA64, BooleanArray}, }, helpers::{Direction, Role, TotalRecords}, protocol::{ - context::{prss::InstrumentedSequentialSharedRandomness, Context}, + RecordId, + context::{Context, prss::InstrumentedSequentialSharedRandomness}, ipa_prf::oprf_padding::{ insecure::OPRFPaddingDp, step::{PaddingDpStep, SendTotalRows}, }, - RecordId, }, report::hybrid::IndistinguishableHybridReport, - secret_sharing::replicated::{semi_honest::AdditiveShare, ReplicatedSecretSharing}, + secret_sharing::replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare}, }; /// Parameter struct for padding parameters. @@ -159,14 +159,16 @@ where padding_input_rows.extend( repeat_with(|| { - let dummy_mk: BA64 = rng.gen(); - repeat(IndistinguishableHybridReport::from( - AdditiveShare::new_excluding_direction( - dummy_mk, - direction_to_excluded_helper, + let dummy_mk: BA64 = rng.r#gen(); + std::iter::repeat_n( + IndistinguishableHybridReport::from( + AdditiveShare::new_excluding_direction( + dummy_mk, + direction_to_excluded_helper, + ), ), - )) - .take(cardinality as usize) + cardinality as usize, + ) }) // this means there will be `sample` many unique // matchkeys to add each with cardinality = `cardinality` @@ -185,10 +187,10 @@ where padding_input_rows: &mut VC, total_number_of_fake_rows: u32, ) { - padding_input_rows.extend( - repeat(IndistinguishableHybridReport::::ZERO) - .take(total_number_of_fake_rows as usize), - ); + padding_input_rows.extend(std::iter::repeat_n( + IndistinguishableHybridReport::::ZERO, + total_number_of_fake_rows as usize, + )); } } @@ -259,10 +261,10 @@ where padding_input_rows: &mut VC, total_number_of_fake_rows: u32, ) { - padding_input_rows.extend( - repeat(IndistinguishableHybridReport::::ZERO) - .take(total_number_of_fake_rows as usize), - ); + padding_input_rows.extend(std::iter::repeat_n( + IndistinguishableHybridReport::::ZERO, + total_number_of_fake_rows as usize, + )); } } @@ -404,17 +406,17 @@ mod tests { use crate::{ error::Error, ff::{ - boolean_array::{BooleanArray, BA3, BA32, BA8}, U128Conversions, + boolean_array::{BA3, BA8, BA32, BooleanArray}, }, helpers::{Direction, Role, TotalRecords}, protocol::{ + RecordId, context::Context, ipa_prf::oprf_padding::{ - apply_dp_padding_pass, insecure, insecure::OPRFPaddingDp, AggregationPadding, - OPRFPadding, PaddingParameters, + AggregationPadding, OPRFPadding, PaddingParameters, apply_dp_padding_pass, + insecure, insecure::OPRFPaddingDp, }, - RecordId, }, report::hybrid::IndistinguishableHybridReport, test_fixture::{Reconstruct, Runner, TestWorld}, diff --git a/ipa-core/src/protocol/ipa_prf/prf_eval.rs b/ipa-core/src/protocol/ipa_prf/prf_eval.rs index 29751593f..38fb47474 100644 --- a/ipa-core/src/protocol/ipa_prf/prf_eval.rs +++ b/ipa-core/src/protocol/ipa_prf/prf_eval.rs @@ -6,18 +6,18 @@ use crate::{ error::Error, ff::{curve_points::RP25519, ec_prime_field::Fp25519}, protocol::{ - basics::{reveal, Reveal, SecureMul}, + BasicProtocols, RecordId, + basics::{Reveal, SecureMul, reveal}, context::{ - upgrade::Upgradable, UpgradableContext, UpgradedContext, UpgradedMaliciousContext, - UpgradedSemiHonestContext, + UpgradableContext, UpgradedContext, UpgradedMaliciousContext, + UpgradedSemiHonestContext, upgrade::Upgradable, }, ipa_prf::step::PrfStep as Step, prss::{FromPrss, SharedRandomness}, - BasicProtocols, RecordId, }, secret_sharing::{ - replicated::{malicious, semi_honest::AdditiveShare}, FieldSimd, Vectorizable, + replicated::{malicious, semi_honest::AdditiveShare}, }, sharding::{NotSharded, Sharded}, }; @@ -163,16 +163,16 @@ mod test { use crate::{ error::Error, ff::{curve_points::RP25519, ec_prime_field::Fp25519}, - helpers::{in_memory_config::MaliciousHelper, Role}, + helpers::{Role, in_memory_config::MaliciousHelper}, protocol::{ basics::Reveal, context::{Context, MacUpgraded, UpgradableContext, Validator}, ipa_prf::{ - prf_eval::{eval_dy_prf, PrfSharing}, + prf_eval::{PrfSharing, eval_dy_prf}, step::PrfStep, }, }, - secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares, Vectorizable}, + secret_sharing::{IntoShares, Vectorizable, replicated::semi_honest::AdditiveShare}, test_executor::run, test_fixture::{Reconstruct, Runner, TestWorld, TestWorldConfig}, }; diff --git a/ipa-core/src/protocol/ipa_prf/shuffle/malicious.rs b/ipa-core/src/protocol/ipa_prf/shuffle/malicious.rs index 2118511b9..a8a34e800 100644 --- a/ipa-core/src/protocol/ipa_prf/shuffle/malicious.rs +++ b/ipa-core/src/protocol/ipa_prf/shuffle/malicious.rs @@ -4,8 +4,8 @@ use std::{ }; use futures::{ - stream::{self, TryStreamExt}, StreamExt, + stream::{self, TryStreamExt}, }; use futures_util::future::{try_join, try_join3}; use generic_array::GenericArray; @@ -16,28 +16,28 @@ use crate::{ error::Error, ff::{Expand, Field, Gf32Bit, Serializable}, helpers::{ - hashing::{compute_possibly_empty_hash, Hash}, - stream::{div_round_up, process_slice_by_chunks, TryFlattenItersExt}, Direction, Role, TotalRecords, + hashing::{Hash, compute_possibly_empty_hash}, + stream::{TryFlattenItersExt, div_round_up, process_slice_by_chunks}, }, protocol::{ + RecordId, basics::{malicious_reveal, mul::semi_honest_multiply}, boolean::step::EightBitStep, context::{Context, ShardedContext}, ipa_prf::shuffle::{ + IntermediateShuffleMessages, sharded::{ - h1_shuffle_for_shard, h2_shuffle_for_shard, h3_shuffle_for_shard, - MaliciousShuffleable, ShuffleShare, Shuffleable, + MaliciousShuffleable, ShuffleShare, Shuffleable, h1_shuffle_for_shard, + h2_shuffle_for_shard, h3_shuffle_for_shard, }, step::{ShardedShuffleStep, VerifyShuffleStep}, - IntermediateShuffleMessages, }, prss::SharedRandomness, - RecordId, }, secret_sharing::{ - replicated::{semi_honest::AdditiveShare, ReplicatedSecretSharing}, SharedValue, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare}, }, seq_join::seq_join, sharding::ShardIndex, @@ -135,7 +135,7 @@ where assert_eq!(S::Share::BITS + 32, ::BITS); // prepare keys - let amount_of_keys: usize = (usize::try_from(S::Share::BITS).unwrap() + 31) / 32; + let amount_of_keys: usize = usize::try_from(S::Share::BITS).unwrap().div_ceil(32); let keys = setup_keys(ctx.narrow(&ShardedShuffleStep::SetupKeys), amount_of_keys).await?; // compute and append tags to rows @@ -552,17 +552,17 @@ fn concatenate_row_and_tag( #[cfg(all(test, unit_test))] mod tests { - use rand::{distributions::Standard, prelude::Distribution, Rng}; + use rand::{Rng, distributions::Standard, prelude::Distribution}; use super::*; use crate::{ ff::{ - boolean_array::{BA112, BA144, BA32}, Serializable, U128Conversions, + boolean_array::{BA32, BA112, BA144}, }, helpers::{ - in_memory_config::{MaliciousHelper, MaliciousHelperContext}, Role, + in_memory_config::{MaliciousHelper, MaliciousHelperContext}, }, secret_sharing::{IntoShares, SharedValue}, test_executor::{run, run_random}, @@ -578,13 +578,14 @@ mod tests { let world = TestWorld::default(); let mut rng = world.rng(); - let record = rng.gen::(); + let record = rng.r#gen::(); let (keys, result) = world .semi_honest(record, |ctx, record| async move { // compute amount of MAC keys - let amount_of_keys: usize = - (usize::try_from(::BITS).unwrap() + 31) / 32; + let amount_of_keys: usize = usize::try_from(::BITS) + .unwrap() + .div_ceil(32); // // generate MAC keys let keys = (0..amount_of_keys) .map(|i| ctx.prss().generate(RecordId::from(i))) @@ -640,8 +641,8 @@ mod tests { S: MaliciousShuffleable, Standard: Distribution, { - let row = ::new(rng.gen(), rng.gen()); - let tag = AdditiveShare::::new(rng.gen::(), rng.gen::()); + let row = ::new(rng.r#gen(), rng.r#gen()); + let tag = AdditiveShare::::new(rng.r#gen::(), rng.r#gen::()); let row_and_tag: Pair = concatenate_row_and_tag(&row, &tag); let mut buf = GenericArray::default(); @@ -689,12 +690,12 @@ mod tests { let world = TestWorld::default(); let mut rng = world.rng(); let records = (0..RECORD_AMOUNT) - .map(|_| rng.gen::()) + .map(|_| rng.r#gen::()) .collect::>(); // last key is not uniform when S:Bits is not a multiple of 32 // since there will be a padding with zeros // but that is ok for test - let keys = rng.gen::(); + let keys = rng.r#gen::(); // convert from S to Vec let converted_keys: Vec = keys.clone().try_into().unwrap(); @@ -820,7 +821,9 @@ mod tests { TestWorldConfig::default(), ); let mut rng = world.rng(); - let mut records = (0..RECORD_AMOUNT).map(|_| rng.gen()).collect::>(); + let mut records = (0..RECORD_AMOUNT) + .map(|_| rng.r#gen()) + .collect::>(); let sharded_result = world .semi_honest(records.clone().into_iter(), |ctx, input| async move { malicious_sharded_shuffle::<_, AdditiveShare>(ctx, input) @@ -854,7 +857,9 @@ mod tests { TestWorldConfig::default(), ); let mut rng = world.rng(); - let mut records = (0..RECORD_AMOUNT).map(|_| rng.gen()).collect::>(); + let mut records = (0..RECORD_AMOUNT) + .map(|_| rng.r#gen()) + .collect::>(); let sharded_result = world .semi_honest(records.clone().into_iter(), |ctx, input| async move { @@ -892,14 +897,16 @@ mod tests { run_random(|mut rng| async move { let target_shard = ShardIndex::from(rng.gen_range(0..u32::try_from(SHARDS).unwrap())); - let mut config = TestWorldConfig::default().with_seed(rng.gen()); + let mut config = TestWorldConfig::default().with_seed(rng.r#gen()); config.stream_interceptor = MaliciousHelper::new(Role::H1, config.role_assignment(), move |ctx, data| { interceptor_h1_to_h2(ctx, Some(target_shard), data); }); let world = TestWorld::>::with_shards(config); - let records = (0..RECORD_AMOUNT).map(|_| rng.gen()).collect::>(); + let records = (0..RECORD_AMOUNT) + .map(|_| rng.r#gen()) + .collect::>(); let sharded_results = world .semi_honest(records.into_iter(), |ctx, shares| async move { malicious_sharded_shuffle::<_, AdditiveShare>(ctx, shares).await @@ -924,14 +931,16 @@ mod tests { run_random(|mut rng| async move { let target_shard = ShardIndex::from(rng.gen_range(0..u32::try_from(SHARDS).unwrap())); - let mut config = TestWorldConfig::default().with_seed(rng.gen()); + let mut config = TestWorldConfig::default().with_seed(rng.r#gen()); config.stream_interceptor = MaliciousHelper::new(Role::H2, config.role_assignment(), move |ctx, data| { interceptor_h2_to_h3(ctx, Some(target_shard), data); }); let world = TestWorld::>::with_shards(config); - let records = (0..RECORD_AMOUNT).map(|_| rng.gen()).collect::>(); + let records = (0..RECORD_AMOUNT) + .map(|_| rng.r#gen()) + .collect::>(); let sharded_results = world .semi_honest(records.into_iter(), |ctx, shares| async move { malicious_sharded_shuffle::<_, AdditiveShare>(ctx, shares).await @@ -957,14 +966,16 @@ mod tests { run_random(|mut rng| async move { let target_shard = ShardIndex::from(rng.gen_range(0..u32::try_from(SHARDS).unwrap())); - let mut config = TestWorldConfig::default().with_seed(rng.gen()); + let mut config = TestWorldConfig::default().with_seed(rng.r#gen()); config.stream_interceptor = MaliciousHelper::new(Role::H3, config.role_assignment(), move |ctx, data| { interceptor_h3_to_h2(ctx, Some(target_shard), data); }); let world = TestWorld::>::with_shards(config); - let records = (0..RECORD_AMOUNT).map(|_| rng.gen()).collect::>(); + let records = (0..RECORD_AMOUNT) + .map(|_| rng.r#gen()) + .collect::>(); let sharded_results = world .semi_honest(records.into_iter(), |ctx, shares| async move { malicious_sharded_shuffle::<_, AdditiveShare>(ctx, shares).await diff --git a/ipa-core/src/protocol/ipa_prf/shuffle/sharded.rs b/ipa-core/src/protocol/ipa_prf/shuffle/sharded.rs index dcb2ce4de..3b3c8cb5a 100644 --- a/ipa-core/src/protocol/ipa_prf/shuffle/sharded.rs +++ b/ipa-core/src/protocol/ipa_prf/shuffle/sharded.rs @@ -15,7 +15,7 @@ use std::{ ops::{Add, AddAssign}, }; -use futures::{future::try_join, stream, StreamExt}; +use futures::{StreamExt, future::try_join, stream}; use rand::seq::SliceRandom; use typenum::Unsigned; @@ -23,22 +23,22 @@ use crate::{ const_assert_eq, error::LengthError, ff::{ - boolean_array::{BA112, BA144, BA32, BA64, BA96}, Gf32Bit, Serializable, U128Conversions, + boolean_array::{BA32, BA64, BA96, BA112, BA144}, }, helpers::{Direction, Error, Role, TotalRecords}, protocol::{ - context::{reshard_iter, ShardedContext}, + RecordId, + context::{ShardedContext, reshard_iter}, ipa_prf::shuffle::{ - step::{ShardedShufflePermuteStep as PermuteStep, ShardedShuffleStep as ShuffleStep}, IntermediateShuffleMessages, + step::{ShardedShufflePermuteStep as PermuteStep, ShardedShuffleStep as ShuffleStep}, }, prss::{FromRandom, SharedRandomness}, - RecordId, }, secret_sharing::{ - replicated::{semi_honest::AdditiveShare, ReplicatedSecretSharing}, Block, Sendable, SharedValue, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare}, }, seq_join::{assert_send, seq_join}, }; @@ -582,7 +582,7 @@ where mod tests { use crate::{ - ff::{boolean_array::BA8, U128Conversions}, + ff::{U128Conversions, boolean_array::BA8}, protocol::ipa_prf::shuffle::sharded::shuffle, test_executor::run, test_fixture::{ diff --git a/ipa-core/src/protocol/ipa_prf/validation_protocol/proof_generation.rs b/ipa-core/src/protocol/ipa_prf/validation_protocol/proof_generation.rs index e496f97e4..db8e55e3d 100644 --- a/ipa-core/src/protocol/ipa_prf/validation_protocol/proof_generation.rs +++ b/ipa-core/src/protocol/ipa_prf/validation_protocol/proof_generation.rs @@ -1,23 +1,23 @@ use std::{array, iter::zip, ops::Mul}; -use typenum::{Unsigned, U, U8}; +use typenum::{U, U8, Unsigned}; use crate::{ error::Error, ff::{Fp61BitPrime, Serializable}, helpers::{Direction, MpcMessage, TotalRecords}, protocol::{ - context::{dzkp_validator::MAX_PROOF_RECURSION, Context}, + RecordId, RecordIdRange, + context::{Context, dzkp_validator::MAX_PROOF_RECURSION}, ipa_prf::{ + CompressedProofGenerator, FirstProofGenerator, malicious_security::{ + FIRST_RECURSION_FACTOR as FRF, lagrange::{CanonicalLagrangeDenominator, LagrangeTable}, prover::{ProverLagrangeInput, ProverValues}, - FIRST_RECURSION_FACTOR as FRF, }, - CompressedProofGenerator, FirstProofGenerator, }, prss::SharedRandomness, - RecordId, RecordIdRange, }, secret_sharing::SharedValue, }; @@ -273,18 +273,18 @@ mod test { use crate::{ protocol::{ + RecordId, RecordIdRange, context::Context, ipa_prf::{ malicious_security::{ - prover::{ProverValues, UVValues}, FIRST_RECURSION_FACTOR, + prover::{ProverValues, UVValues}, }, validation_protocol::{ proof_generation::ProofBatch, - validation::{test::simple_proof_check, BatchToVerify}, + validation::{BatchToVerify, test::simple_proof_check}, }, }, - RecordId, RecordIdRange, }, test_executor::run, test_fixture::{Runner, TestWorld}, @@ -297,7 +297,7 @@ mod test { let mut rng = world.rng(); - let uv_values = repeat_with(|| (rng.gen(), rng.gen())) + let uv_values = repeat_with(|| (rng.r#gen(), rng.r#gen())) .take(100) .collect::>(); let uv_values_iter = uv_values.iter().copied(); diff --git a/ipa-core/src/protocol/ipa_prf/validation_protocol/validation.rs b/ipa-core/src/protocol/ipa_prf/validation_protocol/validation.rs index e4022a60c..5d6f3a8ea 100644 --- a/ipa-core/src/protocol/ipa_prf/validation_protocol/validation.rs +++ b/ipa-core/src/protocol/ipa_prf/validation_protocol/validation.rs @@ -5,31 +5,31 @@ use std::{ use futures_util::future::{try_join, try_join4}; use subtle::ConstantTimeEq; -use typenum::{Unsigned, U120, U448}; +use typenum::{U120, U448, Unsigned}; use crate::{ const_assert_eq, error::{Error, UnwrapInfallible}, ff::{Fp61BitPrime, Serializable}, helpers::{ - hashing::{compute_hash, hash_to_field, Hash}, Direction, MpcMessage, TotalRecords, + hashing::{Hash, compute_hash, hash_to_field}, }, protocol::{ + RecordId, context::{ - dzkp_validator::MAX_PROOF_RECURSION, step::DzkpProofVerifyStep as Step, Context, + Context, dzkp_validator::MAX_PROOF_RECURSION, step::DzkpProofVerifyStep as Step, }, ipa_prf::{ + CompressedProofGenerator, FirstProofGenerator, malicious_security::{ + FIRST_RECURSION_FACTOR as FRF, verifier::{ - compute_g_differences, recursively_compute_final_check, VerifierLagrangeInput, + VerifierLagrangeInput, compute_g_differences, recursively_compute_final_check, }, - FIRST_RECURSION_FACTOR as FRF, }, validation_protocol::proof_generation::ProofBatch, - CompressedProofGenerator, FirstProofGenerator, }, - RecordId, }, secret_sharing::SharedValue, }; @@ -454,19 +454,19 @@ pub mod test { ff::Fp61BitPrime, helpers::Direction, protocol::{ + RecordId, RecordIdRange, context::Context, ipa_prf::{ + CompressedProofGenerator, FirstProofGenerator, malicious_security::{ + FIRST_RECURSION_FACTOR as FRF, lagrange::CanonicalLagrangeDenominator, prover::{ProverValues, UVValues}, - verifier::{compute_sum_share, interpolate_at_r, VerifierValues}, - FIRST_RECURSION_FACTOR as FRF, + verifier::{VerifierValues, compute_sum_share, interpolate_at_r}, }, validation_protocol::{proof_generation::ProofBatch, validation::BatchToVerify}, - CompressedProofGenerator, FirstProofGenerator, }, prss::SharedRandomness, - RecordId, RecordIdRange, }, secret_sharing::SharedValue, test_executor::run, @@ -545,44 +545,47 @@ pub mod test { let mut rng = world.rng(); - let uv_values = repeat_with(|| (rng.gen(), rng.gen())) + let uv_values = repeat_with(|| (rng.r#gen(), rng.r#gen())) .take(100) .collect::>(); let uv_values_iter = uv_values.iter().copied(); let uv_values_iter_ref = &uv_values_iter; - let [(helper_1_left, helper_1_right), (helper_2_left, helper_2_right), (helper_3_left, helper_3_right)] = - world - .semi_honest((), |ctx, ()| async move { - // generate and output VerifierBatch together with h value - let ( - my_batch_left_shares, - shares_of_batch_from_left_prover, - p_mask_from_right_prover, - q_mask_from_left_prover, - ) = ProofBatch::generate( - &ctx.narrow("generate_batch"), - RecordIdRange::ALL, - ProverValues(uv_values_iter_ref.clone()), - ); - - let batch_to_verify = BatchToVerify::generate_batch_to_verify( - ctx.narrow("generate_batch"), - RecordId::FIRST, - my_batch_left_shares, - shares_of_batch_from_left_prover, - p_mask_from_right_prover, - q_mask_from_left_prover, - ) - .await; + let [ + (helper_1_left, helper_1_right), + (helper_2_left, helper_2_right), + (helper_3_left, helper_3_right), + ] = world + .semi_honest((), |ctx, ()| async move { + // generate and output VerifierBatch together with h value + let ( + my_batch_left_shares, + shares_of_batch_from_left_prover, + p_mask_from_right_prover, + q_mask_from_left_prover, + ) = ProofBatch::generate( + &ctx.narrow("generate_batch"), + RecordIdRange::ALL, + ProverValues(uv_values_iter_ref.clone()), + ); - // generate and output challenges - batch_to_verify - .generate_challenges(ctx, RecordId::FIRST) - .await - }) + let batch_to_verify = BatchToVerify::generate_batch_to_verify( + ctx.narrow("generate_batch"), + RecordId::FIRST, + my_batch_left_shares, + shares_of_batch_from_left_prover, + p_mask_from_right_prover, + q_mask_from_left_prover, + ) .await; + // generate and output challenges + batch_to_verify + .generate_challenges(ctx, RecordId::FIRST) + .await + }) + .await; + // verifier when H1 is prover assert_eq!(helper_2_left, helper_3_right); // verifier when H2 is prover @@ -664,54 +667,56 @@ pub mod test { run(|| async move { let world = TestWorld::default(); - let [(h1_c_left, h1_c_right, h1_batch), (h2_c_left, h2_c_right, h2_batch), (h3_c_left, h3_c_right, h3_batch)] = - world - .semi_honest((), |ctx, ()| async move { - // generate u, v values - let (vec_my_u_and_v, _, _, _) = generate_u_v(&ctx, LEN); - - // generate and output VerifierBatch together with h value - let ( - my_batch_left_shares, - shares_of_batch_from_left_prover, - p_mask_from_right_prover, - q_mask_from_left_prover, - ) = ProofBatch::generate( - &ctx.narrow("generate_batch"), - RecordIdRange::ALL, - ProverValues(vec_my_u_and_v.into_iter()), - ); - - let batch_to_verify = BatchToVerify::generate_batch_to_verify( - ctx.narrow("generate_batch"), - RecordId::FIRST, - my_batch_left_shares, - shares_of_batch_from_left_prover, - p_mask_from_right_prover, - q_mask_from_left_prover, - ) - .await; + let [ + (h1_c_left, h1_c_right, h1_batch), + (h2_c_left, h2_c_right, h2_batch), + (h3_c_left, h3_c_right, h3_batch), + ] = world + .semi_honest((), |ctx, ()| async move { + // generate u, v values + let (vec_my_u_and_v, _, _, _) = generate_u_v(&ctx, LEN); - // generate challenges - let (challenges_for_left_prover, challenges_for_right_prover) = - batch_to_verify - .generate_challenges(ctx.narrow("generate_hash"), RecordId::FIRST) - .await; - - assert_eq!( - challenges_for_right_prover.len(), - batch_to_verify.proofs_from_right_prover.len() + 1 - ); - - // output challenges and batches to verify - ( - challenges_for_left_prover, - challenges_for_right_prover, - batch_to_verify, - ) - }) + // generate and output VerifierBatch together with h value + let ( + my_batch_left_shares, + shares_of_batch_from_left_prover, + p_mask_from_right_prover, + q_mask_from_left_prover, + ) = ProofBatch::generate( + &ctx.narrow("generate_batch"), + RecordIdRange::ALL, + ProverValues(vec_my_u_and_v.into_iter()), + ); + + let batch_to_verify = BatchToVerify::generate_batch_to_verify( + ctx.narrow("generate_batch"), + RecordId::FIRST, + my_batch_left_shares, + shares_of_batch_from_left_prover, + p_mask_from_right_prover, + q_mask_from_left_prover, + ) .await; + // generate challenges + let (challenges_for_left_prover, challenges_for_right_prover) = batch_to_verify + .generate_challenges(ctx.narrow("generate_hash"), RecordId::FIRST) + .await; + + assert_eq!( + challenges_for_right_prover.len(), + batch_to_verify.proofs_from_right_prover.len() + 1 + ); + + // output challenges and batches to verify + ( + challenges_for_left_prover, + challenges_for_right_prover, + batch_to_verify, + ) + }) + .await; + // check challenges // h1 prover assert_eq!(h2_c_left, h3_c_right); @@ -769,78 +774,77 @@ pub mod test { run(|| async move { let world = TestWorld::default(); - let [(pq_h1, h1_left, h1_right), (pq_h2, h2_left, h2_right), (pq_h3, h3_left, h3_right)] = - world - .semi_honest((), |ctx, ()| async move { - // generate u, v values - let (vec_my_u_and_v, _, vec_u_from_right_prover, vec_v_from_left_prover) = - generate_u_v(&ctx, LEN); - - // generate and output VerifierBatch together with h value - let ( - my_batch_left_shares, - shares_of_batch_from_left_prover, - p_mask_from_right_prover, - q_mask_from_left_prover, - ) = ProofBatch::generate( - &ctx.narrow("generate_batch"), - RecordIdRange::ALL, - ProverValues(vec_my_u_and_v.into_iter()), - ); - - let batch_to_verify = BatchToVerify::generate_batch_to_verify( - ctx.narrow("generate_batch"), - RecordId::FIRST, - my_batch_left_shares, - shares_of_batch_from_left_prover, - p_mask_from_right_prover, - q_mask_from_left_prover, - ) + let [ + (pq_h1, h1_left, h1_right), + (pq_h2, h2_left, h2_right), + (pq_h3, h3_left, h3_right), + ] = world + .semi_honest((), |ctx, ()| async move { + // generate u, v values + let (vec_my_u_and_v, _, vec_u_from_right_prover, vec_v_from_left_prover) = + generate_u_v(&ctx, LEN); + + // generate and output VerifierBatch together with h value + let ( + my_batch_left_shares, + shares_of_batch_from_left_prover, + p_mask_from_right_prover, + q_mask_from_left_prover, + ) = ProofBatch::generate( + &ctx.narrow("generate_batch"), + RecordIdRange::ALL, + ProverValues(vec_my_u_and_v.into_iter()), + ); + + let batch_to_verify = BatchToVerify::generate_batch_to_verify( + ctx.narrow("generate_batch"), + RecordId::FIRST, + my_batch_left_shares, + shares_of_batch_from_left_prover, + p_mask_from_right_prover, + q_mask_from_left_prover, + ) + .await; + + // generate challenges + let (challenges_for_left_prover, challenges_for_right_prover) = batch_to_verify + .generate_challenges(ctx.narrow("generate_hash"), RecordId::FIRST) .await; - // generate challenges - let (challenges_for_left_prover, challenges_for_right_prover) = - batch_to_verify - .generate_challenges(ctx.narrow("generate_hash"), RecordId::FIRST) - .await; + assert_eq!( + challenges_for_right_prover.len(), + batch_to_verify.proofs_from_right_prover.len() + 1 + ); - assert_eq!( - challenges_for_right_prover.len(), - batch_to_verify.proofs_from_right_prover.len() + 1 - ); + let (p, q) = batch_to_verify.compute_p_and_q_r( + &challenges_for_left_prover, + &challenges_for_right_prover, + VerifierValues(vec_u_from_right_prover.into_iter().chunk_array::()), + VerifierValues(vec_v_from_left_prover.into_iter().chunk_array::()), + ); - let (p, q) = batch_to_verify.compute_p_and_q_r( - &challenges_for_left_prover, - &challenges_for_right_prover, - VerifierValues( - vec_u_from_right_prover.into_iter().chunk_array::(), - ), - VerifierValues(vec_v_from_left_prover.into_iter().chunk_array::()), - ); - - let p_times_q = - BatchToVerify::compute_p_times_q(ctx, RecordId::FIRST, p, q) - .await - .unwrap(); - - let denominator = CanonicalLagrangeDenominator::< - Fp61BitPrime, - { CompressedProofGenerator::PROOF_LENGTH }, - >::new(); - - let g_r_left = interpolate_at_r( - batch_to_verify.proofs_from_left_prover.last().unwrap(), - challenges_for_left_prover.last().unwrap(), - &denominator, - ); - let g_r_right = interpolate_at_r( - batch_to_verify.proofs_from_right_prover.last().unwrap(), - challenges_for_right_prover.last().unwrap(), - &denominator, - ); - (p_times_q, g_r_left, g_r_right) - }) - .await; + let p_times_q = BatchToVerify::compute_p_times_q(ctx, RecordId::FIRST, p, q) + .await + .unwrap(); + + let denominator = CanonicalLagrangeDenominator::< + Fp61BitPrime, + { CompressedProofGenerator::PROOF_LENGTH }, + >::new(); + + let g_r_left = interpolate_at_r( + batch_to_verify.proofs_from_left_prover.last().unwrap(), + challenges_for_left_prover.last().unwrap(), + &denominator, + ); + let g_r_right = interpolate_at_r( + batch_to_verify.proofs_from_right_prover.last().unwrap(), + challenges_for_right_prover.last().unwrap(), + &denominator, + ); + (p_times_q, g_r_left, g_r_right) + }) + .await; // check h1's proof assert_eq!(pq_h3, h2_left + h3_right); diff --git a/ipa-core/src/protocol/prss/crypto.rs b/ipa-core/src/protocol/prss/crypto.rs index cc3ec4f2a..e62fcc693 100644 --- a/ipa-core/src/protocol/prss/crypto.rs +++ b/ipa-core/src/protocol/prss/crypto.rs @@ -1,6 +1,6 @@ use aes::{ - cipher::{BlockEncrypt, KeyInit}, Aes256, + cipher::{BlockEncrypt, KeyInit}, }; use generic_array::{ArrayLength, GenericArray}; use hkdf::Hkdf; @@ -14,8 +14,8 @@ use crate::{ helpers::Direction, protocol::prss::{PrssIndex, PrssIndex128}, secret_sharing::{ - replicated::{semi_honest::AdditiveShare, ReplicatedSecretSharing}, SharedValue, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare}, }, }; @@ -381,11 +381,11 @@ mod tests { use crate::protocol::prss::KeyExchange; let other_gen = KeyExchange::new(&mut thread_rng()); - let gen = KeyExchange::new(&mut thread_rng()) + let key_generator = KeyExchange::new(&mut thread_rng()) .key_exchange(&other_gen.public_key()) .generator("foo".as_bytes()); - let _ = gen.generate(0); - let _ = gen.generate(0); + let _ = key_generator.generate(0); + let _ = key_generator.generate(0); } } diff --git a/ipa-core/src/protocol/prss/mod.rs b/ipa-core/src/protocol/prss/mod.rs index ad185a079..469a88010 100644 --- a/ipa-core/src/protocol/prss/mod.rs +++ b/ipa-core/src/protocol/prss/mod.rs @@ -7,7 +7,7 @@ pub use crypto::{ FromPrss, FromRandom, FromRandomU128, Generator, GeneratorFactory, KeyExchange, SharedRandomness, }; -use generic_array::{sequence::GenericSequence, ArrayLength, GenericArray}; +use generic_array::{ArrayLength, GenericArray, sequence::GenericSequence}; pub(super) use internal::PrssIndex128; pub use seed::{Seed, SeededEndpointSetup}; use x25519_dalek::PublicKey; @@ -472,10 +472,10 @@ pub mod test { use crate::{ ff::{Field, Fp31, U128Conversions}, protocol::{ - prss::{Endpoint, PrssIndex, SharedRandomness}, Gate, + prss::{Endpoint, PrssIndex, SharedRandomness}, }, - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, secret_sharing::SharedValue, test_fixture::make_participants, }; @@ -701,8 +701,8 @@ pub mod test { #[test] fn prss_rng() { fn same_rng(mut a: SequentialSharedRandomness, mut b: SequentialSharedRandomness) { - assert_eq!(a.gen::(), b.gen::()); - assert_eq!(a.gen::<[u8; 20]>(), b.gen::<[u8; 20]>()); + assert_eq!(a.r#gen::(), b.r#gen::()); + assert_eq!(a.r#gen::<[u8; 20]>(), b.r#gen::<[u8; 20]>()); assert_eq!(a.gen_range(7..99), b.gen_range(7..99)); assert_eq!(a.gen_bool(0.3), b.gen_bool(0.3)); } @@ -728,11 +728,11 @@ pub mod test { let (i_left, i_right) = idx.generate_values(0_u128); assert_ne!( i_left & u128::from(u64::MAX), - u128::from(s_left.gen::()) + u128::from(s_left.r#gen::()) ); assert_ne!( i_right & u128::from(u64::MAX), - u128::from(s_right.gen::()) + u128::from(s_right.r#gen::()) ); } diff --git a/ipa-core/src/protocol/prss/seed.rs b/ipa-core/src/protocol/prss/seed.rs index 1215b4d15..83f7e32aa 100644 --- a/ipa-core/src/protocol/prss/seed.rs +++ b/ipa-core/src/protocol/prss/seed.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, convert::Infallible}; use generic_array::GenericArray; -use typenum::{Unsigned, U2, U32, U64}; +use typenum::{U2, U32, U64, Unsigned}; use crate::{ ff::Serializable, @@ -137,8 +137,8 @@ mod tests { use crate::{ protocol::{ - prss::{Endpoint, SeededEndpointSetup, SharedRandomness}, Gate, RecordId, + prss::{Endpoint, SeededEndpointSetup, SharedRandomness}, }, test_fixture::make_participants, utils::array::zip3, @@ -167,7 +167,7 @@ mod tests { // also make sure seeds are unique let r2 = setup_new(&mut thread_rng()); - zip3(r1, r2).map(|(r1, r2)| { + let _ = zip3(r1, r2).map(|(r1, r2)| { assert_ne!(r1.right.entropy, r2.right.entropy); assert_ne!(r1.left.entropy, r2.left.entropy); }); diff --git a/ipa-core/src/query/executor.rs b/ipa-core/src/query/executor.rs index 90b83be26..3cf40813c 100644 --- a/ipa-core/src/query/executor.rs +++ b/ipa-core/src/query/executor.rs @@ -22,14 +22,13 @@ use crate::{ executor::IpaRuntime, ff::Serializable, helpers::{ - negotiate_prss, + BodyStream, Gateway, negotiate_prss, query::{QueryConfig, QueryType}, - BodyStream, Gateway, }, hpke::PrivateKeyRegistry, - protocol::{prss::Endpoint as PrssEndpoint, Gate}, + protocol::{Gate, prss::Endpoint as PrssEndpoint}, query::{ - runner::{execute_hybrid_protocol, QueryResult}, + runner::{QueryResult, execute_hybrid_protocol}, state::RunningQuery, }, sync::Arc, @@ -219,11 +218,11 @@ mod tests { executor::IpaRuntime, ff::{FieldType, Fp31, U128Conversions}, helpers::{ - query::{QueryConfig, QueryType}, BodyStream, Gateway, Role, + query::{QueryConfig, QueryType}, }, - query::{executor::do_query, state::RunningQuery, ProtocolResult}, - secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares}, + query::{ProtocolResult, executor::do_query, state::RunningQuery}, + secret_sharing::{IntoShares, replicated::semi_honest::AdditiveShare}, test_fixture::TestWorld, }; diff --git a/ipa-core/src/query/mod.rs b/ipa-core/src/query/mod.rs index 06470a6bc..f286e87dd 100644 --- a/ipa-core/src/query/mod.rs +++ b/ipa-core/src/query/mod.rs @@ -10,4 +10,4 @@ pub use processor::{ NewQueryError, PrepareQueryError, Processor as QueryProcessor, QueryCompletionError, QueryInputError, QueryKillStatus, QueryKilled, QueryStatusError, }; -pub use state::{min_status, QueryStatus}; +pub use state::{QueryStatus, min_status}; diff --git a/ipa-core/src/query/processor.rs b/ipa-core/src/query/processor.rs index 388bf7c54..c8312316c 100644 --- a/ipa-core/src/query/processor.rs +++ b/ipa-core/src/query/processor.rs @@ -11,17 +11,16 @@ use crate::{ error::Error as ProtocolError, executor::IpaRuntime, helpers::{ - query::{CompareStatusRequest, PrepareQuery, QueryConfig}, - routing::RouteId, BodyStream, BroadcastError, Gateway, GatewayConfig, MpcTransportError, MpcTransportImpl, Role, RoleAssignment, ShardTransportError, ShardTransportImpl, Transport, + query::{CompareStatusRequest, PrepareQuery, QueryConfig}, + routing::RouteId, }, hpke::{KeyRegistry, PrivateKeyOnly}, protocol::QueryId, query::{ - executor, + CompletionHandle, ProtocolResult, executor, state::{QueryState, QueryStatus, RemoveQuery, RunningQueries, StateError}, - CompletionHandle, ProtocolResult, }, sharding::ShardIndex, sync::Arc, @@ -34,15 +33,15 @@ use crate::{ /// /// Query processing consists of multiple steps: /// - A new request to initiate a query arrives from an external party (report collector) to any of the -/// helpers. +/// helpers. /// - Upon receiving that request, helper chooses a unique [`QueryId`] and assigns [`Role`] to every -/// helper. It informs other parties about it and awaits their response. +/// helper. It informs other parties about it and awaits their response. /// - If all parties accept the proposed query, they negotiate shared randomness and signal that -/// they're ready to receive inputs. +/// they're ready to receive inputs. /// - Each party, upon receiving the input as a set of [`AdditiveShare`], immediately starts executing -/// IPA protocol. +/// IPA protocol. /// - When helper party is done, it holds onto the results of the computation until the external party -/// that initiated this request asks for them. +/// that initiated this request asks for them. /// /// This struct is decoupled from the [`Transport`]s used to communicate with other [`Processor`] /// running in other shards or helpers. Many functions require transport as part of their arguments @@ -165,13 +164,13 @@ impl Processor { /// Upon receiving a new query request: /// * processor generates new query id /// * assigns roles to helpers in the ring. - /// Helper that received new query request becomes `Role::H1` (aka coordinator). - /// The coordinator is in theory free to choose helpers for `Role::H2` and `Role::H3` - /// arbitrarily (aka followers), however, this is not currently exercised. + /// Helper that received new query request becomes `Role::H1` (aka coordinator). + /// The coordinator is in theory free to choose helpers for `Role::H2` and `Role::H3` + /// arbitrarily (aka followers), however, this is not currently exercised. /// * Requests Infra and Network layer to create resources for this query /// * sends `prepare` request that describes the query configuration - /// (query id, query type, field type, roles -> endpoints or reverse) - /// to helpers and its shards and waits for the confirmation + /// (query id, query type, field type, roles -> endpoints or reverse) + /// to helpers and its shards and waits for the confirmation /// * records newly created query id internally and sets query state to awaiting data /// * returns query configuration /// @@ -554,20 +553,19 @@ mod tests { use crate::{ executor::IpaRuntime, - ff::{boolean_array::BA64, FieldType}, + ff::{FieldType, boolean_array::BA64}, helpers::{ - make_owned_handler, - query::{PrepareQuery, QueryConfig, QueryType::TestMultiply}, - routing::Addr, ApiError, HandlerBox, HelperIdentity, HelperResponse, InMemoryMpcNetwork, InMemoryShardNetwork, InMemoryTransport, RequestHandler, RoleAssignment, Transport, - TransportIdentity, + TransportIdentity, make_owned_handler, + query::{PrepareQuery, QueryConfig, QueryType::TestMultiply}, + routing::Addr, }, protocol::QueryId, query::{ + NewQueryError, PrepareQueryError, QueryStatus, QueryStatusError, processor::Processor, state::{QueryState, RunningQuery, StateError}, - NewQueryError, PrepareQueryError, QueryStatus, QueryStatusError, }, sharding::ShardIndex, }; @@ -927,13 +925,13 @@ mod tests { mod complete { use crate::{ - helpers::{make_owned_handler, routing::RouteId, Transport}, + helpers::{Transport, make_owned_handler, routing::RouteId}, query::{ + ProtocolResult, QueryCompletionError, processor::{ - tests::{HelperResponse, TestComponents, TestComponentsArgs}, QueryId, + tests::{HelperResponse, TestComponents, TestComponentsArgs}, }, - ProtocolResult, QueryCompletionError, }, sharding::ShardIndex, }; @@ -1293,9 +1291,9 @@ mod tests { helpers::Transport, protocol::QueryId, query::{ + QueryKillStatus, processor::Processor, state::{QueryState, RunningQuery}, - QueryKillStatus, }, test_executor::run, }; diff --git a/ipa-core/src/query/runner/add_in_prime_field.rs b/ipa-core/src/query/runner/add_in_prime_field.rs index 0d616f0f9..ae00df3d9 100644 --- a/ipa-core/src/query/runner/add_in_prime_field.rs +++ b/ipa-core/src/query/runner/add_in_prime_field.rs @@ -55,7 +55,7 @@ mod tests { use crate::{ ff::{Fp31, U128Conversions}, secret_sharing::IntoShares, - test_fixture::{join3v, Reconstruct, TestWorld}, + test_fixture::{Reconstruct, TestWorld, join3v}, }; #[tokio::test] diff --git a/ipa-core/src/query/runner/hybrid.rs b/ipa-core/src/query/runner/hybrid.rs index 94b641b36..392095b21 100644 --- a/ipa-core/src/query/runner/hybrid.rs +++ b/ipa-core/src/query/runner/hybrid.rs @@ -12,21 +12,22 @@ use super::QueryResult; use crate::{ error::{Error, LengthError}, ff::{ + Serializable, U128Conversions, boolean::Boolean, - boolean_array::{BooleanArray, BA3, BA32, BA8}, + boolean_array::{BA3, BA8, BA32, BooleanArray}, curve_points::RP25519, ec_prime_field::Fp25519, - Serializable, U128Conversions, }, helpers::{ + BodyStream, Gateway, LengthDelimitedStream, query::{DpMechanism, HybridQueryParams, QueryConfig, QuerySize}, setup_cross_shard_prss, stream::TryFlattenItersExt, - BodyStream, Gateway, LengthDelimitedStream, }, hpke::PrivateKeyRegistry, protocol::{ - basics::{shard_fin::FinalizerContext, BooleanArrayMul, BooleanProtocols, Reveal}, + Gate, + basics::{BooleanArrayMul, BooleanProtocols, Reveal, shard_fin::FinalizerContext}, context::{ DZKPUpgraded, MacUpgraded, ShardedContext, ShardedMaliciousContext, UpgradableContext, }, @@ -38,15 +39,14 @@ use crate::{ ipa_prf::{oprf_padding::PaddingParameters, prf_eval::PrfSharing, shuffle::ShardedShuffle}, prss::{Endpoint, FromPrss}, step::ProtocolStep::Hybrid, - Gate, }, query::runner::reshard_tag::reshard_aad, report::hybrid::{ EncryptedHybridReport, IndistinguishableHybridReport, UniqueTag, UniqueTagValidator, }, secret_sharing::{ - replicated::semi_honest::AdditiveShare as Replicated, BitDecomposed, TransposeFrom, - Vectorizable, + BitDecomposed, TransposeFrom, Vectorizable, + replicated::semi_honest::AdditiveShare as Replicated, }, seq_join::seq_join, sharding::{ShardConfiguration, Sharded}, @@ -196,32 +196,29 @@ pub async fn execute_hybrid_protocol<'a, R: PrivateKeyRegistry>( #[cfg(all(test, unit_test, feature = "in-memory-infra"))] mod tests { - use std::{ - iter::{repeat, zip}, - sync::Arc, - }; + use std::{iter::zip, sync::Arc}; use rand::rngs::StdRng; use rand_core::SeedableRng; use crate::{ ff::{ - boolean_array::{BA3, BA32, BA8}, U128Conversions, + boolean_array::{BA3, BA8, BA32}, }, helpers::{ - query::{HybridQueryParams, QuerySize}, BodyStream, + query::{HybridQueryParams, QuerySize}, }, hpke::{KeyPair, KeyRegistry}, query::runner::hybrid::Query as HybridQuery, - report::hybrid::{HybridReport, DEFAULT_KEY_ID}, + report::hybrid::{DEFAULT_KEY_ID, HybridReport}, secret_sharing::IntoShares, test_executor::run, test_fixture::{ - flatten3v, - hybrid::{build_hybrid_records_and_expectation, TestHybridRecord}, Reconstruct, RoundRobinInputDistribution, TestWorld, TestWorldConfig, WithShards, + flatten3v, + hybrid::{TestHybridRecord, build_hybrid_records_and_expectation}, }, }; @@ -277,7 +274,7 @@ mod tests { match expected.len() { len if len < 256 => { - expected.extend(repeat(0).take(256 - len)); + expected.extend(std::iter::repeat_n(0, 256 - len)); } len if len > 256 => { panic!("no support for more than 256 breakdown_keys"); diff --git a/ipa-core/src/query/runner/reshard_tag.rs b/ipa-core/src/query/runner/reshard_tag.rs index 9b535fc11..d10c31dac 100644 --- a/ipa-core/src/query/runner/reshard_tag.rs +++ b/ipa-core/src/query/runner/reshard_tag.rs @@ -1,17 +1,17 @@ use std::{ - pin::{pin, Pin}, + pin::{Pin, pin}, task::{Context, Poll}, }; -use futures::{ready, Stream}; +use futures::{Stream, ready}; use pin_project::pin_project; use crate::{ error::Error, helpers::Message, protocol::{ - context::{reshard_try_stream, ShardedContext}, RecordId, + context::{ShardedContext, reshard_try_stream}, }, sharding::ShardIndex, }; @@ -82,11 +82,11 @@ impl>, K, A> Stream for StreamSplitter<'_ #[cfg(all(test, unit_test))] mod tests { - use futures::{stream, StreamExt}; + use futures::{StreamExt, stream}; use crate::{ error::Error, - ff::{boolean_array::BA8, U128Conversions}, + ff::{U128Conversions, boolean_array::BA8}, query::runner::reshard_tag::reshard_aad, secret_sharing::SharedValue, sharding::{ShardConfiguration, ShardIndex}, diff --git a/ipa-core/src/query/runner/sharded_shuffle.rs b/ipa-core/src/query/runner/sharded_shuffle.rs index 2acc6faea..e8d265b60 100644 --- a/ipa-core/src/query/runner/sharded_shuffle.rs +++ b/ipa-core/src/query/runner/sharded_shuffle.rs @@ -7,14 +7,14 @@ use ipa_step::StepNarrow; use crate::{ error::Error, ff::boolean_array::BA64, - helpers::{setup_cross_shard_prss, BodyStream, Gateway, SingleRecordStream}, + helpers::{BodyStream, Gateway, SingleRecordStream, setup_cross_shard_prss}, protocol::{ + Gate, RecordId, basics::{FinalizerContext, ShardAssembledResult}, context::{Context, MaliciousProtocolSteps, ShardedContext, ShardedSemiHonestContext}, ipa_prf::shuffle::ShardedShuffle, prss::Endpoint as PrssEndpoint, step::{ProtocolStep, TestShardedShuffleStep}, - Gate, RecordId, }, query::runner::QueryResult, secret_sharing::replicated::semi_honest::AdditiveShare, @@ -116,11 +116,11 @@ mod tests { use typenum::Unsigned; use crate::{ - ff::{boolean_array::BA64, Serializable, U128Conversions}, + ff::{Serializable, U128Conversions, boolean_array::BA64}, query::runner::sharded_shuffle::execute, - secret_sharing::{replicated::semi_honest::AdditiveShare, IntoShares}, + secret_sharing::{IntoShares, replicated::semi_honest::AdditiveShare}, test_executor::run, - test_fixture::{try_join3_array, Reconstruct, TestWorld, TestWorldConfig, WithShards}, + test_fixture::{Reconstruct, TestWorld, TestWorldConfig, WithShards, try_join3_array}, utils::array::zip3, }; diff --git a/ipa-core/src/query/runner/test_multiply.rs b/ipa-core/src/query/runner/test_multiply.rs index e7ff2410d..95a8b8e60 100644 --- a/ipa-core/src/query/runner/test_multiply.rs +++ b/ipa-core/src/query/runner/test_multiply.rs @@ -5,11 +5,11 @@ use crate::{ ff::{PrimeField, Serializable}, helpers::{BodyStream, Gateway, RecordsStream, TotalRecords}, protocol::{ + RecordId, basics::SecureMul, context::{Context, SemiHonestContext}, prss::Endpoint as PrssEndpoint, step::ProtocolStep, - RecordId, }, query::runner::QueryResult, secret_sharing::replicated::semi_honest::AdditiveShare as Replicated, @@ -76,7 +76,7 @@ mod tests { use crate::{ ff::{Fp31, U128Conversions}, secret_sharing::IntoShares, - test_fixture::{join3v, Reconstruct, TestWorld}, + test_fixture::{Reconstruct, TestWorld, join3v}, }; #[tokio::test] diff --git a/ipa-core/src/query/state.rs b/ipa-core/src/query/state.rs index 148a40565..eca92e80e 100644 --- a/ipa-core/src/query/state.rs +++ b/ipa-core/src/query/state.rs @@ -1,17 +1,17 @@ use std::{ - collections::{hash_map::Entry, HashMap}, + collections::{HashMap, hash_map::Entry}, fmt::{Debug, Display, Formatter}, future::Future, task::Poll, }; -use ::tokio::sync::oneshot::{error::TryRecvError, Receiver}; -use futures::{ready, FutureExt}; +use ::tokio::sync::oneshot::{Receiver, error::TryRecvError}; +use futures::{FutureExt, ready}; use serde::{Deserialize, Serialize}; use crate::{ executor::IpaJoinHandle, - helpers::{query::QueryConfig, RoleAssignment}, + helpers::{RoleAssignment, query::QueryConfig}, protocol::QueryId, query::runner::QueryResult, sync::Mutex, @@ -198,13 +198,13 @@ impl QueryHandle<'_> { inner.get(&self.query_id).map(QueryStatus::from) } - pub fn remove_query_on_drop(&self) -> RemoveQuery { + pub fn remove_query_on_drop(&self) -> RemoveQuery<'_> { RemoveQuery::new(self.query_id, self.queries) } } impl RunningQueries { - pub fn handle(&self, query_id: QueryId) -> QueryHandle { + pub fn handle(&self, query_id: QueryId) -> QueryHandle<'_> { QueryHandle { query_id, queries: self, @@ -256,7 +256,7 @@ impl Drop for RemoveQuery<'_> { #[cfg(all(test, unit_test))] mod tests { - use crate::query::{state::min_status, QueryStatus}; + use crate::query::{QueryStatus, state::min_status}; #[test] fn test_order() { diff --git a/ipa-core/src/report/hybrid.rs b/ipa-core/src/report/hybrid.rs index bcaca20aa..96c4ae131 100644 --- a/ipa-core/src/report/hybrid.rs +++ b/ipa-core/src/report/hybrid.rs @@ -33,26 +33,26 @@ use bytes::{Buf, BufMut, Bytes}; use generic_array::{ArrayLength, GenericArray}; use hpke::Serializable as _; use rand_core::{CryptoRng, RngCore}; -use typenum::{Sum, Unsigned, U12, U16}; +use typenum::{Sum, U12, U16, Unsigned}; use crate::{ const_assert_eq, error::{BoxError, Error}, ff::{ + Serializable, boolean_array::{ - BooleanArray, BooleanArrayReader, BooleanArrayWriter, BA112, BA3, BA32, BA64, BA8, + BA3, BA8, BA32, BA64, BA112, BooleanArray, BooleanArrayReader, BooleanArrayWriter, }, - Serializable, }, hpke::{ - open_in_place, seal_in_place, CryptError, EncapsulationSize, PrivateKeyRegistry, - PublicKeyRegistry, TagSize, + CryptError, EncapsulationSize, PrivateKeyRegistry, PublicKeyRegistry, TagSize, + open_in_place, seal_in_place, }, protocol::ipa_prf::{boolean_ops::expand_shared_array_in_place, shuffle::Shuffleable}, report::hybrid_info::{HybridConversionInfo, HybridImpressionInfo}, secret_sharing::{ - replicated::{semi_honest::AdditiveShare as Replicated, ReplicatedSecretSharing}, SharedValue, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare as Replicated}, }, sharding::ShardIndex, }; @@ -1243,8 +1243,8 @@ mod test { use crate::{ error::Error, ff::{ - boolean_array::{BA3, BA8}, Serializable, + boolean_array::{BA3, BA8}, }, hpke::{KeyPair, KeyRegistry}, report::{ @@ -1252,8 +1252,8 @@ mod test { hybrid_info::{HybridConversionInfo, HybridImpressionInfo}, }, secret_sharing::replicated::{ - semi_honest::{AdditiveShare as Replicated, AdditiveShare}, ReplicatedSecretSharing, + semi_honest::{AdditiveShare as Replicated, AdditiveShare}, }, test_executor::run_random, }; @@ -1265,19 +1265,19 @@ mod test { match event_type { HybridEventType::Impression => { HybridReport::Impression(HybridImpressionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - breakdown_key: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + breakdown_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridImpressionInfo::new(0), }) } HybridEventType::Conversion => { HybridReport::Conversion(HybridConversionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - value: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + value: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridConversionInfo::new( 0, "https://www.example2.com", - rng.gen(), + rng.r#gen(), 0.0, 0.0, ) @@ -1306,8 +1306,8 @@ mod test { fn convert_hybrid_conversion_report_to_indistinguishable_report() { run_random(|mut rng| async move { let conversion_report = HybridConversionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - value: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + value: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridConversionInfo::new(0, "https://www.example2.com", 1_234_567, 0.0, 0.0) .unwrap(), }; @@ -1337,8 +1337,8 @@ mod test { fn convert_hybrid_impression_report_to_indistinguishable_report() { run_random(|mut rng| async move { let impression_report = HybridImpressionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - breakdown_key: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + breakdown_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridImpressionInfo::new(0), }; let indistinguishable_report: IndistinguishableHybridReport = @@ -1387,8 +1387,8 @@ mod test { fn serialization_hybrid_impression() { run_random(|mut rng| async move { let hybrid_impression_report = HybridImpressionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - breakdown_key: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + breakdown_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridImpressionInfo::new(0), }; let mut hybrid_impression_report_bytes = @@ -1406,8 +1406,8 @@ mod test { fn serialization_hybrid_conversion() { run_random(|mut rng| async move { let hybrid_conversion_report = HybridConversionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - value: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + value: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridConversionInfo::new(0, "https://www.example2.com", 1_234_567, 0.0, 0.0) .unwrap(), }; @@ -1429,8 +1429,8 @@ mod test { let key_id = 0; let hybrid_impression_report = HybridImpressionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - breakdown_key: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + breakdown_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridImpressionInfo::new(key_id), }; @@ -1452,8 +1452,8 @@ mod test { fn enc_dec_roundtrip_hybrid_conversion() { run_random(|mut rng| async move { let hybrid_conversion_report = HybridConversionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - value: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + value: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridConversionInfo::new(0, "meta.com", 1_729_707_432, 5.0, 1.1).unwrap(), }; @@ -1499,8 +1499,8 @@ mod test { fn enc_report_serialization() { run_random(|mut rng| async move { let hybrid_conversion_report = HybridConversionReport:: { - match_key: AdditiveShare::new(rng.gen(), rng.gen()), - value: AdditiveShare::new(rng.gen(), rng.gen()), + match_key: AdditiveShare::new(rng.r#gen(), rng.r#gen()), + value: AdditiveShare::new(rng.r#gen(), rng.r#gen()), info: HybridConversionInfo::new(0, "meta.com", 1_729_707_432, 5.0, 1.1).unwrap(), }; @@ -1549,9 +1549,9 @@ mod test { fn serde() { run_random(|mut rng| async move { let report = PrfHybridReport:: { - match_key: rng.gen(), - breakdown_key: Replicated::new(rng.gen(), rng.gen()), - value: Replicated::new(rng.gen(), rng.gen()), + match_key: rng.r#gen(), + breakdown_key: Replicated::new(rng.r#gen(), rng.r#gen()), + value: Replicated::new(rng.r#gen(), rng.r#gen()), }; let mut buf = GenericArray::default(); report.serialize(&mut buf); diff --git a/ipa-core/src/report/hybrid_info.rs b/ipa-core/src/report/hybrid_info.rs index 4d356a8cb..76b6ca48d 100644 --- a/ipa-core/src/report/hybrid_info.rs +++ b/ipa-core/src/report/hybrid_info.rs @@ -1,5 +1,5 @@ use crate::report::hybrid::{ - InvalidHybridReportError, KeyIdentifier, NonAsciiStringError, HELPER_ORIGIN, + HELPER_ORIGIN, InvalidHybridReportError, KeyIdentifier, NonAsciiStringError, }; const DOMAIN: &str = "private-attribution"; @@ -19,7 +19,11 @@ impl HybridImpressionInfo { #[must_use] pub fn byte_len(&self) -> usize { let out_len = std::mem::size_of_val(&self.key_id); - debug_assert_eq!(out_len, self.to_bytes().len(), "Serialization length estimation is incorrect and leads to extra allocation or wasted memory"); + debug_assert_eq!( + out_len, + self.to_bytes().len(), + "Serialization length estimation is incorrect and leads to extra allocation or wasted memory" + ); out_len } @@ -32,7 +36,11 @@ impl HybridImpressionInfo { r.push(self.key_id); - debug_assert_eq!(r.len(), info_len, "Serialization length estimation is incorrect and leads to extra allocation or wasted memory"); + debug_assert_eq!( + r.len(), + info_len, + "Serialization length estimation is incorrect and leads to extra allocation or wasted memory" + ); r.into_boxed_slice() } @@ -48,7 +56,11 @@ impl HybridImpressionInfo { r.push(self.key_id); - debug_assert_eq!(r.len(), info_len, "HPKE Info length estimation is incorrect and leads to extra allocation or wasted memory"); + debug_assert_eq!( + r.len(), + info_len, + "HPKE Info length estimation is incorrect and leads to extra allocation or wasted memory" + ); r.into_boxed_slice() } @@ -105,7 +117,11 @@ impl HybridConversionInfo { + std::mem::size_of_val(&self.timestamp) + std::mem::size_of_val(&self.epsilon) + std::mem::size_of_val(&self.sensitivity); - debug_assert_eq!(out_len, self.to_bytes().len(), "Serialization length estimation is incorrect and leads to extra allocation or wasted memory"); + debug_assert_eq!( + out_len, + self.to_bytes().len(), + "Serialization length estimation is incorrect and leads to extra allocation or wasted memory" + ); out_len } @@ -129,7 +145,11 @@ impl HybridConversionInfo { r.extend_from_slice(&self.epsilon.to_be_bytes()); r.extend_from_slice(&self.sensitivity.to_be_bytes()); - debug_assert_eq!(r.len(), info_len, "Serilization length estimation is incorrect and leads to extra allocation or wasted memory"); + debug_assert_eq!( + r.len(), + info_len, + "Serilization length estimation is incorrect and leads to extra allocation or wasted memory" + ); r.into_boxed_slice() } @@ -156,7 +176,11 @@ impl HybridConversionInfo { r.extend_from_slice(&self.epsilon.to_be_bytes()); r.extend_from_slice(&self.sensitivity.to_be_bytes()); - debug_assert_eq!(r.len(), info_len, "HPKE Info length estimation is incorrect and leads to extra allocation or wasted memory"); + debug_assert_eq!( + r.len(), + info_len, + "HPKE Info length estimation is incorrect and leads to extra allocation or wasted memory" + ); r.into_boxed_slice() } diff --git a/ipa-core/src/secret_sharing/decomposed.rs b/ipa-core/src/secret_sharing/decomposed.rs index 5bdb4456f..1c91566b5 100644 --- a/ipa-core/src/secret_sharing/decomposed.rs +++ b/ipa-core/src/secret_sharing/decomposed.rs @@ -5,11 +5,11 @@ use std::{ use crate::{ error::Error, - ff::{boolean::Boolean, PrimeField}, + ff::{PrimeField, boolean::Boolean}, protocol::prss::{FromPrss, FromRandom, PrssIndex, SharedRandomness}, secret_sharing::{ - replicated::semi_honest::AdditiveShare, Linear as LinearSecretSharing, LinearRefOps, - SharedValue, Vectorizable, + Linear as LinearSecretSharing, LinearRefOps, SharedValue, Vectorizable, + replicated::semi_honest::AdditiveShare, }, }; diff --git a/ipa-core/src/secret_sharing/into_shares.rs b/ipa-core/src/secret_sharing/into_shares.rs index a7bde0764..006e84803 100644 --- a/ipa-core/src/secret_sharing/into_shares.rs +++ b/ipa-core/src/secret_sharing/into_shares.rs @@ -1,7 +1,7 @@ use std::fmt::Debug; use crate::{ - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, secret_sharing::BitDecomposed, }; diff --git a/ipa-core/src/secret_sharing/mod.rs b/ipa-core/src/secret_sharing/mod.rs index 3e3085149..3be4a5ce4 100644 --- a/ipa-core/src/secret_sharing/mod.rs +++ b/ipa-core/src/secret_sharing/mod.rs @@ -18,8 +18,8 @@ use generic_array::ArrayLength; pub use into_shares::IntoShares; #[cfg(any(test, feature = "test-fixture", feature = "cli"))] use rand::{ - distributions::{Distribution, Standard}, Rng, + distributions::{Distribution, Standard}, }; pub use scheme::{Bitwise, Linear, LinearRefOps, SecretSharing}; pub use vector::{ @@ -141,8 +141,8 @@ where Standard: Distribution, { fn share_with(self, rng: &mut R) -> [AdditiveShare; 3] { - let x1 = rng.gen::(); - let x2 = rng.gen::(); + let x1 = rng.r#gen::(); + let x2 = rng.r#gen::(); let x3 = self - (x1 + x2); [ @@ -181,8 +181,8 @@ mod tests { use crate::{ ff::{Field, Fp31}, secret_sharing::{ - replicated::{malicious, semi_honest}, Linear, LinearRefOps, + replicated::{malicious, semi_honest}, }, }; diff --git a/ipa-core/src/secret_sharing/replicated/malicious/additive_share.rs b/ipa-core/src/secret_sharing/replicated/malicious/additive_share.rs index 453ee229e..759381da7 100644 --- a/ipa-core/src/secret_sharing/replicated/malicious/additive_share.rs +++ b/ipa-core/src/secret_sharing/replicated/malicious/additive_share.rs @@ -7,7 +7,7 @@ use std::{ use async_trait::async_trait; use futures::{ future::{join, join_all}, - stream::{iter as stream_iter, StreamExt}, + stream::{StreamExt, iter as stream_iter}, }; use generic_array::{ArrayLength, GenericArray}; use subtle::ConstantTimeEq; @@ -17,8 +17,8 @@ use crate::{ ff::{Field, Gf2, Gf32Bit, PrimeField, Serializable, U128Conversions}, protocol::prss::FromRandom, secret_sharing::{ - replicated::semi_honest::AdditiveShare as SemiHonestAdditiveShare, BitDecomposed, - FieldSimd, Linear as LinearSecretSharing, SecretSharing, SharedValue, + BitDecomposed, FieldSimd, Linear as LinearSecretSharing, SecretSharing, SharedValue, + replicated::semi_honest::AdditiveShare as SemiHonestAdditiveShare, }, seq_join::seq_join, }; @@ -315,7 +315,9 @@ pub enum ExtendableFieldDeserializationError "error deserializing field value when creating a maliciously secure replicated share: {0}" )] FieldError(F::DeserializationError), - #[error("error deserializing extended field value when creating a maliciously secure replicated share: {0}")] + #[error( + "error deserializing extended field value when creating a maliciously secure replicated share: {0}" + )] ExtendedFieldError(EF::DeserializationError), } @@ -448,12 +450,12 @@ mod tests { use crate::{ ff::{Field, Fp31, U128Conversions}, helpers::Role, - rand::{thread_rng, Rng}, + rand::{Rng, thread_rng}, secret_sharing::{ + IntoShares, replicated::{ - semi_honest::AdditiveShare as SemiHonestAdditiveShare, ReplicatedSecretSharing, + ReplicatedSecretSharing, semi_honest::AdditiveShare as SemiHonestAdditiveShare, }, - IntoShares, }, test_fixture::Reconstruct, }; @@ -463,14 +465,14 @@ mod tests { fn test_local_operations() { let mut rng = rand::thread_rng(); - let a = rng.gen::(); - let b = rng.gen::(); - let c = rng.gen::(); - let d = rng.gen::(); - let e = rng.gen::(); - let f = rng.gen::(); + let a = rng.r#gen::(); + let b = rng.r#gen::(); + let c = rng.r#gen::(); + let d = rng.r#gen::(); + let e = rng.r#gen::(); + let f = rng.r#gen::(); // Randomization constant - let r = rng.gen::(); + let r = rng.r#gen::(); let one_shared = Fp31::ONE.share_with(&mut rng); let a_shared = a.share_with(&mut rng); @@ -539,8 +541,8 @@ mod tests { #[tokio::test] async fn downgrade() { let mut rng = thread_rng(); - let x = SemiHonestAdditiveShare::new(rng.gen::(), rng.gen()); - let y = SemiHonestAdditiveShare::new(rng.gen::(), rng.gen()); + let x = SemiHonestAdditiveShare::new(rng.r#gen::(), rng.r#gen()); + let y = SemiHonestAdditiveShare::new(rng.r#gen::(), rng.r#gen()); let m = AdditiveShare::new(x.clone(), y); assert_eq!(x, Downgrade::downgrade(m).await.access_without_downgrade()); } diff --git a/ipa-core/src/secret_sharing/replicated/semi_honest/additive_share.rs b/ipa-core/src/secret_sharing/replicated/semi_honest/additive_share.rs index 2250343f2..1aedf71ce 100644 --- a/ipa-core/src/secret_sharing/replicated/semi_honest/additive_share.rs +++ b/ipa-core/src/secret_sharing/replicated/semi_honest/additive_share.rs @@ -8,10 +8,10 @@ use generic_array::{ArrayLength, GenericArray}; use typenum::Unsigned; use crate::{ - ff::{boolean::Boolean, boolean_array::BooleanArray, ArrayAccess, Expand, Field, Serializable}, + ff::{ArrayAccess, Expand, Field, Serializable, boolean::Boolean, boolean_array::BooleanArray}, secret_sharing::{ - replicated::ReplicatedSecretSharing, FieldSimd, Linear as LinearSecretSharing, - SecretSharing, SharedValue, SharedValueArray, Vectorizable, + FieldSimd, Linear as LinearSecretSharing, SecretSharing, SharedValue, SharedValueArray, + Vectorizable, replicated::ReplicatedSecretSharing, }, }; @@ -514,15 +514,15 @@ impl, const N: usize> Iterator for UnpackIter { + // compiler cannot derive the integer type for div_ceil and make it smooth to use + #[allow(clippy::manual_div_ceil)] for i in 0..($src_rows + 7) / 8 { for j in 0..($src_cols + 7) / 8 { let mut m = [0u8; 8]; @@ -468,6 +470,8 @@ macro_rules! impl_transpose_shim_8_pad { ($src_ty:ty, $src_row:ty, $dst_ty:ty, $dst_row:ty, $src_rows:expr, $src_cols:expr, $error:tt $(,)?) => { impl TransposeFrom<$src_ty> for $dst_ty { type Error = $error; + // compiler cannot derive the integer type for div_ceil and make it smooth to use + #[allow(clippy::manual_div_ceil)] fn transpose_from(&mut self, src: $src_ty) -> Result<(), Self::Error> { self.resize(($src_cols + 7) / 8 * 8, <$dst_row>::ZERO); let src = @@ -730,6 +734,8 @@ impl_transpose_shares_ba_fn_to_bool!(BA64, 256, 64, test_transpose_shares_ba_fn_ /// This version uses the 8x8 transpose kernel and supports dimensions that are not a multiple of 8. macro_rules! impl_transpose_shares_ba_to_bool_small { ($src_row:ty, $src_rows:expr, $src_cols:expr, $test_fn:ident) => { + // compiler cannot derive the integer type for div_ceil and make it smooth to use + #[allow(clippy::manual_div_ceil)] impl TransposeFrom<&[AdditiveShare<$src_row>; $src_rows]> for [AdditiveShare; ($src_cols + 7) / 8 * 8] { @@ -906,13 +912,14 @@ mod tests { }; use rand::{ + Rng, distributions::{Distribution, Standard}, - thread_rng, Rng, + thread_rng, }; use super::*; use crate::{ - ff::{boolean_array::BooleanArray, ArrayAccess}, + ff::{ArrayAccess, boolean_array::BooleanArray}, secret_sharing::Vectorizable, }; @@ -921,7 +928,7 @@ mod tests { Standard: Distribution, { let mut rng = thread_rng(); - array::from_fn(|_| rng.gen()) + array::from_fn(|_| rng.r#gen()) } trait ByteConversion { @@ -1120,7 +1127,7 @@ mod tests { ); let mut rng = thread_rng(); - let m = repeat_with(|| rng.gen()).take(SM).collect::>(); + let m = repeat_with(|| rng.r#gen()).take(SM).collect::>(); let m_t = t_impl(<&[SR; SM]>::try_from(m.as_slice()).unwrap()); verify_transpose(SM, DM, |i, j| m_t[i].get(j), |i, j| m[i].get(j)); @@ -1153,9 +1160,10 @@ mod tests { let mut left_rng = thread_rng(); let mut right_rng = thread_rng(); - let m = repeat_with(|| AdditiveShare::from_fns(|_| left_rng.gen(), |_| right_rng.gen())) - .take(SM) - .collect::>(); + let m = + repeat_with(|| AdditiveShare::from_fns(|_| left_rng.r#gen(), |_| right_rng.r#gen())) + .take(SM) + .collect::>(); let m_t = t_impl(<&[AdditiveShare; SM]>::try_from(m.as_slice()).unwrap()); #[rustfmt::skip] @@ -1193,9 +1201,10 @@ mod tests { let mut left_rng = thread_rng(); let mut right_rng = thread_rng(); - let m = repeat_with(|| AdditiveShare::from_fns(|_| left_rng.gen(), |_| right_rng.gen())) - .take(SM) - .collect::>(); + let m = + repeat_with(|| AdditiveShare::from_fns(|_| left_rng.r#gen(), |_| right_rng.r#gen())) + .take(SM) + .collect::>(); let m_t = t_impl(&m); #[rustfmt::skip] @@ -1233,9 +1242,10 @@ mod tests { let mut left_rng = thread_rng(); let mut right_rng = thread_rng(); - let m = repeat_with(|| AdditiveShare::from_fns(|_| left_rng.gen(), |_| right_rng.gen())) - .take(SM) - .collect::>(); + let m = + repeat_with(|| AdditiveShare::from_fns(|_| left_rng.r#gen(), |_| right_rng.r#gen())) + .take(SM) + .collect::>(); let m_func = |i| AdditiveShare::::clone(&m[i]); let m_t = t_impl(&m_func); @@ -1272,9 +1282,10 @@ mod tests { let mut left_rng = thread_rng(); let mut right_rng = thread_rng(); - let m = repeat_with(|| AdditiveShare::from_fns(|_| left_rng.gen(), |_| right_rng.gen())) - .take(SM) - .collect::>(); + let m = + repeat_with(|| AdditiveShare::from_fns(|_| left_rng.r#gen(), |_| right_rng.r#gen())) + .take(SM) + .collect::>(); let m_t = t_impl(<&[AdditiveShare; SM]>::try_from(m.as_slice()).unwrap()); #[rustfmt::skip] @@ -1293,9 +1304,9 @@ mod tests { >::Array: BooleanArray, >::Array: BooleanArray, Vec>>: for<'a> TransposeFrom< - &'a [BitDecomposed>], - Error = Infallible, - >, + &'a [BitDecomposed>], + Error = Infallible, + >, { let step = min(SM, DM); @@ -1305,9 +1316,10 @@ mod tests { let m0 = bool_shares_test_matrix::(step); let mut left_rng = thread_rng(); let mut right_rng = thread_rng(); - let m1 = repeat_with(|| AdditiveShare::from_fns(|_| left_rng.gen(), |_| right_rng.gen())) - .take(SM) - .collect::>(); + let m1 = + repeat_with(|| AdditiveShare::from_fns(|_| left_rng.r#gen(), |_| right_rng.r#gen())) + .take(SM) + .collect::>(); let mut m = Vec::with_capacity(SM); for (row0, row1) in zip(m0, m1.clone()) { diff --git a/ipa-core/src/seq_join/local.rs b/ipa-core/src/seq_join/local.rs index 951df9701..4bf287fbf 100644 --- a/ipa-core/src/seq_join/local.rs +++ b/ipa-core/src/seq_join/local.rs @@ -7,7 +7,7 @@ use std::{ task::{Context, Poll}, }; -use futures::{stream::Fuse, Future, Stream, StreamExt}; +use futures::{Future, Stream, StreamExt, stream::Fuse}; use pin_project::pin_project; use crate::telemetry::memory::periodic_memory_report; @@ -137,9 +137,9 @@ mod local_test { }; use futures::{ + Future, StreamExt, future::lazy, stream::{poll_fn, repeat_with}, - Future, StreamExt, }; use crate::{ diff --git a/ipa-core/src/seq_join/mod.rs b/ipa-core/src/seq_join/mod.rs index 6bee87e13..9b13b3240 100644 --- a/ipa-core/src/seq_join/mod.rs +++ b/ipa-core/src/seq_join/mod.rs @@ -1,8 +1,8 @@ use std::{future::IntoFuture, num::NonZeroUsize}; use futures::{ - stream::{iter, Iter as StreamIter, TryCollect}, Future, Stream, TryStreamExt, + stream::{Iter as StreamIter, TryCollect, iter}, }; use crate::helpers::stream::ExactSizeStream; @@ -167,9 +167,9 @@ mod test { use std::{convert::Infallible, iter::once, num::NonZeroUsize, task::Poll}; use futures::{ - future::{lazy, BoxFuture}, - stream::{iter, poll_immediate}, Future, Stream, StreamExt, + future::{BoxFuture, lazy}, + stream::{iter, poll_immediate}, }; use crate::{ diff --git a/ipa-core/src/seq_join/multi_thread.rs b/ipa-core/src/seq_join/multi_thread.rs index d68253417..b121851b1 100644 --- a/ipa-core/src/seq_join/multi_thread.rs +++ b/ipa-core/src/seq_join/multi_thread.rs @@ -5,7 +5,7 @@ use std::{ task::{Context, Poll}, }; -use futures::{stream::Fuse, Stream, StreamExt}; +use futures::{Stream, StreamExt, stream::Fuse}; use pin_project::pin_project; use tracing::{Instrument, Span}; @@ -46,9 +46,9 @@ type Spawner<'fut, T> = async_scoped::TokioScope<'fut, T>; unsafe fn create_spawner<'fut, T: Send + 'static>() -> Spawner<'fut, T> { #[cfg(feature = "shuttle")] - return async_scoped::Scope::create(shuttle_spawner::ShuttleSpawner); + return unsafe { async_scoped::Scope::create(shuttle_spawner::ShuttleSpawner) }; #[cfg(not(feature = "shuttle"))] - return async_scoped::TokioScope::create(async_scoped::spawner::use_tokio::Tokio); + return unsafe { async_scoped::TokioScope::create(async_scoped::spawner::use_tokio::Tokio) }; } #[pin_project] diff --git a/ipa-core/src/serde.rs b/ipa-core/src/serde.rs index ed65273d7..54111b9b2 100644 --- a/ipa-core/src/serde.rs +++ b/ipa-core/src/serde.rs @@ -3,7 +3,7 @@ #[cfg(feature = "web-app")] pub mod uri { use hyper::Uri; - use serde::{de::Error, Deserialize, Deserializer}; + use serde::{Deserialize, Deserializer, de::Error}; /// # Errors /// if deserializing from string fails, or if string is not a [`Uri`] @@ -17,7 +17,7 @@ pub mod uri { pub mod option { pub mod uri { use hyper::Uri; - use serde::{de::Error, Deserialize, Deserializer}; + use serde::{Deserialize, Deserializer, de::Error}; /// # Errors /// if deserializing from string fails, or if string is not a [`Uri`] diff --git a/ipa-core/src/sharding.rs b/ipa-core/src/sharding.rs index d1dc7fc48..085217dfe 100644 --- a/ipa-core/src/sharding.rs +++ b/ipa-core/src/sharding.rs @@ -278,7 +278,7 @@ mod tests { } mod conf { - use crate::sharding::{tests::shards, ShardConfiguration, ShardIndex}; + use crate::sharding::{ShardConfiguration, ShardIndex, tests::shards}; struct StaticConfig(u32, u32); impl ShardConfiguration for StaticConfig { diff --git a/ipa-core/src/telemetry/stats.rs b/ipa-core/src/telemetry/stats.rs index 9ce0523fe..9733b2e9e 100644 --- a/ipa-core/src/telemetry/stats.rs +++ b/ipa-core/src/telemetry/stats.rs @@ -1,7 +1,7 @@ use std::{ collections::{ - hash_map::{Entry, Iter}, HashMap, + hash_map::{Entry, Iter}, }, fmt::Display, }; @@ -152,7 +152,7 @@ impl Metrics { /// ## Panics /// Panics if metric does not exist in the snapshot #[must_use] - pub fn assert_metric(&self, name: &'static str) -> MetricAssertion { + pub fn assert_metric(&self, name: &'static str) -> MetricAssertion<'_> { let details = self .counters .get(name) diff --git a/ipa-core/src/test_fixture/app.rs b/ipa-core/src/test_fixture/app.rs index 7ea7957cf..f3ab45767 100644 --- a/ipa-core/src/test_fixture/app.rs +++ b/ipa-core/src/test_fixture/app.rs @@ -5,19 +5,19 @@ use generic_array::GenericArray; use typenum::Unsigned; use crate::{ + AppSetup, HelperApp, app::AppConfig, - cli::{install_collector, LoggingHandle}, + cli::{LoggingHandle, install_collector}, ff::Serializable, helpers::{ - query::{QueryConfig, QueryInput}, ApiError, InMemoryMpcNetwork, InMemoryShardNetwork, Transport, + query::{QueryConfig, QueryInput}, }, protocol::QueryId, - query::{min_status, QueryStatus}, + query::{QueryStatus, min_status}, secret_sharing::IntoShares, test_fixture::try_join3_array, utils::array::zip3, - AppSetup, HelperApp, }; pub trait IntoBuf { diff --git a/ipa-core/src/test_fixture/circuit.rs b/ipa-core/src/test_fixture/circuit.rs index 17920591f..6ec7cbd1d 100644 --- a/ipa-core/src/test_fixture/circuit.rs +++ b/ipa-core/src/test_fixture/circuit.rs @@ -1,6 +1,6 @@ use std::array; -use futures::{future::join3, stream, StreamExt}; +use futures::{StreamExt, future::join3, stream}; use ipa_step::StepNarrow; use rand::distributions::{Distribution, Standard}; @@ -8,16 +8,16 @@ use crate::{ ff::{Field, U128Conversions}, helpers::{GatewayConfig, TotalRecords}, protocol::{ + Gate, RecordId, basics::SecureMul, context::{Context, SemiHonestContext}, step::{ProtocolStep, TestExecutionStep as Step}, - Gate, RecordId, }, rand::thread_rng, - secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, FieldSimd, IntoShares}, + secret_sharing::{FieldSimd, IntoShares, replicated::semi_honest::AdditiveShare as Replicated}, seq_join::seq_join, test_fixture::{ReconstructArr, TestWorld, TestWorldConfig}, - utils::{array::zip3, NonZeroU32PowerOfTwo}, + utils::{NonZeroU32PowerOfTwo, array::zip3}, }; pub struct Inputs, const N: usize> { diff --git a/ipa-core/src/test_fixture/hybrid.rs b/ipa-core/src/test_fixture/hybrid.rs index 335c8bd5f..b318b9e2e 100644 --- a/ipa-core/src/test_fixture/hybrid.rs +++ b/ipa-core/src/test_fixture/hybrid.rs @@ -2,8 +2,8 @@ use std::{borrow::Borrow, collections::HashMap, iter::zip}; use crate::{ ff::{ - boolean_array::{BooleanArray, BA64}, U128Conversions, + boolean_array::{BA64, BooleanArray}, }, rand::Rng, report::{ @@ -13,7 +13,7 @@ use crate::{ }, hybrid_info::{HybridConversionInfo, HybridImpressionInfo}, }, - secret_sharing::{replicated::semi_honest::AdditiveShare as Replicated, IntoShares}, + secret_sharing::{IntoShares, replicated::semi_honest::AdditiveShare as Replicated}, test_fixture::sharing::Reconstruct, }; diff --git a/ipa-core/src/test_fixture/hybrid_event_gen.rs b/ipa-core/src/test_fixture/hybrid_event_gen.rs index 536c0d458..350b01792 100644 --- a/ipa-core/src/test_fixture/hybrid_event_gen.rs +++ b/ipa-core/src/test_fixture/hybrid_event_gen.rs @@ -89,7 +89,7 @@ impl EventGenerator { fn gen_batch_with_params(&mut self, unmatched_conversions: f32, unmatched_impressions: f32) { assert!(unmatched_conversions + unmatched_impressions <= 1.0); - let match_key = self.rng.gen::(); + let match_key = self.rng.r#gen::(); let rand = self.rng.gen_range(0.0..1.0); if rand < unmatched_conversions { let conv = self.gen_conversion(match_key); @@ -152,11 +152,11 @@ mod tests { #[test] fn iter() { - let gen = EventGenerator::with_default_config(thread_rng()); - assert_eq!(10, gen.take(10).collect::>().len()); + let event_gen = EventGenerator::with_default_config(thread_rng()); + assert_eq!(10, event_gen.take(10).collect::>().len()); - let gen = EventGenerator::with_default_config(thread_rng()); - assert_eq!(1000, gen.take(1000).collect::>().len()); + let event_gen = EventGenerator::with_default_config(thread_rng()); + assert_eq!(1000, event_gen.take(1000).collect::>().len()); } #[test] @@ -178,9 +178,9 @@ mod tests { const EXPECTED_HISTOGRAM_WITH_TOLERANCE: [(f64, f64); 3] = [(0.0, 0.0), (EXPECTED_SINGLE, 0.01), (EXPECTED_DOUBLE, 0.02)]; - let gen = EventGenerator::with_default_config(thread_rng()); + let event_gen = EventGenerator::with_default_config(thread_rng()); let mut match_key_to_event_count = HashMap::new(); - for event in gen.take(TEST_COUNT.try_into().unwrap()) { + for event in event_gen.take(TEST_COUNT.try_into().unwrap()) { match event { TestHybridRecord::TestImpression { match_key, .. } => { match_key_to_event_count @@ -223,7 +223,7 @@ mod tests { fn only_impressions_config() { const NUM_EVENTS: usize = 100; const MAX_BREAKDOWN_KEY: u32 = 10; - let gen = EventGenerator::with_config( + let event_gen = EventGenerator::with_config( thread_rng(), Config::new( 10, @@ -232,7 +232,7 @@ mod tests { ), ); let mut match_keys = HashSet::new(); - for event in gen.take(NUM_EVENTS) { + for event in event_gen.take(NUM_EVENTS) { match event { TestHybridRecord::TestImpression { match_key, @@ -254,12 +254,12 @@ mod tests { fn only_conversions_config() { const NUM_EVENTS: usize = 100; const MAX_VALUE: u32 = 10; - let gen = EventGenerator::with_config( + let event_gen = EventGenerator::with_config( thread_rng(), Config::new(MAX_VALUE, 10, ConversionDistribution::OnlyConversions), ); let mut match_keys = HashSet::new(); - for event in gen.take(NUM_EVENTS) { + for event in event_gen.take(NUM_EVENTS) { match event { TestHybridRecord::TestConversion { match_key, value, .. diff --git a/ipa-core/src/test_fixture/logging.rs b/ipa-core/src/test_fixture/logging.rs index 30562d2ff..ce1c6f2ef 100644 --- a/ipa-core/src/test_fixture/logging.rs +++ b/ipa-core/src/test_fixture/logging.rs @@ -21,7 +21,7 @@ pub fn setup() { use tracing::Level; use tracing_subscriber::{ - filter::Directive, fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, + EnvFilter, filter::Directive, fmt, layer::SubscriberExt, util::SubscriberInitExt, }; let default_directive = if let Some(crate_name) = option_env!("CARGO_CRATE_NAME") { diff --git a/ipa-core/src/test_fixture/metrics.rs b/ipa-core/src/test_fixture/metrics.rs index 53c4310fc..684083d43 100644 --- a/ipa-core/src/test_fixture/metrics.rs +++ b/ipa-core/src/test_fixture/metrics.rs @@ -4,10 +4,10 @@ use ipa_metrics::{ MetricChannelType, MetricPartition, MetricsCollectorController, MetricsCurrentThreadContext, MetricsProducer, }; -use rand::Rng; +use rand::random; use tracing::{Level, Span}; -use crate::{rand::thread_rng, telemetry::stats::Metrics, test_fixture::logging}; +use crate::{telemetry::stats::Metrics, test_fixture::logging}; static ONCE: OnceLock<(MetricsProducer, MetricsCollectorController)> = OnceLock::new(); @@ -36,7 +36,7 @@ impl MetricsHandle { #[must_use] pub fn new(level: Level) -> Self { MetricsHandle { - id: thread_rng().gen(), + id: random(), level, } } diff --git a/ipa-core/src/test_fixture/mod.rs b/ipa-core/src/test_fixture/mod.rs index f0f62cbe4..43ccc10fd 100644 --- a/ipa-core/src/test_fixture/mod.rs +++ b/ipa-core/src/test_fixture/mod.rs @@ -28,7 +28,7 @@ pub use hybrid_event_gen::{ }; use rand::{distributions::Standard, prelude::Distribution, rngs::mock::StepRng}; use rand_core::{CryptoRng, RngCore}; -pub use sharing::{get_bits, into_bits, Reconstruct, ReconstructArr}; +pub use sharing::{Reconstruct, ReconstructArr, get_bits, into_bits}; #[cfg(feature = "in-memory-infra")] pub use world::{ Distribute, Random as RandomInputDistribution, RoundRobin as RoundRobinInputDistribution, @@ -39,7 +39,7 @@ use crate::{ ff::{Field, U128Conversions}, protocol::prss::Endpoint as PrssEndpoint, secret_sharing::{ - replicated::semi_honest::AdditiveShare as Replicated, IntoShares, SharedValue, + IntoShares, SharedValue, replicated::semi_honest::AdditiveShare as Replicated, }, }; diff --git a/ipa-core/src/test_fixture/shard_configurator.rs b/ipa-core/src/test_fixture/shard_configurator.rs index 684ffd3dd..9a745b5cf 100644 --- a/ipa-core/src/test_fixture/shard_configurator.rs +++ b/ipa-core/src/test_fixture/shard_configurator.rs @@ -7,7 +7,7 @@ use crate::{ helpers::Role, protocol::prss::Endpoint as PrssEndpoint, sharding::{NotSharded, ShardBinding, ShardIndex, Sharded}, - test_fixture::{make_participants, world::ShardingScheme, Distribute, WithShards}, + test_fixture::{Distribute, WithShards, make_participants, world::ShardingScheme}, }; /// This trait serves the purpose of setting up shard contexts. Each shard shares some diff --git a/ipa-core/src/test_fixture/sharing.rs b/ipa-core/src/test_fixture/sharing.rs index 424e73e17..b42ce5c54 100644 --- a/ipa-core/src/test_fixture/sharing.rs +++ b/ipa-core/src/test_fixture/sharing.rs @@ -3,12 +3,12 @@ use std::{borrow::Borrow, iter::zip, ops::Deref}; use crate::{ ff::{PrimeField, U128Conversions}, secret_sharing::{ + BitDecomposed, SharedValue, Vectorizable, replicated::{ + ReplicatedSecretSharing, malicious::{AdditiveShare as MaliciousReplicated, ExtendableField}, semi_honest::AdditiveShare as Replicated, - ReplicatedSecretSharing, }, - BitDecomposed, SharedValue, Vectorizable, }, }; diff --git a/ipa-core/src/test_fixture/test_gate.rs b/ipa-core/src/test_fixture/test_gate.rs index a59802ff0..7267a6832 100644 --- a/ipa-core/src/test_fixture/test_gate.rs +++ b/ipa-core/src/test_fixture/test_gate.rs @@ -2,7 +2,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use ipa_step::StepNarrow; -use crate::protocol::{step::TestExecutionStep, Gate}; +use crate::protocol::{Gate, step::TestExecutionStep}; /// This manages the gate information for test runs. Most unit tests want to have multiple runs /// using the same instance of [`TestWorld`], but they don't care about the name of that particular diff --git a/ipa-core/src/test_fixture/world.rs b/ipa-core/src/test_fixture/world.rs index f05fb7578..8f531495d 100644 --- a/ipa-core/src/test_fixture/world.rs +++ b/ipa-core/src/test_fixture/world.rs @@ -13,47 +13,45 @@ use std::{ }; use async_trait::async_trait; -use futures::{future::join_all, stream::FuturesOrdered, Future, StreamExt}; +use futures::{Future, StreamExt, future::join_all, stream::FuturesOrdered}; use rand::{ + CryptoRng, Rng, RngCore, SeedableRng, distributions::{Distribution, Standard}, rngs::StdRng, - CryptoRng, Rng, RngCore, SeedableRng, }; use tracing::{Instrument, Level, Span}; use crate::{ helpers::{ - in_memory_config::{passthrough, DynStreamInterceptor}, Gateway, GatewayConfig, HelperIdentity, InMemoryMpcNetwork, InMemoryShardNetwork, InMemoryTransport, Role, RoleAssignment, TotalRecords, Transport, + in_memory_config::{DynStreamInterceptor, passthrough}, }, protocol::{ + Gate, QueryId, RecordId, context::{ - dzkp_validator::DZKPValidator, upgrade::Upgradable, Context, - DZKPUpgradedMaliciousContext, DZKPUpgradedSemiHonestContext, MaliciousContext, - SemiHonestContext, ShardedMaliciousContext, ShardedSemiHonestContext, + Context, DZKPUpgradedMaliciousContext, DZKPUpgradedSemiHonestContext, MaliciousContext, + SemiHonestContext, ShardedMaliciousContext, ShardedSemiHonestContext, TEST_DZKP_STEPS, UpgradableContext, UpgradedContext, UpgradedMaliciousContext, Validator, - TEST_DZKP_STEPS, + dzkp_validator::DZKPValidator, upgrade::Upgradable, }, prss::Endpoint as PrssEndpoint, - Gate, QueryId, RecordId, }, rand::thread_rng, secret_sharing::{ + IntoShares, replicated::malicious::{ DowngradeMalicious, ExtendableField, ThisCodeIsAuthorizedToDowngradeFromMalicious, }, - IntoShares, }, sharding::{NotSharded, ShardBinding, ShardIndex, Sharded}, - telemetry::{stats::Metrics, StepStatsCsvExporter}, + telemetry::{StepStatsCsvExporter, stats::Metrics}, test_fixture::{ - logging, make_participants, + Reconstruct, logging, make_participants, metrics::MetricsHandle, shard_configurator::{Configurator, ShardConfigurator}, sharing::ValidateMalicious, - test_gate::{gate_vendor, TestGateVendor}, - Reconstruct, + test_gate::{TestGateVendor, gate_vendor}, }, utils::array::zip3_ref, }; @@ -136,11 +134,11 @@ pub struct TestWorldConfig { /// for each communication round between any pair of helpers. /// The application include: /// * Malicious behavior. This can help simulating a malicious - /// actor being present in the system by running one or several - /// additive attacks. + /// actor being present in the system by running one or several + /// additive attacks. /// * Data corruption. Tests can simulate bit flips that occur - /// at the network layer and check whether IPA can recover from - /// these (checksums, etc). + /// at the network layer and check whether IPA can recover from + /// these (checksums, etc). /// /// The interface is pretty low level because of the layer /// where it operates. [`StreamInterceptor`] interface provides @@ -385,7 +383,7 @@ impl TestWorld { pub fn rng(&self) -> impl Rng + CryptoRng { // We need to use the `TestWorld` RNG within the `Runner` helpers, which // unfortunately take `&self`. - StdRng::from_seed(self.rng.lock().unwrap().gen()) + StdRng::from_seed(self.rng.lock().unwrap().r#gen()) } async fn with_timeout(&self, fut: F) -> F::Output { @@ -978,33 +976,33 @@ mod tests { use crate::{ ff::{ - boolean::Boolean, - boolean_array::{BA3, BA64, BA8}, ArrayAccess, Field, Fp31, U128Conversions, + boolean::Boolean, + boolean_array::{BA3, BA8, BA64}, }, helpers::{ - in_memory_config::{MaliciousHelper, MaliciousHelperContext}, Direction, Role, TotalRecords, + in_memory_config::{MaliciousHelper, MaliciousHelperContext}, }, protocol::{ + RecordId, basics::SecureMul, boolean::step::EightBitStep, context::{ - dzkp_validator::DZKPValidator, upgrade::Upgradable, Context, DZKPContext, - ShardedContext, UpgradableContext, UpgradedContext, Validator, TEST_DZKP_STEPS, + Context, DZKPContext, ShardedContext, TEST_DZKP_STEPS, UpgradableContext, + UpgradedContext, Validator, dzkp_validator::DZKPValidator, upgrade::Upgradable, }, ipa_prf::boolean_ops::addition_sequential::integer_add, prss::SharedRandomness, - RecordId, }, rand::Rng, secret_sharing::{ - replicated::{semi_honest::AdditiveShare, ReplicatedSecretSharing}, SharedValue, + replicated::{ReplicatedSecretSharing, semi_honest::AdditiveShare}, }, sharding::{ShardConfiguration, ShardIndex}, test_executor::{run, run_random}, - test_fixture::{world::WithShards, Reconstruct, Runner, TestWorld, TestWorldConfig}, + test_fixture::{Reconstruct, Runner, TestWorld, TestWorldConfig, world::WithShards}, }; #[test] @@ -1300,7 +1298,7 @@ mod tests { let world = TestWorld::with_config(&config); let mut rng = world.rng(); - let input: (Fp31, Fp31) = (rng.gen(), rng.gen()); + let input: (Fp31, Fp31) = (rng.r#gen(), rng.r#gen()); world .malicious(input, |ctx, input| async move { let validator = ctx.set_total_records(1).validator(); @@ -1318,11 +1316,10 @@ mod tests { }) .await; - let result = u_and_w.lock().unwrap().clone(); - result + u_and_w.lock().unwrap().clone() } - let seed = rng.gen(); + let seed = rng.r#gen(); let first_result = test(seed).await; let second_result = test(seed).await; @@ -1351,7 +1348,7 @@ mod tests { let world = TestWorld::with_config(&config); let mut rng = world.rng(); - let input: (BA8, BA8) = (rng.gen(), rng.gen()); + let input: (BA8, BA8) = (rng.r#gen(), rng.r#gen()); world .malicious(input, |ctx, input| async move { let validator = ctx.set_total_records(1).dzkp_validator(TEST_DZKP_STEPS, 8); @@ -1368,11 +1365,10 @@ mod tests { }) .await; - let result = proof_diff.lock().unwrap().clone(); - result + proof_diff.lock().unwrap().clone() } - let seed = rng.gen(); + let seed = rng.r#gen(); let first_result = test(seed).await; let second_result = test(seed).await; diff --git a/ipa-core/src/utils/mod.rs b/ipa-core/src/utils/mod.rs index 6829f57fa..af55a6240 100644 --- a/ipa-core/src/utils/mod.rs +++ b/ipa-core/src/utils/mod.rs @@ -4,4 +4,4 @@ pub mod arraychunks; mod power_of_two; #[cfg(target_pointer_width = "64")] -pub use power_of_two::{non_zero_prev_power_of_two, NonZeroU32PowerOfTwo}; +pub use power_of_two::{NonZeroU32PowerOfTwo, non_zero_prev_power_of_two}; diff --git a/ipa-core/tests/common/tempdir.rs b/ipa-core/tests/common/tempdir.rs index 3c056ab44..51c75432b 100644 --- a/ipa-core/tests/common/tempdir.rs +++ b/ipa-core/tests/common/tempdir.rs @@ -37,7 +37,7 @@ impl Drop for TempDir { fn drop(&mut self) { if !self.delete || thread::panicking() { let td = self.inner.take().unwrap(); - let _ = td.into_path(); + let _ = td.keep(); } } } diff --git a/ipa-core/tests/helper_networks.rs b/ipa-core/tests/helper_networks.rs index 8845dcd83..177ee0512 100644 --- a/ipa-core/tests/helper_networks.rs +++ b/ipa-core/tests/helper_networks.rs @@ -3,13 +3,13 @@ mod common; use std::{array, path::Path, process::Command}; use common::{ - spawn_helpers, tempdir::TempDir, test_multiply, test_network, CommandExt, UnwrapStatusExt, - HELPER_BIN, + CommandExt, HELPER_BIN, UnwrapStatusExt, spawn_helpers, tempdir::TempDir, test_multiply, + test_network, }; use ipa_core::{cli::CliPaths, helpers::HelperIdentity}; use crate::common::{ - test_sharded_network, AddInPrimeField, Multiply, ShardTcpListeners, ShardedShuffle, + AddInPrimeField, Multiply, ShardTcpListeners, ShardedShuffle, test_sharded_network, }; #[test] diff --git a/ipa-core/tests/hybrid.rs b/ipa-core/tests/hybrid.rs index 8d4f41e5f..f32a96f8f 100644 --- a/ipa-core/tests/hybrid.rs +++ b/ipa-core/tests/hybrid.rs @@ -18,14 +18,14 @@ use std::{ use bytes::Bytes; use command_fds::CommandFdExt; use common::{ - spawn_shards, tempdir::TempDir, test_sharded_setup, CommandExt, TerminateOnDropExt, - UnwrapStatusExt, + CommandExt, TerminateOnDropExt, UnwrapStatusExt, spawn_shards, tempdir::TempDir, + test_sharded_setup, }; use futures_util::{StreamExt, TryStreamExt}; use ipa_core::{ cli::playbook::HybridQueryResult, error::BoxError, - helpers::{query::HybridQueryParams, LengthDelimitedStream}, + helpers::{LengthDelimitedStream, query::HybridQueryParams}, }; use rand::thread_rng; use rand_core::RngCore; @@ -143,11 +143,13 @@ fn test_hybrid() { .expect("file should exist as it's created above in the test"), ) .expect("should match hard coded format from in_the_clear"); - assert!(output - .breakdowns - .iter() - .zip(expected_result.iter()) - .all(|(a, b)| a == b)); + assert!( + output + .breakdowns + .iter() + .zip(expected_result.iter()) + .all(|(a, b)| a == b) + ); } #[test] @@ -285,11 +287,13 @@ fn test_hybrid_poll() { .expect("file should exist as it's created above in the test"), ) .expect("should match hard coded format from in_the_clear"); - assert!(output - .breakdowns - .iter() - .zip(expected_result.iter()) - .all(|(a, b)| a == b)); + assert!( + output + .breakdowns + .iter() + .zip(expected_result.iter()) + .all(|(a, b)| a == b) + ); } fn create_upload_files( diff --git a/ipa-metrics-prometheus/Cargo.toml b/ipa-metrics-prometheus/Cargo.toml index 36ce2be11..3e32b1781 100644 --- a/ipa-metrics-prometheus/Cargo.toml +++ b/ipa-metrics-prometheus/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ipa-metrics-prometheus" version = "0.1.0" -edition = "2021" +edition = "2024" [features] default = [] diff --git a/ipa-metrics-prometheus/src/exporter.rs b/ipa-metrics-prometheus/src/exporter.rs index 8ba17f905..168b612c4 100644 --- a/ipa-metrics-prometheus/src/exporter.rs +++ b/ipa-metrics-prometheus/src/exporter.rs @@ -1,7 +1,7 @@ use std::io; use ipa_metrics::MetricsStore; -use opentelemetry::{metrics::MeterProvider, KeyValue}; +use opentelemetry::{KeyValue, metrics::MeterProvider}; use opentelemetry_sdk::metrics::SdkMeterProvider; use prometheus::{self, Encoder, TextEncoder}; @@ -48,7 +48,7 @@ mod test { use std::thread; - use ipa_metrics::{counter, install_new_thread, MetricChannelType}; + use ipa_metrics::{MetricChannelType, counter, install_new_thread}; use super::PrometheusMetricsExporter; diff --git a/ipa-metrics-tracing/Cargo.toml b/ipa-metrics-tracing/Cargo.toml index 061bfe4ff..dfc3520d6 100644 --- a/ipa-metrics-tracing/Cargo.toml +++ b/ipa-metrics-tracing/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ipa-metrics-tracing" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] # requires partitions feature because without it, it does not make sense to use diff --git a/ipa-metrics-tracing/src/layer.rs b/ipa-metrics-tracing/src/layer.rs index 85d07d910..9955c2357 100644 --- a/ipa-metrics-tracing/src/layer.rs +++ b/ipa-metrics-tracing/src/layer.rs @@ -2,14 +2,14 @@ use std::fmt::Debug; use ipa_metrics::{CurrentThreadPartitionContext, MetricPartition, MetricsCurrentThreadContext}; use tracing::{ + Id, Subscriber, field::{Field, Visit}, span::{Attributes, Record}, - Id, Subscriber, }; use tracing_subscriber::{ + Layer, layer::Context, registry::{Extensions, ExtensionsMut, LookupSpan}, - Layer, }; pub const FIELD: &str = concat!(env!("CARGO_PKG_NAME"), "-", "metrics-partition"); @@ -99,7 +99,7 @@ mod tests { use ipa_metrics::CurrentThreadPartitionContext; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; - use crate::{layer::FIELD, MetricsPartitioningLayer}; + use crate::{MetricsPartitioningLayer, layer::FIELD}; #[test] fn basic() { diff --git a/ipa-metrics-tracing/src/lib.rs b/ipa-metrics-tracing/src/lib.rs index c72bb9e54..8c95a051e 100644 --- a/ipa-metrics-tracing/src/lib.rs +++ b/ipa-metrics-tracing/src/lib.rs @@ -4,4 +4,4 @@ mod layer; -pub use layer::{MetricsPartitioningLayer, FIELD as PARTITION_FIELD}; +pub use layer::{FIELD as PARTITION_FIELD, MetricsPartitioningLayer}; diff --git a/ipa-metrics/Cargo.toml b/ipa-metrics/Cargo.toml index cc9ec52f0..d610263fa 100644 --- a/ipa-metrics/Cargo.toml +++ b/ipa-metrics/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ipa-metrics" version = "0.1.0" -edition = "2021" +edition = "2024" [features] default = [] diff --git a/ipa-metrics/src/collector.rs b/ipa-metrics/src/collector.rs index 94022e340..6c7ba4ccc 100644 --- a/ipa-metrics/src/collector.rs +++ b/ipa-metrics/src/collector.rs @@ -3,8 +3,8 @@ use std::cell::RefCell; use crossbeam_channel::{Receiver, Select}; use crate::{ - controller::{Command, Status}, ControllerCommand, MetricsStore, + controller::{Command, Status}, }; thread_local! { @@ -112,8 +112,8 @@ mod tests { }; use crate::{ - controller::Status, counter, install, install_new_thread, producer::Producer, - MetricChannelType, + MetricChannelType, controller::Status, counter, install, install_new_thread, + producer::Producer, }; struct MeteredScope<'scope, 'env: 'scope>(&'scope Scope<'scope, 'env>, Producer); diff --git a/ipa-metrics/src/context.rs b/ipa-metrics/src/context.rs index f166d610b..b7b28418f 100644 --- a/ipa-metrics/src/context.rs +++ b/ipa-metrics/src/context.rs @@ -127,13 +127,13 @@ impl Drop for MetricsContext { mod tests { use std::thread; - use crate::{context::CurrentThreadContext, MetricsContext}; + use crate::{MetricsContext, context::CurrentThreadContext}; /// Each thread has its local store by default, and it is exclusive to it #[test] #[cfg(feature = "partitions")] fn local_store() { - use crate::{context::CurrentThreadContext, CurrentThreadPartitionContext}; + use crate::{CurrentThreadPartitionContext, context::CurrentThreadContext}; CurrentThreadPartitionContext::set(0xdead_beef); counter!("foo", 7); diff --git a/ipa-metrics/src/key.rs b/ipa-metrics/src/key.rs index 620e193e3..5dcf35228 100644 --- a/ipa-metrics/src/key.rs +++ b/ipa-metrics/src/key.rs @@ -29,7 +29,7 @@ use std::{ pub use Name as MetricName; pub(super) use OwnedName as OwnedMetricName; -use crate::label::{Label, OwnedLabel, MAX_LABELS}; +use crate::label::{Label, MAX_LABELS, OwnedLabel}; #[macro_export] macro_rules! metric_name { @@ -61,9 +61,7 @@ macro_rules! metric_name { ) }}; // Match when no key-value pairs are provided - ($metric:expr) => {{ - $crate::MetricName::from_parts($metric, []) - }}; + ($metric:expr) => {{ $crate::MetricName::from_parts($metric, []) }}; } /// Metric name that is created at callsite on each metric invocation. @@ -212,7 +210,7 @@ pub fn compute_hash(value: V) -> u64 { #[cfg(test)] mod tests { use crate::{ - key::{compute_hash, Name}, + key::{Name, compute_hash}, label::Label, }; diff --git a/ipa-metrics/src/lib.rs b/ipa-metrics/src/lib.rs index 2449d41a3..dc4731708 100644 --- a/ipa-metrics/src/lib.rs +++ b/ipa-metrics/src/lib.rs @@ -22,7 +22,7 @@ pub use controller::{ Status as ControllerStatus, }; pub use key::{MetricName, OwnedName, UniqueElements}; -pub use label::{label_hasher, Label, LabelValue}; +pub use label::{Label, LabelValue, label_hasher}; #[cfg(feature = "partitions")] pub use partitioned::{ CurrentThreadContext as CurrentThreadPartitionContext, Partition as MetricPartition, diff --git a/ipa-metrics/src/partitioned.rs b/ipa-metrics/src/partitioned.rs index 3b2419fae..5ced273a1 100644 --- a/ipa-metrics/src/partitioned.rs +++ b/ipa-metrics/src/partitioned.rs @@ -20,10 +20,10 @@ use hashbrown::hash_map::Entry; use rustc_hash::FxBuildHasher; use crate::{ + MetricName, key::OwnedMetricName, kind::CounterValue, store::{CounterHandle, Store}, - MetricName, }; thread_local! { diff --git a/ipa-metrics/src/producer.rs b/ipa-metrics/src/producer.rs index f9ee42cc3..4700a7800 100644 --- a/ipa-metrics/src/producer.rs +++ b/ipa-metrics/src/producer.rs @@ -1,6 +1,6 @@ use crossbeam_channel::Sender; -use crate::{context::CurrentThreadContext, MetricsStore}; +use crate::{MetricsStore, context::CurrentThreadContext}; /// A handle to enable centralized metrics collection from the current thread. /// diff --git a/ipa-metrics/src/store.rs b/ipa-metrics/src/store.rs index e893ffd84..483e9c571 100644 --- a/ipa-metrics/src/store.rs +++ b/ipa-metrics/src/store.rs @@ -3,7 +3,7 @@ use std::{borrow::Borrow, hash::BuildHasher}; use hashbrown::hash_map::RawEntryMut; use rustc_hash::FxBuildHasher; -use crate::{key::OwnedMetricName, kind::CounterValue, MetricName}; +use crate::{MetricName, key::OwnedMetricName, kind::CounterValue}; /// A basic store. Currently only supports counters. /// Counters and other metrics are stored to optimize writes. That means, one lookup @@ -121,7 +121,7 @@ impl CounterHandle<'_, LABELS> { mod tests { use std::hash::{DefaultHasher, Hash, Hasher}; - use crate::{counter, metric_name, store::Store, LabelValue}; + use crate::{LabelValue, counter, metric_name, store::Store}; impl LabelValue for &'static str { fn hash(&self) -> u64 { diff --git a/ipa-step-derive/Cargo.toml b/ipa-step-derive/Cargo.toml index 9fb5f35ef..76a66c284 100644 --- a/ipa-step-derive/Cargo.toml +++ b/ipa-step-derive/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ipa-step-derive" version = "0.1.0" -edition = "2021" +edition = "2024" [lib] proc-macro = true diff --git a/ipa-step-derive/src/lib.rs b/ipa-step-derive/src/lib.rs index 2298e3969..e57447d37 100644 --- a/ipa-step-derive/src/lib.rs +++ b/ipa-step-derive/src/lib.rs @@ -8,11 +8,11 @@ mod variant; use std::env; -use ipa_step::{name::GateName, COMPACT_GATE_INCLUDE_ENV}; +use ipa_step::{COMPACT_GATE_INCLUDE_ENV, name::GateName}; use proc_macro::TokenStream as TokenStreamBasic; use proc_macro2::{Span, TokenStream}; use quote::quote; -use syn::{parse_macro_input, Data, DeriveInput, Ident}; +use syn::{Data, DeriveInput, Ident, parse_macro_input}; use variant::Generator; use crate::variant::VariantAttribute; @@ -127,7 +127,7 @@ fn derive_step_impl(ast: &DeriveInput) -> Result { Data::Union(..) => { return ast .ident - .error("CompactStep can only be derived for a struct or enum") + .error("CompactStep can only be derived for a struct or enum"); } }; Ok(g.generate(ident, &attr)) diff --git a/ipa-step-derive/src/track.rs b/ipa-step-derive/src/track.rs index 643f6604a..e16841011 100644 --- a/ipa-step-derive/src/track.rs +++ b/ipa-step-derive/src/track.rs @@ -5,11 +5,11 @@ use std::{ }; use proc_macro2::{ - token_stream::IntoIter as TokenTreeIter, Delimiter, Punct, Spacing, Span, TokenStream, - TokenTree, + Delimiter, Punct, Spacing, Span, TokenStream, TokenTree, + token_stream::IntoIter as TokenTreeIter, }; -use quote::{quote, ToTokens, TokenStreamExt}; -use syn::{parse::Parser, parse2, token::Pub, Ident, LitStr, Visibility}; +use quote::{ToTokens, TokenStreamExt, quote}; +use syn::{Ident, LitStr, Visibility, parse::Parser, parse2, token::Pub}; use crate::IntoSpan; diff --git a/ipa-step-derive/src/variant.rs b/ipa-step-derive/src/variant.rs index 792aa8fd1..8cdcb54a6 100644 --- a/ipa-step-derive/src/variant.rs +++ b/ipa-step-derive/src/variant.rs @@ -2,11 +2,11 @@ use ipa_step::name::UnderscoreStyle; use proc_macro2::{Literal, TokenStream}; use quote::{format_ident, quote}; use syn::{ - meta::ParseNestedMeta, spanned::Spanned, Attribute, DataEnum, ExprPath, Fields, Ident, LitInt, - LitStr, Type, TypePath, Variant, + Attribute, DataEnum, ExprPath, Fields, Ident, LitInt, LitStr, Type, TypePath, Variant, + meta::ParseNestedMeta, spanned::Spanned, }; -use crate::{sum::ExtendedSum, IntoSpan}; +use crate::{IntoSpan, sum::ExtendedSum}; struct VariantAttrParser<'a> { full_name: String, @@ -387,8 +387,9 @@ impl Generator { if let Some(child) = step_child { let idx = self.arm_count.clone() + quote!((<#child as ::ipa_step::CompactStep>::STEP_COUNT + 1) * ::ipa_step::CompactGateIndex::try_from(*i).unwrap()); - let out_of_bounds_msg = - format!("Step index {{i}} out of bounds for {step_full_name} with count {step_count}. Consider using bounds-checked step constructors."); + let out_of_bounds_msg = format!( + "Step index {{i}} out of bounds for {step_full_name} with count {step_count}. Consider using bounds-checked step constructors." + ); self.index_arms.extend(quote! { #arm(i) if *i < #step_integer::try_from(#step_count).unwrap() => #idx, #arm(i) => panic!(#out_of_bounds_msg), @@ -431,8 +432,9 @@ impl Generator { } else { let idx = self.arm_count.clone() + quote!(::ipa_step::CompactGateIndex::try_from(*i).unwrap()); - let out_of_bounds_msg = - format!("Step index {{i}} out of bounds for {step_full_name} with count {step_count}. Consider using bounds-checked step constructors."); + let out_of_bounds_msg = format!( + "Step index {{i}} out of bounds for {step_full_name} with count {step_count}. Consider using bounds-checked step constructors." + ); self.index_arms.extend(quote! { #arm(i) if *i < #step_integer::try_from(#step_count).unwrap() => #idx, #arm(i) => panic!(#out_of_bounds_msg), diff --git a/ipa-step-test/Cargo.toml b/ipa-step-test/Cargo.toml index 18bb52dfe..c0baef669 100644 --- a/ipa-step-test/Cargo.toml +++ b/ipa-step-test/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ipa-step-test" version = "0.1.0" -edition = "2021" +edition = "2024" build = "build.rs" [dependencies] diff --git a/ipa-step/Cargo.toml b/ipa-step/Cargo.toml index 9c1eb8102..cded6faf5 100644 --- a/ipa-step/Cargo.toml +++ b/ipa-step/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ipa-step" version = "0.1.0" -edition = "2021" +edition = "2024" [features] # This is used for build.rs scripts. diff --git a/ipa-step/src/descriptive.rs b/ipa-step/src/descriptive.rs index 6e9e99ddd..9d964df5c 100644 --- a/ipa-step/src/descriptive.rs +++ b/ipa-step/src/descriptive.rs @@ -3,7 +3,7 @@ use std::{ hash::{Hash, Hasher}, }; -use ipa_metrics::{label_hasher, LabelValue}; +use ipa_metrics::{LabelValue, label_hasher}; use serde::Deserialize; use crate::{Gate, Step, StepNarrow}; diff --git a/ipa-step/src/gate.rs b/ipa-step/src/gate.rs index 0aa45cc46..43ef204e2 100644 --- a/ipa-step/src/gate.rs +++ b/ipa-step/src/gate.rs @@ -5,9 +5,9 @@ use std::{collections::HashMap, env, fs::write, path::PathBuf}; use proc_macro2::TokenStream; use quote::quote; -use syn::{parse2, parse_str, Ident, Path}; +use syn::{Ident, Path, parse_str, parse2}; -use crate::{hash::HashingSteps, name::GateName, CompactGateIndex, CompactStep}; +use crate::{CompactGateIndex, CompactStep, hash::HashingSteps, name::GateName}; fn crate_path(p: &str) -> String { let Some((_, p)) = p.split_once("::") else { diff --git a/ipa-step/src/hash.rs b/ipa-step/src/hash.rs index 133d3713a..61164f7d0 100644 --- a/ipa-step/src/hash.rs +++ b/ipa-step/src/hash.rs @@ -1,8 +1,8 @@ use std::collections::BTreeMap; use proc_macro2::{Ident, TokenStream}; -use quote::{format_ident, quote, ToTokens}; -use syn::{parse_str, Path}; +use quote::{ToTokens, format_ident, quote}; +use syn::{Path, parse_str}; use crate::{CompactGateIndex, StepHasher}; @@ -34,7 +34,9 @@ impl HashingSteps { pub fn hash(&mut self, step: &str, gate: CompactGateIndex) { let h = step.hash_step(); if let Some(old_val) = self.inner.insert(h, gate) { - panic!("Hash collision for {step}: {h} => {old_val} and {gate}. Check that there are no duplicate steps defined in the protocol."); + panic!( + "Hash collision for {step}: {h} => {old_val} and {gate}. Check that there are no duplicate steps defined in the protocol." + ); } }