Skip to content

Commit

Permalink
Upgrade to rust 1.65 & secp256k1 v0.24.1 (#234)
Browse files Browse the repository at this point in the history
* chore: upgrade to Rust 1.65

* chore: upgrade secp256k1 to 0.24.1

Fix: rust-bitcoin/rust-secp256k1#491

* chore: run clippy
  • Loading branch information
huitseeker committed Nov 16, 2022
1 parent 7a248d1 commit e6d5338
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 152 deletions.
359 changes: 226 additions & 133 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions fastcrypto-zkp/src/verifier.rs
Expand Up @@ -68,9 +68,9 @@ const G1_IDENTITY: blst_p1 = blst_p1 {

/// Returns the log base 2 of b in O(lg(N)) time.
fn log_2_byte(b: u8) -> usize {
let mut r = if b > 0xF { 1 } else { 0 } << 2;
let mut r = u8::from(b > 0xF) << 2;
let mut b = b >> r;
let shift = if b > 0x3 { 1 } else { 0 } << 1;
let shift = u8::from(b > 0x3) << 1;
b >>= shift + 1;
r |= shift | b;
r.into()
Expand Down Expand Up @@ -138,7 +138,7 @@ fn g1_linear_combination(
} else {
let mut scratch: Vec<u8>;
unsafe {
scratch = vec![0u8; blst_p1s_mult_pippenger_scratch_sizeof(len) as usize];
scratch = vec![0u8; blst_p1s_mult_pippenger_scratch_sizeof(len)];
}

let mut scalars = vec![blst_scalar::default(); len];
Expand Down
2 changes: 1 addition & 1 deletion fastcrypto/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ eyre = "0.6.8"
hex = "0.4.3"
hkdf = { version = "0.12.3", features = ["std"] }
rand = { version = "0.8.5", features = ["std"] }
rust_secp256k1 = { version = "0.24.0", package = "secp256k1", features = ["recovery", "rand-std", "bitcoin_hashes", "global-context"] }
rust_secp256k1 = { version = "0.24.1", package = "secp256k1", features = ["recovery", "rand-std", "bitcoin_hashes", "global-context"] }
serde = { version = "1.0.147", features = ["derive"] }
serde_bytes = "0.11.7"
serde_with = "2.0.1"
Expand Down
6 changes: 3 additions & 3 deletions fastcrypto/src/ed25519.rs
Expand Up @@ -131,7 +131,7 @@ impl VerifyingKey for Ed25519PublicKey {
batch.queue((vk_bytes, sigs[i].sig, msg))
}
batch
.verify(&mut OsRng)
.verify(OsRng)
.map_err(|_| eyre!("Signature verification failed"))
}

Expand Down Expand Up @@ -159,7 +159,7 @@ impl VerifyingKey for Ed25519PublicKey {
batch.queue((vk_bytes, sigs[i].sig, msgs[i].borrow()))
}
batch
.verify(&mut OsRng)
.verify(OsRng)
.map_err(|_| eyre!("Signature verification failed"))
}
}
Expand Down Expand Up @@ -448,7 +448,7 @@ impl Display for Ed25519AggregateSignature {
"{:?}",
self.sigs
.iter()
.map(|x| Base64::encode(&x.to_bytes()))
.map(|x| Base64::encode(x.to_bytes()))
.collect::<Vec<_>>()
)
}
Expand Down
4 changes: 2 additions & 2 deletions fastcrypto/src/hash.rs
Expand Up @@ -52,7 +52,7 @@ impl<const DIGEST_LEN: usize> Digest<DIGEST_LEN> {

impl<const DIGEST_LEN: usize> fmt::Debug for Digest<DIGEST_LEN> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "{}", Base64::encode(&self.digest))
write!(f, "{}", Base64::encode(self.digest))
}
}

Expand All @@ -61,7 +61,7 @@ impl<const DIGEST_LEN: usize> fmt::Display for Digest<DIGEST_LEN> {
write!(
f,
"{}",
Base64::encode(&self.digest).get(0..DIGEST_LEN).unwrap()
Base64::encode(self.digest).get(0..DIGEST_LEN).unwrap()
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion fastcrypto/src/pubkey_bytes.rs
Expand Up @@ -30,7 +30,7 @@ where

impl<T, const N: usize> Display for PublicKeyBytes<T, N> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
let s = hex::encode(&self.bytes);
let s = hex::encode(self.bytes);
write!(f, "k#{}", s)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion fastcrypto/src/tests/ed25519_tests.rs
Expand Up @@ -98,7 +98,7 @@ fn test_serde_signatures_human_readable() {
assert_eq!(
format!(
r#"{{"base64":"{}"}}"#,
Base64::encode(&signature.sig.to_bytes())
Base64::encode(signature.sig.to_bytes())
),
serialized
);
Expand Down
2 changes: 1 addition & 1 deletion fastcrypto/src/tests/encoding_tests.rs
Expand Up @@ -19,7 +19,7 @@ fn test_hex_decode_err() {

#[test]
fn test_hex_encode_format() {
assert_eq!(encode_with_format(&[1]), "0x01");
assert_eq!(encode_with_format([1]), "0x01");
assert_eq!(encode_with_format(Hex::decode("0x01").unwrap()), "0x01");
}

Expand Down
12 changes: 6 additions & 6 deletions fastcrypto/src/tests/hash_tests.rs
Expand Up @@ -10,7 +10,7 @@ use crate::hash::{
fn test_sha256() {
let data =
hex::decode("301d56460954541aab6dd7ddc0dd08f8cb3ebd884784a0e797905107533cae62").unwrap();
let digest = Sha256::digest(&data);
let digest = Sha256::digest(data);
assert_eq!(
digest.as_ref(),
hex::decode("2196d60feda3cd3787885c10a905e11fae911c32a0eb67fd290ade5df7eab140").unwrap()
Expand All @@ -21,7 +21,7 @@ fn test_sha256() {
fn test_sha3_256() {
let data =
hex::decode("301d56460954541aab6dd7ddc0dd08f8cb3ebd884784a0e797905107533cae62").unwrap();
let digest = Sha3_256::digest(&data);
let digest = Sha3_256::digest(data);
assert_eq!(
digest.as_ref(),
hex::decode("8fa965f6b63464045e1a8a80e3175fec4e5468d2904f6d7338cf83a65528a8f5").unwrap()
Expand All @@ -32,7 +32,7 @@ fn test_sha3_256() {
fn test_sha512() {
let data =
hex::decode("301d56460954541aab6dd7ddc0dd08f8cb3ebd884784a0e797905107533cae62").unwrap();
let digest = Sha512::digest(&data);
let digest = Sha512::digest(data);
assert_eq!(
digest.as_ref(),
hex::decode("cbd83ff929e1b4a72e144b5533e59edba3a90f761e188bd809f994137d67ecd8b87e4c250d461f7f4c64c22f10e9f5c598849f2685f5b828b501e38d2b252d12").unwrap()
Expand All @@ -43,7 +43,7 @@ fn test_sha512() {
fn test_keccak_256() {
let data =
hex::decode("301d56460954541aab6dd7ddc0dd08f8cb3ebd884784a0e797905107533cae62").unwrap();
let digest = Keccak256::digest(&data);
let digest = Keccak256::digest(data);
assert_eq!(
digest.as_ref(),
hex::decode("efecd3c9e52abd231ce0ce9548f0f9083fe040b291de26a3baa698956a847156").unwrap()
Expand All @@ -54,7 +54,7 @@ fn test_keccak_256() {
fn test_blake2b_256() {
let data =
hex::decode("301d56460954541aab6dd7ddc0dd08f8cb3ebd884784a0e797905107533cae62").unwrap();
let digest = Blake2b256::digest(&data);
let digest = Blake2b256::digest(data);
assert_eq!(
digest.as_ref(),
hex::decode("cc4e83cd4f030b0aabe27cf65a3ff92d0b5445f6466282e6b83a529b66094ebb").unwrap()
Expand All @@ -65,7 +65,7 @@ fn test_blake2b_256() {
fn test_blake3() {
let data =
hex::decode("301d56460954541aab6dd7ddc0dd08f8cb3ebd884784a0e797905107533cae62").unwrap();
let digest = Blake3::digest(&data);
let digest = Blake3::digest(data);
assert_eq!(
digest.as_ref(),
hex::decode("1b6d57a5017077b00cc9ce0641fb8ddcc136fbdb83325b31597fbe9441d9b269").unwrap()
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
@@ -1 +1 @@
1.64.0
1.65.0

0 comments on commit e6d5338

Please sign in to comment.