diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3c1a47f9..0c14e3ec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,5 @@ name: Tests - on: push: branches: @@ -9,11 +8,10 @@ on: # Make sure CI fails on all warnings, including Clippy lints env: - RUSTFLAGS: "-Dwarnings" - RUSTDOCFLAGS: "-Dwarnings" + RUSTFLAGS: "-Dwarnings" + RUSTDOCFLAGS: "-Dwarnings" jobs: - fmt: name: Rustfmt runs-on: ubuntu-latest @@ -38,11 +36,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@1.63.0 + - uses: dtolnay/rust-toolchain@1.85.0 - uses: Swatinem/rust-cache@v2 - - run: | - cargo update -p proptest --precise "1.2.0" - cargo update -p tempfile --precise "3.3.0" - run: cargo tree --all-features # to debug deps issues - run: cargo build --release --all-features @@ -66,9 +61,9 @@ jobs: - name: test-on-target uses: actions-rs/cargo@v1 with: - use-cross: ${{ matrix.target != 'x86_64-unknown-linux-gnu' }} + use-cross: ${{ matrix.target != 'x86_64-unknown-linux-gnu' }} command: test - args: --all-features --release --target ${{ matrix.target }} + args: --all-features --release --target ${{ matrix.target }} # test nightly build/test test-nightly: @@ -84,31 +79,29 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - package: [ "secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun" ] + package: ["secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun"] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.0.0 - run: cargo test --release --no-default-features -p ${{ matrix.package }} - # test with alloc feature only test-alloc: runs-on: ubuntu-latest strategy: matrix: - package: [ "secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun" ] + package: ["secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun"] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2.0.0 - run: cargo test --release --no-default-features --features alloc -p ${{ matrix.package }} - doc-build: - name: doc-build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - run: cargo doc --no-deps --workspace --all-features + name: doc-build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo doc --no-deps --workspace --all-features diff --git a/CHANGELOG.md b/CHANGELOG.md index c8c88c49..d22c87ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## Unreleased + +- Upgrade to bincode v2 +- MSRV 1.63 -> 1.85 + ## v0.11.0 - Added `prelude` module for convenient importing diff --git a/Cargo.toml b/Cargo.toml index 1a3bdb11..557f9e2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ members = [ "arithmetic_macros" ] resolver = "2" + +[workspace.dependencies] +bincode = { version = "2", default-features = false, features = ["derive"] } diff --git a/arithmetic_macros/Cargo.toml b/arithmetic_macros/Cargo.toml index 10f5f70d..8bd22567 100644 --- a/arithmetic_macros/Cargo.toml +++ b/arithmetic_macros/Cargo.toml @@ -7,7 +7,7 @@ license = "0BSD" homepage = "https://github.com/LLFourn/secp256kfun/tree/master/ecdsa_fun" repository = "https://github.com/LLFourn/secp256kfun" readme = "README.md" -edition = "2021" +edition = "2024" [lib] proc-macro = true diff --git a/arithmetic_macros/src/optree.rs b/arithmetic_macros/src/optree.rs index ec952486..9dd647b1 100644 --- a/arithmetic_macros/src/optree.rs +++ b/arithmetic_macros/src/optree.rs @@ -1,7 +1,7 @@ #![allow(unused)] use super::Input; -use proc_macro2::{token_stream, Delimiter, Punct, Span, TokenStream, TokenTree}; -use quote::{quote_spanned, ToTokens}; +use proc_macro2::{Delimiter, Punct, Span, TokenStream, TokenTree, token_stream}; +use quote::{ToTokens, quote_spanned}; use std::{fmt::Display, iter::Peekable}; #[derive(Clone)] @@ -39,7 +39,7 @@ impl core::fmt::Debug for OpTree { .debug_tuple(&unary.kind.to_string()) .field(&unary.subj) .finish(), - Self::LitInt(arg0) => write!(f, "{}", arg0), + Self::LitInt(arg0) => write!(f, "{arg0}"), } } } @@ -80,13 +80,17 @@ impl InfixKind { impl core::fmt::Display for InfixKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", match self { - InfixKind::Add => "+", - InfixKind::Mul => "*", - InfixKind::Sub => "-", - InfixKind::LinComb => ".*", - InfixKind::Div => "/", - }) + write!( + f, + "{}", + match self { + InfixKind::Add => "+", + InfixKind::Mul => "*", + InfixKind::Sub => "-", + InfixKind::LinComb => ".*", + InfixKind::Div => "/", + } + ) } } @@ -105,10 +109,14 @@ pub enum UnaryKind { impl core::fmt::Display for UnaryKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", match self { - UnaryKind::Neg => "-", - UnaryKind::Ref => "&", - }) + write!( + f, + "{}", + match self { + UnaryKind::Neg => "-", + UnaryKind::Ref => "&", + } + ) } } @@ -155,7 +163,7 @@ fn rule_term(input: &mut Input) -> Result { return Err(Error { span: group.span(), problem: "can only use '(..)' or '{..}'".into(), - }) + }); } } } @@ -171,7 +179,7 @@ fn rule_term(input: &mut Input) -> Result { return Err(Error { span: tt.span(), problem: "this is an invalid term".into(), - }) + }); } }; diff --git a/ecdsa_fun/Cargo.toml b/ecdsa_fun/Cargo.toml index c0c1b601..72826e4e 100644 --- a/ecdsa_fun/Cargo.toml +++ b/ecdsa_fun/Cargo.toml @@ -2,8 +2,8 @@ name = "ecdsa_fun" version = "0.11.0" authors = ["LLFourn "] -edition = "2021" -rust-version = "1.63" +edition = "2024" +rust-version = "1.85.0" license = "0BSD" homepage = "https://github.com/LLFourn/secp256kfun/tree/master/ecdsa_fun" repository = "https://github.com/LLFourn/secp256kfun" @@ -17,7 +17,7 @@ keywords = ["bitcoin", "ecdsa", "secp256k1"] secp256kfun = { path = "../secp256kfun", version = "0.11", default-features = false } sigma_fun = { path = "../sigma_fun", version = "0.8", features = ["secp256k1"], default-features = false, optional = true } rand_chacha = { version = "0.3", optional = true } # needed for adaptor signatures atm but would be nice to get rid of -bincode = { version = "1.0", optional = true } +bincode = { workspace = true, optional = true } [dev-dependencies] rand = "0.8" @@ -42,8 +42,8 @@ libsecp_compat_0_30 = ["secp256kfun/libsecp_compat_0_30"] std = ["alloc"] alloc = ["secp256kfun/alloc", "sigma_fun?/alloc" ] serde = ["secp256kfun/serde","sigma_fun?/serde"] -adaptor = ["dep:sigma_fun", "dep:bincode", "dep:rand_chacha"] -bincode = [ "secp256kfun/bincode", "dep:bincode" ] +adaptor = ["dep:sigma_fun", "bincode", "dep:rand_chacha"] +bincode = [ "secp256kfun/bincode", "dep:bincode", "sigma_fun?/bincode" ] proptest = ["secp256kfun/proptest"] diff --git a/ecdsa_fun/benches/bench_ecdsa.rs b/ecdsa_fun/benches/bench_ecdsa.rs index 371042a1..771d75a0 100644 --- a/ecdsa_fun/benches/bench_ecdsa.rs +++ b/ecdsa_fun/benches/bench_ecdsa.rs @@ -1,5 +1,5 @@ -use criterion::{criterion_group, criterion_main, Criterion}; -use secp256kfun::{nonce::Deterministic, secp256k1, Scalar}; +use criterion::{Criterion, criterion_group, criterion_main}; +use secp256kfun::{Scalar, nonce::Deterministic, secp256k1}; use sha2::Sha256; const MESSAGE: &[u8; 32] = b"hello world you are beautiful!!!"; @@ -49,7 +49,7 @@ fn verify_ecdsa(c: &mut Criterion) { } { - use secp256k1::{ecdsa::Signature, Message, PublicKey, Secp256k1, SecretKey}; + use secp256k1::{Message, PublicKey, Secp256k1, SecretKey, ecdsa::Signature}; let secp = Secp256k1::new(); let sig = Signature::from_compact(signature.to_bytes().as_ref()).unwrap(); let secret_key = SecretKey::from_slice(&SK.to_bytes()[..]).unwrap(); diff --git a/ecdsa_fun/src/adaptor/encrypted_signature.rs b/ecdsa_fun/src/adaptor/encrypted_signature.rs index 14cfd7f5..79d3a0fa 100644 --- a/ecdsa_fun/src/adaptor/encrypted_signature.rs +++ b/ecdsa_fun/src/adaptor/encrypted_signature.rs @@ -1,5 +1,5 @@ use super::DLEQ; -use crate::fun::{marker::*, Point, Scalar}; +use crate::fun::{Point, Scalar, marker::*}; use sigma_fun::CompactProof; /// `PointNonce` is a [`NonZero`] Point that also has an x-coordinate that is NonZero @@ -29,7 +29,7 @@ secp256kfun::impl_display_debug_serialize! { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, bincode::Encode, bincode::Decode)] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -52,20 +52,19 @@ pub(crate) struct EncryptedSignatureInternal { #[derive(Clone, PartialEq)] pub struct EncryptedSignature(pub(crate) EncryptedSignatureInternal); -#[cfg(feature = "serde")] secp256kfun::impl_display_debug_serialize! { fn to_bytes(es: &EncryptedSignature) -> [u8;162] { let mut bytes = [0u8;162]; - bytes.copy_from_slice(bincode::serialize(&es.0).unwrap().as_slice()); + let size = bincode::encode_into_slice(&es.0, &mut bytes[..], bincode::config::legacy()).expect("infallible"); + assert_eq!(size, 162); bytes } } -#[cfg(feature = "serde")] secp256kfun::impl_fromstr_deserialize! { name => "ECDSA adaptor signature", fn from_bytes(bytes: [u8;162]) -> Option { - bincode::deserialize(&bytes[..]).ok().map(EncryptedSignature) + bincode::decode_from_slice(&bytes[..], bincode::config::legacy()).ok().map(|(v,_)| EncryptedSignature(v)) } } @@ -104,10 +103,18 @@ mod test { &encryption_key, b"hello world you are beautiful!!!", ); - let serialized = bincode::serialize(&encrypted_signature).unwrap(); + let serialized = bincode::encode_to_vec( + bincode::serde::Compat(&encrypted_signature), + bincode::config::standard(), + ) + .unwrap(); assert_eq!(serialized.len(), 33 + 33 + 32 + 64); - let deseriazed = bincode::deserialize::(&serialized[..]).unwrap(); + let (deseriazed, _) = bincode::decode_from_slice::< + bincode::serde::Compat, + _, + >(&serialized[..], bincode::config::standard()) + .unwrap(); - assert_eq!(deseriazed, encrypted_signature); + assert_eq!(deseriazed.0, encrypted_signature); } } diff --git a/ecdsa_fun/src/adaptor/mod.rs b/ecdsa_fun/src/adaptor/mod.rs index 06727eb2..68515301 100644 --- a/ecdsa_fun/src/adaptor/mod.rs +++ b/ecdsa_fun/src/adaptor/mod.rs @@ -14,10 +14,11 @@ //! use ecdsa_fun::{ //! adaptor::{Adaptor, EncryptedSignature, HashTranscript}, //! fun::{ +//! G, Scalar, //! digest::{Digest, Update}, //! g, //! marker::*, -//! nonce, Scalar, G, +//! nonce, //! }, //! }; //! use rand::rngs::ThreadRng; @@ -63,17 +64,17 @@ //! None => panic!("signature is not the decryption of our original encrypted signature"), //! } //! ``` -use crate::{Signature, ECDSA}; +use crate::{ECDSA, Signature}; use secp256kfun::{ - derive_nonce_rng, + G, Point, Scalar, Tag, derive_nonce_rng, digest::generic_array::typenum::U32, g, marker::*, nonce::{NoNonces, NonceGen}, - s, Point, Scalar, Tag, G, + s, }; pub use sigma_fun::HashTranscript; -use sigma_fun::{secp256k1, Eq, FiatShamir, ProverTranscript, Transcript}; +use sigma_fun::{Eq, FiatShamir, ProverTranscript, Transcript, secp256k1}; mod encrypted_signature; pub use encrypted_signature::*; @@ -326,9 +327,11 @@ mod test { )); let signature = ecdsa_adaptor.decrypt_signature(&decryption_key, ciphertext.clone()); - assert!(ecdsa_adaptor - .ecdsa - .verify(&verification_key, msg, &signature)); + assert!( + ecdsa_adaptor + .ecdsa + .verify(&verification_key, msg, &signature) + ); let recoverd_decryption_sk = ecdsa_adaptor .recover_decryption_key(&encryption_key, &signature, &ciphertext) diff --git a/ecdsa_fun/src/lib.rs b/ecdsa_fun/src/lib.rs index d8df6a97..27105928 100755 --- a/ecdsa_fun/src/lib.rs +++ b/ecdsa_fun/src/lib.rs @@ -14,7 +14,7 @@ mod libsecp_compat; use fun::Tag; -use fun::{derive_nonce, g, marker::*, nonce::NonceGen, s, Point, Scalar, G}; +use fun::{G, Point, Scalar, derive_nonce, g, marker::*, nonce::NonceGen, s}; pub use secp256kfun as fun; pub use secp256kfun::nonce; mod signature; @@ -54,7 +54,7 @@ impl ECDSA { /// /// # Example /// ``` - /// use ecdsa_fun::{nonce, ECDSA}; + /// use ecdsa_fun::{ECDSA, nonce}; /// use rand::rngs::ThreadRng; /// use sha2::Sha256; /// let nonce_gen = nonce::Synthetic::>::default(); @@ -94,7 +94,7 @@ impl ECDSA { /// /// # Example /// ``` - /// use ecdsa_fun::{fun::Scalar, ECDSA}; + /// use ecdsa_fun::{ECDSA, fun::Scalar}; /// let ecdsa = ECDSA::verify_only(); /// let secret_key = Scalar::random(&mut rand::thread_rng()); /// let verification_key = ecdsa.verification_key_for(&secret_key); @@ -121,7 +121,7 @@ impl ECDSA { g!((s_inv * m) * G + (s_inv * R_x) * verification_key) .non_zero() - .map_or(false, |implied_R| implied_R.x_eq_scalar(R_x)) + .is_some_and(|implied_R| implied_R.x_eq_scalar(R_x)) } } @@ -132,8 +132,9 @@ impl ECDSA { /// /// ``` /// use ecdsa_fun::{ + /// ECDSA, /// fun::{digest::Digest, prelude::*}, - /// nonce, ECDSA, + /// nonce, /// }; /// use rand::rngs::ThreadRng; /// use sha2::Sha256; diff --git a/ecdsa_fun/src/libsecp_compat.rs b/ecdsa_fun/src/libsecp_compat.rs index d27046d6..8b1ac7c5 100644 --- a/ecdsa_fun/src/libsecp_compat.rs +++ b/ecdsa_fun/src/libsecp_compat.rs @@ -1,6 +1,6 @@ #[cfg(feature = "libsecp_compat_0_27")] mod v0_27 { - use crate::{fun::secp256k1_0_27::ecdsa, Signature}; + use crate::{Signature, fun::secp256k1_0_27::ecdsa}; impl From for ecdsa::Signature { fn from(sig: Signature) -> Self { @@ -17,7 +17,7 @@ mod v0_27 { #[cfg(feature = "libsecp_compat_0_28")] mod v0_28 { - use crate::{fun::secp256k1_0_28::ecdsa, Signature}; + use crate::{Signature, fun::secp256k1_0_28::ecdsa}; impl From for ecdsa::Signature { fn from(sig: Signature) -> Self { @@ -34,7 +34,7 @@ mod v0_28 { #[cfg(feature = "libsecp_compat_0_29")] mod v0_29 { - use crate::{fun::secp256k1_0_29::ecdsa, Signature}; + use crate::{Signature, fun::secp256k1_0_29::ecdsa}; impl From for ecdsa::Signature { fn from(sig: Signature) -> Self { @@ -51,7 +51,7 @@ mod v0_29 { #[cfg(feature = "libsecp_compat_0_30")] mod v0_30 { - use crate::{fun::secp256k1_0_30::ecdsa, Signature}; + use crate::{Signature, fun::secp256k1_0_30::ecdsa}; impl From for ecdsa::Signature { fn from(sig: Signature) -> Self { diff --git a/ecdsa_fun/src/signature.rs b/ecdsa_fun/src/signature.rs index 4ea03924..78c9844f 100644 --- a/ecdsa_fun/src/signature.rs +++ b/ecdsa_fun/src/signature.rs @@ -1,4 +1,4 @@ -use secp256kfun::{marker::*, Scalar}; +use secp256kfun::{Scalar, marker::*}; /// An ECDSA signature #[derive(Clone, PartialEq)] pub struct Signature { diff --git a/ecdsa_fun/tests/adaptor_test_vectors.rs b/ecdsa_fun/tests/adaptor_test_vectors.rs index de42477f..13a6794d 100644 --- a/ecdsa_fun/tests/adaptor_test_vectors.rs +++ b/ecdsa_fun/tests/adaptor_test_vectors.rs @@ -2,10 +2,10 @@ static DLC_SPEC_JSON: &str = include_str!("./test_vectors.json"); use ecdsa_fun::{ + Signature, adaptor::{Adaptor, EncryptedSignature, HashTranscript}, - fun::{serde, Point, Scalar}, + fun::{Point, Scalar, serde}, nonce::NoNonces, - Signature, }; use sha2::Sha256; @@ -46,7 +46,7 @@ struct Serialization { } #[test] -fn run_test_vectors() { +fn run_ecdsa_adaptor_test_vectors() { let ecdsa_adaptor = Adaptor::, _>::verify_only(); let test_vectors = serde_json::from_str::>(DLC_SPEC_JSON).unwrap(); for t in test_vectors { diff --git a/ecdsa_fun/tests/against_c_lib.rs b/ecdsa_fun/tests/against_c_lib.rs index d8421ca7..a83638cc 100644 --- a/ecdsa_fun/tests/against_c_lib.rs +++ b/ecdsa_fun/tests/against_c_lib.rs @@ -1,8 +1,7 @@ #![cfg(feature = "libsecp_compat")] use ecdsa_fun::fun::{ - hex, - secp256k1::{self, ecdsa, Message, PublicKey, SecretKey}, - Point, Scalar, + Point, Scalar, hex, + secp256k1::{self, Message, PublicKey, SecretKey, ecdsa}, }; const TEST_SOUNDNESS: usize = 20; @@ -27,9 +26,10 @@ fn ecdsa_sign() { let signature = ecdsa.sign(&secret_key, &message); let c_message = Message::from_digest_slice(&message[..]).unwrap(); let c_siganture = ecdsa::Signature::from_compact(&signature.to_bytes()).unwrap(); - assert!(secp - .verify_ecdsa(&c_message, &c_siganture, &c_public_key) - .is_ok()); + assert!( + secp.verify_ecdsa(&c_message, &c_siganture, &c_public_key) + .is_ok() + ); } } @@ -85,7 +85,8 @@ fn ecdsa_sign_high_message() { let signature = ecdsa.sign(&secret_key, &message); let c_message = Message::from_digest_slice(&message[..]).unwrap(); let c_siganture = ecdsa::Signature::from_compact(&signature.to_bytes()).unwrap(); - assert!(secp - .verify_ecdsa(&c_message, &c_siganture, &c_public_key) - .is_ok()); + assert!( + secp.verify_ecdsa(&c_message, &c_siganture, &c_public_key) + .is_ok() + ); } diff --git a/rustfmt.toml b/rustfmt.toml index e4700023..30305d90 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,7 +1,3 @@ -edition = "2021" -condense_wildcard_suffixes = true -format_macro_matchers = true -imports_granularity="Crate" +edition = "2024" use_field_init_shorthand = true format_code_in_doc_comments = true -overflow_delimited_expr = true diff --git a/schnorr_fun/Cargo.toml b/schnorr_fun/Cargo.toml index 4b240aa0..f7afbc8b 100644 --- a/schnorr_fun/Cargo.toml +++ b/schnorr_fun/Cargo.toml @@ -3,8 +3,8 @@ name = "schnorr_fun" version = "0.11.0" authors = ["LLFourn "] -edition = "2021" -rust-version = "1.63" +edition = "2024" +rust-version = "1.85.0" license = "0BSD" homepage = "https://github.com/LLFourn/secp256kfun/tree/master/schnorr_fun" repository = "https://github.com/LLFourn/secp256kfun" @@ -16,12 +16,12 @@ keywords = ["bitcoin", "schnorr"] [dependencies] secp256kfun = { path = "../secp256kfun", version = "0.11", default-features = false } bech32 = { version = "0.11", optional = true, default-features = false, features = ["alloc"] } +bincode = { workspace = true, optional = true } [dev-dependencies] secp256kfun = { path = "../secp256kfun", version = "0.11", features = ["proptest", "bincode", "alloc"] } rand = { version = "0.8" } lazy_static = "1.4" -bincode = "1.0" sha2 = "0.10" serde_json = "1" rand_chacha = { version = "0.3" } @@ -40,7 +40,7 @@ required-features = ["libsecp_compat"] default = ["std"] alloc = ["secp256kfun/alloc" ] std = ["alloc", "secp256kfun/std"] -bincode = ["secp256kfun/bincode"] +bincode = [ "dep:bincode", "secp256kfun/bincode"] serde = ["secp256kfun/serde"] libsecp_compat = ["libsecp_compat_0_30", "secp256kfun/libsecp_compat"] libsecp_compat_0_27 = ["secp256kfun/libsecp_compat_0_27"] diff --git a/schnorr_fun/benches/bench_schnorr.rs b/schnorr_fun/benches/bench_schnorr.rs index 9e34100b..5b96af02 100755 --- a/schnorr_fun/benches/bench_schnorr.rs +++ b/schnorr_fun/benches/bench_schnorr.rs @@ -1,9 +1,9 @@ //! This broken and just as a reference until we get proper bip340 benchmarks from proper rust lib #![allow(non_upper_case_globals)] -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{Criterion, criterion_group, criterion_main}; use schnorr_fun::{ - fun::{marker::*, nonce, secp256k1, Scalar}, Message, Schnorr, + fun::{Scalar, marker::*, nonce, secp256k1}, }; use sha2::Sha256; diff --git a/schnorr_fun/src/adaptor/encrypted_signature.rs b/schnorr_fun/src/adaptor/encrypted_signature.rs index 46e03b6d..d3f3474c 100644 --- a/schnorr_fun/src/adaptor/encrypted_signature.rs +++ b/schnorr_fun/src/adaptor/encrypted_signature.rs @@ -1,4 +1,4 @@ -use secp256kfun::{marker::*, Point, Scalar}; +use secp256kfun::{Point, Scalar, marker::*}; /// A one-time encrypted Schnorr signature or "adaptor signature". /// @@ -10,11 +10,7 @@ use secp256kfun::{marker::*, Point, Scalar}; derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), serde(crate = "crate::fun::serde") )] -#[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") -)] +#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] pub struct EncryptedSignature { /// The `R` point in the signature @@ -47,7 +43,7 @@ mod test { #[test] fn encrypted_signature_serialization_roundtrip() { use super::*; - use crate::{adaptor::*, fun::Scalar, Message}; + use crate::{Message, adaptor::*, fun::Scalar}; let schnorr = crate::new_with_deterministic_nonces::(); let kp = schnorr.new_keypair(Scalar::random(&mut rand::thread_rng())); let encryption_key = Point::random(&mut rand::thread_rng()); @@ -56,9 +52,18 @@ mod test { &encryption_key, Message::::plain("test", b"foo"), ); - let serialized = bincode::serialize(&encrypted_signature).unwrap(); + let serialized = bincode::encode_to_vec( + bincode::serde::Compat(&encrypted_signature), + bincode::config::standard(), + ) + .unwrap(); assert_eq!(serialized.len(), 65); - let deserialized = bincode::deserialize::(&serialized).unwrap(); - assert_eq!(encrypted_signature, deserialized); + let deserialized = bincode::decode_from_slice::< + bincode::serde::Compat, + _, + >(&serialized, bincode::config::standard()) + .unwrap() + .0; + assert_eq!(encrypted_signature, deserialized.0); } } diff --git a/schnorr_fun/src/adaptor/mod.rs b/schnorr_fun/src/adaptor/mod.rs index 560ac281..521c0926 100644 --- a/schnorr_fun/src/adaptor/mod.rs +++ b/schnorr_fun/src/adaptor/mod.rs @@ -12,9 +12,9 @@ //! ``` //! use rand::rngs::ThreadRng; //! use schnorr_fun::{ -//! adaptor::{Adaptor, EncryptedSign}, -//! fun::{marker::*, nonce, Scalar}, //! Message, Schnorr, +//! adaptor::{Adaptor, EncryptedSign}, +//! fun::{Scalar, marker::*, nonce}, //! }; //! use sha2::Sha256; //! let nonce_gen = nonce::Synthetic::>::default(); @@ -48,8 +48,8 @@ //! } //! ``` use crate::{ - fun::{derive_nonce, nonce, prelude::*, KeyPair}, Message, Schnorr, Signature, + fun::{KeyPair, derive_nonce, nonce, prelude::*}, }; mod encrypted_signature; pub use encrypted_signature::EncryptedSignature; @@ -191,7 +191,6 @@ where g!(decryption_key * G).normalize() } - #[must_use] fn verify_encrypted_signature( &self, verification_key: &Point, diff --git a/schnorr_fun/src/binonce.rs b/schnorr_fun/src/binonce.rs index 8244ce55..5567c3b3 100644 --- a/schnorr_fun/src/binonce.rs +++ b/schnorr_fun/src/binonce.rs @@ -4,7 +4,7 @@ //! Your public nonces are derived from scalars which must be kept secret. //! Derived binonces should be unique and and must not be reused for signing under any circumstances //! as this can leak your secret key. -use secp256kfun::{g, hash::HashInto, marker::*, rand_core::RngCore, Point, Scalar, G}; +use secp256kfun::{G, Point, Scalar, g, hash::HashInto, marker::*, rand_core::RngCore}; /// A nonce (pair of points) that each party must share with the others in the first stage of signing. /// diff --git a/schnorr_fun/src/frost/chilldkg.rs b/schnorr_fun/src/frost/chilldkg.rs index 3d9bd433..e5e81167 100644 --- a/schnorr_fun/src/frost/chilldkg.rs +++ b/schnorr_fun/src/frost/chilldkg.rs @@ -33,17 +33,18 @@ //! - [`certpedpop`]: `encpedpop` where each party also certifies the output so they can cryptographically convince each other that the key generation was successful. //! //! [ChillDKG]: https://github.com/BlockstreamResearch/bip-frost-dkg -use crate::{frost::*, Schnorr}; +use crate::{Schnorr, frost::*}; use alloc::{ collections::{BTreeMap, BTreeSet}, vec::Vec, }; use secp256kfun::{ + KeyPair, hash::{Hash32, HashAdd}, nonce::NonceGen, poly, prelude::*, - rand_core, KeyPair, + rand_core, }; /// SimplePedPop is a bare bones secure distributed key generation algorithm that leaves a lot left @@ -68,11 +69,7 @@ pub mod simplepedpop { /// and if at least one of these parties is honest then the final secret key will not be known by an /// attacker (unless they obtain `t` shares!). #[derive(Clone, Debug, PartialEq)] - #[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") - )] + #[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -144,11 +141,7 @@ pub mod simplepedpop { /// Produced by [`Contributor::gen_keygen_input`]. This is sent from the each /// `Contributor` to the *coordinator*. - #[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") - )] + #[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -270,11 +263,7 @@ pub mod simplepedpop { /// Key generation inputs after being aggregated by the coordinator #[derive(Clone, Debug, PartialEq)] - #[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") - )] + #[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -445,11 +434,15 @@ pub mod simplepedpop { impl core::fmt::Display for ReceiveShareError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "{}", match self { - ReceiveShareError::InvalidPop => "Invalid POP for one of the contributions", - ReceiveShareError::InvalidSecretShare => - "The share extracted from the key generation was invalid", - }) + write!( + f, + "{}", + match self { + ReceiveShareError::InvalidPop => "Invalid POP for one of the contributions", + ReceiveShareError::InvalidSecretShare => + "The share extracted from the key generation was invalid", + } + ) } } } @@ -473,11 +466,7 @@ pub mod encpedpop { /// and if at least one of these parties is honest then the final secret key will not be known by an /// attacker (unless they obtain `t` shares!). #[derive(Clone, Debug, PartialEq)] - #[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") - )] + #[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -553,11 +542,7 @@ pub mod encpedpop { /// Key generation inputs after being aggregated by the coordinator #[derive(Clone, Debug, PartialEq)] - #[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") - )] + #[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -677,11 +662,7 @@ pub mod encpedpop { /// Produced by [`Contributor::gen_keygen_input`]. This is sent from the each /// `Contributor` to the *coordinator*. - #[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") - )] + #[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -1202,10 +1183,10 @@ pub mod certpedpop { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { CertificateError::InvalidCert { key } => { - write!(f, "certificate for key {} was invalid", key) + write!(f, "certificate for key {key} was invalid") } CertificateError::Missing { key } => { - write!(f, "certificate for key {} was missing", key) + write!(f, "certificate for key {key} was missing") } } } diff --git a/schnorr_fun/src/frost/mod.rs b/schnorr_fun/src/frost/mod.rs index ac9c5093..ad667ca6 100644 --- a/schnorr_fun/src/frost/mod.rs +++ b/schnorr_fun/src/frost/mod.rs @@ -96,17 +96,16 @@ mod session; pub use session::*; pub mod chilldkg; pub use crate::binonce::{Nonce, NonceKeyPair}; -use crate::{binonce, Message, Schnorr, Signature}; +use crate::{Message, Schnorr, Signature, binonce}; use alloc::collections::{BTreeMap, BTreeSet}; use core::num::NonZeroU32; use secp256kfun::{ - derive_nonce_rng, + KeyPair, derive_nonce_rng, hash::{Hash32, HashAdd, Tag}, nonce::{self, NonceGen}, poly, prelude::*, rand_core::{RngCore, SeedableRng}, - KeyPair, }; /// The index of a party's secret share. @@ -186,7 +185,7 @@ where /// # Examples /// /// ``` - /// use schnorr_fun::{frost::Frost, nonce::Deterministic, Schnorr}; + /// use schnorr_fun::{Schnorr, frost::Frost, nonce::Deterministic}; /// use sha2::Sha256; /// let schnorr = Schnorr::>::default(); /// let frost = Frost::new(schnorr); @@ -208,8 +207,7 @@ impl Frost { /// /// Parameters: /// - /// - `frost_key`: the joint public key we are signing under. This can be an `EvenY` or `Normal` - /// It will return the same nonce regardless. + /// - `frost_key`: the joint public key we are signing under. This can be an `EvenY` or `Normal` It will return the same nonce regardless. /// - `secret`: you're secret key share for the `frost_key` /// - `session_id`: a string of bytes that is **unique for each signing attempt**. /// diff --git a/schnorr_fun/src/frost/session.rs b/schnorr_fun/src/frost/session.rs index 40083ffc..9cdc1d45 100644 --- a/schnorr_fun/src/frost/session.rs +++ b/schnorr_fun/src/frost/session.rs @@ -1,7 +1,7 @@ use crate::{ + Signature, binonce::{self, SecretNonce}, frost::PartyIndex, - Signature, }; use alloc::collections::{BTreeMap, BTreeSet}; use secp256kfun::{poly, prelude::*}; @@ -13,11 +13,7 @@ use super::{PairedSecretShare, SharedKey, SignatureShare, VerificationShare}; /// /// [`coordinator_sign_session`]: super::Frost::coordinator_sign_session #[derive(Clone, Debug, PartialEq)] -#[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") -)] +#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -155,11 +151,7 @@ impl CoordinatorSignSession { /// /// [`party_sign_session`]: super::Frost::party_sign_session #[derive(Clone, Debug, PartialEq)] -#[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") -)] +#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] #[cfg_attr( feature = "serde", derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), @@ -249,7 +241,10 @@ impl core::fmt::Display for VerifySignatureSharesError { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match self { VerifySignatureSharesError::NotEnough { missing } => { - write!(f, "not enough signature shares have been collected to finish the signature. You need {missing} more.") + write!( + f, + "not enough signature shares have been collected to finish the signature. You need {missing} more." + ) } VerifySignatureSharesError::Invalid(invalid) => write!(f, "{invalid}"), } diff --git a/schnorr_fun/src/frost/share.rs b/schnorr_fun/src/frost/share.rs index 4d5a5d25..7e727de2 100644 --- a/schnorr_fun/src/frost/share.rs +++ b/schnorr_fun/src/frost/share.rs @@ -108,12 +108,11 @@ secp256kfun::impl_display_debug_serialize! { #[derive(Copy, Clone, Debug)] #[cfg_attr( feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), + derive(bincode::Encode, bincode::Decode), bincode( - crate = "crate::fun::bincode", - encode_bounds = "Point: crate::fun::bincode::Encode", - decode_bounds = "Point: crate::fun::bincode::Decode", - borrow_decode_bounds = "Point: crate::fun::bincode::BorrowDecode<'__de>" + encode_bounds = "Point: bincode::Encode", + decode_bounds = "Point: bincode::Decode<__Context>", + borrow_decode_bounds = "Point: bincode::BorrowDecode<'__de, __Context>" ) )] #[cfg_attr( @@ -299,7 +298,7 @@ pub struct VerificationShare { #[cfg(feature = "share_backup")] mod share_backup { use super::*; - use bech32::{primitives::decode::CheckedHrpstring, Bech32m, ByteIterExt, Fe32IterExt, Hrp}; + use bech32::{Bech32m, ByteIterExt, Fe32IterExt, Hrp, primitives::decode::CheckedHrpstring}; use core::{fmt, str::FromStr}; /// the threshold under which we encode the share index in the human readable section. @@ -323,7 +322,7 @@ mod share_backup { let mut u32_index_bytes = [0u8; 4]; u32_index_bytes.copy_from_slice(&bytes[28..]); let u32_index = u32::from_be_bytes(u32_index_bytes); - Hrp::parse(&format!("frost[{}]", u32_index)).unwrap() + Hrp::parse(&format!("frost[{u32_index}]")).unwrap() } else { share_index_bytes = Some( self.index @@ -344,7 +343,7 @@ mod share_backup { .chars(); for c in chars { - write!(f, "{}", c)?; + write!(f, "{c}")?; } Ok(()) } @@ -466,7 +465,7 @@ mod share_backup { mod test { use super::*; use crate::frost::SecretShare; - use secp256kfun::{proptest::prelude::*, Scalar}; + use secp256kfun::{Scalar, proptest::prelude::*}; proptest! { #[test] @@ -510,12 +509,11 @@ mod test { use crate::frost::{self, chilldkg::simplepedpop}; use alloc::vec::Vec; use secp256kfun::{ - g, + G, g, proptest::{ prelude::*, test_runner::{RngAlgorithm, TestRng}, }, - G, }; proptest! { #[test] diff --git a/schnorr_fun/src/frost/shared_key.rs b/schnorr_fun/src/frost/shared_key.rs index c610f33e..621a03e9 100644 --- a/schnorr_fun/src/frost/shared_key.rs +++ b/schnorr_fun/src/frost/shared_key.rs @@ -13,11 +13,7 @@ use secp256kfun::{poly, prelude::*}; derive(crate::fun::serde::Serialize), serde(crate = "crate::fun::serde") )] -#[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode), - bincode(crate = "crate::fun::bincode",) -)] +#[cfg_attr(feature = "bincode", derive(bincode::Encode))] pub struct SharedKey { /// The public point polynomial that defines the access structure to the FROST key. point_polynomial: Vec>, @@ -265,7 +261,7 @@ impl PartialEq> for SharedKey { } #[cfg(feature = "bincode")] -impl crate::fun::bincode::Decode for SharedKey { +impl bincode::Decode for SharedKey { fn decode( decoder: &mut D, ) -> Result { @@ -308,11 +304,11 @@ impl<'de, T: PointType, Z: ZeroChoice> crate::fun::serde::Deserialize<'de> for S } #[cfg(feature = "bincode")] -crate::fun::bincode::impl_borrow_decode!(SharedKey); +bincode::impl_borrow_decode!(SharedKey); #[cfg(feature = "bincode")] -crate::fun::bincode::impl_borrow_decode!(SharedKey); +bincode::impl_borrow_decode!(SharedKey); #[cfg(feature = "bincode")] -crate::fun::bincode::impl_borrow_decode!(SharedKey); +bincode::impl_borrow_decode!(SharedKey); #[cfg(test)] mod test { @@ -321,7 +317,6 @@ mod test { #[cfg(feature = "bincode")] #[test] fn bincode_encoding_decoding_roundtrip() { - use crate::fun::bincode; let poly_zero = SharedKey::::from_poly( poly::point::normalize(vec![ g!(0 * G), @@ -377,17 +372,21 @@ mod test { ) .unwrap(); - assert!(bincode::decode_from_slice::, _>( - &bytes_poly_zero, - bincode::config::standard(), - ) - .is_err()); + assert!( + bincode::decode_from_slice::, _>( + &bytes_poly_zero, + bincode::config::standard(), + ) + .is_err() + ); - assert!(bincode::decode_from_slice::, _>( - &bytes_poly_minus_one, - bincode::config::standard(), - ) - .is_err()); + assert!( + bincode::decode_from_slice::, _>( + &bytes_poly_minus_one, + bincode::config::standard(), + ) + .is_err() + ); assert_eq!(poly_zero_got, poly_zero); assert_eq!(poly_one_got, poly_one); diff --git a/schnorr_fun/src/message.rs b/schnorr_fun/src/message.rs index 375739fd..da6e6608 100644 --- a/schnorr_fun/src/message.rs +++ b/schnorr_fun/src/message.rs @@ -1,8 +1,8 @@ use secp256kfun::{ + Slice, digest::{self}, hash::HashInto, marker::*, - Slice, }; /// A message to be signed. diff --git a/schnorr_fun/src/musig.rs b/schnorr_fun/src/musig.rs index fca66a11..18d846ba 100644 --- a/schnorr_fun/src/musig.rs +++ b/schnorr_fun/src/musig.rs @@ -5,7 +5,7 @@ //! ``` //! # use schnorr_fun::binonce::NonceKeyPair; //! use rand_chacha::ChaCha20Rng; -//! use schnorr_fun::{musig, nonce::Deterministic, Message, Schnorr}; +//! use schnorr_fun::{Message, Schnorr, musig, nonce::Deterministic}; //! use sha2::Sha256; //! // use sha256 with deterministic nonce generation -- be careful! //! let musig = musig::new_with_deterministic_nonces::(); @@ -72,17 +72,17 @@ //! [the excellent paper]: https://eprint.iacr.org/2020/1261.pdf //! [secp256k1-zkp]: https://github.com/ElementsProject/secp256k1-zkp/pull/131 use crate::{ + Message, Schnorr, Signature, adaptor::EncryptedSignature, binonce::{self, SecretNonce}, - Message, Schnorr, Signature, }; use alloc::vec::Vec; use secp256kfun::{ + KeyPair, hash::{Hash32, HashAdd, Tag}, nonce::{self, NoNonces, NonceGen}, prelude::*, rand_core::{RngCore, SeedableRng}, - KeyPair, }; /// The MuSig context. @@ -276,10 +276,10 @@ impl MuSig { /// /// ``` /// use schnorr_fun::{ + /// Schnorr, /// fun::{Point, Scalar}, /// musig::MuSig, /// nonce::Deterministic, - /// Schnorr, /// }; /// # let my_secret_key = Scalar::random(&mut rand::thread_rng()); /// # let their_public_key = Point::random(&mut rand::thread_rng()); @@ -338,11 +338,10 @@ where /// /// Parameters: /// - /// - `agg_key`: the joint public key we are signing under. This can be an `XOnly` or `Normal`. - /// It will return the same nonce regardless. + /// - `agg_key`: the joint public key we are signing under. This can be an `XOnly` or `Normal`. It will return the same nonce regardless. /// - `secret`: you're secret key as part of `agg_key`. This **must be the secret key you are - /// going to sign with**. It cannot be an "untweaked" version of the signing key. It must be - /// exactly equal to the secret key you pass to [`sign`] (the MuSig specification requires this). + /// going to sign with**. It cannot be an "untweaked" version of the signing key. It must be + /// exactly equal to the secret key you pass to [`sign`] (the MuSig specification requires this). /// - `session_id`: a string of bytes that is **unique for each signing attempt**. /// /// The application should decide upon a unique `session_id` per call to this function. If the @@ -387,11 +386,7 @@ where derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), serde(crate = "crate::fun::serde") )] -#[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") -)] +#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] pub struct Ordinary; /// Marks the [`SignSession`] as being used to create an adaptor (a.k.a. one-time encrypted) @@ -402,11 +397,7 @@ pub struct Ordinary; derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), serde(crate = "crate::fun::serde") )] -#[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") -)] +#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] pub struct Adaptor { y_needs_negation: bool, } @@ -425,11 +416,7 @@ pub struct Adaptor { derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize), serde(crate = "crate::fun::serde") )] -#[cfg_attr( - feature = "bincode", - derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode), - bincode(crate = "crate::fun::bincode") -)] +#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))] pub struct SignSession { b: Scalar, c: Scalar, diff --git a/schnorr_fun/src/schnorr.rs b/schnorr_fun/src/schnorr.rs index df4a4583..0a43def7 100644 --- a/schnorr_fun/src/schnorr.rs +++ b/schnorr_fun/src/schnorr.rs @@ -1,14 +1,14 @@ use secp256kfun::{hash::Hash32, nonce::NoNonces}; use crate::{ + Message, Signature, fun::{ - derive_nonce, + KeyPair, derive_nonce, hash::{HashAdd, Tag}, nonce::{self, NonceGen}, prelude::*, - rand_core, KeyPair, + rand_core, }, - Message, Signature, }; /// An instance of a [BIP-340] style Schnorr signature scheme. @@ -18,7 +18,7 @@ use crate::{ /// - `nonce_gen`: The [`NonceGen`] used to hash the signing inputs (and perhaps additional randomness) to produce the secret nonce. /// /// [_Fiat-Shamir_]: https://en.wikipedia.org/wiki/Fiat%E2%80%93Shamir_heuristic -/// [`NonceGen`]: crate::fun::hash::NonceGen +/// [`NonceGen`]: crate::fun::nonce::NonceGen /// [BIP-340]: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki #[derive(Clone, Debug, PartialEq)] pub struct Schnorr { @@ -67,8 +67,8 @@ where /// ``` /// use rand::rngs::ThreadRng; /// use schnorr_fun::{ - /// nonce::{Deterministic, GlobalRng, Synthetic}, /// Schnorr, + /// nonce::{Deterministic, GlobalRng, Synthetic}, /// }; /// use sha2::Sha256; /// // Use synthetic nonces (preferred) @@ -96,7 +96,7 @@ where /// # Examples /// /// ``` - /// use schnorr_fun::{nonce::Deterministic, Schnorr}; + /// use schnorr_fun::{Schnorr, nonce::Deterministic}; /// use sha2::Sha256; /// /// let schnorr = Schnorr::>::default(); @@ -169,7 +169,7 @@ impl Schnorr { /// Here's how you could use this to roll your own signatures. /// /// ``` - /// use schnorr_fun::{fun::prelude::*, Message, Schnorr, Signature}; + /// use schnorr_fun::{Message, Schnorr, Signature, fun::prelude::*}; /// let schnorr = schnorr_fun::new_with_deterministic_nonces::(); /// let message = Message::::plain("my-app", b"we rolled our own schnorr!"); /// let keypair = schnorr.new_keypair(Scalar::random(&mut rand::thread_rng())); diff --git a/schnorr_fun/src/signature.rs b/schnorr_fun/src/signature.rs index 2a3872bc..3baec762 100644 --- a/schnorr_fun/src/signature.rs +++ b/schnorr_fun/src/signature.rs @@ -1,4 +1,4 @@ -use crate::fun::{marker::*, rand_core::RngCore, Point, Scalar}; +use crate::fun::{Point, Scalar, marker::*, rand_core::RngCore}; /// A Schnorr signature. #[derive(Clone, Eq, Copy)] @@ -52,7 +52,7 @@ impl Signature { /// /// # Examples /// ``` - /// use schnorr_fun::{fun::marker::*, Signature}; + /// use schnorr_fun::{Signature, fun::marker::*}; /// let signature = Signature::random(&mut rand::thread_rng()); /// let secret_sig = signature.set_secrecy::(); /// ``` @@ -129,13 +129,22 @@ mod test { #[test] fn signature_serialization_roundtrip() { use super::*; - use crate::{fun::Scalar, Message}; + use crate::{Message, fun::Scalar}; let schnorr = crate::new_with_deterministic_nonces::(); let kp = schnorr.new_keypair(Scalar::random(&mut rand::thread_rng())); let signature = schnorr.sign(&kp, Message::::plain("test", b"foo")); - let serialized = bincode::serialize(&signature).unwrap(); + let serialized = bincode::encode_to_vec( + bincode::serde::Compat(&signature), + bincode::config::standard(), + ) + .unwrap(); assert_eq!(serialized.len(), 64); - let deserialized = bincode::deserialize::(&serialized).unwrap(); - assert_eq!(signature, deserialized); + let deserialized = bincode::decode_from_slice::, _>( + &serialized, + bincode::config::standard(), + ) + .unwrap() + .0; + assert_eq!(signature, deserialized.0); } } diff --git a/schnorr_fun/tests/against_c_lib.rs b/schnorr_fun/tests/against_c_lib.rs index b483f888..d2d47755 100644 --- a/schnorr_fun/tests/against_c_lib.rs +++ b/schnorr_fun/tests/against_c_lib.rs @@ -1,8 +1,8 @@ #![cfg(all(feature = "libsecp_compat", feature = "proptest", feature = "alloc"))] use proptest::prelude::*; use schnorr_fun::{ - fun::{marker::*, proptest, secp256k1, Scalar}, Message, Schnorr, + fun::{Scalar, marker::*, proptest, secp256k1}, }; use secp256kfun::{ digest::Digest, diff --git a/schnorr_fun/tests/bip340.rs b/schnorr_fun/tests/bip340.rs index acc58fc4..fb9e5dd8 100644 --- a/schnorr_fun/tests/bip340.rs +++ b/schnorr_fun/tests/bip340.rs @@ -1,11 +1,11 @@ use schnorr_fun::{ + Message, Schnorr, Signature, fun::{ - hex, + Scalar, hex, marker::*, nonce::{NonceRng, Synthetic}, - rand_core, Scalar, + rand_core, }, - Message, Schnorr, Signature, }; use secp256kfun::Point; use sha2::Sha256; diff --git a/schnorr_fun/tests/frost_prop.rs b/schnorr_fun/tests/frost_prop.rs index ae4c74d7..9270bf4f 100644 --- a/schnorr_fun/tests/frost_prop.rs +++ b/schnorr_fun/tests/frost_prop.rs @@ -3,9 +3,9 @@ use chilldkg::encpedpop; use rand::seq::SliceRandom; use rand_chacha::ChaCha20Rng; use schnorr_fun::{ - frost::*, - fun::{marker::*, Scalar}, Message, + frost::*, + fun::{Scalar, marker::*}, }; use secp256kfun::proptest::{ arbitrary::any, diff --git a/schnorr_fun/tests/musig_keyagg.rs b/schnorr_fun/tests/musig_keyagg.rs index b4dfcd3c..1d66d96c 100644 --- a/schnorr_fun/tests/musig_keyagg.rs +++ b/schnorr_fun/tests/musig_keyagg.rs @@ -1,6 +1,6 @@ #![cfg(feature = "serde")] use schnorr_fun::{ - fun::{marker::*, serde, Point, Scalar}, + fun::{Point, Scalar, marker::*, serde}, musig, }; static TEST_JSON: &str = include_str!("musig/key_agg_vectors.json"); diff --git a/schnorr_fun/tests/musig_sign_verify.rs b/schnorr_fun/tests/musig_sign_verify.rs index ca074399..1387405f 100644 --- a/schnorr_fun/tests/musig_sign_verify.rs +++ b/schnorr_fun/tests/musig_sign_verify.rs @@ -1,8 +1,8 @@ #![cfg(feature = "serde")] use schnorr_fun::{ - binonce, - fun::{marker::*, serde, Point, Scalar}, - musig, Message, + Message, binonce, + fun::{Point, Scalar, marker::*, serde}, + musig, }; static TEST_JSON: &str = include_str!("musig/sign_verify_vectors.json"); use secp256kfun::hex; diff --git a/schnorr_fun/tests/musig_tweak.rs b/schnorr_fun/tests/musig_tweak.rs index 9793b5e4..fdb997bc 100644 --- a/schnorr_fun/tests/musig_tweak.rs +++ b/schnorr_fun/tests/musig_tweak.rs @@ -3,9 +3,10 @@ use std::{rc::Rc, sync::Arc}; use schnorr_fun::{ + Message, binonce::{self, NonceKeyPair}, - fun::{marker::*, serde, Point, Scalar}, - musig, Message, + fun::{Point, Scalar, marker::*, serde}, + musig, }; static TEST_JSON: &'static str = include_str!("musig/tweak_vectors.json"); use secp256kfun::hex; diff --git a/secp256kfun/Cargo.toml b/secp256kfun/Cargo.toml index 0bb5d9c7..27ddab13 100644 --- a/secp256kfun/Cargo.toml +++ b/secp256kfun/Cargo.toml @@ -7,8 +7,8 @@ homepage = "https://github.com/LLFourn/secp256kfun" repository = "https://github.com/LLFourn/secp256kfun" documentation = "https://docs.rs/secp256kfun" description = "A mid-level secp256k1 library optimized for fun!" -edition = "2021" -rust-version = "1.63" +edition = "2024" +rust-version = "1.85.0" categories = ["cryptography", "cryptography::cryptocurrencies"] readme = "README.md" keywords = ["bitcoin", "secp256k1"] @@ -23,7 +23,7 @@ secp256kfun_arithmetic_macros = { version = "0.1.0", path = "../arithmetic_macro # optional serde = { version = "1.0", optional = true, default-features = false, features = ["derive"] } proptest = { version = "1", optional = true } -bincode = { version = "2.0.0-rc.3", optional = true, default-features = false, features = ["derive"] } +bincode = { workspace = true, optional = true } secp256k1_0_27 = { package = "secp256k1", version = "0.27", optional = true, default-features = false } secp256k1_0_28 = { package = "secp256k1", version = "0.28", optional = true, default-features = false } @@ -36,7 +36,8 @@ serde_json = "1" rand = { version = "0.8" } lazy_static = "1.4" sha2 = "0.10" -proptest = "1" +# proptest 1.7 has a breaking change dep on new rand_core 🤦 +proptest = "=1.6" criterion = "0.4" [target.'cfg(target_arch = "wasm32")'.dev-dependencies] diff --git a/secp256kfun/README.md b/secp256kfun/README.md index 3e1c6572..89f7f432 100644 --- a/secp256kfun/README.md +++ b/secp256kfun/README.md @@ -174,7 +174,7 @@ assert_eq!(commitment, pedersen_commit(A, &B, &r, &x)); ## MSRV -Minimum supported rust version is `v1.63`. +Minimum supported rust version is `v1.85.0`. ## LICENSE diff --git a/secp256kfun/benches/bench_ecmult.rs b/secp256kfun/benches/bench_ecmult.rs index 9e6fd57e..6ad7f85a 100755 --- a/secp256kfun/benches/bench_ecmult.rs +++ b/secp256kfun/benches/bench_ecmult.rs @@ -1,6 +1,6 @@ #![allow(non_snake_case)] -use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; -use secp256kfun::{g, op, Point, Scalar, G}; +use criterion::{BatchSize, Criterion, criterion_group, criterion_main}; +use secp256kfun::{G, Point, Scalar, g, op}; fn scalar_mul_point(c: &mut Criterion) { let mut group = c.benchmark_group("ecmult"); diff --git a/secp256kfun/benches/bench_point.rs b/secp256kfun/benches/bench_point.rs index 838d3976..7d38bcef 100644 --- a/secp256kfun/benches/bench_point.rs +++ b/secp256kfun/benches/bench_point.rs @@ -1,6 +1,6 @@ #![allow(non_snake_case)] -use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; -use secp256kfun::{g, Point, Scalar, G}; +use criterion::{BatchSize, Criterion, criterion_group, criterion_main}; +use secp256kfun::{G, Point, Scalar, g}; fn point_add(c: &mut Criterion) { let mut group = c.benchmark_group("point_add"); diff --git a/secp256kfun/examples/quick_bip340.rs b/secp256kfun/examples/quick_bip340.rs index 74f77f03..ccb9360d 100755 --- a/secp256kfun/examples/quick_bip340.rs +++ b/secp256kfun/examples/quick_bip340.rs @@ -2,10 +2,10 @@ #![allow(non_snake_case)] use rand::thread_rng; use secp256kfun::{ - g, + G, Point, Scalar, g, hash::{HashAdd, Tag}, marker::*, - s, Point, Scalar, G, + s, }; use sha2::Sha256; diff --git a/secp256kfun/src/backend/k256_impl.rs b/secp256kfun/src/backend/k256_impl.rs index 697f9562..508e5708 100644 --- a/secp256kfun/src/backend/k256_impl.rs +++ b/secp256kfun/src/backend/k256_impl.rs @@ -1,7 +1,7 @@ pub use crate::vendor::k256::Scalar; use crate::{ backend::{BackendPoint, BackendScalar, TimeSensitive}, - vendor::k256::{mul, AffinePoint, FieldBytes, FieldElement, ProjectivePoint}, + vendor::k256::{AffinePoint, FieldBytes, FieldElement, ProjectivePoint, mul}, }; use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq}; diff --git a/secp256kfun/src/backend/mod.rs b/secp256kfun/src/backend/mod.rs index e803319e..3d6d3bb7 100644 --- a/secp256kfun/src/backend/mod.rs +++ b/secp256kfun/src/backend/mod.rs @@ -20,6 +20,7 @@ pub trait BackendPoint { fn norm_from_coordinates(x: [u8; 32], y: [u8; 32]) -> Option; } +#[allow(dead_code)] pub trait TimeSensitive { fn scalar_mul_norm_point(lhs: &Scalar, rhs: &Point) -> Point; fn scalar_mul_point(lhs: &Scalar, rhs: &Point) -> Point; diff --git a/secp256kfun/src/hash.rs b/secp256kfun/src/hash.rs index 7c3904a9..b564af1e 100644 --- a/secp256kfun/src/hash.rs +++ b/secp256kfun/src/hash.rs @@ -7,7 +7,7 @@ use digest::FixedOutput; use crate::digest::{ crypto_common::BlockSizeUser, - generic_array::typenum::{PartialDiv, Unsigned, U32}, + generic_array::typenum::{PartialDiv, U32, Unsigned}, }; /// Extension trait for some cryptotraphic function that can be domain separated by a tag. /// Used for hashes and [nonce generators][`NonceGen`]. diff --git a/secp256kfun/src/keypair.rs b/secp256kfun/src/keypair.rs index 2451396f..4de13983 100644 --- a/secp256kfun/src/keypair.rs +++ b/secp256kfun/src/keypair.rs @@ -1,10 +1,10 @@ -use crate::{g, marker::*, Point, Scalar, G}; +use crate::{G, Point, Scalar, g, marker::*}; /// A secret and public key pair. /// /// ## Synopsis /// /// ``` -/// use secp256kfun::{prelude::*, KeyPair}; +/// use secp256kfun::{KeyPair, prelude::*}; /// let my_secret_key = Scalar::random(&mut rand::thread_rng()); /// let my_keypair: KeyPair = KeyPair::new(my_secret_key.clone()); /// let my_xonly_keypair: KeyPair = KeyPair::new_xonly(my_secret_key); @@ -68,7 +68,7 @@ impl KeyPair { /// /// # Example /// ``` - /// use secp256kfun::{g, marker::*, s, KeyPair, Scalar, G}; + /// use secp256kfun::{G, KeyPair, Scalar, g, marker::*, s}; /// /// let original_secret_key = Scalar::random(&mut rand::thread_rng()); /// let keypair = KeyPair::new_xonly(original_secret_key.clone()); diff --git a/secp256kfun/src/lib.rs b/secp256kfun/src/lib.rs index a4a3d322..44316b74 100755 --- a/secp256kfun/src/lib.rs +++ b/secp256kfun/src/lib.rs @@ -104,5 +104,5 @@ pub use secp256k1_0_30 as secp256k1; /// Convenience module to import the most frequently used tools pub mod prelude { - pub use crate::{g, marker::*, s, Point, Scalar, G}; + pub use crate::{G, Point, Scalar, g, marker::*, s}; } diff --git a/secp256kfun/src/libsecp_compat.rs b/secp256kfun/src/libsecp_compat.rs index 326459f8..05e0a43d 100644 --- a/secp256kfun/src/libsecp_compat.rs +++ b/secp256kfun/src/libsecp_compat.rs @@ -1,6 +1,6 @@ #[cfg(feature = "libsecp_compat_0_27")] mod v0_27 { - use crate::{marker::*, Point, Scalar}; + use crate::{Point, Scalar, marker::*}; use secp256k1::{PublicKey, SecretKey, XOnlyPublicKey}; use secp256k1_0_27 as secp256k1; @@ -103,7 +103,7 @@ mod v0_27 { #[cfg(feature = "libsecp_compat_0_28")] mod v0_28 { - use crate::{marker::*, Point, Scalar}; + use crate::{Point, Scalar, marker::*}; use secp256k1::{PublicKey, SecretKey, XOnlyPublicKey}; use secp256k1_0_28 as secp256k1; @@ -206,7 +206,7 @@ mod v0_28 { #[cfg(feature = "libsecp_compat_0_29")] mod v0_29 { - use crate::{marker::*, Point, Scalar}; + use crate::{Point, Scalar, marker::*}; use secp256k1::{PublicKey, SecretKey, XOnlyPublicKey}; use secp256k1_0_29 as secp256k1; @@ -309,7 +309,7 @@ mod v0_29 { #[cfg(feature = "libsecp_compat_0_30")] mod v0_30 { - use crate::{marker::*, Point, Scalar}; + use crate::{Point, Scalar, marker::*}; use secp256k1::{PublicKey, SecretKey, XOnlyPublicKey}; use secp256k1_0_30 as secp256k1; diff --git a/secp256kfun/src/macros.rs b/secp256kfun/src/macros.rs index 8458411f..970ec5af 100644 --- a/secp256kfun/src/macros.rs +++ b/secp256kfun/src/macros.rs @@ -30,8 +30,8 @@ macro_rules! s { /// - ` + ` adds two points /// - ` - ` subtracts one point from another /// - ` .* ` does a [dot product](https://en.wikipedia.org/wiki/Dot_product) -/// between a list of points and scalars. If one list is shorter than the other then the excess -/// points or scalars will be multiplied by 0. See [`op::point_scalar_dot_product`]. +/// between a list of points and scalars. If one list is shorter than the other then the excess +/// points or scalars will be multiplied by 0. See [`op::point_scalar_dot_product`]. /// /// The terms of the expression can be any variable followed by simple method calls, attribute /// access etc. If your term involves more expressions (anything involving specifying types using @@ -42,7 +42,7 @@ macro_rules! s { /// /// Simple scalar multiplication by [`G`] but will work with any [`Point`] /// ``` -/// use secp256kfun::{g, Scalar, G}; +/// use secp256kfun::{G, Scalar, g}; /// let x = Scalar::random(&mut rand::thread_rng()); /// let X = g!(x * G); /// ``` @@ -426,7 +426,7 @@ macro_rules! impl_fromstr_deserialize { #[cfg(feature = "bincode")] #[cfg_attr(docsrs, doc(cfg(feature = "bincode")))] - impl$(<$($tpl $(:$tcl)?),*>)? $crate::bincode::de::Decode for $type { + impl<__Context, $($($tpl $(:$tcl)?),*)?> $crate::bincode::de::Decode<__Context> for $type { fn decode(decoder: &mut D) -> Result { use $crate::bincode::de::read::Reader; let mut $input = [0u8; $len]; @@ -442,7 +442,7 @@ macro_rules! impl_fromstr_deserialize { #[cfg(feature = "bincode")] #[cfg_attr(docsrs, doc(cfg(feature = "bincode")))] - impl<'de, $($($tpl $(:$tcl)?),*)?> $crate::bincode::BorrowDecode<'de> for $type { + impl<'de, __Context, $($($tpl $(:$tcl)?),*)? > $crate::bincode::BorrowDecode<'de, __Context> for $type { fn borrow_decode>( decoder: &mut D, ) -> core::result::Result { diff --git a/secp256kfun/src/marker/point_type.rs b/secp256kfun/src/marker/point_type.rs index c57d1fbe..328baa25 100644 --- a/secp256kfun/src/marker/point_type.rs +++ b/secp256kfun/src/marker/point_type.rs @@ -43,7 +43,7 @@ pub struct Normal; /// possible. To normalize a `NonNormal` point call `normalize` on the point. /// /// ``` -/// use secp256kfun::{g, marker::*, Scalar, G}; +/// use secp256kfun::{G, Scalar, g, marker::*}; /// let scalar = Scalar::random(&mut rand::thread_rng()); /// let non_normal_point = g!(scalar * G); /// let normal_point = non_normal_point.normalize(); diff --git a/secp256kfun/src/marker/secrecy.rs b/secp256kfun/src/marker/secrecy.rs index e81e52bf..78fe5137 100644 --- a/secp256kfun/src/marker/secrecy.rs +++ b/secp256kfun/src/marker/secrecy.rs @@ -5,7 +5,7 @@ /// /// - [`Secret`]: This value must be kept secret from parties I interact with. /// - [`Public`]: This value is known or it would not harm my security if this -/// value is known to all parties I interact with. +/// value is known to all parties I interact with. /// /// Note this consideration is only important if you do operations on the value /// during an interaction with a party. So if you would like to keep scalar `x` @@ -19,7 +19,7 @@ /// and `.public()` methods allow you to change the default. /// /// ``` -/// use secp256kfun::{g, marker::*, Point, Scalar, G}; +/// use secp256kfun::{G, Point, Scalar, g, marker::*}; /// let x = Scalar::random(&mut rand::thread_rng()); /// let H = Point::random(&mut rand::thread_rng()); /// let X = g!(x * H); // This is constant time because x is secret by default. diff --git a/secp256kfun/src/nonce.rs b/secp256kfun/src/nonce.rs index bc58517c..35cea0c1 100644 --- a/secp256kfun/src/nonce.rs +++ b/secp256kfun/src/nonce.rs @@ -17,7 +17,7 @@ //! //! [`NonceGen`]: crate::nonce::NonceGen //! [`derive_nonce!`]: crate::derive_nonce! -use crate::{hash::*, marker::*, Scalar}; +use crate::{Scalar, hash::*, marker::*}; use core::marker::PhantomData; use rand_core::RngCore; @@ -83,7 +83,6 @@ impl NonceRng for std::sync::Mutex { /// /// [BIP-340]: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki /// [`ThreadRng`]: https://docs.rs/rand/latest/rand/rngs/struct.ThreadRng.html -/// [`OsRng`]: rand_core::OsRng /// [`GlobalRng`]: crate::nonce::GlobalRng #[derive(Debug, Default, Clone, PartialEq)] pub struct Synthetic { @@ -138,8 +137,8 @@ pub struct GlobalRng { /// /// ``` /// use secp256kfun::{ -/// nonce::{Deterministic, NonceGen}, /// Tag, +/// nonce::{Deterministic, NonceGen}, /// }; /// use sha2::Sha256; /// let nonce_gen = Deterministic::::default().tag(b"BIP0340"); diff --git a/secp256kfun/src/op.rs b/secp256kfun/src/op.rs index a1b9d1d9..c19b2d46 100644 --- a/secp256kfun/src/op.rs +++ b/secp256kfun/src/op.rs @@ -13,9 +13,9 @@ //! [`Scalars`]: crate::Scalar #[allow(unused_imports)] use crate::{ + Point, Scalar, backend::{self, ConstantTime, TimeSensitive, VariableTime}, marker::*, - Point, Scalar, }; use core::borrow::Borrow; @@ -275,7 +275,7 @@ pub fn point_is_y_even(A: &Point) -> bool { #[cfg(test)] mod test { - use crate::{marker::*, Point, Scalar, G}; + use crate::{G, Point, Scalar, marker::*}; use core::str::FromStr; #[test] diff --git a/secp256kfun/src/point.rs b/secp256kfun/src/point.rs index 28728831..0167411a 100644 --- a/secp256kfun/src/point.rs +++ b/secp256kfun/src/point.rs @@ -1,8 +1,9 @@ use crate::{ + Scalar, backend::{self, BackendPoint, TimeSensitive}, hash::HashInto, marker::*, - op, Scalar, + op, }; use core::{ marker::PhantomData, @@ -125,7 +126,7 @@ impl Point { /// /// # Examples /// ``` - /// use secp256kfun::{marker::*, Point, G}; + /// use secp256kfun::{G, Point, marker::*}; /// let bytes = [ /// 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, /// 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152, @@ -174,7 +175,7 @@ impl Point { /// /// # Examples /// ``` - /// use secp256kfun::{marker::*, Point}; + /// use secp256kfun::{Point, marker::*}; /// let point = Point::random(&mut rand::thread_rng()); /// let (point_with_even_y, was_odd) = point.clone().into_point_with_even_y(); /// ``` @@ -196,7 +197,7 @@ impl Point { /// ## Examples /// /// ``` - /// use secp256kfun::{marker::*, Point, G}; + /// use secp256kfun::{G, Point, marker::*}; /// assert_eq!(Point::::generator(), *G); /// ``` /// @@ -219,7 +220,7 @@ impl Point { /// # Examples /// /// ``` - /// use secp256kfun::{marker::*, Point, Scalar, G}; + /// use secp256kfun::{G, Point, Scalar, marker::*}; /// let mut secret_key = Scalar::random(&mut rand::thread_rng()); /// let public_key = Point::even_y_from_scalar_mul(G, &mut secret_key); /// assert!(public_key.is_y_even()); @@ -403,7 +404,7 @@ impl Point { /// # Example /// Round trip serialization with [`from_bytes`] /// ``` - /// use secp256kfun::{marker::*, Point}; + /// use secp256kfun::{Point, marker::*}; /// let point = Point::random(&mut rand::thread_rng()); /// let bytes = point.to_bytes(); /// assert!(bytes[0] == 0x02 || bytes[0] == 0x03); @@ -438,7 +439,7 @@ impl Point { /// /// # Example /// ``` - /// use secp256kfun::{g, marker::*, s, Point, G}; + /// use secp256kfun::{G, Point, g, marker::*, s}; /// let zero = Point::::zero(); /// assert!(zero.is_zero()); /// assert_eq!(g!(zero + G), *G); @@ -481,7 +482,7 @@ impl Point { /// # Example /// /// ``` - /// use secp256kfun::{marker::*, Point}; + /// use secp256kfun::{Point, marker::*}; /// let point = Point::random(&mut rand::thread_rng()); /// let bytes = point.to_bytes_uncompressed(); /// assert_eq!(Point::from_bytes_uncompressed(bytes).unwrap(), point); @@ -590,7 +591,7 @@ impl SubAssign> for Point core::iter::Sum for Point { fn sum>(mut iter: I) -> Self { - let mut sum = iter.next().unwrap_or(Point::zero()); + let mut sum = iter.next().unwrap_or_default(); for point in iter { sum += point; } @@ -601,7 +602,7 @@ impl core::iter::Sum for Point { #[cfg(test)] mod test { use super::*; - use crate::{g, G}; + use crate::{G, g}; use proptest::prelude::*; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::wasm_bindgen_test as test; diff --git a/secp256kfun/src/poly.rs b/secp256kfun/src/poly.rs index fb99deb5..8fb5a46a 100644 --- a/secp256kfun/src/poly.rs +++ b/secp256kfun/src/poly.rs @@ -6,7 +6,7 @@ //! //! [`Scalars`]: crate::Scalar //! [`Points`]: crate::Point -use crate::{g, marker::*, s, Point, Scalar, G}; +use crate::{G, Point, Scalar, g, marker::*, s}; use alloc::vec::Vec; use rand_core::RngCore; @@ -29,7 +29,7 @@ pub mod scalar { /// # Example /// /// ``` - /// use secp256kfun::{poly, Scalar}; + /// use secp256kfun::{Scalar, poly}; /// let secret_poly = (0..5) /// .map(|_| Scalar::random(&mut rand::thread_rng())) /// .collect::>(); diff --git a/secp256kfun/src/proptest_impls.rs b/secp256kfun/src/proptest_impls.rs index b658f72c..91a7d89a 100644 --- a/secp256kfun/src/proptest_impls.rs +++ b/secp256kfun/src/proptest_impls.rs @@ -2,7 +2,7 @@ //! //! [`Arbitrary`]: proptest::arbitrary::Arbitrary -use crate::{marker::*, Point, Scalar, G}; +use crate::{G, Point, Scalar, marker::*}; use ::proptest::prelude::*; impl Arbitrary for Scalar { diff --git a/secp256kfun/src/scalar.rs b/secp256kfun/src/scalar.rs index 21ca5296..2addf763 100644 --- a/secp256kfun/src/scalar.rs +++ b/secp256kfun/src/scalar.rs @@ -22,7 +22,7 @@ use rand_core::RngCore; /// cryptography is that scalar _multiplication_ can be done efficiently: /// /// ``` -/// use secp256kfun::{g, Scalar, G}; +/// use secp256kfun::{G, Scalar, g}; /// let x = Scalar::random(&mut rand::thread_rng()); /// let X = g!(x * G); /// ``` @@ -84,7 +84,7 @@ impl Scalar { /// /// # Example /// ``` - /// use secp256kfun::{marker::*, Scalar}; + /// use secp256kfun::{Scalar, marker::*}; /// assert!(Scalar::::from_bytes([0u8; 32]).is_some()); /// // NonZero scalar's can't be zero /// assert!(Scalar::::from_bytes([0u8; 32]).is_none()); @@ -174,7 +174,7 @@ impl Scalar { /// # Example /// /// ``` - /// use secp256kfun::{marker::*, s, Scalar}; + /// use secp256kfun::{Scalar, marker::*, s}; /// let a = Scalar::random(&mut rand::thread_rng()); /// let a_inverse = a.invert(); /// assert_eq!(s!(a * a_inverse), s!(1)); @@ -200,7 +200,7 @@ impl Scalar { /// # Example /// /// ``` - /// use secp256kfun::{marker::*, s, Scalar}; + /// use secp256kfun::{Scalar, marker::*, s}; /// /// /// Returns an iterator of 1, x, x², x³ ... /// fn powers(x: Scalar) -> impl Iterator> { @@ -209,18 +209,14 @@ impl Scalar { /// }) /// } /// - /// assert_eq!(powers(s!(2)).take(4).collect::>(), vec![ - /// s!(1), - /// s!(2), - /// s!(4), - /// s!(8) - /// ]); - /// assert_eq!(powers(s!(0)).take(4).collect::>(), vec![ - /// s!(1).mark_zero(), - /// s!(0), - /// s!(0), - /// s!(0) - /// ]); + /// assert_eq!( + /// powers(s!(2)).take(4).collect::>(), + /// vec![s!(1), s!(2), s!(4), s!(8)] + /// ); + /// assert_eq!( + /// powers(s!(0)).take(4).collect::>(), + /// vec![s!(1).mark_zero(), s!(0), s!(0), s!(0)] + /// ); /// ``` pub fn mark_zero_choice(self) -> Scalar { Scalar::from_inner(self.0) @@ -239,7 +235,7 @@ impl Scalar { /// cryptographically secure random number generator. /// # Example /// ``` - /// use secp256kfun::{g, Scalar, G}; + /// use secp256kfun::{G, Scalar, g}; /// let secret_scalar = Scalar::random(&mut rand::thread_rng()); /// let public_point = g!(secret_scalar * G); /// ``` @@ -300,7 +296,7 @@ impl Scalar { /// # Example /// ``` /// # use core::convert::TryInto; - /// use secp256kfun::{hex, marker::*, s, Scalar}; + /// use secp256kfun::{Scalar, hex, marker::*, s}; /// let scalar = Scalar::::from_bytes_mod_order(*b"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); /// assert_eq!(scalar.to_bytes(), *b"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); /// let scalar_overflowed = Scalar::::from_bytes_mod_order( @@ -319,7 +315,7 @@ impl Scalar { /// /// # Example /// ``` - /// use secp256kfun::{marker::*, Scalar}; + /// use secp256kfun::{Scalar, marker::*}; /// let bytes = b"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; /// assert!(Scalar::::from_slice_mod_order(&bytes[..31]).is_none()); /// assert_eq!( @@ -575,23 +571,25 @@ mod test { #[test] fn from_slice() { - assert!(Scalar::::from_slice( - b"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".as_ref() - ) - .is_some()); - assert!(Scalar::::from_slice( - b"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".as_ref() - ) - .is_none()); + assert!( + Scalar::::from_slice(b"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".as_ref()) + .is_some() + ); + assert!( + Scalar::::from_slice(b"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".as_ref()) + .is_none() + ); - assert!(Scalar::::from_slice( - hex::decode_array::<32>( - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + assert!( + Scalar::::from_slice( + hex::decode_array::<32>( + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + ) + .unwrap() + .as_ref() ) - .unwrap() - .as_ref() - ) - .is_none()); + .is_none() + ); } #[test] diff --git a/secp256kfun/src/slice.rs b/secp256kfun/src/slice.rs index 1cf83571..c482f25a 100644 --- a/secp256kfun/src/slice.rs +++ b/secp256kfun/src/slice.rs @@ -14,7 +14,7 @@ use subtle::ConstantTimeEq; /// # Example /// /// ``` -/// use secp256kfun::{marker::*, Slice}; +/// use secp256kfun::{Slice, marker::*}; /// let bytes = b"a secret message"; /// let secret_slice = Slice::::from(bytes.as_ref()); /// ``` diff --git a/secp256kfun/src/vendor/k256.rs b/secp256kfun/src/vendor/k256.rs index c9897ae7..4af49e82 100644 --- a/secp256kfun/src/vendor/k256.rs +++ b/secp256kfun/src/vendor/k256.rs @@ -9,7 +9,7 @@ pub use scalar::Scalar; pub mod mul; #[allow(unused)] pub mod util; -use digest::generic_array::{typenum::U32, GenericArray}; +use digest::generic_array::{GenericArray, typenum::U32}; const CURVE_EQUATION_B_SINGLE: u32 = 7u32; diff --git a/secp256kfun/src/vendor/k256/affine.rs b/secp256kfun/src/vendor/k256/affine.rs index 844d4ba8..aab9a617 100644 --- a/secp256kfun/src/vendor/k256/affine.rs +++ b/secp256kfun/src/vendor/k256/affine.rs @@ -1,6 +1,6 @@ //! Affine points -use super::{FieldBytes, FieldElement, ProjectivePoint, Scalar, CURVE_EQUATION_B}; +use super::{CURVE_EQUATION_B, FieldBytes, FieldElement, ProjectivePoint, Scalar}; use core::ops::{Mul, Neg}; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; diff --git a/secp256kfun/src/vendor/k256/projective.rs b/secp256kfun/src/vendor/k256/projective.rs index 95dc3441..dc9b897f 100644 --- a/secp256kfun/src/vendor/k256/projective.rs +++ b/secp256kfun/src/vendor/k256/projective.rs @@ -1,6 +1,6 @@ //! Projective points -use super::{AffinePoint, FieldElement, CURVE_EQUATION_B_SINGLE}; +use super::{AffinePoint, CURVE_EQUATION_B_SINGLE, FieldElement}; use core::{ iter::Sum, ops::{Add, AddAssign, Neg, Sub, SubAssign}, diff --git a/secp256kfun/src/vendor/k256/scalar/scalar_4x64.rs b/secp256kfun/src/vendor/k256/scalar/scalar_4x64.rs index ab83338b..4569109d 100644 --- a/secp256kfun/src/vendor/k256/scalar/scalar_4x64.rs +++ b/secp256kfun/src/vendor/k256/scalar/scalar_4x64.rs @@ -2,8 +2,8 @@ //! Ported from use super::super::{ - util::{adc64, sbb64}, FieldBytes, + util::{adc64, sbb64}, }; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption}; diff --git a/secp256kfun/tests/against_c_lib.rs b/secp256kfun/tests/against_c_lib.rs index 19708100..ecbe572f 100755 --- a/secp256kfun/tests/against_c_lib.rs +++ b/secp256kfun/tests/against_c_lib.rs @@ -4,7 +4,7 @@ mod against_c_lib { use proptest::prelude::*; use secp256k1::{All, PublicKey, Secp256k1, SecretKey}; - use secp256kfun::{g, marker::*, op::double_mul, s, secp256k1, Point, Scalar, G}; + use secp256kfun::{G, Point, Scalar, g, marker::*, op::double_mul, s, secp256k1}; lazy_static::lazy_static! { static ref SECP: Secp256k1 = Secp256k1::new(); diff --git a/secp256kfun/tests/expression_macros.rs b/secp256kfun/tests/expression_macros.rs index cbc8838b..b7c4989b 100755 --- a/secp256kfun/tests/expression_macros.rs +++ b/secp256kfun/tests/expression_macros.rs @@ -1,6 +1,6 @@ #![allow(non_snake_case)] -use secp256kfun::{g, op, s, Point, Scalar}; +use secp256kfun::{Point, Scalar, g, op, s}; #[derive(Clone)] struct Has { diff --git a/sigma_fun/Cargo.toml b/sigma_fun/Cargo.toml index 07a8fe7e..84743b62 100644 --- a/sigma_fun/Cargo.toml +++ b/sigma_fun/Cargo.toml @@ -2,8 +2,8 @@ name = "sigma_fun" version = "0.8.0" authors = ["LLFourn "] -edition = "2021" -rust-version = "1.63" +edition = "2024" +rust-version = "1.85.0" license = "0BSD" description = "A framework for making Sigma protocols fun!" homepage = "https://github.com/LLFourn/secp256kfun/tree/master/sigma_fun" @@ -19,21 +19,22 @@ digest = "0.10" secp256kfun = { path = "../secp256kfun", version = "0.11", default-features = false, optional = true } curve25519-dalek = { package = "curve25519-dalek-ng", version = "4", default-features = false, optional = true, features = ["u64_backend"] } serde = { package = "serde", version = "1.0", optional = true, default-features = false, features = ["derive"] } +bincode = { workspace = true, optional = true } rand_core = "0.6" [dev-dependencies] secp256kfun = { path = "../secp256kfun", version = "0.11", default-features = false, features = ["proptest"] } rand = "0.8" sha2 = "0.10" -bincode = "1" proptest = "1" rand_chacha = "0.3" [features] default = ["alloc", "secp256k1"] -alloc = ["serde?/alloc", "secp256kfun/alloc"] +alloc = ["serde?/alloc", "secp256kfun/alloc", "bincode?/alloc"] secp256k1 = ["secp256kfun"] ed25519 = ["curve25519-dalek"] +bincode = ["dep:bincode", "secp256kfun?/bincode"] serde = ["dep:serde", "secp256kfun?/serde", "curve25519-dalek?/serde", "generic-array/serde"] [package.metadata.docs.rs] diff --git a/sigma_fun/src/all.rs b/sigma_fun/src/all.rs index 94e35ffa..2474e4f9 100644 --- a/sigma_fun/src/all.rs +++ b/sigma_fun/src/all.rs @@ -1,11 +1,11 @@ use crate::{ - rand_core::{CryptoRng, RngCore}, Sigma, + rand_core::{CryptoRng, RngCore}, }; use alloc::vec::Vec; use core::marker::PhantomData; use digest::Update; -use generic_array::{typenum::Unsigned, GenericArray}; +use generic_array::{GenericArray, typenum::Unsigned}; /// Combinator for proving all of N statements of the same type is true. #[derive(Default, Clone, Debug, PartialEq)] diff --git a/sigma_fun/src/and.rs b/sigma_fun/src/and.rs index b17cc8f6..bf4fd320 100644 --- a/sigma_fun/src/and.rs +++ b/sigma_fun/src/and.rs @@ -130,7 +130,7 @@ crate::impl_display!(And); mod test { #[cfg(feature = "secp256k1")] mod secp256k1 { - use crate::{secp256k1::fun::Scalar, And, HashTranscript}; + use crate::{And, HashTranscript, secp256k1::fun::Scalar}; use ::proptest::prelude::*; use rand_chacha::ChaCha20Rng; use sha2::Sha256; diff --git a/sigma_fun/src/ed25519.rs b/sigma_fun/src/ed25519.rs index ce13429a..122366fe 100644 --- a/sigma_fun/src/ed25519.rs +++ b/sigma_fun/src/ed25519.rs @@ -11,16 +11,16 @@ //! [`is_torsion_free`]: crate::ed25519::curve25519_dalek::edwards::EdwardsPoint::is_torsion_free //! [`ristretto`]: crate::ed25519::curve25519_dalek::ristretto use crate::{ - rand_core::{CryptoRng, RngCore}, Sigma, + rand_core::{CryptoRng, RngCore}, }; use core::marker::PhantomData; pub use curve25519_dalek; use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, edwards::EdwardsPoint, scalar::Scalar}; use digest::Update; use generic_array::{ - typenum::{self, type_operators::IsLessOrEqual, U31}, ArrayLength, GenericArray, + typenum::{self, U31, type_operators::IsLessOrEqual}, }; /// Proves knowledge of `x` such that `A = x * B` for some `A` and `B` included in the statement. diff --git a/sigma_fun/src/eq.rs b/sigma_fun/src/eq.rs index 600fb426..5c0fd529 100644 --- a/sigma_fun/src/eq.rs +++ b/sigma_fun/src/eq.rs @@ -1,6 +1,7 @@ +#![allow(clippy::upper_case_acronyms)] use crate::{ - rand_core::{CryptoRng, RngCore}, Sigma, + rand_core::{CryptoRng, RngCore}, }; use digest::Update; @@ -28,11 +29,11 @@ where // following. If they share the following it doesn't necessarily mean they // are Eq compatible but it's the best we can do for now. B: Sigma< - ChallengeLength = A::ChallengeLength, - Witness = A::Witness, - Response = A::Response, - AnnounceSecret = A::AnnounceSecret, - >, + ChallengeLength = A::ChallengeLength, + Witness = A::Witness, + Response = A::Response, + AnnounceSecret = A::AnnounceSecret, + >, { type Witness = A::Witness; type Statement = (A::Statement, B::Statement); @@ -129,8 +130,8 @@ crate::impl_display!(Eq); mod test { #![allow(unused_imports)] use crate::{ - typenum::{U20, U31, U32}, Eq, FiatShamir, HashTranscript, + typenum::{U20, U31, U32}, }; use ::proptest::prelude::*; use rand_chacha::ChaCha20Rng; @@ -147,7 +148,6 @@ mod test { ) => {{ let statement = &$statement; let witness = &$witness; - #[allow(clippy::upper_case_acronyms)] type DLEQ = Eq<$mod::DLG<$len>, $mod::DL<$len>>; let proof_system = FiatShamir::>::default(); @@ -155,7 +155,7 @@ mod test { assert!(proof_system.verify(statement, &proof)); let mut bogus_statement = statement.clone(); - bogus_statement.1 .0 = $unrelated_point; + bogus_statement.1.0 = $unrelated_point; if &bogus_statement != statement { assert!(!proof_system.verify(&bogus_statement, &proof)); @@ -169,10 +169,7 @@ mod test { #[cfg(feature = "secp256k1")] mod secp256k1 { use super::*; - use crate::secp256k1::{ - self, - fun::{Point, Scalar}, - }; + use crate::secp256k1::{self, fun::prelude::*}; #[test] #[cfg(feature = "alloc")] fn secp256k1_dleq_has_correct_name() { @@ -183,6 +180,26 @@ mod test { assert_eq!(&format!("{dleq}"), "eq(DLG(secp256k1),DL(secp256k1))"); } + #[test] + #[cfg(all(feature = "bincode", feature = "alloc"))] + fn bincode_roundtrip() { + type DLEQ = Eq, secp256k1::DL>; + let x = s!(42); + let H = Point::random(&mut rand::thread_rng()); + let xG = g!(x * G).normalize(); + let xH = g!(x * H).normalize(); + let statement = ((xG), (H, xH)); + let proof_system = FiatShamir::>::default(); + let proof = proof_system.prove(&x, &statement, Some(&mut rand::thread_rng())); + let encoded = bincode::encode_to_vec(&proof, bincode::config::standard()).unwrap(); + let (decoded, _) = bincode::decode_from_slice::, _>( + &encoded[..], + bincode::config::standard(), + ) + .unwrap(); + assert_eq!(decoded, proof); + } + proptest! { #[test] fn test_dleq_secp256k1( diff --git a/sigma_fun/src/eq_all.rs b/sigma_fun/src/eq_all.rs index 6530cddf..a4385bc3 100644 --- a/sigma_fun/src/eq_all.rs +++ b/sigma_fun/src/eq_all.rs @@ -1,11 +1,11 @@ use crate::{ - rand_core::{CryptoRng, RngCore}, Sigma, + rand_core::{CryptoRng, RngCore}, }; use alloc::vec::Vec; use core::marker::PhantomData; use digest::Update; -use generic_array::{typenum::Unsigned, GenericArray}; +use generic_array::{GenericArray, typenum::Unsigned}; /// Combinator for proving any number of statements of the same kind have the same witness. #[derive(Debug, Clone, Default, PartialEq)] diff --git a/sigma_fun/src/ext/dl_secp256k1_ed25519_eq.rs b/sigma_fun/src/ext/dl_secp256k1_ed25519_eq.rs index 25df676d..1a1d607e 100644 --- a/sigma_fun/src/ext/dl_secp256k1_ed25519_eq.rs +++ b/sigma_fun/src/ext/dl_secp256k1_ed25519_eq.rs @@ -17,25 +17,23 @@ //! //! [MRL-0010]: https://web.getmonero.org/resources/research-lab/pubs/MRL-0010.pdf use crate::{ - ed25519, + All, And, Eq, FiatShamir, Or, ProverTranscript, Sigma, Transcript, ed25519, or::Either, secp256k1, secp256k1::fun::{ - g, + G as GP, Point as PointP, Scalar as ScalarP, g, marker::*, rand_core::{CryptoRng, RngCore}, s, subtle::{self, ConditionallySelectable}, - Point as PointP, Scalar as ScalarP, G as GP, }, - All, And, Eq, FiatShamir, Or, ProverTranscript, Sigma, Transcript, }; use alloc::vec::Vec; use curve25519_dalek::{ constants::ED25519_BASEPOINT_TABLE, edwards::EdwardsPoint as PointQ, scalar::Scalar as ScalarQ, traits::Identity, }; -use generic_array::typenum::{U252, U31}; +use generic_array::typenum::{U31, U252}; static GQ: &curve25519_dalek::edwards::EdwardsBasepointTable = &ED25519_BASEPOINT_TABLE; /// The underlying sigma protocol we will use to prove the relationship between the two sets of commitments. @@ -284,8 +282,8 @@ fn to_bits(secret_key: &ScalarQ) -> [bool; COMMITMENT_BITS] { mod test { use super::*; use crate::{ - ed25519::test::{ed25519_point, ed25519_scalar}, HashTranscript, + ed25519::test::{ed25519_point, ed25519_scalar}, }; use ::proptest::prelude::*; use rand_chacha::ChaCha20Rng; @@ -317,7 +315,7 @@ mod test { } } - #[cfg(feature = "serde")] + #[cfg(all(feature = "serde", feature = "bincode"))] proptest! { #![proptest_config(ProptestConfig::with_cases(3))] #[test] @@ -329,11 +327,11 @@ mod test { let proof_system = CrossCurveDLEQ::::new(HP, HQ); let (proof, _) = proof_system.prove(&secret, &mut rand::thread_rng()); - let proof_serialized = bincode::serialize(&proof).unwrap(); - let proof_deserialized: CrossCurveDLEQProof = - bincode::deserialize(&proof_serialized).unwrap(); + let proof_serialized = bincode::encode_to_vec(bincode::serde::Compat(&proof), bincode::config::standard()).unwrap(); + let proof_deserialized: bincode::serde::Compat = + bincode::decode_from_slice(&proof_serialized, bincode::config::standard()).unwrap().0; - assert_eq!(proof_deserialized, proof); + assert_eq!(proof_deserialized.0, proof); } } } diff --git a/sigma_fun/src/fiat_shamir.rs b/sigma_fun/src/fiat_shamir.rs index 2bc43d02..ea1f487c 100644 --- a/sigma_fun/src/fiat_shamir.rs +++ b/sigma_fun/src/fiat_shamir.rs @@ -1,4 +1,4 @@ -use crate::{generic_array::GenericArray, ProverTranscript, Sigma, Transcript}; +use crate::{ProverTranscript, Sigma, Transcript, generic_array::GenericArray}; use rand_core::{CryptoRng, RngCore}; /// Applies the Fiat-Shamir transform to a given [`Sigma`] protocol given a [`Transcript`]. @@ -97,3 +97,58 @@ pub struct CompactProof { /// R pub response: S::Response, } + +/// Implements bincode encoding for `CompactProof` for challenge lengths of 32. This is a +/// restriction until we can upgrade generic array. +#[cfg(feature = "bincode")] +#[cfg_attr(docsrs, doc(cfg(feature = "bincode")))] +impl bincode::Encode for CompactProof +where + S: Sigma, + S::Response: bincode::Encode, +{ + fn encode( + &self, + encoder: &mut E, + ) -> Result<(), bincode::error::EncodeError> { + let mut bytes = [0u8; 32]; + bytes.copy_from_slice(self.challenge.as_slice()); + bytes.encode(encoder)?; + self.response.encode(encoder)?; + Ok(()) + } +} + +#[cfg(feature = "bincode")] +#[cfg_attr(docsrs, doc(cfg(feature = "bincode")))] +impl bincode::Decode for CompactProof +where + S: Sigma, + S::Response: bincode::Decode, +{ + fn decode>( + decoder: &mut D, + ) -> Result { + let challenge = <[u8; 32]>::decode(decoder)?; + let response = S::Response::decode(decoder)?; + + Ok(CompactProof { + challenge: GenericArray::from_exact_iter(challenge).unwrap(), + response, + }) + } +} + +#[cfg(feature = "bincode")] +#[cfg_attr(docsrs, doc(cfg(feature = "bincode")))] +impl<'de, S: Sigma, Context> bincode::BorrowDecode<'de, Context> for CompactProof +where + S: Sigma, + S::Response: bincode::Decode, +{ + fn borrow_decode>( + decoder: &mut D, + ) -> Result { + bincode::Decode::decode(decoder) + } +} diff --git a/sigma_fun/src/or.rs b/sigma_fun/src/or.rs index 256582f0..1c1047e0 100644 --- a/sigma_fun/src/or.rs +++ b/sigma_fun/src/or.rs @@ -1,9 +1,9 @@ use crate::{ - rand_core::{CryptoRng, RngCore}, Sigma, + rand_core::{CryptoRng, RngCore}, }; use digest::Update; -use generic_array::{functional::FunctionalSequence, GenericArray}; +use generic_array::{GenericArray, functional::FunctionalSequence}; /// Combinator for proving that `A` OR `B` is true. #[derive(Default, Clone, Debug, PartialEq)] @@ -86,13 +86,13 @@ impl> Sigma for Or Self::Announcement { match announce_secret { - (Either::Left((ref announce_secret, ref sim_response)), sim_challenge) => ( + (Either::Left((announce_secret, sim_response)), sim_challenge) => ( self.lhs.announce(&statement.0, announce_secret), self.rhs .implied_announcement(&statement.1, sim_challenge, sim_response) .expect("computationally unreachable for any large language"), ), - (Either::Right((ref sim_response, ref announce_secret)), sim_challenge) => ( + (Either::Right((sim_response, announce_secret)), sim_challenge) => ( self.lhs .implied_announcement(&statement.0, sim_challenge, sim_response) .expect("computationally unreachable for any large language"), @@ -109,14 +109,14 @@ impl> Sigma for Or::default(); rng.fill_bytes(sim_challenge.as_mut_slice()); match witness { - Either::Left(ref witness) => { + Either::Left(witness) => { let sim_response = self.rhs.sample_response(rng); ( Either::Left((self.lhs.gen_announce_secret(witness, rng), sim_response)), sim_challenge, ) } - Either::Right(ref witness) => { + Either::Right(witness) => { let sim_response = self.lhs.sample_response(rng); ( Either::Right((sim_response, self.rhs.gen_announce_secret(witness, rng))), @@ -190,16 +190,16 @@ mod test { #[cfg(feature = "secp256k1")] mod secp256k1 { use crate::{ + Either, HashTranscript, Or, secp256k1::{ self, fun::{Point, Scalar}, }, - Either, HashTranscript, Or, }; use ::proptest::prelude::*; use generic_array::typenum::U32; use rand_chacha::ChaCha20Rng; - use secp256kfun::{g, G}; + use secp256kfun::{G, g}; use sha2::Sha256; proptest! { diff --git a/sigma_fun/src/secp256k1.rs b/sigma_fun/src/secp256k1.rs index f6d2ef09..3175001a 100644 --- a/sigma_fun/src/secp256k1.rs +++ b/sigma_fun/src/secp256k1.rs @@ -2,17 +2,17 @@ //! //! [`secp256kfun`]: crate::secp256k1::fun use crate::{ - rand_core::{CryptoRng, RngCore}, Sigma, + rand_core::{CryptoRng, RngCore}, }; use core::marker::PhantomData; use digest::Update; use generic_array::{ - typenum::{self, type_operators::IsLessOrEqual, U32}, ArrayLength, GenericArray, + typenum::{self, U32, type_operators::IsLessOrEqual}, }; pub use secp256kfun as fun; -use secp256kfun::{g, marker::*, s, Point, Scalar}; +use secp256kfun::{Point, Scalar, g, marker::*, s}; /// Proves knowledge of `x` such that `A = x * B` for some `A` and `B` included in the statement. #[derive(Clone, Debug, Default, PartialEq)] diff --git a/sigma_fun/src/transcript.rs b/sigma_fun/src/transcript.rs index ca926fa2..08ad9010 100644 --- a/sigma_fun/src/transcript.rs +++ b/sigma_fun/src/transcript.rs @@ -1,13 +1,13 @@ use core::marker::PhantomData; use crate::{ + Sigma, Writable, rand_core::{CryptoRng, RngCore, SeedableRng}, typenum::{ - marker_traits::NonZero, type_operators::IsLessOrEqual, PartialDiv, Unsigned, U32, U64, + PartialDiv, U32, U64, Unsigned, marker_traits::NonZero, type_operators::IsLessOrEqual, }, - Sigma, Writable, }; -use digest::{crypto_common::BlockSizeUser, FixedOutput, Update}; +use digest::{FixedOutput, Update, crypto_common::BlockSizeUser}; use generic_array::GenericArray; /// A trait for a Fiat-Shamir proof transcript.