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

Add frost-secp256k1-tr crate (BIP340/BIP341) #584

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b380fd5
add frost-secp256k1-tr crate (BIP340/BIP341)
zebra-lucky Nov 20, 2023
ab6b0d0
run cargo fmt on frost-secp256k1-tr
zebra-lucky Dec 25, 2023
8204166
fix use of tweaked public key
mimoo Dec 27, 2023
a307130
additional fixes for use of tweaked pubkey
zebra-lucky Jan 10, 2024
6d8be7c
give more consistent names to taproot functions
zebra-lucky Dec 26, 2023
20da59a
add DKG vector test for frost-secp256k1-tr
zebra-lucky Jan 11, 2024
00cdfe5
cargo fmt
conradoplg Feb 5, 2024
bdc8fb4
fix gencode-related issues
conradoplg Feb 6, 2024
a66b9a2
clippy fixes
conradoplg Feb 6, 2024
142556f
Refactor Ciphersuite taproot methods for universal applicability (#2)
conduition Feb 21, 2024
0ed163f
fix docstrings in frost-core/src/traits.rs
zebra-lucky Feb 22, 2024
c63a3ca
update frost-secp256-tr code to changes from 1.0.0
zebra-lucky Feb 24, 2024
e5b3f5d
encapsulate BIP341 tapscript commitment in new SigningTarget type
conduition Mar 2, 2024
155dfa6
add effective_key method to VerifyingKey
conduition Mar 2, 2024
1268f5c
Fix typo for VerifyingKey.effective_key
zebra-lucky Mar 5, 2024
1c085ba
remove debugging assert_eq from tests/vectors.rs
zebra-lucky Mar 6, 2024
c1b8663
fix reference to SigningTarget.message instead of cloned signing target
conduition Mar 16, 2024
8f52646
remove unneeded Into invocation
conduition Mar 16, 2024
5d2d683
fix reference to internal function
conduition Mar 16, 2024
20c2c98
add integration tests to cover taproot-tweaked signing
conduition Mar 16, 2024
15688ab
ensure taproot signatures always use even nonce points
conduition Apr 24, 2024
d580241
serialize taproot signatures as 64 bytes with x-only nonce
conduition Apr 24, 2024
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
Prev Previous commit
Next Next commit
fix gencode-related issues
  • Loading branch information
conradoplg authored and zebra-lucky committed Feb 24, 2024
commit bdc8fb4cbffb5dfbe99ca807876f1e1b1aa7890f
1 change: 1 addition & 0 deletions frost-core/src/round2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ where
/// [`verify_signature_share`]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-14.html#name-signature-share-verificatio
#[cfg_attr(feature = "internals", visibility::make(pub))]
#[cfg_attr(docsrs, doc(cfg(feature = "internals")))]
#[allow(clippy::too_many_arguments)]
pub(crate) fn verify(
&self,
identifier: Identifier<C>,
Expand Down
2 changes: 1 addition & 1 deletion frost-secp256k1-tr/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
An implementation of Schnorr signatures on the secp256k1 curve for both single and threshold numbers
of signers (FROST) with support of Taproot (BIP340/BIP341).
of signers (FROST).

## Example: key generation with trusted dealer and FROST signing

Expand Down
2 changes: 1 addition & 1 deletion frost-secp256k1-tr/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
use rand::thread_rng;

use frost_secp256k1::*;
use frost_secp256k1_tr::*;

fn bench_secp256k1_batch_verify(c: &mut Criterion) {
let mut rng = thread_rng();
Expand Down
14 changes: 7 additions & 7 deletions frost-secp256k1-tr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ const CONTEXT_STRING: &str = "FROST-secp256k1-SHA256-TR-v1";
pub struct Secp256K1Sha256;

/// Digest the hasher to a Scalar
pub fn hasher_to_scalar(hasher: Sha256) -> Scalar {
fn hasher_to_scalar(hasher: Sha256) -> Scalar {
let sp = ScalarPrimitive::new(U256::from_be_slice(&hasher.finalize())).unwrap();
Scalar::from(&sp)
}

/// Create a BIP340 compliant tagged hash
pub fn tagged_hash(tag: &str) -> Sha256 {
fn tagged_hash(tag: &str) -> Sha256 {
let mut hasher = Sha256::new();
let mut tag_hasher = Sha256::new();
tag_hasher.update(tag.as_bytes());
Expand All @@ -206,7 +206,7 @@ pub fn tagged_hash(tag: &str) -> Sha256 {
}

/// Create a BIP341 compliant taproot tweak
pub fn tweak(
fn tweak(
public_key: &<<Secp256K1Sha256 as Ciphersuite>::Group as Group>::Element,
merkle_root: &[u8],
) -> Scalar {
Expand All @@ -217,19 +217,19 @@ pub fn tweak(
}

/// Create a BIP341 compliant tweaked public key
pub fn tweaked_public_key(
fn tweaked_public_key(
public_key: &<<Secp256K1Sha256 as Ciphersuite>::Group as Group>::Element,
merkle_root: &[u8],
) -> <<Secp256K1Sha256 as Ciphersuite>::Group as Group>::Element {
let mut pk = public_key.clone();
let mut pk = *public_key;
if public_key.to_affine().y_is_odd().into() {
pk = -pk;
}
ProjectivePoint::GENERATOR * tweak(&pk, merkle_root) + pk
}

/// Creates a real BIP341 tweaked public key by assuming an even y-coordinate.
pub fn real_tweaked_pubkey(
fn real_tweaked_pubkey(
public_key: &<<Secp256K1Sha256 as Ciphersuite>::Group as Group>::Element,
merkle_root: &[u8],
) -> <<Secp256K1Sha256 as Ciphersuite>::Group as Group>::Element {
Expand All @@ -240,7 +240,7 @@ pub fn real_tweaked_pubkey(
}

/// Create a BIP341 compliant tweaked secret key
pub fn tweaked_secret_key(
fn tweaked_secret_key(
secret: <<<Secp256K1Sha256 as Ciphersuite>::Group as Group>::Field as Field>::Scalar,
public_key: &<<Secp256K1Sha256 as Ciphersuite>::Group as Group>::Element,
merkle_root: &[u8],
Expand Down
2 changes: 1 addition & 1 deletion frost-secp256k1-tr/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn check_sign_with_dealer_fails_with_invalid_max_signers() {
/// This is testing that Shamir's secret sharing to compute and arbitrary
/// value is working.
#[test]
fn check_share_generation_secp256k1_sha256() {
fn check_share_generation_secp256k1_tr_sha256() {
let rng = thread_rng();
frost_core::tests::ciphersuite_generic::check_share_generation::<Secp256K1Sha256, _>(rng);
}
Expand Down
4 changes: 2 additions & 2 deletions gencode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ fn main() -> ExitCode {
"Secp256K1",
"FROST(secp256k1, SHA-256)",
"FROST-secp256k1-SHA256-TR-v1",
"secp256k1_sha256",
"secp256k1",
"secp256k1_tr_sha256",
"secp256k1_tr",
"<S>",
],
),
Expand Down