diff --git a/Cargo.toml b/Cargo.toml index c86f50742..6bfa5468f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,3 +105,7 @@ trivially_copy_pass_by_ref = "deny" unnecessary_wraps = "deny" should_panic_without_expect = "deny" needless_pass_by_value = "deny" +too_many_lines = "deny" +cast_possible_wrap = "deny" +cast_sign_loss = "deny" +cast_possible_truncation = "deny" diff --git a/crates/proof-of-sql/benches/scaffold/querys.rs b/crates/proof-of-sql/benches/scaffold/querys.rs index 3b345e9be..d34440459 100644 --- a/crates/proof-of-sql/benches/scaffold/querys.rs +++ b/crates/proof-of-sql/benches/scaffold/querys.rs @@ -1,3 +1,4 @@ +#![allow(clippy::cast_possible_wrap)] use super::OptionalRandBound; use proof_of_sql::base::database::ColumnType; diff --git a/crates/proof-of-sql/benches/scaffold/random_util.rs b/crates/proof-of-sql/benches/scaffold/random_util.rs index 63cb48aa4..05c77980f 100644 --- a/crates/proof-of-sql/benches/scaffold/random_util.rs +++ b/crates/proof-of-sql/benches/scaffold/random_util.rs @@ -12,6 +12,7 @@ pub type OptionalRandBound = Option i64>; /// Will panic if: /// - The provided identifier cannot be parsed into an `Identifier` type. /// - An unsupported `ColumnType` is encountered, triggering a panic in the `todo!()` macro. +#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] pub fn generate_random_columns<'a, S: Scalar>( alloc: &'a Bump, rng: &mut impl Rng, diff --git a/crates/proof-of-sql/examples/posql_db/main.rs b/crates/proof-of-sql/examples/posql_db/main.rs index a9138ae11..a796ed25e 100644 --- a/crates/proof-of-sql/examples/posql_db/main.rs +++ b/crates/proof-of-sql/examples/posql_db/main.rs @@ -146,6 +146,7 @@ fn end_timer(instant: Instant) { /// - **Proof Verification Failure**: Panics if the proof verification process fails. /// - **Serialization/Deserialization Failure**: Panics if the proof cannot be serialized or deserialized. /// - **Record Batch Conversion Failure**: Panics if the query result cannot be converted into a `RecordBatch`. +#[allow(clippy::too_many_lines)] fn main() { let args = CliArgs::parse(); println!("Warming up GPU..."); diff --git a/crates/proof-of-sql/src/base/commitment/column_commitment_metadata.rs b/crates/proof-of-sql/src/base/commitment/column_commitment_metadata.rs index 263e76c68..75b49f0bb 100644 --- a/crates/proof-of-sql/src/base/commitment/column_commitment_metadata.rs +++ b/crates/proof-of-sql/src/base/commitment/column_commitment_metadata.rs @@ -791,6 +791,7 @@ mod tests { ); } + #[allow(clippy::too_many_lines)] #[test] fn we_cannot_perform_arithmetic_on_mismatched_metadata() { let boolean_metadata = ColumnCommitmentMetadata { diff --git a/crates/proof-of-sql/src/base/database/arrow_array_to_column_conversion.rs b/crates/proof-of-sql/src/base/database/arrow_array_to_column_conversion.rs index b78373a5d..15770f312 100644 --- a/crates/proof-of-sql/src/base/database/arrow_array_to_column_conversion.rs +++ b/crates/proof-of-sql/src/base/database/arrow_array_to_column_conversion.rs @@ -196,6 +196,7 @@ impl ArrayRefExt for ArrayRef { /// /// # Panics /// - When any range is OOB, i.e. indexing 3..6 or 5..5 on array of size 2. + #[allow(clippy::too_many_lines)] fn to_column<'a, S: Scalar>( &'a self, alloc: &'a Bump, diff --git a/crates/proof-of-sql/src/base/database/column.rs b/crates/proof-of-sql/src/base/database/column.rs index b4db556c0..382806a47 100644 --- a/crates/proof-of-sql/src/base/database/column.rs +++ b/crates/proof-of-sql/src/base/database/column.rs @@ -390,6 +390,7 @@ impl ColumnType { } } + #[allow(clippy::cast_possible_truncation)] /// Returns the bit size of the column type. #[must_use] pub fn bit_size(&self) -> u32 { diff --git a/crates/proof-of-sql/src/base/database/column_operation.rs b/crates/proof-of-sql/src/base/database/column_operation.rs index 9a18e8e07..32c129694 100644 --- a/crates/proof-of-sql/src/base/database/column_operation.rs +++ b/crates/proof-of-sql/src/base/database/column_operation.rs @@ -2016,6 +2016,7 @@ mod test { )); } + #[allow(clippy::too_many_lines)] #[test] fn we_can_try_add_decimal_columns() { // lhs is integer and rhs is decimal with nonnegative scale @@ -2195,6 +2196,7 @@ mod test { )); } + #[allow(clippy::too_many_lines)] #[test] fn we_can_try_subtract_decimal_columns() { // lhs is integer and rhs is decimal with nonnegative scale @@ -2355,6 +2357,7 @@ mod test { )); } + #[allow(clippy::too_many_lines)] #[test] fn we_can_try_multiply_decimal_columns() { // lhs is integer and rhs is decimal with nonnegative scale @@ -2535,6 +2538,7 @@ mod test { )); } + #[allow(clippy::too_many_lines)] #[test] fn we_can_try_divide_decimal_columns() { // lhs is integer and rhs is decimal with nonnegative scale diff --git a/crates/proof-of-sql/src/base/database/group_by_util.rs b/crates/proof-of-sql/src/base/database/group_by_util.rs index b27d3fcbb..cd5d3ebc7 100644 --- a/crates/proof-of-sql/src/base/database/group_by_util.rs +++ b/crates/proof-of-sql/src/base/database/group_by_util.rs @@ -36,6 +36,7 @@ pub enum AggregateColumnsError { ColumnLengthMismatch, } +#[allow(clippy::missing_panics_doc)] /// This is a function that gives the result of a group by query similar to the following: /// ```sql /// SELECT , , ..., SUM(), SUM(), ..., @@ -124,7 +125,11 @@ pub fn aggregate_columns<'a, S: Scalar>( .collect(); // Cast the counts to something compatible with BigInt. - let count_column_out = alloc.alloc_slice_fill_iter(counts.into_iter().map(|c| c as i64)); + let count_column_out = alloc.alloc_slice_fill_iter( + counts + .into_iter() + .map(|c| c.try_into().expect("Count should fit within i64")), + ); Ok(AggregatedColumns { group_by_columns: group_by_columns_out, diff --git a/crates/proof-of-sql/src/base/database/group_by_util_test.rs b/crates/proof-of-sql/src/base/database/group_by_util_test.rs index d729044b3..7d61fe888 100644 --- a/crates/proof-of-sql/src/base/database/group_by_util_test.rs +++ b/crates/proof-of-sql/src/base/database/group_by_util_test.rs @@ -111,6 +111,7 @@ fn we_can_aggregate_columns_with_empty_group_by() { assert_eq!(aggregate_result.min_columns, expected_min_result); } +#[allow(clippy::too_many_lines)] #[test] fn we_can_aggregate_columns() { let slice_a = &[3, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 3]; diff --git a/crates/proof-of-sql/src/base/database/owned_and_arrow_conversions.rs b/crates/proof-of-sql/src/base/database/owned_and_arrow_conversions.rs index 579b9f362..adf4f94af 100644 --- a/crates/proof-of-sql/src/base/database/owned_and_arrow_conversions.rs +++ b/crates/proof-of-sql/src/base/database/owned_and_arrow_conversions.rs @@ -140,6 +140,8 @@ impl TryFrom for OwnedColumn { } impl TryFrom<&ArrayRef> for OwnedColumn { type Error = OwnedArrowConversionError; + + #[allow(clippy::too_many_lines)] /// # Panics /// /// Will panic if downcasting fails for the following types: diff --git a/crates/proof-of-sql/src/base/database/owned_column_operation.rs b/crates/proof-of-sql/src/base/database/owned_column_operation.rs index 1fba3f1dc..fba0f2032 100644 --- a/crates/proof-of-sql/src/base/database/owned_column_operation.rs +++ b/crates/proof-of-sql/src/base/database/owned_column_operation.rs @@ -67,6 +67,7 @@ impl OwnedColumn { } /// Element-wise equality check for two columns + #[allow(clippy::too_many_lines)] pub fn element_wise_eq(&self, rhs: &Self) -> ColumnOperationResult { if self.len() != rhs.len() { return Err(ColumnOperationError::DifferentColumnLength { @@ -248,6 +249,7 @@ impl OwnedColumn { } /// Element-wise <= check for two columns + #[allow(clippy::too_many_lines)] pub fn element_wise_le(&self, rhs: &Self) -> ColumnOperationResult { if self.len() != rhs.len() { return Err(ColumnOperationError::DifferentColumnLength { @@ -428,6 +430,7 @@ impl OwnedColumn { } /// Element-wise >= check for two columns + #[allow(clippy::too_many_lines)] pub fn element_wise_ge(&self, rhs: &Self) -> ColumnOperationResult { if self.len() != rhs.len() { return Err(ColumnOperationError::DifferentColumnLength { @@ -611,6 +614,7 @@ impl OwnedColumn { impl Add for OwnedColumn { type Output = ColumnOperationResult; + #[allow(clippy::too_many_lines)] fn add(self, rhs: Self) -> Self::Output { if self.len() != rhs.len() { return Err(ColumnOperationError::DifferentColumnLength { @@ -804,6 +808,7 @@ impl Add for OwnedColumn { impl Sub for OwnedColumn { type Output = ColumnOperationResult; + #[allow(clippy::too_many_lines)] fn sub(self, rhs: Self) -> Self::Output { if self.len() != rhs.len() { return Err(ColumnOperationError::DifferentColumnLength { @@ -1001,6 +1006,7 @@ impl Sub for OwnedColumn { impl Mul for OwnedColumn { type Output = ColumnOperationResult; + #[allow(clippy::too_many_lines)] fn mul(self, rhs: Self) -> Self::Output { if self.len() != rhs.len() { return Err(ColumnOperationError::DifferentColumnLength { @@ -1198,6 +1204,7 @@ impl Mul for OwnedColumn { impl Div for OwnedColumn { type Output = ColumnOperationResult; + #[allow(clippy::too_many_lines)] fn div(self, rhs: Self) -> Self::Output { if self.len() != rhs.len() { return Err(ColumnOperationError::DifferentColumnLength { diff --git a/crates/proof-of-sql/src/base/database/scalar_and_i256_conversions.rs b/crates/proof-of-sql/src/base/database/scalar_and_i256_conversions.rs index 3ea407f41..9a44c3766 100644 --- a/crates/proof-of-sql/src/base/database/scalar_and_i256_conversions.rs +++ b/crates/proof-of-sql/src/base/database/scalar_and_i256_conversions.rs @@ -27,6 +27,7 @@ pub fn convert_scalar_to_i256(val: &S) -> i256 { } } +#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] /// Converts an arrow i256 into limbed representation and then /// into a type implementing [Scalar] #[must_use] diff --git a/crates/proof-of-sql/src/base/database/test_accessor_utility.rs b/crates/proof-of-sql/src/base/database/test_accessor_utility.rs index ea9224b94..2b06081dd 100644 --- a/crates/proof-of-sql/src/base/database/test_accessor_utility.rs +++ b/crates/proof-of-sql/src/base/database/test_accessor_utility.rs @@ -48,7 +48,7 @@ impl Default for RandomTestAccessorDescriptor { /// - When calling `.unwrap()` on the result of `RecordBatch::try_new(schema, columns)`, which /// will panic if the schema and columns do not align correctly or if there are any other /// underlying errors. -#[allow(dead_code)] +#[allow(dead_code, clippy::too_many_lines)] pub fn make_random_test_accessor_data( rng: &mut StdRng, cols: &[(&str, ColumnType)], diff --git a/crates/proof-of-sql/src/base/encode/scalar_varint.rs b/crates/proof-of-sql/src/base/encode/scalar_varint.rs index d904590b8..09ad90430 100644 --- a/crates/proof-of-sql/src/base/encode/scalar_varint.rs +++ b/crates/proof-of-sql/src/base/encode/scalar_varint.rs @@ -17,6 +17,8 @@ use core::cmp::{max, Ordering}; pub fn write_scalar_varint>(buf: &mut [u8], x: &MontScalar) -> usize { write_u256_varint(buf, x.zigzag()) } + +#[allow(clippy::cast_possible_truncation)] pub fn write_u256_varint(buf: &mut [u8], mut zig_x: U256) -> usize { let mut pos = 0; diff --git a/crates/proof-of-sql/src/base/encode/varint_trait.rs b/crates/proof-of-sql/src/base/encode/varint_trait.rs index 8f9fdbd27..4e7c4478e 100644 --- a/crates/proof-of-sql/src/base/encode/varint_trait.rs +++ b/crates/proof-of-sql/src/base/encode/varint_trait.rs @@ -53,6 +53,7 @@ pub trait VarInt: Sized + Copy { } } +#[allow(clippy::cast_sign_loss)] #[inline] fn zigzag_encode(from: i64) -> u64 { ((from << 1) ^ (from >> 63)) as u64 @@ -61,6 +62,7 @@ fn zigzag_encode(from: i64) -> u64 { // see: http://stackoverflow.com/a/2211086/56332 // casting required because operations like unary negation // cannot be performed on unsigned integers +#[allow(clippy::cast_possible_wrap, clippy::cast_sign_loss)] #[inline] fn zigzag_decode(from: u64) -> i64 { ((from >> 1) ^ (-((from & 1) as i64)) as u64) as i64 @@ -75,7 +77,7 @@ macro_rules! impl_varint { (self as u64).required_space() } - #[allow(clippy::cast_lossless)] + #[allow(clippy::cast_lossless, clippy::cast_possible_truncation)] fn decode_var(src: &[u8]) -> Option<(Self, usize)> { let (n, s) = u64::decode_var(src)?; // This check is required to ensure that we actually return `None` when `src` has a value that would overflow `Self`. @@ -99,7 +101,7 @@ macro_rules! impl_varint { (self as i64).required_space() } - #[allow(clippy::cast_lossless)] + #[allow(clippy::cast_lossless, clippy::cast_possible_truncation)] fn decode_var(src: &[u8]) -> Option<(Self, usize)> { let (n, s) = i64::decode_var(src)?; // This check is required to ensure that we actually return `None` when `src` has a value that would overflow `Self`. @@ -185,6 +187,7 @@ impl VarInt for u64 { } } + #[allow(clippy::cast_possible_truncation)] #[inline] fn encode_var(self, dst: &mut [u8]) -> usize { assert!(dst.len() >= self.required_space()); @@ -247,6 +250,7 @@ impl VarInt for u128 { } // Adapted from integer-encoding-rs. See third_party/license/integer-encoding.LICENSE +#[allow(clippy::cast_sign_loss)] #[inline] fn zigzag_encode_i128(from: i128) -> u128 { ((from << 1) ^ (from >> 127)) as u128 @@ -255,6 +259,7 @@ fn zigzag_encode_i128(from: i128) -> u128 { // see: http://stackoverflow.com/a/2211086/56332 // casting required because operations like unary negation // cannot be performed on unsigned integers +#[allow(clippy::cast_possible_wrap, clippy::cast_sign_loss)] #[inline] fn zigzag_decode_i128(from: u128) -> i128 { ((from >> 1) ^ (-((from & 1) as i128)) as u128) as i128 diff --git a/crates/proof-of-sql/src/base/math/decimal.rs b/crates/proof-of-sql/src/base/math/decimal.rs index e7b3c30cb..dda6bc116 100644 --- a/crates/proof-of-sql/src/base/math/decimal.rs +++ b/crates/proof-of-sql/src/base/math/decimal.rs @@ -126,6 +126,7 @@ impl Decimal { } /// Scale the decimal to the new scale factor. Negative scaling and overflow error out. + #[allow(clippy::cast_sign_loss)] pub fn with_precision_and_scale( &self, new_precision: Precision, @@ -142,6 +143,7 @@ impl Decimal { } /// Get a decimal with given precision and scale from an i64 + #[allow(clippy::cast_sign_loss)] pub fn from_i64(value: i64, precision: Precision, scale: i8) -> DecimalResult { const MINIMAL_PRECISION: u8 = 19; let raw_precision = precision.value(); @@ -160,6 +162,7 @@ impl Decimal { } /// Get a decimal with given precision and scale from an i128 + #[allow(clippy::cast_sign_loss)] pub fn from_i128(value: i128, precision: Precision, scale: i8) -> DecimalResult { const MINIMAL_PRECISION: u8 = 39; let raw_precision = precision.value(); @@ -243,7 +246,7 @@ mod scale_adjust_test { assert!(try_into_to_scalar::( &decimal, - Precision::new(decimal.value().digits() as u8).unwrap(), + Precision::new(u8::try_from(decimal.value().digits()).unwrap_or(u8::MAX)).unwrap(), target_scale ) .is_err()); @@ -282,7 +285,7 @@ mod scale_adjust_test { let limbs = try_into_to_scalar::( &decimal, - Precision::new(decimal.value().digits() as u8).unwrap(), + Precision::new(u8::try_from(decimal.value().digits()).unwrap_or(u8::MAX)).unwrap(), target_scale, ) .unwrap(); @@ -297,13 +300,14 @@ mod scale_adjust_test { let expected_limbs = [12345, 0, 0, 0]; let limbs = try_into_to_scalar::( &decimal, - Precision::new(decimal.value().digits() as u8).unwrap(), + Precision::new(u8::try_from(decimal.value().digits()).unwrap_or(u8::MAX)).unwrap(), target_scale, ) .unwrap(); assert_eq!(limbs, -Curve25519Scalar::from(expected_limbs)); } + #[allow(clippy::cast_possible_wrap)] #[test] fn we_can_match_decimals_at_extrema() { // a big decimal cannot scale up past the supported precision @@ -313,7 +317,7 @@ mod scale_adjust_test { let target_scale = 6; // now precision exceeds maximum assert!(try_into_to_scalar::( &decimal, - Precision::new(decimal.value().digits() as u8,).unwrap(), + Precision::new(u8::try_from(decimal.value().digits()).unwrap_or(u8::MAX),).unwrap(), target_scale ) .is_err()); @@ -352,7 +356,7 @@ mod scale_adjust_test { let target_scale = MAX_SUPPORTED_PRECISION as i8; assert!(try_into_to_scalar::( &decimal, - Precision::new(decimal.value().digits() as u8,).unwrap(), + Precision::new(u8::try_from(decimal.value().digits()).unwrap_or(u8::MAX),).unwrap(), target_scale ) .is_ok()); @@ -372,7 +376,7 @@ mod scale_adjust_test { let target_scale = 75; assert!(try_into_to_scalar::( &decimal, - Precision::new(decimal.value().digits() as u8,).unwrap(), + Precision::new(u8::try_from(decimal.value().digits()).unwrap_or(u8::MAX),).unwrap(), target_scale ) .is_err()); diff --git a/crates/proof-of-sql/src/base/math/log.rs b/crates/proof-of-sql/src/base/math/log.rs index 3ed20fb06..8748e16ee 100644 --- a/crates/proof-of-sql/src/base/math/log.rs +++ b/crates/proof-of-sql/src/base/math/log.rs @@ -71,6 +71,7 @@ mod tests { assert_eq!(log2_up(4u32), 2); } + #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] #[test] fn test_log2_bytes_ceil() { // 0-1 edge cases diff --git a/crates/proof-of-sql/src/base/polynomial/interpolate.rs b/crates/proof-of-sql/src/base/polynomial/interpolate.rs index ed821e3c6..031a64830 100644 --- a/crates/proof-of-sql/src/base/polynomial/interpolate.rs +++ b/crates/proof-of-sql/src/base/polynomial/interpolate.rs @@ -76,7 +76,11 @@ where /// Let `d` be `evals.len() - 1` and let `f` be the polynomial such that `f(i) = evals[i]`. /// The output of this function is the vector of coefficients of `f`, with the leading coefficient first. /// That is, `f(x) = evals[j] * x^(d - j)`. -#[allow(clippy::missing_panics_doc)] +#[allow( + clippy::missing_panics_doc, + clippy::cast_possible_truncation, + clippy::cast_possible_wrap +)] // This function is guaranteed not to panic because: // - The product in `inv()` will never be zero, as the numbers being multiplied are all non-zero by construction. // - If there are no elements to reduce, `unwrap_or(vec![])` provides an empty vector as a safe fallback. @@ -90,6 +94,7 @@ where + Inv> + Product, { + assert!(i32::try_from(evals.len()).is_ok()); let n = evals.len().max(1) - 1; evals .iter() diff --git a/crates/proof-of-sql/src/base/polynomial/interpolate_test.rs b/crates/proof-of-sql/src/base/polynomial/interpolate_test.rs index ec40d3c57..2ee9ecfc1 100644 --- a/crates/proof-of-sql/src/base/polynomial/interpolate_test.rs +++ b/crates/proof-of-sql/src/base/polynomial/interpolate_test.rs @@ -89,7 +89,10 @@ fn interpolate_uni_poly_gives_correct_value_for_known_evaluation() { ]; for i in 0..evaluations.len() { assert_eq!( - interpolate_uni_poly(&evaluations, Curve25519Scalar::from(i as u32)), + interpolate_uni_poly( + &evaluations, + Curve25519Scalar::from(u32::try_from(i).unwrap_or(u32::MAX)) + ), evaluations[i] ); } diff --git a/crates/proof-of-sql/src/base/scalar/mont_scalar.rs b/crates/proof-of-sql/src/base/scalar/mont_scalar.rs index 84a7a0b94..aab1dd288 100644 --- a/crates/proof-of-sql/src/base/scalar/mont_scalar.rs +++ b/crates/proof-of-sql/src/base/scalar/mont_scalar.rs @@ -562,6 +562,8 @@ where MontScalar: Scalar, { type Error = ScalarConversionError; + + #[allow(clippy::cast_possible_wrap)] fn try_from(value: MontScalar) -> Result { let (sign, abs): (i128, [u64; 4]) = if value > >::MAX_SIGNED { (-1, (-value).into()) diff --git a/crates/proof-of-sql/src/base/scalar/mont_scalar_test.rs b/crates/proof-of-sql/src/base/scalar/mont_scalar_test.rs index 8301bad5d..1db934cfe 100644 --- a/crates/proof-of-sql/src/base/scalar/mont_scalar_test.rs +++ b/crates/proof-of-sql/src/base/scalar/mont_scalar_test.rs @@ -427,6 +427,7 @@ fn strings_of_arbitrary_size_map_to_different_scalars() { } } +#[allow(clippy::cast_sign_loss)] #[test] fn byte_arrays_of_arbitrary_size_map_to_different_scalars() { let mut prev_scalars = IndexSet::default(); diff --git a/crates/proof-of-sql/src/proof_primitive/dory/blitzar_metadata_table.rs b/crates/proof-of-sql/src/proof_primitive/dory/blitzar_metadata_table.rs index c03ccdd4e..c4a0138cc 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/blitzar_metadata_table.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/blitzar_metadata_table.rs @@ -121,6 +121,7 @@ fn copy_column_data_to_slice( } } +#[allow(clippy::cast_possible_truncation)] /// Creates the metadata tables for Blitzar's `vlen_msm` algorithm. /// /// # Arguments diff --git a/crates/proof-of-sql/src/proof_primitive/dory/dory_vmv_helper.rs b/crates/proof-of-sql/src/proof_primitive/dory/dory_vmv_helper.rs index a1534f913..4041ddbc3 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/dory_vmv_helper.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/dory_vmv_helper.rs @@ -56,7 +56,7 @@ pub(super) fn compute_T_vec_prime( prover_setup.blitzar_msm( &mut blitzar_commits, - data_size as u32, + u32::try_from(data_size).expect("the size of `data_size` should fit in u32"), a_transpose.as_slice(), ); diff --git a/crates/proof-of-sql/src/proof_primitive/dory/pack_scalars.rs b/crates/proof-of-sql/src/proof_primitive/dory/pack_scalars.rs index 40473eae7..1be1b836a 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/pack_scalars.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/pack_scalars.rs @@ -325,7 +325,10 @@ pub fn bit_table_and_scalars_for_packed_msm( let bit_table_sub_commits_sum = bit_table.iter().sum::() as usize; // Add offsets to handle signed values to the bit table. - bit_table.extend(iter::repeat(BYTE_SIZE as u32).take(OFFSET_SIZE + committable_columns.len())); + bit_table.extend( + iter::repeat(u32::try_from(BYTE_SIZE).unwrap_or(u32::MAX)) + .take(OFFSET_SIZE + committable_columns.len()), + ); let bit_table_full_sum_in_bytes = bit_table.iter().sum::() as usize / BYTE_SIZE; // Create the packed_scalar array. diff --git a/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs b/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs index 59cf6a640..032dee470 100644 --- a/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs +++ b/crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs @@ -170,7 +170,9 @@ impl CanonicalDeserialize for PublicParameters { ) -> Result { // Deserialize max_nu (u64) let max_nu_u64 = u64::deserialize_with_mode(&mut reader, compress, validate)?; - let max_nu = max_nu_u64 as usize; + let max_nu: usize = max_nu_u64 + .try_into() + .map_err(|_| SerializationError::InvalidData)?; // Deserialize Gamma_1 (Vec) let Gamma_1: Vec = (0..(1 << max_nu)) diff --git a/crates/proof-of-sql/src/sql/postprocessing/group_by_postprocessing.rs b/crates/proof-of-sql/src/sql/postprocessing/group_by_postprocessing.rs index 1c8ecaad9..e75d3b24f 100644 --- a/crates/proof-of-sql/src/sql/postprocessing/group_by_postprocessing.rs +++ b/crates/proof-of-sql/src/sql/postprocessing/group_by_postprocessing.rs @@ -196,6 +196,7 @@ impl GroupByPostprocessing { impl PostprocessingStep for GroupByPostprocessing { /// Apply the group by transformation to the given `OwnedTable`. + #[allow(clippy::too_many_lines)] fn apply(&self, owned_table: OwnedTable) -> PostprocessingResult> { // First evaluate all the aggregated columns let alloc = Bump::new(); diff --git a/crates/proof-of-sql/src/sql/postprocessing/group_by_postprocessing_test.rs b/crates/proof-of-sql/src/sql/postprocessing/group_by_postprocessing_test.rs index f0fc572ad..df4ded3ed 100644 --- a/crates/proof-of-sql/src/sql/postprocessing/group_by_postprocessing_test.rs +++ b/crates/proof-of-sql/src/sql/postprocessing/group_by_postprocessing_test.rs @@ -63,6 +63,7 @@ fn we_can_make_group_by_postprocessing() { ); } +#[allow(clippy::too_many_lines)] #[test] fn we_can_do_simple_group_bys() { // SELECT 1 as cons FROM tab @@ -202,6 +203,7 @@ fn we_can_do_simple_group_bys() { assert_eq!(actual_table, expected_table); } +#[allow(clippy::too_many_lines)] #[test] fn we_can_do_complex_group_bys() { // SELECT 2 * MAX(2 * a + 1) as max_a, MIN(b + 4) - 2.4 as min_b, SUM(c * 1.4) as sum_c, COUNT(d) + 3 as count_d FROM tab diff --git a/crates/proof-of-sql/src/sql/postprocessing/slice_postprocessing_test.rs b/crates/proof-of-sql/src/sql/postprocessing/slice_postprocessing_test.rs index 742047bd6..6d664b1b8 100644 --- a/crates/proof-of-sql/src/sql/postprocessing/slice_postprocessing_test.rs +++ b/crates/proof-of-sql/src/sql/postprocessing/slice_postprocessing_test.rs @@ -22,6 +22,7 @@ fn we_can_slice_an_owned_table_using_only_a_positive_limit_value() { assert_eq!(actual_table, expected_table); } +#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] #[test] fn we_can_slice_an_owned_table_using_only_a_zero_limit_value() { let limit = 0; @@ -38,6 +39,7 @@ fn we_can_slice_an_owned_table_using_only_a_zero_limit_value() { assert_eq!(actual_table, expected_table); } +#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)] #[test] fn we_can_slice_an_owned_table_using_only_a_positive_offset_value() { let offset = 3; @@ -54,6 +56,11 @@ fn we_can_slice_an_owned_table_using_only_a_positive_offset_value() { assert_eq!(actual_table, expected_table); } +#[allow( + clippy::cast_sign_loss, + clippy::cast_possible_truncation, + clippy::cast_possible_wrap +)] #[test] fn we_can_slice_an_owned_table_using_only_a_negative_offset_value() { let offset = -2; @@ -76,6 +83,11 @@ fn we_can_slice_an_owned_table_using_only_a_negative_offset_value() { assert_eq!(actual_table, expected_table); } +#[allow( + clippy::cast_sign_loss, + clippy::cast_possible_truncation, + clippy::cast_possible_wrap +)] #[test] fn we_can_slice_an_owned_table_using_both_limit_and_offset_values() { let offset = -2; diff --git a/crates/proof-of-sql/src/sql/proof/provable_query_result.rs b/crates/proof-of-sql/src/sql/proof/provable_query_result.rs index 9e4e7ba14..b45d1dd18 100644 --- a/crates/proof-of-sql/src/sql/proof/provable_query_result.rs +++ b/crates/proof-of-sql/src/sql/proof/provable_query_result.rs @@ -17,7 +17,9 @@ pub struct ProvableQueryResult { data: Vec, } +// TODO: Handle truncation properly. The `allow(clippy::cast_possible_truncation)` is a temporary fix and should be replaced with proper logic to manage possible truncation scenarios. impl ProvableQueryResult { + #[allow(clippy::cast_possible_truncation)] /// The number of columns in the result #[must_use] pub fn num_columns(&self) -> usize { @@ -29,6 +31,8 @@ impl ProvableQueryResult { pub fn num_columns_mut(&mut self) -> &mut u64 { &mut self.num_columns } + + #[allow(clippy::cast_possible_truncation)] /// The number of rows in the result #[must_use] pub fn table_length(&self) -> usize { @@ -77,6 +81,7 @@ impl ProvableQueryResult { } } + #[allow(clippy::cast_possible_truncation)] #[allow( clippy::missing_panics_doc, reason = "Assertions ensure preconditions are met, eliminating the possibility of panic." diff --git a/crates/proof-of-sql/src/sql/proof/provable_result_column.rs b/crates/proof-of-sql/src/sql/proof/provable_result_column.rs index c804e4738..1896fceec 100644 --- a/crates/proof-of-sql/src/sql/proof/provable_result_column.rs +++ b/crates/proof-of-sql/src/sql/proof/provable_result_column.rs @@ -21,7 +21,8 @@ impl<'a, T: ProvableResultElement<'a>> ProvableResultColumn for &[T] { fn write(&self, out: &mut [u8], length: u64) -> usize { let mut res = 0; for i in 0..length { - res += self[i as usize].encode(&mut out[res..]); + let index: usize = usize::try_from(i).expect("Index out of bounds"); + res += self[index].encode(&mut out[res..]); } res } diff --git a/crates/proof-of-sql/src/sql/proof/result_element_serialization.rs b/crates/proof-of-sql/src/sql/proof/result_element_serialization.rs index b03306957..df9247434 100644 --- a/crates/proof-of-sql/src/sql/proof/result_element_serialization.rs +++ b/crates/proof-of-sql/src/sql/proof/result_element_serialization.rs @@ -254,7 +254,10 @@ mod tests { let dist = Uniform::new(1, usize::MAX); for _ in 0..100 { - let value = dist.sample(&mut rng) as i64; + let value = match dist.sample(&mut rng).try_into() { + Ok(val) => val, + Err(_) => i64::MAX, + }; let mut out = vec![0_u8; value.required_bytes()]; value.encode(&mut out[..]); @@ -316,6 +319,7 @@ mod tests { } } + #[allow(clippy::cast_possible_truncation)] #[test] fn arbitrary_encoded_buffers_are_correctly_decoded() { let mut rng = StdRng::from_seed([0u8; 32]); diff --git a/crates/proof-of-sql/src/sql/proof_exprs/comparison_util.rs b/crates/proof-of-sql/src/sql/proof_exprs/comparison_util.rs index ed7794122..c25445340 100644 --- a/crates/proof-of-sql/src/sql/proof_exprs/comparison_util.rs +++ b/crates/proof-of-sql/src/sql/proof_exprs/comparison_util.rs @@ -37,6 +37,7 @@ fn unchecked_subtract_impl<'a, S: Scalar>( )] /// Scale LHS and RHS to the same scale if at least one of them is decimal /// and take the difference. This function is used for comparisons. +#[allow(clippy::cast_sign_loss)] pub(crate) fn scale_and_subtract<'a, S: Scalar>( alloc: &'a Bump, lhs: Column<'a, S>, diff --git a/crates/proof-of-sql/src/sql/proof_plans/group_by_exec_test.rs b/crates/proof-of-sql/src/sql/proof_plans/group_by_exec_test.rs index 062bcc425..04ade4bf4 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/group_by_exec_test.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/group_by_exec_test.rs @@ -75,6 +75,7 @@ fn we_can_prove_a_group_by_with_bigint_columns() { assert_eq!(res, expected); } +#[allow(clippy::too_many_lines)] #[test] fn we_can_prove_a_complex_group_by_query_with_many_columns() { let scalar_filter_data: Vec = [ diff --git a/crates/proof-of-sql/src/utils/parse.rs b/crates/proof-of-sql/src/utils/parse.rs index caeda9a6e..415ecb1c3 100644 --- a/crates/proof-of-sql/src/utils/parse.rs +++ b/crates/proof-of-sql/src/utils/parse.rs @@ -9,6 +9,7 @@ use sqlparser::{ parser::Parser, }; +#[allow(clippy::cast_possible_truncation)] /// Parse a DDL file and return a map of table names to bigdecimal columns /// /// # Panics