Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.10.0 release #179

Merged
merged 6 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CHANGELOG


## Unreleased
## v0.10.0

- Change `Scalar::from_bytes` to work for `Scalar<_, NonZero>` as well.
- Updated compatibility to `rust-secp256k1` v0.28.0
Expand Down
10 changes: 7 additions & 3 deletions arithmetic_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[package]
name = "secp256kfun_arithmetic_macros"
version = "0.9.0"
version = "0.1.0"
documentation = "https://docs.rs/secp256kfun_arithmetic_macros"
description = "Helper macros for secp256kfun's aritmetic macros"
license = "0BSD"
homepage = "https://github.com/LLFourn/secp256kfun/tree/master/ecdsa_fun"
repository = "https://github.com/LLFourn/secp256kfun"
readme = "README.md"
edition = "2021"

[lib]
proc-macro = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
proc-macro2 = "1"
quote = "1"
3 changes: 3 additions & 0 deletions arithmetic_macros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# secp256kfun arithmetic macros

Helper crate to define the `g!` and `s!` arithmetic macros.
8 changes: 8 additions & 0 deletions arithmetic_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//!
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(non_snake_case)]
#![doc = include_str!("../README.md")]
#![warn(missing_docs)]

mod optree;
use optree::{Infix, InfixKind, Node, OpTree};
use proc_macro::TokenStream;
Expand All @@ -7,6 +13,7 @@ use std::iter::Peekable;
type Input = Peekable<proc_macro2::token_stream::IntoIter>;

#[proc_macro]
/// Helper to generate the `s!` macro
pub fn gen_s(input: TokenStream) -> TokenStream {
let input: proc_macro2::TokenStream = input.into();
let mut iter = input.into_iter().peekable();
Expand Down Expand Up @@ -76,6 +83,7 @@ fn compile_s(path: &Ident, node: Node) -> proc_macro2::TokenStream {
}

#[proc_macro]
/// Helper to generate the `g!` macro
pub fn gen_g(input: TokenStream) -> TokenStream {
let input: proc_macro2::TokenStream = input.into();
let mut iter = input.into_iter().peekable();
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions ecdsa_fun/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ecdsa_fun"
version = "0.9.0"
version = "0.10.0"
authors = ["LLFourn <[email protected]>"]
edition = "2021"
rust-version = "1.63"
Expand All @@ -14,8 +14,8 @@ categories = ["cryptography", "cryptography::cryptocurrencies"]
keywords = ["bitcoin", "ecdsa", "secp256k1"]

[dependencies]
secp256kfun = { path = "../secp256kfun", version = "0.9", default-features = false }
sigma_fun = { path = "../sigma_fun", version = "0.6", features = ["secp256k1"], default-features = false, optional = true }
secp256kfun = { path = "../secp256kfun", version = "0.10", default-features = false }
sigma_fun = { path = "../sigma_fun", version = "0.7", 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 }

Expand Down
2 changes: 1 addition & 1 deletion ecdsa_fun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Built on [secp256kfun].

``` toml
[dependencies]
ecdsa_fun = "0.9"
ecdsa_fun = "0.10"
sha2 = "0.10" # You need a hash function for nonce derivation
```

Expand Down
1 change: 0 additions & 1 deletion ecdsa_fun/src/adaptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ mod test {
use rand::rngs::ThreadRng;
use rand_chacha::ChaCha20Rng;
use sha2::Sha256;
use sigma_fun::HashTranscript;

#[test]
fn end_to_end() {
Expand Down
11 changes: 4 additions & 7 deletions ecdsa_fun/tests/against_c_lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#![cfg(feature = "libsecp_compat")]
use ecdsa_fun::{
self,
fun::{
hex,
secp256k1::{self, ecdsa, Message, PublicKey, SecretKey},
Point, Scalar,
},
use ecdsa_fun::fun::{
hex,
secp256k1::{self, ecdsa, Message, PublicKey, SecretKey},
Point, Scalar,
};

const TEST_SOUNDNESS: usize = 20;
Expand Down
6 changes: 3 additions & 3 deletions schnorr_fun/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[package]
name = "schnorr_fun"
version = "0.9.1"
version = "0.10.0"
authors = ["LLFourn <[email protected]>"]
edition = "2021"
rust-version = "1.63"
Expand All @@ -14,11 +14,11 @@ categories = ["cryptography", "cryptography::cryptocurrencies"]
keywords = ["bitcoin", "schnorr"]

[dependencies]
secp256kfun = { path = "../secp256kfun", version = "0.9", default-features = false }
secp256kfun = { path = "../secp256kfun", version = "0.10", default-features = false }
bech32 = { version = "0.9", optional = true, default-features = false }

[dev-dependencies]
secp256kfun = { path = "../secp256kfun", version = "0.9", features = ["proptest"] }
secp256kfun = { path = "../secp256kfun", version = "0.10", features = ["proptest"] }
rand = { version = "0.8" }
lazy_static = "1.4"
bincode = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion schnorr_fun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This implementation is based on the [BIP-340] specification, but is flexible eno

``` toml
[dependencies]
schnorr_fun = "0.9"
schnorr_fun = "0.10"
sha2 = "0.10"
```

Expand Down Expand Up @@ -60,6 +60,7 @@ assert!(schnorr.verify(&verification_key, message, &signature));
- `bincode`: for `bincode` v2 `Encode`/`Decode` implementations
- `libsecp_compat`: for `From` implementations between `rust-secp256k1`'s Schnorr signatures.
- `proptest` to enable `secp256kfun/proptest`.
- `share_backup` to enable bech32 backups of FROST secret shares

[1]: https://d-nb.info/1156214580/34
[BIP-340]: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
Expand Down
4 changes: 2 additions & 2 deletions secp256kfun/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secp256kfun"
version = "0.9.1"
version = "0.10.0"
authors = ["LLFourn <[email protected]>"]
license = "0BSD"
homepage = "https://github.com/LLFourn/secp256kfun"
Expand All @@ -18,7 +18,7 @@ keywords = ["bitcoin", "secp256k1"]
digest = { version = "0.10", default-features = false }
subtle = { package = "subtle-ng", version = "2", default-features = false }
rand_core = { version = "0.6", default-features = false }
secp256kfun_arithmetic_macros = { version = "0.9.0", path = "../arithmetic_macros" }
secp256kfun_arithmetic_macros = { version = "0.1.0", path = "../arithmetic_macros" }

# optional
serde = { version = "1.0", optional = true, default-features = false, features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion secp256kfun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _Low-level_ libraries like [parity/libsecp256k1][4] make it possible but the res

```toml
[dependencies]
secp256kfun = "0.9"
secp256kfun = "0.10"
```

### Should use?
Expand Down
2 changes: 1 addition & 1 deletion secp256kfun/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub fn point_is_y_even<T: Normalized, S>(A: &Point<T, S, NonZero>) -> bool {

#[cfg(test)]
mod test {
use crate::{g, marker::*, Point, Scalar, G};
use crate::{marker::*, Point, Scalar, G};
use core::str::FromStr;

#[test]
Expand Down
140 changes: 3 additions & 137 deletions secp256kfun/src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,15 @@
//!
//! [`Scalars`]: crate::Scalar
//! [`Points`]: crate::Point
use crate::{g, marker::*, s, Point, Scalar, G};
#[cfg(feature = "alloc")]
use alloc::vec::Vec;

use crate::{
marker::{Public, Secrecy, ZeroChoice},
s, Scalar,
};
use core::iter;
use rand_core::RngCore;

/// Functions for dealing with scalar polynomials
pub mod scalar {
use super::*;
use rand_core::RngCore;

use crate::{
g,
marker::{Secrecy, Secret, Zero, ZeroChoice},
poly::powers,
s, Point, Scalar, G,
};

/// Evaluate a scalar polynomial defined by coefficients, at some scalar index.
///
Expand Down Expand Up @@ -80,14 +70,6 @@ pub mod scalar {
/// Functions for dealing with point polynomials
pub mod point {
use super::*;
use core::iter;

use crate::{
g,
marker::{NonNormal, PointType, Public, Secrecy, Zero, ZeroChoice},
poly::powers,
s, Point, Scalar,
};

/// Evaluate a point polynomial defined by coefficients, at some index.
///
Expand Down Expand Up @@ -206,119 +188,3 @@ pub fn eval_basis_poly_at_0<'a>(
s!(acc * x_m / denominator).public()
})
}

#[cfg(test)]
mod test {
use crate::{
g,
marker::{Normal, Zero},
poly, Point, G,
};

use super::*;

#[test]
fn test_lagrange_lambda() {
let res = s!((1 * 4 * 5) / { s!((1 - 2) * (4 - 2) * (5 - 2)).non_zero().unwrap() });
assert_eq!(
res,
eval_basis_poly_at_0(s!(2), [s!(1), s!(4), s!(5)].iter())
);
}

#[test]
fn test_add_poly() {
let poly1 = vec![g!(1 * G), g!(2 * G), g!(3 * G)];
let poly2 = vec![g!(8 * G), g!(5 * G), g!(11 * G)];

let addition = poly::point::add(&poly1, &poly2);
assert_eq!(addition, vec![g!(9 * G), g!(7 * G), g!(14 * G)])
}

#[test]
fn test_add_poly_unequal_len() {
let poly1 = vec![g!(1 * G)];
let poly2 = vec![g!(8 * G), g!(5 * G)];
let addition = poly::point::add(&poly1, &poly2);
assert_eq!(addition, vec![g!(9 * G), g!(5 * G)]);

let poly1 = vec![g!(3 * G), g!(1 * G)];
let poly2 = vec![g!(5 * G)];
let addition = poly::point::add(&poly1, &poly2);
assert_eq!(addition, vec![g!(8 * G), g!(1 * G)]);
}

#[test]
fn test_recover_public_poly() {
let poly = vec![g!(1 * G), g!(2 * G), g!(3 * G)];
let indicies = vec![s!(1).public(), s!(3).public(), s!(2).public()];
let points = indicies
.clone()
.into_iter()
.map(|index| {
(
index,
poly::point::eval(&poly, index.public())
.normalize()
.non_zero()
.unwrap(),
)
})
.collect::<Vec<_>>();

let interpolation = poly::point::interpolate(points);
assert_eq!(interpolation, poly)
}

#[test]
fn test_recover_overdetermined_poly() {
let poly = vec![g!(1 * G), g!(2 * G), g!(3 * G)];
let indicies = vec![
s!(1).public(),
s!(2).public(),
s!(3).public(),
s!(4).public(),
s!(5).public(),
];
let points = indicies
.clone()
.into_iter()
.map(|index| {
(
index,
poly::point::eval(&poly, index.public())
.normalize()
.non_zero()
.unwrap(),
)
})
.collect::<Vec<_>>();

let interpolation = poly::point::interpolate(points);

let (interpolated_coeffs, zero_coeffs) = interpolation.split_at(poly.len());
let n_extra_points = indicies.len() - poly.len();
assert_eq!(
(0..n_extra_points)
.map(|_| Point::<Normal, Public, Zero>::zero().public().normalize())
.collect::<Vec<_>>(),
zero_coeffs.to_vec()
);
assert_eq!(interpolated_coeffs, poly);
}

#[test]
fn test_reconstruct_shared_secret() {
let indicies = vec![s!(1).public(), s!(2).public(), s!(3).public()];
let scalar_poly = vec![s!(42), s!(53), s!(64)];

let secret_shares: Vec<_> = indicies
.clone()
.into_iter()
.map(|index| (index, poly::scalar::eval(&scalar_poly, index)))
.collect();

let reconstructed_secret = poly::scalar::interpolate_and_eval_poly_at_0(secret_shares);
assert_eq!(scalar_poly[0], reconstructed_secret);
}
}
2 changes: 1 addition & 1 deletion secp256kfun/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl<Z> Ord for Scalar<Public, Z> {
#[cfg(test)]
mod test {
use super::*;
use crate::{hex, op, s};
use crate::{hex, s};
use proptest::prelude::*;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
Expand Down
1 change: 0 additions & 1 deletion secp256kfun/src/vendor/k256/scalar/scalar_4x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use super::super::{
util::{adc64, sbb64},
FieldBytes,
};
use core::convert::TryInto;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

/// Constant representing the modulus
Expand Down
Loading
Loading