Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
richajaindce committed Oct 23, 2023
1 parent 01fcbbb commit a43e3ba
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 281 deletions.
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ path = "benches/oneshot/ipa.rs"
harness = false
required-features = ["enable-benches", "descriptive-gate"]

[[bench]]
name = "oneshot_oprf_ipa"
path = "benches/oneshot/oprf_ipa.rs"
harness = false
required-features = ["enable-benches", "descriptive-gate"]

[[test]]
name = "helper_networks"
required-features = ["cli", "web-app", "real-world-infra", "test-fixture", "descriptive-gate"]
Expand Down
24 changes: 15 additions & 9 deletions benches/oneshot/ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ipa::{
ff::Fp32BitPrime,
helpers::{query::IpaQueryConfig, GatewayConfig},
test_fixture::{
ipa::{ipa_in_the_clear, test_ipa, IpaSecurityModel},
ipa::{ipa_in_the_clear, test_ipa, test_oprf_ipa, IpaSecurityModel},
EventGenerator, EventGeneratorConfig, TestWorld, TestWorldConfig,
},
};
Expand Down Expand Up @@ -70,6 +70,8 @@ struct Args {
/// Needed for benches.
#[arg(long, hide = true)]
bench: bool,
#[arg(short = 'o', long)]
oprf: bool,
}

impl Args {
Expand Down Expand Up @@ -132,14 +134,18 @@ async fn run(args: Args) -> Result<(), Error> {
tracing::trace!("Preparation complete in {:?}", _prep_time.elapsed());

let _protocol_time = Instant::now();
test_ipa::<BenchField>(
&world,
&raw_data,
&expected_results,
args.config(),
args.mode,
)
.await;
if args.oprf {
test_oprf_ipa::<BenchField>(&world, raw_data, &expected_results, args.config()).await;
} else {
test_ipa::<BenchField>(
&world,
&raw_data,
&expected_results,
args.config(),
args.mode,
)
.await;
}
tracing::trace!(
"{m:?} IPA for {q} records took {t:?}",
m = args.mode,
Expand Down
165 changes: 0 additions & 165 deletions benches/oneshot/oprf_ipa.rs

This file was deleted.

2 changes: 1 addition & 1 deletion pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ check "Sort benchmark" \
cargo bench --bench oneshot_sort --no-default-features --features="enable-benches descriptive-gate"

check "OPRF IPA benchmark" \
cargo bench --bench oneshot_oprf_ipa --no-default-features --features="enable-benches descriptive-gate" -- -n 62
cargo bench --bench oneshot_ipa --no-default-features --features="enable-benches descriptive-gate" -- -n 62 --oprf --per-user-cap 2 --max-trigger-value 4
4 changes: 3 additions & 1 deletion src/bin/report_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ async fn ipa(
(IpaSecurityModel::SemiHonest, true) => {
query_type = QueryType::OprfIpa(ipa_query_config.clone());
}
(IpaSecurityModel::Malicious, true) => panic!("OPRF for malicious is not implemented as yet"),
(IpaSecurityModel::Malicious, true) => {
panic!("OPRF for malicious is not implemented as yet")
}
};

let input_rows = input.iter::<TestRawDataRecord>().collect::<Vec<_>>();
Expand Down
5 changes: 0 additions & 5 deletions src/cli/playbook/ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ pub async fn playbook_oprf_ipa<F>(
) -> IpaQueryResult
where
F: PrimeField,
AdditiveShare<Timestamp>: Serializable,
AdditiveShare<BreakdownKey>: Serializable,
AdditiveShare<TriggerValue>: Serializable,
AdditiveShare<F>: Serializable,
{
let mut buffers: [_; 3] = std::array::from_fn(|_| Vec::new());
Expand Down Expand Up @@ -237,8 +234,6 @@ where
tracing::info!("Running IPA for {query_size:?} records took {t:?}", t = lat);
let mut breakdowns = vec![0; usize::try_from(query_config.max_breakdown_key).unwrap()];
for (breakdown_key, trigger_value) in results.into_iter().enumerate() {
// TODO: make the data type used consistent with `ipa_in_the_clear`
// I think using u32 is wrong, we should move to u128
breakdowns[breakdown_key] += u32::try_from(trigger_value.as_u128()).unwrap();
}

Expand Down
6 changes: 4 additions & 2 deletions src/net/http_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ pub mod query {
match self.query_type {
#[cfg(any(test, feature = "test-fixture", feature = "cli"))]
QueryType::TestMultiply => Ok(()),
QueryType::SemiHonestIpa(config) | QueryType::MaliciousIpa(config) | QueryType::OprfIpa(config)=> {
QueryType::SemiHonestIpa(config)
| QueryType::MaliciousIpa(config)
| QueryType::OprfIpa(config) => {
write!(
f,
"&per_user_credit_cap={}&max_breakdown_key={}&num_multi_bits={}",
Expand Down Expand Up @@ -586,4 +588,4 @@ pub mod query {

pub const AXUM_PATH: &str = "/:query_id/complete";
}
}
}
7 changes: 6 additions & 1 deletion src/protocol/boolean/saturating_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ impl<S: LinearSecretSharing<Gf2>> SaturatingSum<S> {
S: LinearSecretSharing<Gf2> + BasicProtocols<C, Gf2>,
for<'a> &'a S: LinearRefOps<'a, S, Gf2>,
{
assert!(self.sum.len() >= value.len());
assert!(
self.sum.len() >= value.len(),
"running sum {:?} was smaller than value to be added {:?}",
self.sum.len(),
value.len()
);

let mut output_sum = Vec::with_capacity(self.sum.len());
let mut carry_in = S::ZERO;
Expand Down
5 changes: 3 additions & 2 deletions src/protocol/prf_sharding/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ where
"Asking for more buckets ({breakdown_count}) than bits in the key ({}) allow",
BK::BITS
);

assert!(
breakdown_count <= 128,
breakdown_count <= 256,
"Our step implementation (BitOpStep) cannot go past 64"
);
let mut row_contribution = vec![value; breakdown_count];
Expand Down Expand Up @@ -221,7 +222,7 @@ pub mod tests {
RecordId::from(0),
breakdown_key_share,
value_share,
129,
257,
false,
)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/step/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Step for str {}
/// updated with a new step scheme.
#[derive(Step)]
pub enum BitOpStep {
#[dynamic(64)]
#[dynamic(128)]
Bit(usize),
}

Expand Down
7 changes: 4 additions & 3 deletions src/query/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,12 @@ pub fn execute(
let ctx = SemiHonestContext::new(prss, gateway);
Box::pin(
OprfIpaQuery::<_, Fp32BitPrime>::new(ipa_config)
.execute(ctx, config.size, input)
.then(|res| ready(res.map(|out| Box::new(out) as Box<dyn Result>))),
.execute(ctx, config.size, input)
.then(|res| ready(res.map(|out| Box::new(out) as Box<dyn Result>))),
)
},
), }
),
}
}

pub fn do_query<F>(
Expand Down
20 changes: 12 additions & 8 deletions src/query/runner/oprf_ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,19 @@ where
// Until then, we convert the output to something next function is happy about.

let user_cap: i32 = config.per_user_credit_cap.try_into().unwrap();
if (user_cap & (user_cap - 1)) != 0 {
panic!("This code only works for a user cap which is a power of 2");
}
assert!(
user_cap & (user_cap - 1) == 0,
"This code only works for a user cap which is a power of 2"
);

attribution_and_capping_and_aggregation::<C, BreakdownKey, TriggerValue, F, _, Replicated<Gf2>>(
ctx,
sharded_input,
user_cap.ilog2().try_into().unwrap(),
)
attribution_and_capping_and_aggregation::<
C,
BreakdownKey,
TriggerValue,
F,
_,
Replicated<Gf2>,
>(ctx, sharded_input, user_cap.ilog2().try_into().unwrap())
.await
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,6 @@ where
TS: GaloisField,
BK: GaloisField,
TV: GaloisField,
Replicated<TS>: Serializable,
Replicated<BK>: Serializable,
Replicated<TV>: Serializable,
{
pub timestamp: Replicated<TS>,
pub mk_oprf: u64,
Expand All @@ -315,8 +312,7 @@ impl Serializable for u64 {
fn deserialize(buf: &GenericArray<u8, Self::Size>) -> Self {
let mut buf_to = [0u8; 8];
buf_to[..buf.len()].copy_from_slice(buf);

Self::try_from(u64::from_le_bytes(buf_to)).unwrap()
u64::from_le_bytes(buf_to)
}
}

Expand Down
Loading

0 comments on commit a43e3ba

Please sign in to comment.