Skip to content

Implement signature grinding #695

@evanlinjin

Description

@evanlinjin

Describe the bug
BDK does not do signature grinding for ecdsa signatures.

Expected behavior
BDK should have signature grinding.

Additional context

This is what BDK currently does.

bdk/src/wallet/signer.rs

Lines 460 to 463 in a147740

let sig = secp.sign_ecdsa(
&Message::from_slice(&hash.into_inner()[..]).unwrap(),
secret_key,
);

But we have this to use.

https://github.com/rust-bitcoin/rust-secp256k1/blob/7fde3325075f16ec4b8c2c624fee523cc5225047/src/ecdsa/mod.rs#L341-L344

    /// Constructs a signature for `msg` using the secret key `sk`, RFC6979 nonce
    /// and "grinds" the nonce by passing extra entropy if necessary to produce
    /// a signature that is less than 71 - `bytes_to_grind` bytes. The number
    /// of signing operation performed by this function is exponential in the
    /// number of bytes grinded.
    /// Requires a signing capable context.
    pub fn sign_ecdsa_grind_r(&self, msg: &Message, sk: &SecretKey, bytes_to_grind: usize) -> Signature {
        let len_check = |s : &ffi::Signature| der_length_check(s, 71 - bytes_to_grind);
        self.sign_grind_with_check(msg, sk, len_check)
    }

More context

After we are certain that the BDK ECDSA signer(s) implementation uses signature grinding, we should optimize fee-rate calculation to take into consideration of grinding.

Do we need another signer method to inform whether the signer does ecdsa signature grinding?

Metadata

Metadata

Labels

discussionThere's still a discussion ongoingnew featureNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions