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

fix(frost-secp256k1-tr): empty merkle root tweak should still hash the x-only pk #815

Merged
merged 1 commit into from
Dec 30, 2024
Merged
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
27 changes: 11 additions & 16 deletions frost-secp256k1-tr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ fn tweak<T: AsRef<[u8]>>(
merkle_root: Option<T>,
) -> Scalar {
match merkle_root {
None => Secp256K1ScalarField::zero(),
None => {
let mut hasher = tagged_hash("TapTweak");
hasher.update(public_key.to_affine().x());
hasher_to_scalar(hasher)
}
Some(root) => {
let mut hasher = tagged_hash("TapTweak");
hasher.update(public_key.to_affine().x());
Expand Down Expand Up @@ -481,10 +485,9 @@ impl Ciphersuite for Secp256K1Sha256TR {
// > key should commit to an unspendable script path instead of having
// > no script path. This can be achieved by computing the output key
// > point as Q = P + int(hashTapTweak(bytes(P)))G.
let merkle_root = [0u8; 0];
Ok((
key_package.tweak(Some(&merkle_root)),
public_key_package.tweak(Some(&merkle_root)),
key_package.tweak::<&[u8]>(None),
public_key_package.tweak::<&[u8]>(None),
))
}
}
Expand Down Expand Up @@ -862,12 +865,8 @@ pub mod round2 {
key_package: &keys::KeyPackage,
merkle_root: Option<&[u8]>,
) -> Result<SignatureShare, Error> {
if merkle_root.is_some() {
let key_package = key_package.clone().tweak(merkle_root);
frost::round2::sign(signing_package, signer_nonces, &key_package)
} else {
frost::round2::sign(signing_package, signer_nonces, key_package)
}
let key_package = key_package.clone().tweak(merkle_root);
frost::round2::sign(signing_package, signer_nonces, &key_package)
}
}

Expand Down Expand Up @@ -904,12 +903,8 @@ pub fn aggregate_with_tweak(
public_key_package: &keys::PublicKeyPackage,
merkle_root: Option<&[u8]>,
) -> Result<Signature, Error> {
if merkle_root.is_some() {
let public_key_package = public_key_package.clone().tweak(merkle_root);
frost::aggregate(signing_package, signature_shares, &public_key_package)
} else {
frost::aggregate(signing_package, signature_shares, public_key_package)
}
let public_key_package = public_key_package.clone().tweak(merkle_root);
frost::aggregate(signing_package, signature_shares, &public_key_package)
}

/// A signing key for a Schnorr signature on FROST(secp256k1, SHA-256).
Expand Down
Loading