ACINQ / bitcoin-lib

Simple bitcoin library written in Scala
Apache License 2.0
111 stars 50 forks source link

Bitcoin-lib may produce valid but different signatures from bitcoin-core #25

Open araspitzu opened 6 years ago

araspitzu commented 6 years ago

There is a scenario where the signature produced by bitcoin-lib is different than the one made by bitcoin-core, it's a legacy multisig (P2SH) with 2-of-2 signatures required. For clarity i reproduced the issue in bitcoin using regtest mode and comparing the produced scriptSig with the one from bitcoin-lib, the example is located here, to run the test:

$ test/functional/regtest_signature.py

The test in bitcoin-lib tries to sign the same input of the same transaction (also with same private keys) and results in a mismatch of the signature (specifically the last in the 2-of-2), this is located here.This test shows that the signature script (for legacy p2sh multisig) produced in this case is different from the one made by bitcoin-core. I also added sighash tests (both in bitcoin-core and bitcoin-lib) to check that we're signing the same data, those test can be found in the same git branch of the above examples.

sstone commented 6 years ago

Bitcoin-lib still creates valid signatures, but they may be different from the ones created by bitcoin core since https://github.com/bitcoin/bitcoin/commit/18dfea0dd082af18dfb02981b7ee1cd44d514388. AFAICT none of the reference tests depend on creating exactly the same sigs and will still pass, but I guess that in some cases in may make the life of lib developers a bit harder. Reproducing exactly the same behaviour is not so easy yet because first the JNI bindings for libsecp256k1 would have to be updated, so I'll leave this issue open in case someone wonders why our sigs may be different from core's. Thanks for the test data!