Skip to content

Commit

Permalink
remove udeps + exclude changelog from triggering release prs (#161)
Browse files Browse the repository at this point in the history
* remove udeps + exclude changelog from triggering release prs

* lints
  • Loading branch information
0xJepsen authored Sep 25, 2024
1 parent 58d32e3 commit 6271931
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 0 additions & 17 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
56 changes: 28 additions & 28 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
12 changes: 6 additions & 6 deletions .taplo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions src/encryption/symmetric/modes/gcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ where [(); C::BLOCK_SIZE - 4]:
counter.increment()?;

// Step 2: Encrypt the plaintext using the `CTR` object.
let ctr = CTR::<C, 4>::new(new_nonce.try_into().unwrap());
let ctr = CTR::<C, 4>::new(new_nonce.into());
let ciphertext = ctr.encrypt(&self.key, &counter, plaintext)?;

// Step3: Generate Tag
Expand Down Expand Up @@ -198,7 +198,7 @@ where [(); C::BLOCK_SIZE - 4]:
counter.increment()?;

// Step 3: Decrypt ciphertext.
let ctr = CTR::<C, 4>::new(new_nonce.try_into().unwrap());
let ctr = CTR::<C, 4>::new(new_nonce.into());
let plaintext = ctr.decrypt(&self.key, &counter, ciphertext)?;

Ok((plaintext.to_vec(), tag))
Expand Down
18 changes: 9 additions & 9 deletions src/hashes/ghash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ impl From<GCMField> for Vec<u8> {
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;
}
}
Expand Down Expand Up @@ -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::<Monomial, AESField, 128>::from(x_coeffs);
let poly_y = Polynomial::<Monomial, AESField, 128>::from(y_coeffs);
let poly_f =
Expand All @@ -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();
Expand All @@ -182,7 +182,7 @@ impl GHASH {
v = GCMField { coeffs: v1.try_into().unwrap() };

if v1_bit == AESField::ONE {
v = v + r;
v += r;
}
}

Expand Down Expand Up @@ -269,11 +269,11 @@ mod tests {

let zf = GHASH::poly_multiply(xf, yf);

let z_coeffs: Vec<u8> = zf.try_into().unwrap();
let z_coeffs: Vec<u8> = zf.into();
let z_hex = encode_hex(&z_coeffs);

let expected_zf = GHASH::poly_multiply_spec(xf, yf);
let expected_z_coeffs: Vec<u8> = expected_zf.try_into().unwrap();
let expected_z_coeffs: Vec<u8> = expected_zf.into();
let expected_z_hex = encode_hex(&expected_z_coeffs);

println!("Got: {z_hex}\nExp: {expected_z_hex}");
Expand Down
2 changes: 1 addition & 1 deletion src/hmac/bin/hmac_sha256_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
18 changes: 8 additions & 10 deletions src/multi_var_poly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ pub struct MultiVarPolynomial<F: FiniteField> {
fn generate_cartesian_product(l: Vec<usize>) -> Vec<Vec<usize>> {
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);
Expand Down Expand Up @@ -148,22 +148,20 @@ impl<F: FiniteField> MultiVarPolynomial<F> {
///
/// ## Returns:
/// - The result of evaluating the polynomial at the given point.
pub fn evaluation(&self, r: &Vec<F>) -> 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.
Expand All @@ -182,7 +180,7 @@ impl<F: FiniteField> MultiVarPolynomial<F> {
let cood_f: Vec<F> = cood.iter().map(|&x| F::from(x)).collect();
sum += self.evaluation(&cood_f);
}
return sum;
sum
}

/// Multiplies the polynomial by a scalar.
Expand Down
4 changes: 2 additions & 2 deletions src/multi_var_poly/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn test_multivar_polynomial_evaluation() {
let poly = MultiVarPolynomial::<PlutoBaseField>::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);
Expand All @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions src/sumcheck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<F: FiniteField> SumCheckProver<F> {
///
/// ## 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.
Expand Down Expand Up @@ -74,9 +74,9 @@ impl<F: FiniteField> SumCheckProver<F> {
.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()
}
}

Expand Down Expand Up @@ -113,7 +113,7 @@ impl<F: FiniteField> SumCheckProver<F> {
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;
}
Expand Down Expand Up @@ -170,8 +170,8 @@ impl<F: FiniteField> SumCheckVerifier<F> {
);
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!(
Expand All @@ -187,14 +187,14 @@ impl<F: FiniteField> SumCheckVerifier<F> {
// 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.
Expand Down Expand Up @@ -247,8 +247,8 @@ impl<F: FiniteField> SumCheck<F> {
///
/// ## Returns:
/// - A boolean indicating whether the evaluation matches the claim.
pub fn evaluation_oracle(&self, r: &Vec<F>, 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.
Expand Down

0 comments on commit 6271931

Please sign in to comment.