Closed dangershony closed 3 years ago
A quick solution is to add a flag to SigningOptions
that will not grind (or will ignore the IsHigh
condition)
The problem seems to be that you are using enforceLowR = true
when you really are okay with low and high Rs. Try passing enforceLowR = false
.
Btw, this is what the IsHigh
and enforceLowR
is abaout: https://github.com/bitcoin/bitcoin/pull/13666
Try passing enforceLowR = false. Ah lol of course how did I not associate that flag 😜 I will try the flag.
Thanks for the link mate.
That was my issue thanks @lontivero for the help 👍
We grind the signature to save 1 byte per sig.
It seems EC sig is not always deterministic but still valid.
When I try to sign one of the BOLT test vectors in a 2_of_2 P2WSH commitment transaction one of the signature payload does not match the test vector.
The excepted witness redeem script:
The result using NBitcoin Secp256k1 signing code
Notice the second signature in the redeem script is not the same
I narrowed it down to the grinding part of the signature (in the
ECPrivKey
extension methodSign
:When signing the first key that produces a similar sig as the test vector the while loop is not triggered
When signing the second key with a different sig
Then we go in the while loop for a second attempt at signing that the reason the sig is different. In a test I wrote if I ignore the
sig.r.IsHigh = true
condition and skip the loop then I get the expect sigWhat is the purpose of
sig.r.IsHigh
? Shall I try to change the code so we pass a flag that allow to ignore it? (what are the security implications?)We need a cryptographer... 🤔 🆘 😱