Skip to content

Commit

Permalink
Fix new clippy warnings
Browse files Browse the repository at this point in the history
Rust 1.74 brought new lints
  • Loading branch information
akoshelev committed Nov 17, 2023
1 parent ce7705c commit 6b648ef
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub enum Error {
#[error("Value truncation error: {0}")]
FieldValueTruncation(String),
#[error("Invalid query parameter: {0}")]
InvalidQueryParameter(String),
InvalidQueryParameter(BoxError),
#[error("invalid report: {0}")]
InvalidReport(#[from] InvalidReportError),
#[error("unsupported: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion src/ff/galois_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ macro_rules! bit_array_impl {
}

#[test]
#[should_panic]
#[should_panic(expected = "index < usize::try_from")]
pub fn out_of_count_index() {
let s = $name::try_from(1_u128).unwrap();
// Below assert doesn't matter. The indexing should panic
Expand Down
6 changes: 4 additions & 2 deletions src/protocol/attribution/credit_capping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where
if (u128::from(cap) * 2) >= F::PRIME.into() {
return Err(crate::error::Error::InvalidQueryParameter(format!(
"The cap {cap} must be less than 1/2 of the prime modulus to make overflow detectable, and propagable."
)));
).into()));
}

//
Expand Down Expand Up @@ -527,7 +527,9 @@ mod tests {
}

#[tokio::test]
#[should_panic]
#[should_panic(
expected = "must be less than 1/2 of the prime modulus to make overflow detectable, and propagable"
)]
pub async fn invalid_cap_value() {
// Input doesn't matter here, since the test should panic before the computation starts.
let input: Vec<GenericReportTestInput<Fp32BitPrime, MatchKey, BreakdownKey>> = credit_capping_test_input!(
Expand Down
3 changes: 3 additions & 0 deletions src/protocol/basics/apply_permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub fn apply<T>(permutation: &[u32], values: &mut [T]) {
/// reordered into (D, C, A, B).
///
/// ![Apply inv steps][applyinv]
///
/// ## Panics
/// If permutation size and values size do not match.
pub fn apply_inv<T>(permutation: &[u32], values: &mut [T]) {
assert_eq!(permutation.len(), values.len());
let mut permuted = bitvec![0; permutation.len()];
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/basics/mul/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,21 +322,21 @@ pub(in crate::protocol) mod test {

#[test]
#[cfg(debug_assertions)]
#[should_panic]
#[should_panic(expected = "attempting to do a multiplication that can be performed locally")]
fn no_work_vzz() {
(ZeroPositions::Pvzz, ZeroPositions::Pvzz).work_for(Role::H1);
}

#[test]
#[cfg(debug_assertions)]
#[should_panic]
#[should_panic(expected = "attempting to do a multiplication that can be performed locally")]
fn no_work_vzv() {
(ZeroPositions::Pzvz, ZeroPositions::Pzvz).work_for(Role::H2);
}

#[test]
#[cfg(debug_assertions)]
#[should_panic]
#[should_panic(expected = "attempting to do a multiplication that can be performed locally")]
fn no_work_zzv() {
(ZeroPositions::Pzzv, ZeroPositions::Pzzv).work_for(Role::H3);
}
Expand Down
47 changes: 36 additions & 11 deletions src/protocol/ipa_prf/prf_sharding/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ impl From<usize> for BucketStep {
}
}

#[derive(thiserror::Error, Debug)]
pub enum MoveToBucketError {
#[error("Bad value for the breakdown key: {0}")]
InvalidBreakdownKey(String),
}

impl From<MoveToBucketError> for Error {
fn from(error: MoveToBucketError) -> Self {
match error {
e @ MoveToBucketError::InvalidBreakdownKey(_) => {
Error::InvalidQueryParameter(Box::new(e))
}
}
}
}

#[embed_doc_image("tree-aggregation", "images/tree_aggregation.png")]
/// This function moves a single value to a correct bucket using tree aggregation approach
///
Expand All @@ -57,6 +73,9 @@ impl From<usize> for BucketStep {
/// extra processing to ensure contribution doesn't end up in a wrong bucket. However, this requires extra multiplications.
/// This would potentially not be needed in IPA (as the breakdown key is provided by the report collector, so a bad value only spoils their own result) but useful for PAM.
/// This can be by passing `robust` as true.
///
/// ## Errors
/// If `breakdown_count` does not fit into `BK` bits or greater than or equal to $2^9$
pub async fn move_single_value_to_bucket<BK, C, S, F>(
ctx: C,
record_id: RecordId,
Expand All @@ -71,17 +90,23 @@ where
S: LinearSecretSharing<F> + Serializable + SecureMul<C>,
F: PrimeField + ExtendableField,
{
const MAX_BREAKDOWNS: usize = 512; // constrained by the compact step ability to generate dynamic steps
let mut step: usize = 1 << BK::BITS;

assert!(
breakdown_count <= 1 << BK::BITS,
"Asking for more buckets ({breakdown_count}) than bits in the key ({}) allow",
BK::BITS
);
assert!(
breakdown_count <= 512,
"Our step implementation (BucketStep) cannot go past 256"
);
if breakdown_count > step {
Err(MoveToBucketError::InvalidBreakdownKey(format!(
"Asking for more buckets ({breakdown_count}) than bits in the breakdown key ({}) allow",
BK::BITS
)))?;
}

if breakdown_count > MAX_BREAKDOWNS {
Err(MoveToBucketError::InvalidBreakdownKey(
"Our step implementation (BucketStep) cannot go past {MAX_BREAKDOWNS} breakdown keys"
.to_string(),
))?;
}

let mut row_contribution = vec![value; breakdown_count];

for (tree_depth, bit_of_bdkey) in bd_key.iter().enumerate().rev() {
Expand Down Expand Up @@ -222,15 +247,15 @@ pub mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Asking for more buckets")]
fn move_out_of_range_too_many_buckets_type() {
run(move || async move {
_ = move_to_bucket(MAX_BREAKDOWN_COUNT + 1, 0, false).await;
});
}

#[test]
#[should_panic]
#[should_panic(expected = "Asking for more buckets")]
fn move_out_of_range_too_many_buckets_steps() {
run(move || async move {
let breakdown_key_bits = get_bits::<Fp32BitPrime>(0, Gf9Bit::BITS);
Expand Down
12 changes: 9 additions & 3 deletions src/protocol/prss/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ pub mod test {
}

#[test]
#[should_panic]
#[should_panic(
expected = "Attempt access a sequential PRSS for protocol/test after another access"
)]
fn indexed_then_sequential() {
let [p1, _p2, _p3] = participants();

Expand All @@ -502,7 +504,9 @@ pub mod test {
}

#[test]
#[should_panic]
#[should_panic(
expected = "Attempt to get an indexed PRSS for protocol/test after retrieving a sequential PRSS"
)]
fn sequential_then_indexed() {
let [p1, _p2, _p3] = participants();

Expand All @@ -526,7 +530,9 @@ pub mod test {

#[test]
#[cfg(debug_assertions)]
#[should_panic]
#[should_panic(
expected = "Generated randomness for index '100' twice using the same key 'protocol/test'"
)]
fn indexed_rejects_the_same_index() {
let [p1, _p2, _p3] = participants();
let step = Gate::default().narrow("test");
Expand Down
3 changes: 3 additions & 0 deletions src/protocol/sort/apply_sort/shuffle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ where
/// The Shuffle object receives a step function and appends a `ShuffleStep` to form a concrete step
///
/// ![Shuffle steps][shuffle]
///
/// ## Errors
/// If the underlying multiplicaion protocol fails on any of the input records.
pub async fn shuffle_shares<C, I>(
input: Vec<I>,
random_permutations: (&[u32], &[u32]),
Expand Down

0 comments on commit 6b648ef

Please sign in to comment.