OutCast3k / coinbin

Javascript Bitcoin Wallet. Supports Multisig, Stealth, HD, SegWit, Bech32, Time Locked Addresses, RBF and more!
https://coinb.in/
MIT License
905 stars 621 forks source link

[bug] 2:3 multisig transaction decode not shown correctly #212

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hey outcast3k,

when using this multisig (2:3) transaction:

unsigned:

0200000001304233ceb9331ae0c98c5cefea9b30f4ed3811dc8aca471d31671e8853a5b0530100000000ffffffff0132e00000000000001976a9146e6a71a663b9952ed8af1aa456997cf52f14c20388ac00000000

signed:

0200000001304233ceb9331ae0c98c5cefea9b30f4ed3811dc8aca471d31671e8853a5b05301000000b500473044022065ad415e3b8b232432193e9727ae51a65015a16229652eb9f9a0f5038b2a93e602205c88b803c7e9391b7c9902e9cf30daa0f52491410ebe9d80cd03146267c5ad7801004c69522102ab224d0d8de7d5ad5568bf4f66b9c29ea7afd0f196176f9b09a311c11da6377e2102d8adfda5e3266bc9f237c67135f795e069dabe594a39f2908e666d27c4e000fe2102f485412017ef4fba059a514e3d90d95c1b0f3dced6ab158ef697127a8a1cb58e53aeffffffff0132e00000000000001976a9146e6a71a663b9952ed8af1aa456997cf52f14c20388ac00000000

and trying to verify it I see no details about being a multisig transaction: Alt text

As soon as I sign the the transaction with one key and decode it again I get: Alt text

this is incorrect too, since the transaction was only signed by one key, not by two. Transaction was generated using bitcoind:

  "version": 190001,
junderw commented 4 years ago

bitcoind and coinbin are not compatible.

You must generate the unsigned tx with coinbin, and do all the signatures with coinbin. Once all signatures are complete you can broadcast using coinbin OR bitcoind.

ghost commented 4 years ago

@junderw using an older version of bitcoind it was compatible, are there any plans to include compatibility?

junderw commented 4 years ago

PSBT was created to fix this problem. But bitcoind even has limited PSBT support.

@OutCast3k I made a library called bip174 for PSBT, if you want to bundle that and include it, we can use it in a similar fashion to bitcoinjs-lib to create a very functional PSBT implementation for coinbin.

junderw commented 4 years ago

@OutCast3k or if you just want to bundle in bitcoinjs-lib you can have the whole PSBT class with all the bells and whistles.

ghost commented 4 years ago

@junderw Running an older version of bitcoind is not causing this problem, maybe you can use the generated TX above to check if the issue is related to PSBT and solved by your library, I'm unsure about this, since it was working before with the older version of bitcoind, seems like you're more in involved in the bitcoin protocol.

junderw commented 4 years ago

tl;dr PSBT is a standard for formatting unsigned transactions.

Until PSBT was designed, bitcoind would randomly change the format since the only format that matters is the format for SIGNED transactions.

So rather than playing cat and mouse with bitcoind, adding PSBT support will be better in the long run. But you would need to use a special RPC to get the unsigned transaction to come out as a PSBT. (iirc)

ghost commented 4 years ago

@junderw Can you provide more details about how to the RPC interface and what commands to call?

Creating and signing raw transactions in general is known by me.

junderw commented 4 years ago

@OutCast3k looks like the Gzipped bundle for bip174 is 6kB and bjs-lib is 85.4kB...

bip174 + some glue code should be enough to allow for PSBT creation / signing / extracting of signed transaction...

But the interface for the end user would need to be overhauled.

If you are willing to come up with an idea for how we plug it in, I would be willing to help with writing the glue code.

junderw commented 4 years ago

@Devrandomuser Read the docs: https://github.com/bitcoin/bitcoin/blob/master/doc/psbt.md

ghost commented 4 years ago

@OutCast3k Any decision already?

OutCast3k commented 4 years ago

Its not possible to determine if your unsigned transaction is used for a multisig address

however I have modified the code to make it better handle signed transactions and will release this update very shortly.

thanks

OutCast3k commented 4 years ago

closed. fix is live.