I signed a bitcoin testnet transaction using nbitcoin library and got an output:


then I signed the same transaction with bitcoin-core and it returned an output :


On comparing the outputs, the txwitness stack value differs.

bitcoin-core witness data

"txinwitness": [

nBitcoin witness data

 "txinwitness": [

But still, I'm able to send the transaction signed by nBitcoin.

So my questions are:

1) what are the values in witness stack?

2) why the same transaction have different txwitness value?

1 Answer 1


Bitcoin signatures have two components: s and R. To sign a Bitcoin transaction with private key k, the signing algorithm generates an ephemeral private key r. The R component of the signature is the x-coordinate of that ephemeral public key. The s component of the signature is calculated in the following way: s = r-1 (Hash(m) + k * R) mod p; where Hash(m) is the hash of the transaction data m.

Since, s changes with r, as shown in the equation above, the signature component will be completely different when you compare two transactions signed if their ephemeral key generation algorithm differs.

Most softwares uses RFC 6979 to deterministically but securely generate the ephemeral key used to sign transactions. So for two identical transactions, the ephemeral key should be the same and that is the reason you are seeing the same signatures on different Bitcoin Core software. However, RFC 6979 algorithm also allows the usage of other additional optional data while generating the ephemeral key. This additional optional data might be different for different softwares and as a result you are seeing different (s,R) signature from Bitcoin-Core and nBitcoin.

  • What is P in this equation s = r-1 (Hash(m) + k * R) mod p ?
    – Akshay Dev
    Dec 18, 2019 at 11:10
  • If S changes with R, why bitcoin core, even on different machines produce the same signature?
    – Akshay Dev
    Dec 18, 2019 at 11:12
  • 1
    @AkshayDev I have updated my answer to make it more clear. The mod p (modulo prime number p) indicates that the Bitcoin curve (secp256k1) is over a finite field of prime order p.
    – Ugam Kamat
    Dec 18, 2019 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.