Skip to content
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
33 changes: 13 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Tests


on:
push:
branches:
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Unreleased

- Upgrade to bincode v2
- MSRV 1.63 -> 1.85

## v0.11.0

- Added `prelude` module for convenient importing
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ members = [
"arithmetic_macros"
]
resolver = "2"

[workspace.dependencies]
bincode = { version = "2", default-features = false, features = ["derive"] }
2 changes: 1 addition & 1 deletion arithmetic_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 24 additions & 16 deletions arithmetic_macros/src/optree.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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}"),
}
}
}
Expand Down Expand Up @@ -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 => "/",
}
)
}
}

Expand All @@ -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 => "&",
}
)
}
}

Expand Down Expand Up @@ -155,7 +163,7 @@ fn rule_term(input: &mut Input) -> Result<Node, Error> {
return Err(Error {
span: group.span(),
problem: "can only use '(..)' or '{..}'".into(),
})
});
}
}
}
Expand All @@ -171,7 +179,7 @@ fn rule_term(input: &mut Input) -> Result<Node, Error> {
return Err(Error {
span: tt.span(),
problem: "this is an invalid term".into(),
})
});
}
};

Expand Down
10 changes: 5 additions & 5 deletions ecdsa_fun/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name = "ecdsa_fun"
version = "0.11.0"
authors = ["LLFourn <lloyd.fourn@gmail.com>"]
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"
Expand All @@ -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"
Expand All @@ -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"]


Expand Down
6 changes: 3 additions & 3 deletions ecdsa_fun/benches/bench_ecdsa.rs
Original file line number Diff line number Diff line change
@@ -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!!!";
Expand Down Expand Up @@ -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();
Expand Down
25 changes: 16 additions & 9 deletions ecdsa_fun/src/adaptor/encrypted_signature.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -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<EncryptedSignature> {
bincode::deserialize(&bytes[..]).ok().map(EncryptedSignature)
bincode::decode_from_slice(&bytes[..], bincode::config::legacy()).ok().map(|(v,_)| EncryptedSignature(v))
}
}

Expand Down Expand Up @@ -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::<EncryptedSignature>(&serialized[..]).unwrap();
let (deseriazed, _) = bincode::decode_from_slice::<
bincode::serde::Compat<EncryptedSignature>,
_,
>(&serialized[..], bincode::config::standard())
.unwrap();

assert_eq!(deseriazed, encrypted_signature);
assert_eq!(deseriazed.0, encrypted_signature);
}
}
19 changes: 11 additions & 8 deletions ecdsa_fun/src/adaptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading