From 627193173829f97f03609ac164b855bd2bf922bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jepsen=20=E2=9C=A8?= <57912727+0xJepsen@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:20:58 -0700 Subject: [PATCH] remove udeps + exclude changelog from triggering release prs (#161) * remove udeps + exclude changelog from triggering release prs * lints --- .clippy.toml | 2 +- .github/workflows/lint.yaml | 17 -------- .rustfmt.toml | 56 +++++++++++++-------------- .taplo.toml | 12 +++--- Cargo.toml | 8 ++-- rust-toolchain.toml | 2 +- src/encryption/symmetric/modes/gcm.rs | 4 +- src/hashes/ghash.rs | 18 ++++----- src/hmac/bin/hmac_sha256_bin.rs | 2 +- src/multi_var_poly/mod.rs | 18 ++++----- src/multi_var_poly/tests.rs | 4 +- src/sumcheck/mod.rs | 22 +++++------ 12 files changed, 73 insertions(+), 92 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 429501f..d38d35a 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -2,4 +2,4 @@ # https://rust-lang.github.io/rust-clippy/master/index.html # Don't warn for functions with too many arguments. Default: 7 -too-many-arguments-threshold = 10 +too-many-arguments-threshold=10 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index f5a0670..0853d8e 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -38,20 +38,3 @@ jobs: - name: cargo clippy run: cargo clippy --all - - udeps: - name: udeps - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - - name: Install Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: nightly-2024-06-10 - - - name: install udeps - run: cargo install --git https://github.com/est31/cargo-udeps --locked - - - name: cargo udeps - run: cargo udeps diff --git a/.rustfmt.toml b/.rustfmt.toml index a6271c6..fccf462 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -3,42 +3,42 @@ # https://rust-lang.github.io/rustfmt # version-related -edition = "2021" # redundant, fmt will read Cargo.toml for editor edition year -unstable_features = true -use_try_shorthand = true # replace any `try!` (2015 Rust) with `?` +edition ="2021" # redundant, fmt will read Cargo.toml for editor edition year +unstable_features=true +use_try_shorthand=true # replace any `try!` (2015 Rust) with `?` # misc formatting -condense_wildcard_suffixes = true # replace: (a,b,_,_)=(1, 2, 3, 4); -> (a,b,..)=(1, 2, 3, 4); -format_code_in_doc_comments = true # format code blocks in doc comments -format_macro_matchers = true # $a: ident -> $a:ident -format_strings = true # break and insert newlines for long string literals -match_block_trailing_comma = true # include comma in match blocks after '}' -normalize_comments = true # convert /*..*/ to //.. where possible -reorder_impl_items = true # move `type` and `const` declarations to top of impl block -struct_field_align_threshold = 20 # align struct arguments' types vertically -use_field_init_shorthand = true # struct initialization short {x: x} -> {x} +condense_wildcard_suffixes =true # replace: (a,b,_,_)=(1, 2, 3, 4); -> (a,b,..)=(1, 2, 3, 4); +format_code_in_doc_comments =true # format code blocks in doc comments +format_macro_matchers =true # $a: ident -> $a:ident +format_strings =true # break and insert newlines for long string literals +match_block_trailing_comma =true # include comma in match blocks after '}' +normalize_comments =true # convert /*..*/ to //.. where possible +reorder_impl_items =true # move `type` and `const` declarations to top of impl block +struct_field_align_threshold=20 # align struct arguments' types vertically +use_field_init_shorthand =true # struct initialization short {x: x} -> {x} # reduce whitespace -blank_lines_upper_bound = 1 # default: 1. Sometimes useful to change to 0 to condense a file. -brace_style = "PreferSameLine" # prefer starting `{` without inserting extra \n -fn_single_line = true # if it's a short 1-liner, let it be a short 1-liner -match_arm_blocks = false # remove unnecessary {} in match arms -newline_style = "Unix" # not auto, we won the culture war. \n over \r\n -overflow_delimited_expr = true # prefer ]); to ]\n); -where_single_line = true # put where on a single line if possible +blank_lines_upper_bound=1 # default: 1. Sometimes useful to change to 0 to condense a file. +brace_style ="PreferSameLine" # prefer starting `{` without inserting extra \n +fn_single_line =true # if it's a short 1-liner, let it be a short 1-liner +match_arm_blocks =false # remove unnecessary {} in match arms +newline_style ="Unix" # not auto, we won the culture war. \n over \r\n +overflow_delimited_expr=true # prefer ]); to ]\n); +where_single_line =true # put where on a single line if possible # imports preferences -group_imports = "StdExternalCrate" # create import groupings for std, external libs, and internal deps -imports_granularity = "Crate" # aggressively group imports +group_imports ="StdExternalCrate" # create import groupings for std, external libs, and internal deps +imports_granularity="Crate" # aggressively group imports # width settings: everything to 100 -comment_width = 100 # default: 80 -inline_attribute_width = 60 # inlines #[cfg(test)]\nmod test -> #[cfg(test)] mod test -max_width = 100 # default: 100 -use_small_heuristics = "Max" # don't ever newline short of `max_width`. -wrap_comments = true # wrap comments at `comment_width` +comment_width =100 # default: 80 +inline_attribute_width=60 # inlines #[cfg(test)]\nmod test -> #[cfg(test)] mod test +max_width =100 # default: 100 +use_small_heuristics ="Max" # don't ever newline short of `max_width`. +wrap_comments =true # wrap comments at `comment_width` # format_strings = true # wrap strings at `max_length` # tabs and spaces -hard_tabs = false # (def: false) use spaces over tabs -tab_spaces = 2 # 2 > 4, it's just math. +hard_tabs =false # (def: false) use spaces over tabs +tab_spaces=2 # 2 > 4, it's just math. diff --git a/.taplo.toml b/.taplo.toml index e88b1f4..f58bb47 100644 --- a/.taplo.toml +++ b/.taplo.toml @@ -3,17 +3,17 @@ [formatting] # align entries vertically -align_entries = true +align_entries=true # allow up to 1 consecutive empty line (default: 2) -allowed_blank_lines = 1 +allowed_blank_lines=1 # collapse arrays into one line if they fit -array_auto_collapse = true +array_auto_collapse=true # default: 80 -column_width = 100 +column_width=100 # remove whitespace around '=' -compact_entries = true +compact_entries=true # alphabetically sort entries not separated by line breaks -reorder_keys = false +reorder_keys=false # align entries vertically (default: true) # align_comments =false # expand arrays into multiple lines (default: true) diff --git a/Cargo.toml b/Cargo.toml index 9b9d0e0..d553de9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,8 @@ edition ="2021" license ="Apache2.0 OR MIT" name ="ronkathon" repository ="https://github.com/pluto/ronkathon" -version = "0.1.0" +version ="0.1.0" +exclude =["CHANGELOG.md"] [dependencies] rand ="0.8.5" @@ -29,12 +30,11 @@ ark-serialize={ git="https://github.com/arkworks-rs/algebra/" } ark-std ={ git="https://github.com/arkworks-rs/std/" } [[bin]] -name = "hmac_sha256_bin" -path = "src/hmac/bin/hmac_sha256_bin.rs" +name="hmac_sha256_bin" +path="src/hmac/bin/hmac_sha256_bin.rs" [[example]] name="aes_chained_cbc" [[example]] name="symmetric_group" - diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 3299962..175afcc 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -3,7 +3,7 @@ [toolchain] # what toolchain to use. -channel = "nightly-2024-06-10" +channel="nightly-2024-06-10" # option to specify a date to pin to a particular release # date = "2024-03-19" diff --git a/src/encryption/symmetric/modes/gcm.rs b/src/encryption/symmetric/modes/gcm.rs index 06b4390..816d87c 100644 --- a/src/encryption/symmetric/modes/gcm.rs +++ b/src/encryption/symmetric/modes/gcm.rs @@ -125,7 +125,7 @@ where [(); C::BLOCK_SIZE - 4]: counter.increment()?; // Step 2: Encrypt the plaintext using the `CTR` object. - let ctr = CTR::::new(new_nonce.try_into().unwrap()); + let ctr = CTR::::new(new_nonce.into()); let ciphertext = ctr.encrypt(&self.key, &counter, plaintext)?; // Step3: Generate Tag @@ -198,7 +198,7 @@ where [(); C::BLOCK_SIZE - 4]: counter.increment()?; // Step 3: Decrypt ciphertext. - let ctr = CTR::::new(new_nonce.try_into().unwrap()); + let ctr = CTR::::new(new_nonce.into()); let plaintext = ctr.decrypt(&self.key, &counter, ciphertext)?; Ok((plaintext.to_vec(), tag)) diff --git a/src/hashes/ghash.rs b/src/hashes/ghash.rs index b6dacba..625ac28 100644 --- a/src/hashes/ghash.rs +++ b/src/hashes/ghash.rs @@ -73,8 +73,8 @@ impl From for Vec { let mut bytes = Vec::new(); for block in value.coeffs.chunks(8) { let mut byte: u8 = 0; - for i in 0..8 { - if block[i] == AESField::ONE { + for (i, &b) in block.iter().take(8).enumerate() { + if b == AESField::ONE { byte += (1 << (7 - i)) as u8; } } @@ -142,8 +142,8 @@ impl GHASH { /// Returns the result of multiplication of two GCMField elements, /// modulo the field polynomial, f = 1 + α + α^2 + α^7 + α^128 fn poly_multiply(x: GCMField, y: GCMField) -> GCMField { - let x_coeffs: [AESField; 128] = x.coeffs.try_into().unwrap(); - let y_coeffs: [AESField; 128] = y.coeffs.try_into().unwrap(); + let x_coeffs: [AESField; 128] = x.coeffs; + let y_coeffs: [AESField; 128] = y.coeffs; let poly_x = Polynomial::::from(x_coeffs); let poly_y = Polynomial::::from(y_coeffs); let poly_f = @@ -166,12 +166,12 @@ impl GHASH { r_coeffs.rotate_left(120); let r = GCMField { coeffs: r_coeffs.try_into().unwrap() }; - let mut z = GCMField::from(0 as usize); + let mut z = GCMField::from(0_usize); let mut v = y; for bit in x.coeffs { if bit == AESField::ONE { - z = z + v; + z += v; } let mut v1 = v.coeffs.to_vec(); @@ -182,7 +182,7 @@ impl GHASH { v = GCMField { coeffs: v1.try_into().unwrap() }; if v1_bit == AESField::ONE { - v = v + r; + v += r; } } @@ -269,11 +269,11 @@ mod tests { let zf = GHASH::poly_multiply(xf, yf); - let z_coeffs: Vec = zf.try_into().unwrap(); + let z_coeffs: Vec = zf.into(); let z_hex = encode_hex(&z_coeffs); let expected_zf = GHASH::poly_multiply_spec(xf, yf); - let expected_z_coeffs: Vec = expected_zf.try_into().unwrap(); + let expected_z_coeffs: Vec = expected_zf.into(); let expected_z_hex = encode_hex(&expected_z_coeffs); println!("Got: {z_hex}\nExp: {expected_z_hex}"); diff --git a/src/hmac/bin/hmac_sha256_bin.rs b/src/hmac/bin/hmac_sha256_bin.rs index 48f0ef7..2fab20d 100644 --- a/src/hmac/bin/hmac_sha256_bin.rs +++ b/src/hmac/bin/hmac_sha256_bin.rs @@ -15,7 +15,7 @@ fn main() { // Pass the first argument to the function let key = args[1].as_bytes(); let message = args[2].as_bytes(); - let result = hex::encode(hmac_sha256(&key, &message)); + let result = hex::encode(hmac_sha256(key, message)); println!("Result: {}", result); } diff --git a/src/multi_var_poly/mod.rs b/src/multi_var_poly/mod.rs index c9c84d5..bbf0a05 100644 --- a/src/multi_var_poly/mod.rs +++ b/src/multi_var_poly/mod.rs @@ -54,10 +54,10 @@ pub struct MultiVarPolynomial { fn generate_cartesian_product(l: Vec) -> Vec> { let mut result = vec![vec![]]; - for i in 0..l.len() { + for element in &l { let mut new_result = Vec::new(); for item in result.iter() { - for j in 0..l[i] { + for j in 0..*element { let mut new_item = item.clone(); new_item.push(j); new_result.push(new_item); @@ -148,22 +148,20 @@ impl MultiVarPolynomial { /// /// ## Returns: /// - The result of evaluating the polynomial at the given point. - pub fn evaluation(&self, r: &Vec) -> F { + pub fn evaluation(&self, r: &[F]) -> F { assert_eq!(r.len(), self.num_var()); let degree_plus_1 = self.degree.iter().map(|x| x + 1).collect(); let cartesian_prod = generate_cartesian_product(degree_plus_1); let mut result = F::ZERO; - for i in 0..cartesian_prod.len() { - let cood = &cartesian_prod[i]; - let coeff = self.coefficients[i].clone(); + for (cood, coeff) in cartesian_prod.iter().zip(&self.coefficients) { let mut eval_term = F::ONE; for j in 0..cood.len() { let exp = cood[j]; - eval_term = eval_term * (r[j].pow(exp)); + eval_term *= r[j].pow(exp); } - result += coeff * eval_term; + result += *coeff * eval_term; } - return result; + result } /// Returns the number of variables in the polynomial. @@ -182,7 +180,7 @@ impl MultiVarPolynomial { let cood_f: Vec = cood.iter().map(|&x| F::from(x)).collect(); sum += self.evaluation(&cood_f); } - return sum; + sum } /// Multiplies the polynomial by a scalar. diff --git a/src/multi_var_poly/tests.rs b/src/multi_var_poly/tests.rs index 9d23fcd..ec19bee 100644 --- a/src/multi_var_poly/tests.rs +++ b/src/multi_var_poly/tests.rs @@ -16,7 +16,7 @@ fn test_multivar_polynomial_evaluation() { let poly = MultiVarPolynomial::::new(degree, coefficients).unwrap(); // Evaluate the polynomial at (x, y) = (2, 3) - let result = poly.evaluation(&vec![PlutoBaseField::new(2), PlutoBaseField::new(3)]); + let result = poly.evaluation(&[PlutoBaseField::new(2), PlutoBaseField::new(3)]); // Calculate the expected result let expected = PlutoBaseField::new(43); @@ -41,7 +41,7 @@ fn test_multivar_from_coods() { let poly = MultiVarPolynomial::from_coordinates(coordinates, coefficients).unwrap(); // Evaluate the polynomial at (x, y) = (2, 3) - let result = poly.evaluation(&vec![PlutoBaseField::new(2), PlutoBaseField::new(3)]); + let result = poly.evaluation(&[PlutoBaseField::new(2), PlutoBaseField::new(3)]); // Calculate the expected result let expected = PlutoBaseField::new(43); diff --git a/src/sumcheck/mod.rs b/src/sumcheck/mod.rs index 7839ef3..bf392ac 100644 --- a/src/sumcheck/mod.rs +++ b/src/sumcheck/mod.rs @@ -41,7 +41,7 @@ impl SumCheckProver { /// /// ## Returns: /// - The sum of the polynomial over the boolean hypercube. - pub fn sum_poly(&self) -> F { return self.multi_var_poly.sum_over_bool_hypercube(); } + pub fn sum_poly(&self) -> F { self.multi_var_poly.sum_over_bool_hypercube() } /// Generates the univariate polynomial to be sent to the Verifier in the current round of the /// protocol. @@ -74,9 +74,9 @@ impl SumCheckProver { .sum_over_bool_hypercube(), ); } - return poly_to_send; + poly_to_send } else { - return self.multi_var_poly.coefficients.clone(); + self.multi_var_poly.coefficients.clone() } } @@ -113,7 +113,7 @@ impl SumCheckProver { self.multi_var_poly = new_multi_var_poly; } else { self.multi_var_poly = - MultiVarPolynomial::new(vec![0], vec![self.multi_var_poly.evaluation(&vec![r])]).unwrap(); + MultiVarPolynomial::new(vec![0], vec![self.multi_var_poly.evaluation(&[r])]).unwrap(); } self.current_round += 1; } @@ -170,8 +170,8 @@ impl SumCheckVerifier { ); let h_poly_at_0 = h_poly[0]; let mut h_poly_at_1 = F::ZERO; - for i in 0..h_poly.len() { - h_poly_at_1 += h_poly[i]; + for item in h_poly.clone() { + h_poly_at_1 += item; } let sum = h_poly_at_0 + h_poly_at_1; assert_eq!( @@ -187,14 +187,14 @@ impl SumCheckVerifier { // we are implementing univariate polynomial evaluation here, since we can't use existing // [`Polynomial`] with variable size degree let mut new_claim = F::ZERO; - for i in 0..h_poly.len() { - new_claim += h_poly[i] * challenge.pow(i); + for (i, coeff) in h_poly.iter().enumerate() { + new_claim += *coeff * challenge.pow(i); } self.claim = new_claim; self.current_round += 1; self.challenges_sent.push(challenge); - return challenge; + challenge } /// Verifies the final result of the protocol using the provided oracle. @@ -247,8 +247,8 @@ impl SumCheck { /// /// ## Returns: /// - A boolean indicating whether the evaluation matches the claim. - pub fn evaluation_oracle(&self, r: &Vec, claim: F) -> bool { - return self.multi_var_poly.evaluation(r) == claim; + pub fn evaluation_oracle(&self, r: &[F], claim: F) -> bool { + self.multi_var_poly.evaluation(r) == claim } /// Runs the interactive sum-check protocol between the prover and verifier.