From d3a69078a9106bb7fb5266282bd3bb8882a832b1 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 17 Jun 2021 18:42:30 +0700 Subject: [PATCH 1/7] cargofmt the code --- src/lib.rs | 9 ++++++--- src/primitives/cl_dl_lcm.rs | 16 +++++++++------- src/primitives/cl_dl_public_setup.rs | 17 ++++++++++------- src/primitives/mod.rs | 23 +++++++++++++---------- src/primitives/poe.rs | 8 +++++--- src/primitives/polynomial_comm.rs | 16 +++++++++------- src/primitives/vdf.rs | 11 +++++++---- 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e7b3cb6..86ea2ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,13 +11,16 @@ extern crate serde_derive; extern crate curv; extern crate serde; extern crate serde_json; -use curv::arithmetic::traits::*; -use curv::BigInt; + use libc::c_char; + use std::ffi::CStr; use std::mem::swap; use std::ops::Neg; -use std::{str, ptr}; +use std::{ptr, str}; + +use curv::arithmetic::traits::*; +use curv::BigInt; pub mod primitives; diff --git a/src/primitives/cl_dl_lcm.rs b/src/primitives/cl_dl_lcm.rs index 8bcec52..c380a76 100644 --- a/src/primitives/cl_dl_lcm.rs +++ b/src/primitives/cl_dl_lcm.rs @@ -1,3 +1,12 @@ +use std::os::raw::c_int; + +use curv::arithmetic::traits::*; +use curv::cryptographic_primitives::hashing::hash_sha256::HSha256; +use curv::cryptographic_primitives::hashing::traits::Hash; +use curv::elliptic::curves::secp256_k1::{FE, GE}; +use curv::elliptic::curves::traits::{ECPoint, ECScalar}; +use curv::BigInt; + use super::ErrorReason; use crate::bn_to_gen; use crate::isprime; @@ -6,13 +15,6 @@ use crate::primitives::is_prime; use crate::primitives::numerical_log; use crate::primitives::prng; use crate::BinaryQF; -use curv::arithmetic::traits::*; -use curv::cryptographic_primitives::hashing::hash_sha256::HSha256; -use curv::cryptographic_primitives::hashing::traits::Hash; -use curv::elliptic::curves::secp256_k1::{FE, GE}; -use curv::elliptic::curves::traits::{ECPoint, ECScalar}; -use curv::BigInt; -use std::os::raw::c_int; const SECURITY_PARAMETER: usize = 128; const C: usize = 10; diff --git a/src/primitives/cl_dl_public_setup.rs b/src/primitives/cl_dl_public_setup.rs index e4d05ee..e0f9da4 100644 --- a/src/primitives/cl_dl_public_setup.rs +++ b/src/primitives/cl_dl_public_setup.rs @@ -15,6 +15,15 @@ //! element and the plaintext of a CL ciphertext in a CL-group with a public //! setup is given in https://eprint.iacr.org/2020/084.pdf (see section 5.2) +use std::os::raw::c_int; + +use curv::arithmetic::traits::*; +use curv::cryptographic_primitives::hashing::hash_sha256::HSha256; +use curv::cryptographic_primitives::hashing::traits::Hash; +use curv::elliptic::curves::secp256_k1::{FE, GE}; +use curv::elliptic::curves::traits::{ECPoint, ECScalar}; +use curv::BigInt; + use super::ErrorReason; use crate::bn_to_gen; use crate::isprime; @@ -23,13 +32,6 @@ use crate::primitives::is_prime; use crate::primitives::numerical_log; use crate::primitives::prng; use crate::BinaryQF; -use curv::arithmetic::traits::*; -use curv::cryptographic_primitives::hashing::hash_sha256::HSha256; -use curv::cryptographic_primitives::hashing::traits::Hash; -use curv::elliptic::curves::secp256_k1::{FE, GE}; -use curv::elliptic::curves::traits::{ECPoint, ECScalar}; -use curv::BigInt; -use std::os::raw::c_int; const SECURITY_PARAMETER: usize = 128; const C: usize = 10; @@ -518,6 +520,7 @@ mod test { use super::*; const seed: &'static str = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848"; + #[test] fn encrypt_and_decrypt() { let group = CLGroup::new_from_setup(&1600, &BigInt::from_str_radix(seed, 10).unwrap()); diff --git a/src/primitives/mod.rs b/src/primitives/mod.rs index 21734bd..795c4c7 100644 --- a/src/primitives/mod.rs +++ b/src/primitives/mod.rs @@ -1,19 +1,22 @@ -pub mod cl_dl_lcm; -pub mod cl_dl_public_setup; -pub mod poe; -pub mod polynomial_comm; -pub mod vdf; +use std::error::Error; +use std::fmt; +use std::ops::Shl; -use crate::curv::cryptographic_primitives::hashing::traits::Hash; -use crate::BinaryQF; use curv::arithmetic::traits::*; use curv::cryptographic_primitives::hashing::hash_sha256::HSha256; use curv::cryptographic_primitives::hashing::hmac_sha512::HMacSha512; use curv::cryptographic_primitives::hashing::traits::KeyedHash; use curv::BigInt; -use std::error::Error; -use std::fmt; -use std::ops::Shl; + +use crate::curv::cryptographic_primitives::hashing::traits::Hash; +use crate::BinaryQF; + +pub mod cl_dl_lcm; +pub mod cl_dl_public_setup; +pub mod poe; +pub mod polynomial_comm; +pub mod vdf; + #[derive(Debug, Clone, Copy)] pub struct ProofError; diff --git a/src/primitives/poe.rs b/src/primitives/poe.rs index 1ca5386..d04256d 100644 --- a/src/primitives/poe.rs +++ b/src/primitives/poe.rs @@ -1,9 +1,10 @@ +use curv::arithmetic::traits::*; +use curv::BigInt; + use super::ErrorReason; use crate::pari_init; use crate::primitives::hash_to_prime; use crate::BinaryQF; -use curv::arithmetic::traits::*; -use curv::BigInt; /// This is a proof of exponentiation as given in https://eprint.iacr.org/2019/1229.pdf section 3.4 /// The prover can efficiently convince a verifier that a large exponentiation @@ -52,10 +53,11 @@ impl PoEProof { #[cfg(test)] mod tests { + use curv::BigInt; + use super::PoEProof; use crate::curv::arithmetic::traits::*; use crate::primitives::cl_dl_lcm::HSMCL; - use curv::BigInt; #[test] fn test_poe_valid_proof() { diff --git a/src/primitives/polynomial_comm.rs b/src/primitives/polynomial_comm.rs index 42e6595..0693cff 100644 --- a/src/primitives/polynomial_comm.rs +++ b/src/primitives/polynomial_comm.rs @@ -1,9 +1,3 @@ -use super::ErrorReason; -use crate::pari_init; -use crate::primitives::is_prime; -use crate::primitives::poe::PoEProof; -use crate::ABDeltaTriple; -use crate::BinaryQF; use curv::arithmetic::traits::*; use curv::cryptographic_primitives::hashing::hash_sha256::HSha256; use curv::cryptographic_primitives::hashing::traits::Hash; @@ -11,6 +5,13 @@ use curv::elliptic::curves::secp256_k1::FE; use curv::elliptic::curves::traits::ECScalar; use curv::BigInt; +use super::ErrorReason; +use crate::pari_init; +use crate::primitives::is_prime; +use crate::primitives::poe::PoEProof; +use crate::ABDeltaTriple; +use crate::BinaryQF; + /// Polynomial commitment as given in the paper: Transparent SNARKs from DARK Compilers /// (https://eprint.iacr.org/2019/1229.pdf), subsection 4.2 and 4.3 /// The following algorithms are implemented: @@ -532,12 +533,13 @@ fn pick_random_element(disc: &BigInt) -> BinaryQF { #[cfg(test)] mod tests { - use super::PolyComm; use curv::arithmetic::traits::*; use curv::elliptic::curves::secp256_k1::FE; use curv::elliptic::curves::traits::ECScalar; use curv::BigInt; + use super::PolyComm; + #[test] fn test_commit_open() { // sample coef vector diff --git a/src/primitives/vdf.rs b/src/primitives/vdf.rs index 9d8c69b..b51dc4e 100644 --- a/src/primitives/vdf.rs +++ b/src/primitives/vdf.rs @@ -1,3 +1,6 @@ +use curv::arithmetic::traits::*; +use curv::BigInt; + use crate::pari_init; use crate::primitives::hash_to_prime; use crate::primitives::is_prime; @@ -5,8 +8,6 @@ use crate::primitives::prng; use crate::primitives::ErrorReason; use crate::ABDeltaTriple; use crate::BinaryQF; -use curv::arithmetic::traits::*; -use curv::BigInt; /// Wesolowski VDF, based on https://eprint.iacr.org/2018/712.pdf. /// Original paper: https://eprint.iacr.org/2018/623.pdf @@ -143,10 +144,12 @@ fn h_g(disc: &BigInt, x: &BigInt) -> (BigInt, BigInt) { #[cfg(test)] mod tests { + use std::time::Instant; + + use curv::BigInt; + use super::VDF; use crate::curv::arithmetic::traits::Samplable; - use curv::BigInt; - use std::time::Instant; #[test] fn test_vdf_valid_proof() { From aa7a61e849325d0d0418fb28bd3177d19edb00e0 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 17 Jun 2021 18:45:15 +0700 Subject: [PATCH 2/7] Remove unused constant --- src/lib.rs | 1 - src/primitives/cl_dl_public_setup.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 86ea2ac..8fb8cf3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] -#![allow(dead_code)] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/src/primitives/cl_dl_public_setup.rs b/src/primitives/cl_dl_public_setup.rs index e0f9da4..59a86cc 100644 --- a/src/primitives/cl_dl_public_setup.rs +++ b/src/primitives/cl_dl_public_setup.rs @@ -34,7 +34,6 @@ use crate::primitives::prng; use crate::BinaryQF; const SECURITY_PARAMETER: usize = 128; -const C: usize = 10; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CLGroup { From bd2fc82d100007a0b10f121054bedb6b79bab61d Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 17 Jun 2021 19:15:36 +0700 Subject: [PATCH 3/7] Fix clippy warnings --- src/lib.rs | 57 ++++++----------- src/primitives/cl_dl_lcm.rs | 48 +++++++-------- src/primitives/cl_dl_public_setup.rs | 42 ++++++------- src/primitives/mod.rs | 17 +++--- src/primitives/polynomial_comm.rs | 91 +++++++++++++--------------- src/primitives/vdf.rs | 38 ++++++------ 6 files changed, 128 insertions(+), 165 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8fb8cf3..16c259d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#![allow(clippy::upper_case_acronyms)] +#![allow(clippy::many_single_char_names)] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); @@ -84,32 +86,22 @@ impl BinaryQF { } pub fn is_reduced(&self) -> bool { - if self.is_normal() && self.a <= self.c && !(self.a == self.c && self.b < BigInt::zero()) { - return true; - } else { - return false; - } + self.is_normal() && self.a <= self.c && !(self.a == self.c && self.b < BigInt::zero()) } pub fn normalize(&self) -> Self { // assume delta<0 and a>0 let a_sub_b: BigInt = &self.a - &self.b; let s_f = a_sub_b.div_floor(&(BigInt::from(2) * &self.a)); - let binary_qf = BinaryQF { + BinaryQF { a: self.a.clone(), b: &self.b + BigInt::from(2) * &s_f * &self.a, c: &self.a * &s_f.pow(2) + &self.b * &s_f + &self.c, - }; - - binary_qf + } } pub fn is_normal(&self) -> bool { - if self.b <= self.a && self.b > -self.a.clone() { - return true; - } else { - return false; - } + self.b <= self.a && self.b > -self.a.clone() } pub fn primeform(quad_disc: &BigInt, q: &BigInt) -> Self { let quad_disc_gen = bn_to_gen(&quad_disc); @@ -120,8 +112,7 @@ impl BinaryQF { let bqf = BinaryQF::pari_qf_to_qf(pf); - let bqf_norm = bqf.normalize(); - bqf_norm + bqf.normalize() } pub fn compose(&self, qf2: &BinaryQF) -> Self { @@ -132,9 +123,7 @@ impl BinaryQF { let qf_pari_c = unsafe { qfbcompraw(qf_pari_a, qf_pari_b) }; - let qf_c = BinaryQF::pari_qf_to_qf(qf_pari_c); - - qf_c + BinaryQF::pari_qf_to_qf(qf_pari_c) } pub fn inverse(&self) -> Self { @@ -146,14 +135,11 @@ impl BinaryQF { } pub fn rho(&self) -> Self { - let qf_new = BinaryQF { + BinaryQF { a: self.c.clone(), b: self.b.clone().neg(), c: self.a.clone(), - }; - let h = qf_new.normalize(); - - h + } } pub fn reduce(&self) -> Self { @@ -175,8 +161,7 @@ impl BinaryQF { let pari_n = bn_to_gen(n); let pari_qf_exp = unsafe { nupow(pari_qf, pari_n, ptr::null_mut()) }; - let qf_exp = BinaryQF::pari_qf_to_qf(pari_qf_exp); - qf_exp + BinaryQF::pari_qf_to_qf(pari_qf_exp) } // gotoNonMax: outputs: f=phi_q^(-1)(F), a binary quadratic form of disc. delta*conductor^2 // f is non normalized @@ -192,8 +177,7 @@ impl BinaryQF { b: b_new, delta, }; - let qf = BinaryQF::binary_quadratic_form_disc(&abdelta); - qf + BinaryQF::binary_quadratic_form_disc(&abdelta) } // compute (p^(2),p,-)^k in class group of disc. delta @@ -203,7 +187,7 @@ impl BinaryQF { } let mut k_inv = BigInt::mod_inv(k, p).unwrap(); if k_inv.mod_floor(&BigInt::from(2)) == BigInt::zero() { - k_inv = k_inv - p; + k_inv -= p; }; let k_inv_p = k_inv * p; let abdelta = ABDeltaTriple { @@ -211,18 +195,16 @@ impl BinaryQF { b: k_inv_p, delta: delta.clone(), }; - let qf = BinaryQF::binary_quadratic_form_disc(&abdelta); - qf + BinaryQF::binary_quadratic_form_disc(&abdelta) } pub fn discrete_log_f(p: &BigInt, delta: &BigInt, c: &BinaryQF) -> BigInt { let principal_qf = BinaryQF::binary_quadratic_form_principal(delta); if c == &principal_qf { - return BigInt::zero(); + BigInt::zero() } else { let Lk = c.b.div_floor(p); - let Lk_inv = BigInt::mod_inv(&Lk, p).unwrap(); - return Lk_inv; + BigInt::mod_inv(&Lk, p).unwrap() } } @@ -231,9 +213,8 @@ impl BinaryQF { let a = bn_to_gen(&self.a); let b = bn_to_gen(&self.b); let c = bn_to_gen(&self.c); - let qf_pari = unsafe { qfi(a, b, c) }; // GEN qfi(GEN a, GEN b, GEN c) (assumes b^2 − 4ac < 0) - qf_pari + unsafe { qfi(a, b, c) } } // construct BinaryQF from pari GEN encoded qfb @@ -427,14 +408,14 @@ pub fn bn_to_gen(bn: &BigInt) -> GEN { let elem1 = mkintn(1i64, ints_vec[num_int_bound - i - 1]); let elem2 = shifti(gen, (size_int) as i64); gen = gadd(elem1, elem2); - i = i + 1 + i += 1 } if neg1 == -1 { gen = gneg(gen); } - return gen; + gen } } diff --git a/src/primitives/cl_dl_lcm.rs b/src/primitives/cl_dl_lcm.rs index c380a76..f12c910 100644 --- a/src/primitives/cl_dl_lcm.rs +++ b/src/primitives/cl_dl_lcm.rs @@ -106,7 +106,7 @@ impl HSMCL { qtilde = next_probable_prime(&r); } - assert!(&(BigInt::from(4) * q) < &qtilde); + assert!((BigInt::from(4) * q) < qtilde); let delta_k = -q * &qtilde; let delta_q = &delta_k * q.pow(2); @@ -166,7 +166,7 @@ impl HSMCL { qtilde = next_probable_prime(&r); } - assert!(&(BigInt::from(4) * q) < &qtilde); + assert!((BigInt::from(4) * q) < qtilde); let delta_k = -q * &qtilde; let delta_q = &delta_k * q.pow(2); @@ -195,7 +195,7 @@ impl HSMCL { } prime_forms_vec.push(BinaryQF::primeform(&delta_k, &r)); r = next_probable_small_prime(&r); - i = i + 1; + i += 1; } let mut rgoth = BinaryQF::binary_quadratic_form_principal(&delta_k); @@ -208,15 +208,15 @@ impl HSMCL { let mut prod_exponent = BigInt::one(); while i < prime_forms_vec.len() { // extract 15bits - rand_bits_i = prng(seed, i.clone(), 15); + rand_bits_i = prng(seed, i, 15); while rand_bits_i.gcd(&prod_exponent) != BigInt::one() { - rand_bits_i = rand_bits_i + 1; + rand_bits_i += 1; } rgoth = rgoth .compose(&prime_forms_vec[i].exp(&rand_bits_i)) .reduce(); - prod_exponent = prod_exponent * &rand_bits_i; - i = i + 1; + prod_exponent *= &rand_bits_i; + i += 1; } let rgoth_square = rgoth.compose(&rgoth).reduce(); @@ -255,7 +255,7 @@ impl HSMCL { } prime_forms_vec.push(BinaryQF::primeform(&pk.delta_k, &r)); r = next_probable_small_prime(&r); - i = i + 1; + i += 1; } let mut rgoth = BinaryQF::binary_quadratic_form_principal(&pk.delta_k); @@ -269,15 +269,15 @@ impl HSMCL { let mut prod_exponent = BigInt::one(); while i < prime_forms_vec.len() { // extract 15bits - rand_bits_i = prng(seed, i.clone(), 15); + rand_bits_i = prng(seed, i, 15); while rand_bits_i.gcd(&prod_exponent) != BigInt::one() { - rand_bits_i = rand_bits_i + 1; + rand_bits_i += 1; } rgoth = rgoth .compose(&prime_forms_vec[i].exp(&rand_bits_i)) .reduce(); - prod_exponent = prod_exponent * &rand_bits_i; - i = i + 1; + prod_exponent *= &rand_bits_i; + i += 1; } let rgoth_square = rgoth.compose(&rgoth).reduce(); @@ -329,21 +329,19 @@ impl HSMCL { //TODO: add unit test pub fn eval_scal(c: &Ciphertext, val: &BigInt) -> Ciphertext { unsafe { pari_init(10000000, 2) }; - let c_new = Ciphertext { + Ciphertext { c1: c.c1.exp(&val), c2: c.c2.exp(&val), - }; - c_new + } } //TODO: add unit test pub fn eval_sum(c1: &Ciphertext, c2: &Ciphertext) -> Ciphertext { unsafe { pari_init(10000000, 2) }; - let c_new = Ciphertext { + Ciphertext { c1: c1.c1.compose(&c2.c1).reduce(), c2: c1.c2.compose(&c2.c2).reduce(), - }; - c_new + } } } @@ -351,7 +349,7 @@ pub fn next_probable_prime(r: &BigInt) -> BigInt { let one = BigInt::from(1); let mut qtilde = r + &one; while !is_prime(&qtilde) { - qtilde = qtilde + &one; + qtilde += &one; } qtilde } @@ -364,7 +362,7 @@ pub fn next_probable_small_prime(r: &BigInt) -> BigInt { let mut qtilde_gen = bn_to_gen(&(r + &one)); unsafe { while isprime(qtilde_gen) as c_int != 1 { - qtilde = qtilde + &one; + qtilde += &one; qtilde_gen = bn_to_gen(&qtilde); } } @@ -458,11 +456,11 @@ impl CLDLProof { for i in 0..repeat { let k_slice_i = (k.clone() >> (i * C)) & ten.clone(); //length test u1: - if &self.u_vec[i].u1 > &sample_size || &self.u_vec[i].u1 < &BigInt::zero() { + if self.u_vec[i].u1 > sample_size || self.u_vec[i].u1 < BigInt::zero() { flag = false; } // length test u2: - if &self.u_vec[i].u2 > &FE::q() || &self.u_vec[i].u2 < &BigInt::zero() { + if self.u_vec[i].u2 > FE::q() || self.u_vec[i].u2 < BigInt::zero() { flag = false; } let c1k = self.ciphertext.c1.exp(&k_slice_i); @@ -474,9 +472,9 @@ impl CLDLProof { let k_slice_i_bias_fe: FE = ECScalar::from(&(k_slice_i.clone() + BigInt::one())); let g = GE::generator(); - let t2kq = (self.t_vec[i].T + self.q.clone() * k_slice_i_bias_fe) - .sub_point(&self.q.get_element()); - let u2p = &g * &ECScalar::from(&self.u_vec[i].u2); + let t2kq = + (self.t_vec[i].T + self.q * k_slice_i_bias_fe).sub_point(&self.q.get_element()); + let u2p = g * ::from(&self.u_vec[i].u2); if t2kq != u2p { flag = false; } diff --git a/src/primitives/cl_dl_public_setup.rs b/src/primitives/cl_dl_public_setup.rs index 59a86cc..64041fa 100644 --- a/src/primitives/cl_dl_public_setup.rs +++ b/src/primitives/cl_dl_public_setup.rs @@ -90,7 +90,7 @@ impl CLGroup { qtilde = next_probable_prime(&r); } - debug_assert!(&(BigInt::from(4) * q) < &qtilde); + debug_assert!((BigInt::from(4) * q) < qtilde); let delta_k = -q * &qtilde; let delta_q = &delta_k * q.pow(2); @@ -119,7 +119,7 @@ impl CLGroup { } prime_forms_vec.push(BinaryQF::primeform(&delta_k, &r)); r = next_probable_small_prime(&r); - i = i + 1; + i += 1; } let mut rgoth = BinaryQF::binary_quadratic_form_principal(&delta_k); @@ -132,15 +132,15 @@ impl CLGroup { let mut prod_exponent = BigInt::one(); while i < prime_forms_vec.len() { // extract 15bits - rand_bits_i = prng(seed, i.clone(), 15); + rand_bits_i = prng(seed, i, 15); while rand_bits_i.gcd(&prod_exponent) != BigInt::one() { - rand_bits_i = rand_bits_i + 1; + rand_bits_i += 1; } rgoth = rgoth .compose(&prime_forms_vec[i].exp(&rand_bits_i)) .reduce(); - prod_exponent = prod_exponent * &rand_bits_i; - i = i + 1; + prod_exponent *= &rand_bits_i; + i += 1; } let rgoth_square = rgoth.compose(&rgoth).reduce(); @@ -173,7 +173,7 @@ impl CLGroup { } prime_forms_vec.push(BinaryQF::primeform(&self.delta_k, &r)); r = next_probable_small_prime(&r); - i = i + 1; + i += 1; } let mut rgoth = BinaryQF::binary_quadratic_form_principal(&self.delta_k); @@ -187,15 +187,15 @@ impl CLGroup { let mut prod_exponent = BigInt::one(); while i < prime_forms_vec.len() { // extract 15bits - rand_bits_i = prng(seed, i.clone(), 15); + rand_bits_i = prng(seed, i, 15); while rand_bits_i.gcd(&prod_exponent) != BigInt::one() { - rand_bits_i = rand_bits_i + 1; + rand_bits_i += 1; } rgoth = rgoth .compose(&prime_forms_vec[i].exp(&rand_bits_i)) .reduce(); - prod_exponent = prod_exponent * &rand_bits_i; - i = i + 1; + prod_exponent *= &rand_bits_i; + i += 1; } let rgoth_square = rgoth.compose(&rgoth).reduce(); @@ -307,7 +307,7 @@ fn next_probable_prime(r: &BigInt) -> BigInt { let one = BigInt::from(1); let mut qtilde = r + &one; while !is_prime(&qtilde) { - qtilde = qtilde + &one; + qtilde += &one; } qtilde } @@ -320,7 +320,7 @@ fn next_probable_small_prime(r: &BigInt) -> BigInt { let mut qtilde_gen = bn_to_gen(&(r + &one)); unsafe { while isprime(qtilde_gen) as c_int != 1 { - qtilde = qtilde + &one; + qtilde += &one; qtilde_gen = bn_to_gen(&qtilde); } } @@ -446,11 +446,11 @@ impl CLDLProof { * (BigInt::from(2).pow(40) + BigInt::one()); //length test u1: - if &self.u1u2.u1 > &sample_size || &self.u1u2.u1 < &BigInt::zero() { + if self.u1u2.u1 > sample_size || self.u1u2.u1 < BigInt::zero() { flag = false; } // length test u2: - if &self.u1u2.u2 > &FE::q() || &self.u1u2.u2 < &BigInt::zero() { + if self.u1u2.u2 > FE::q() || self.u1u2.u2 < BigInt::zero() { flag = false; } @@ -464,7 +464,7 @@ impl CLDLProof { let k_bias_fe: FE = ECScalar::from(&(k.clone() + BigInt::one())); let g = GE::generator(); let t2kq = (self.t_triple.T + X * &k_bias_fe).sub_point(&X.get_element()); - let u2p = &g * &ECScalar::from(&self.u1u2.u2); + let u2p = g * ::from(&self.u1u2.u2); if t2kq != u2p { flag = false; } @@ -497,21 +497,19 @@ pub fn decrypt(group: &CLGroup, secret_key: &SK, c: &Ciphertext) -> FE { /// Multiplies the encrypted value by `val`. pub fn eval_scal(c: &Ciphertext, val: &BigInt) -> Ciphertext { unsafe { pari_init(10000000, 2) }; - let c_new = Ciphertext { + Ciphertext { c1: c.c1.exp(&val), c2: c.c2.exp(&val), - }; - c_new + } } /// Homomorphically adds two ciphertexts so that the resulting ciphertext is the sum of the two input ciphertexts pub fn eval_sum(c1: &Ciphertext, c2: &Ciphertext) -> Ciphertext { unsafe { pari_init(10000000, 2) }; - let c_new = Ciphertext { + Ciphertext { c1: c1.c1.compose(&c2.c1).reduce(), c2: c1.c2.compose(&c2.c2).reduce(), - }; - c_new + } } #[cfg(test)] diff --git a/src/primitives/mod.rs b/src/primitives/mod.rs index 795c4c7..ad996da 100644 --- a/src/primitives/mod.rs +++ b/src/primitives/mod.rs @@ -50,41 +50,40 @@ fn numerical_log(x: &BigInt) -> BigInt { let mut bi = x.sqrt(); let mut k = 0; while k < 1000 { - k = k + 1; + k += 1; aip1 = (&ai + &bi).div_floor(&two); bip1 = (ai * bi).sqrt(); ai = aip1; bi = bip1; } - let log = two * (x - 1).div_floor(&(ai + bi)); - log + two * (x - 1).div_floor(&(ai + bi)) } pub fn hash_to_prime(u: &BinaryQF, w: &BinaryQF) -> BigInt { let mut candidate = HSha256::create_hash(&[&u.a, &u.b, &u.c, &w.a, &w.b, &w.c]); if candidate.modulus(&BigInt::from(2)) == BigInt::zero() { - candidate = candidate + BigInt::one(); + candidate += BigInt::one(); } while !is_prime(&candidate) { - candidate = candidate + BigInt::from(2); + candidate += BigInt::from(2); } candidate } fn prng(seed: &BigInt, i: usize, bitlen: usize) -> BigInt { let i_bn = BigInt::from(i as i32); - let mut res = HMacSha512::create_hmac(&i_bn, &vec![seed]); + let mut res = HMacSha512::create_hmac(&i_bn, &[seed]); let mut tmp: BigInt = res.clone(); let mut res_bit_len = res.bit_length(); while res_bit_len < bitlen { - tmp = HMacSha512::create_hmac(&i_bn, &vec![&tmp]); - res = &res.shl(res_bit_len.clone()) + &tmp; + tmp = HMacSha512::create_hmac(&i_bn, &[&tmp]); + res = &res.shl(res_bit_len) + &tmp; res_bit_len = res.bit_length(); } // prune to get |res| = bitlen - res >> (res_bit_len - &bitlen) + res >> (res_bit_len - bitlen) } // Runs the following three tests on a given `candidate` to determine diff --git a/src/primitives/polynomial_comm.rs b/src/primitives/polynomial_comm.rs index 0693cff..6183f29 100644 --- a/src/primitives/polynomial_comm.rs +++ b/src/primitives/polynomial_comm.rs @@ -88,8 +88,8 @@ impl PolyComm { let coef_vec_int = (0..coef_vec.len()) .map(|i| { let mut coef_i_bn = coef_vec[i].to_big_int(); - if &coef_i_bn > &p_minus1_half { - coef_i_bn = coef_i_bn - &pp.p; + if coef_i_bn > p_minus1_half { + coef_i_bn -= &pp.p; } coef_i_bn }) @@ -111,8 +111,8 @@ impl PolyComm { let coef_vec_int = (0..coef_vec.len()) .map(|i| { let mut coef_i_bn = coef_vec[i].to_big_int(); - if &coef_i_bn > &p_minus1_half { - coef_i_bn = coef_i_bn - &pp.p; + if coef_i_bn > p_minus1_half { + coef_i_bn -= &pp.p; } coef_i_bn }) @@ -140,8 +140,7 @@ impl PolyComm { let mut coef_vec_rev = coef_vec_int.iter().rev(); let head = coef_vec_rev.next().unwrap(); let tail = coef_vec_rev; - let z = tail.fold(head.clone(), |acc, x| x + acc * q); - z + tail.fold(head.clone(), |acc, x| x + acc * q) } pub fn decode(p: &BigInt, q: &BigInt, y: &BigInt) -> Vec { @@ -150,8 +149,8 @@ impl PolyComm { let bits_in_y = BigInt::from(y.bit_length() as u32); let bits_in_q = BigInt::from(q.bit_length() as u32); let mut d: BigInt = one.clone(); - while &(&d * &bits_in_q) < &bits_in_y { - d = d + &one + while (&d * &bits_in_q) < bits_in_y { + d += &one } let mut coef_vec: Vec = Vec::new(); @@ -166,7 +165,7 @@ impl PolyComm { } else { s_0 = &s_0 + &p_half; } - q_k = q_k * q; + q_k *= q; let f_0: BigInt = s_0 - s_minus_1; @@ -179,17 +178,17 @@ impl PolyComm { let mut s_k_minus_1 = y.mod_floor(&q_k); if s_k_minus_1 > q_k.div_floor(&two) { s_k_minus_1 = &q_k - &s_k_minus_1; - case = case + 1; + case += 1; } else { - case = case + 10; + case += 10; } let q_k_plus_1 = &q_k * q; let mut s_k = y.mod_floor(&q_k_plus_1); - if &s_k > &(q_k_plus_1.div_floor(&two)) { + if s_k > q_k_plus_1.div_floor(&two) { s_k = &q_k_plus_1 - &s_k; - case = case + 100; + case += 100; } else { - case = case + 1000; + case += 1000; } let mut f_k: BigInt = (s_k - s_k_minus_1).div_floor(&q_k); @@ -203,9 +202,9 @@ impl PolyComm { coef_vec.push(ECScalar::from(&f_k)); q_k = q_k_plus_1; - d = d - &one; + d -= &one; } - return coef_vec; + coef_vec } pub fn eval_prove(&self, pp: &PP, z: &FE, y: &FE, coef_vec: &[FE]) -> NiEvalProof { @@ -218,8 +217,8 @@ impl PolyComm { let mut coef_vec_int = (0..coef_vec.len()) .map(|i| { let mut coef_i_bn = coef_vec[i].to_big_int(); - if &coef_i_bn > &p_minus1_half { - coef_i_bn = coef_i_bn - &pp.p; + if coef_i_bn > p_minus1_half { + coef_i_bn -= &pp.p; } coef_i_bn @@ -290,7 +289,7 @@ impl PolyComm { c_l_vec, c_r_vec, poe_proof_vec, - f_const: eval_proof.f_const.clone(), + f_const: eval_proof.f_const, d, b, }; @@ -300,8 +299,8 @@ impl PolyComm { //step 12 let d_prime = (d + 1) / 2 - 1; //step 13 - let f_l_coef = &mut coef_vec[0..d_prime + 1].to_vec().clone(); - let f_r_coef = &mut coef_vec[d_prime + 1..].to_vec().clone(); + let f_l_coef = &mut coef_vec[0..d_prime + 1].to_vec(); + let f_r_coef = &mut coef_vec[d_prime + 1..].to_vec(); //step 14 let mut f_l_coef_rev = f_l_coef.iter().rev(); @@ -330,7 +329,7 @@ impl PolyComm { let c_r = pp.g.exp(&f_r_q).reduce(); //step18 - let q_pow_d_prime_plus1 = pp.q.pow((d_prime.clone() + 1) as u32); + let q_pow_d_prime_plus1 = pp.q.pow((d_prime + 1) as u32); let c_l_inverse = c_l.inverse(); let c_over_c_l = c_l_inverse.compose(&c).reduce(); let poe_proof = PoEProof::prove(&q_pow_d_prime_plus1, &c_r, &c_over_c_l); @@ -340,7 +339,7 @@ impl PolyComm { let alpha = HSha256::create_hash(&[&y_l, &y_r]); let mut alpha = alpha.mod_floor(&pp.p); if alpha > (&pp.p - BigInt::one()).div_floor(&BigInt::from(2)) { - alpha = alpha - &pp.p; + alpha -= &pp.p; } //step 20 @@ -375,17 +374,16 @@ impl PolyComm { c_r_vec.extend_from_slice(&eval_proof.c_r_vec[..]); poe_proof_vec.extend_from_slice(&eval_proof.poe_proof_vec[..]); - let proof = NiEvalProof { + NiEvalProof { y_l_vec, y_r_vec, c_l_vec, c_r_vec, poe_proof_vec, - f_const: eval_proof.f_const.clone(), + f_const: eval_proof.f_const, d, b, - }; - return proof; + } } } @@ -396,16 +394,15 @@ impl NiEvalProof { let mut flag = true; if self.d == 0 { //step3 - let bound: u32 = - 2 * (BigInt::from(self.d.clone() as i32) + BigInt::one()).bit_length() as u32; + let bound: u32 = 2 * (BigInt::from(self.d as i32) + BigInt::one()).bit_length() as u32; let sig_p_d = pp.p.pow(bound); - if &(sig_p_d * &self.b) > &pp.q { + if (sig_p_d * &self.b) > pp.q { flag = false; } //step 4: - if &self.f_const.abs() > &self.b { + if self.f_const.abs() > self.b { flag = false; } // step 5: @@ -425,11 +422,11 @@ impl NiEvalProof { } } - if (self.d.clone() + 1) % 2 == 1 { - let d_prime = self.d.clone() + 1; + if (self.d + 1) % 2 == 1 { + let d_prime = self.d + 1; let c_prime = c.exp(&pp.q); let y_prime = y.mul(&z.get_element()); - let b_prime = &self.b * BigInt::from(self.d.clone() as u32); + let b_prime = &self.b * BigInt::from(self.d as u32); self.b = b_prime; self.d = d_prime; @@ -441,20 +438,17 @@ impl NiEvalProof { } } //step 12 - let d_prime = (self.d.clone() + 1) / 2 - 1; + let d_prime = (self.d + 1) / 2 - 1; // pop out y_l, y_r. let y_l = self.y_l_vec.remove(0); let y_r = self.y_r_vec.remove(0); //step 17 - let z_pow_d_prime_p1 = BigInt::mod_pow( - &z.to_big_int(), - &BigInt::from((d_prime.clone() + 1) as u32), - &pp.p, - ); + let z_pow_d_prime_p1 = + BigInt::mod_pow(&z.to_big_int(), &BigInt::from((d_prime + 1) as u32), &pp.p); let y_r_z_pow_d_prime_p1 = BigInt::mod_mul(&z_pow_d_prime_p1, &y_r, &pp.p); let y_l_y_r_z_pow_d_prime_p1 = BigInt::mod_add(&y_r_z_pow_d_prime_p1, &y_l, &pp.p); - if &y.to_big_int() != &y_l_y_r_z_pow_d_prime_p1 { + if y.to_big_int() != y_l_y_r_z_pow_d_prime_p1 { flag = false; } @@ -462,7 +456,7 @@ impl NiEvalProof { let poe_proof = self.poe_proof_vec.remove(0); let c_l = self.c_l_vec.remove(0); let c_r = self.c_r_vec.remove(0); - let q_pow_d_prime_plus1 = pp.q.pow((d_prime.clone() + 1) as u32); + let q_pow_d_prime_plus1 = pp.q.pow((d_prime + 1) as u32); let c_l_inverse = c_l.inverse(); let c_over_c_l = c_l_inverse.compose(&c).reduce(); @@ -482,7 +476,7 @@ impl NiEvalProof { let alpha = HSha256::create_hash(&[&y_l, &y_r]); let mut alpha = alpha.mod_floor(&pp.p); if alpha > (&pp.p - BigInt::one()).div_floor(&BigInt::from(2)) { - alpha = alpha - &pp.p; + alpha -= &pp.p; } //step 20 @@ -494,10 +488,10 @@ impl NiEvalProof { self.b = b_prime; self.d = d_prime; let res = self.eval_verify(c_prime, pp, z, &y_prime_fe); - if flag == true && res.is_ok() { - return Ok(()); + if flag && res.is_ok() { + Ok(()) } else { - return Err(ErrorReason::EvalError); + Err(ErrorReason::EvalError) } } } @@ -505,7 +499,6 @@ impl NiEvalProof { // helper function: generate random group element from disc (used in setup) // see protocol description in vdf h_g function fn pick_random_element(disc: &BigInt) -> BinaryQF { - let mut i = 0; let two = BigInt::from(2); let max = BigInt::from(20); let mut b = &two * BigInt::sample(disc.bit_length()) + BigInt::one(); @@ -517,7 +510,6 @@ fn pick_random_element(disc: &BigInt) -> BinaryQF { b = &two * BigInt::sample(disc.bit_length()) + BigInt::one(); b2_minus_disc = b.pow(2) - disc; u = b2_minus_disc.div_floor(&four); - i = i + 1; c = (&c.next_prime()).mod_floor(&max); } let a = u.div_floor(&c); @@ -527,8 +519,7 @@ fn pick_random_element(disc: &BigInt) -> BinaryQF { delta: disc.clone(), }; - let g = BinaryQF::binary_quadratic_form_disc(&a_b_delta).reduce(); - g + BinaryQF::binary_quadratic_form_disc(&a_b_delta).reduce() } #[cfg(test)] diff --git a/src/primitives/vdf.rs b/src/primitives/vdf.rs index b51dc4e..be5091a 100644 --- a/src/primitives/vdf.rs +++ b/src/primitives/vdf.rs @@ -24,8 +24,8 @@ impl VDF { pub fn setup(security_param: usize, x: &BigInt) -> ABDeltaTriple { let mut disc: BigInt; - disc = -BigInt::sample(security_param.clone()); // TODO: double check 1600 bits determinant should provide 120 bit security - // based on "Survey on IQ cryptography" 3.2 + disc = -BigInt::sample(security_param); // TODO: double check 1600 bits determinant should provide 120 bit security + // based on "Survey on IQ cryptography" 3.2 while disc.mod_floor(&BigInt::from(4)) != BigInt::one() || !is_prime(&(-&disc)) { disc = -BigInt::sample(security_param); } @@ -36,11 +36,7 @@ impl VDF { //first line: g <- H_G(x). We will use x to seed a prng and use the prng to choose random // a and b. let (a, b) = h_g(&disc, x); - ABDeltaTriple { - a, - b, - delta: disc.clone(), - } + ABDeltaTriple { a, b, delta: disc } } //algorithm 3 from https://eprint.iacr.org/2018/623.pdf @@ -55,7 +51,7 @@ impl VDF { while &i < t { y = y.compose(&y).reduce(); - i = i + BigInt::one(); + i += BigInt::one(); } let l = hash_to_prime(&g, &y); @@ -73,17 +69,16 @@ impl VDF { b = r2.div_floor(&l); r = r2.mod_floor(&l); pi = pi.exp(&two).compose(&g.exp(&b)).reduce(); - i = i + BigInt::one(); + i += BigInt::one(); } - let vdf = VDF { + VDF { x: x.clone(), y, pi, t: t.clone(), a_b_delta: a_b_delta.clone(), - }; - vdf + } } //algorithm 2 from https://eprint.iacr.org/2018/623.pdf @@ -95,9 +90,9 @@ impl VDF { let g = BinaryQF::binary_quadratic_form_disc(&self.a_b_delta).reduce(); // test that g,y are elements of the class : https://eprint.iacr.org/2018/712.pdf 2.1 line 0 - if &g.discriminant() != &self.a_b_delta.delta - || &self.y.discriminant() != &self.a_b_delta.delta - || &self.pi.discriminant() != &self.a_b_delta.delta + if g.discriminant() != self.a_b_delta.delta + || self.y.discriminant() != self.a_b_delta.delta + || self.pi.discriminant() != self.a_b_delta.delta { return Err(ErrorReason::VDFVerifyError); } @@ -106,9 +101,10 @@ impl VDF { let r = BigInt::mod_pow(&BigInt::from(2), &&self.t, &l); let pi_l_g_r = self.pi.exp(&l).compose(&g.exp(&r)).reduce(); - match pi_l_g_r == self.y { - true => return Ok(()), - false => return Err(ErrorReason::VDFVerifyError), + if pi_l_g_r == self.y { + Ok(()) + } else { + Err(ErrorReason::VDFVerifyError) } } } @@ -126,16 +122,16 @@ fn h_g(disc: &BigInt, x: &BigInt) -> (BigInt, BigInt) { let mut i = 0; let two = BigInt::from(2); let max = BigInt::from(20); - let mut b = &two * prng(&x, i.clone(), disc.bit_length()) + BigInt::one(); + let mut b = &two * prng(&x, i, disc.bit_length()) + BigInt::one(); let mut c = two.clone(); let mut b2_minus_disc: BigInt = b.pow(2) - disc; let four = BigInt::from(4); let mut u = b2_minus_disc.div_floor(&four); while u.mod_floor(&c) != BigInt::zero() { - b = &two * prng(&x, i.clone(), disc.bit_length()) + BigInt::one(); + b = &two * prng(&x, i, disc.bit_length()) + BigInt::one(); b2_minus_disc = b.pow(2) - disc; u = b2_minus_disc.div_floor(&four); - i = i + 1; + i += 1; c = (&c.next_prime()).mod_floor(&max); } let a = u.div_floor(&c); From 2a10ea8705f4082944328847d2cd178c6f6ceb96 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 17 Jun 2021 19:18:21 +0700 Subject: [PATCH 4/7] Remove `extern crate` statements --- Cargo.toml | 3 +-- src/lib.rs | 11 +++-------- src/primitives/cl_dl_lcm.rs | 2 ++ src/primitives/cl_dl_public_setup.rs | 2 ++ src/primitives/mod.rs | 2 +- src/primitives/poe.rs | 4 +++- src/primitives/vdf.rs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b55e0e6..9768960 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,7 @@ bindgen = "0.50" [dependencies] libc = "0.2.0" -serde = "1.0" -serde_derive = "1.0" +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" ring-algorithm = "0.2.3" num-traits = "0.2" diff --git a/src/lib.rs b/src/lib.rs index 16c259d..5931754 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,13 +6,6 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); -extern crate libc; -#[macro_use] -extern crate serde_derive; -extern crate curv; -extern crate serde; -extern crate serde_json; - use libc::c_char; use std::ffi::CStr; @@ -20,6 +13,8 @@ use std::mem::swap; use std::ops::Neg; use std::{ptr, str}; +use serde::{Deserialize, Serialize}; + use curv::arithmetic::traits::*; use curv::BigInt; @@ -436,7 +431,7 @@ mod tests { use proptest::prelude::*; use super::*; - use crate::curv::arithmetic::traits::Samplable; + use curv::arithmetic::traits::Samplable; #[test] fn test_qf_to_pari_qf_to_qf() { diff --git a/src/primitives/cl_dl_lcm.rs b/src/primitives/cl_dl_lcm.rs index f12c910..8ab484d 100644 --- a/src/primitives/cl_dl_lcm.rs +++ b/src/primitives/cl_dl_lcm.rs @@ -1,5 +1,7 @@ use std::os::raw::c_int; +use serde::{Deserialize, Serialize}; + use curv::arithmetic::traits::*; use curv::cryptographic_primitives::hashing::hash_sha256::HSha256; use curv::cryptographic_primitives::hashing::traits::Hash; diff --git a/src/primitives/cl_dl_public_setup.rs b/src/primitives/cl_dl_public_setup.rs index 64041fa..a8a7654 100644 --- a/src/primitives/cl_dl_public_setup.rs +++ b/src/primitives/cl_dl_public_setup.rs @@ -17,6 +17,8 @@ use std::os::raw::c_int; +use serde::{Deserialize, Serialize}; + use curv::arithmetic::traits::*; use curv::cryptographic_primitives::hashing::hash_sha256::HSha256; use curv::cryptographic_primitives::hashing::traits::Hash; diff --git a/src/primitives/mod.rs b/src/primitives/mod.rs index ad996da..a3fd171 100644 --- a/src/primitives/mod.rs +++ b/src/primitives/mod.rs @@ -8,8 +8,8 @@ use curv::cryptographic_primitives::hashing::hmac_sha512::HMacSha512; use curv::cryptographic_primitives::hashing::traits::KeyedHash; use curv::BigInt; -use crate::curv::cryptographic_primitives::hashing::traits::Hash; use crate::BinaryQF; +use curv::cryptographic_primitives::hashing::traits::Hash; pub mod cl_dl_lcm; pub mod cl_dl_public_setup; diff --git a/src/primitives/poe.rs b/src/primitives/poe.rs index d04256d..897cd64 100644 --- a/src/primitives/poe.rs +++ b/src/primitives/poe.rs @@ -1,3 +1,5 @@ +use serde::{Deserialize, Serialize}; + use curv::arithmetic::traits::*; use curv::BigInt; @@ -56,8 +58,8 @@ mod tests { use curv::BigInt; use super::PoEProof; - use crate::curv::arithmetic::traits::*; use crate::primitives::cl_dl_lcm::HSMCL; + use curv::arithmetic::traits::*; #[test] fn test_poe_valid_proof() { diff --git a/src/primitives/vdf.rs b/src/primitives/vdf.rs index be5091a..4c25d4c 100644 --- a/src/primitives/vdf.rs +++ b/src/primitives/vdf.rs @@ -145,7 +145,7 @@ mod tests { use curv::BigInt; use super::VDF; - use crate::curv::arithmetic::traits::Samplable; + use curv::arithmetic::traits::Samplable; #[test] fn test_vdf_valid_proof() { From cc2a0c3dee8598f0effc7d099e0ff3d0821902a3 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 17 Jun 2021 19:30:28 +0700 Subject: [PATCH 5/7] Bump version, update Cargo.toml --- Cargo.toml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9768960..56d3a77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,17 @@ [package] name = "class_group" -version = "0.5.2" -authors = ["omershlo "] +version = "0.5.3" edition = "2018" +description = "Rust library for building IQC: cryptography based on class groups (Cl) of imaginary quadratic orders" +license = "GPL-3.0-or-later" +repository = "https://github.com/ZenGo-X/class" +categories = ["cryptography", "algorithms", "api-bindings"] +keywords = ["IQC", "class-group", "imaginary", "cryptoagorithms"] + +authors = ["omershlo "] links = "libpari" build = "build.rs" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + [build-dependencies] bindgen = "0.50" From c3cea1b88cd7ee77b557a1dcc7cac923609e7174 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 17 Jun 2021 19:32:49 +0700 Subject: [PATCH 6/7] Add travis configuration --- .travis.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..24c6993 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,21 @@ +language: rust +cache: cargo +rust: stable +virt: lxd + +before_install: + - rustup component add rustfmt clippy + +script: + - cargo build --verbose + - cargo test --verbose -- --test-threads=1 + - cargo fmt --all -- --check + - cargo clippy -- -D clippy::all + +deploy: + provider: cargo + token: + secure: "Qdd5mNWfpwnuFPt46TJcYkhYdA+bO4WX1+noiwRhRVim8Q04RU+DMVTxe5bysImV/u3n1u3M66gKUuVtaifn/MqCQOj72MHJGxU3a0muNXXFVaN9EzJehGxWj6Ps81jV8XXGbap8+0DCXxXLBC/f92Rnoyna3/+/GK5eUGInVkidkT2GLyxNiQMGFy2HeZywES9/oRHQTmoUX7sW1JizJbx2O0Ibf4B50lEdsHAsfb1zCP8eR1qe6oJUSfARFaFq85y0Vp88CDnBTJcNR+ACCZweN0NsWiyKcGe2+IRKnX/rFGdiemoVg20mw+D4Iyu61Pi4ZBGFenEL3NEbrFff9jsulEX1CDdHRrvk1xBlLJqgJ8biH2vVL9ALxl6doGOYN3tfa94xgS7Y3akr+BVFmZ0ofPOq3rNhINgyKnF9qUglx+LCcLDiG+UjtBUn+TCsTKdqhyu067oozs1sv9cCpFuzARJSTE1Noy3YqZe7T4rJWCyiq1K451IYVj4gcb4DNn8x/ypoSK+bzRG6fiuO2uBJqrVKJVJx5/+gXFNFT1OLEdGGOyboNlrL/SEoqVA6lL0H4qmVgfwf5qbNJsojj0UW5ipxZyvg6CldNNYhuVfCgij17JbqaQY4knbkkpqSB3p6E6zkMzw3Qcn6TqpV4S1dzmZclUmwZxK95eTC/dU=" + on: + tags: true + condition: "$TRAVIS_TAG =~ ^v[0-9.]+$" From 2cb07ed7f0fcc21d89173672947b38b140733ac8 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 18 Jun 2021 18:13:13 +0700 Subject: [PATCH 7/7] Fix rho --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 5931754..1c5e5aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -135,6 +135,7 @@ impl BinaryQF { b: self.b.clone().neg(), c: self.a.clone(), } + .normalize() } pub fn reduce(&self) -> Self {