OutCast3k / coinbin

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

TImelock address confusion - Guide not clear, or broken? #171

Closed neocogent closed 5 years ago

neocogent commented 5 years ago

I've been trying a simple Timelock address test using <$1 to see if I understand how it works. I just used the New, Timelock Address menu item and created the redeem script. I funded a small amount on that address.

To test that I can send from the timelock address I am now trying to sign and broadcast a tx in Electrum (because that is where I can easily use my Trezor). I used the redeem script on Coinb.in to create a tx (on Coinb.in) paying from that hodl address to my own address. I cpy/paste to load that raw tx data into Electrum. It all seems to work and I can view and sign the tx fine in Electrum. But when broadcast it always gives an error Error: 64: scriptsig-not-pushonly returned by the network.

I then found your guides and checked that process. It seems to be the same but step 5 does not give details on how to correctly create the spending tx. I may have done this wrong but I'm unsure. Can this guide be clarified if there is anything unusual? For example, during redeem script verification there is a field "required signature" with address but I've no idea where to use that or if even needed.

I get a p2sh address 3... for hodl address but a 1... for signature address. I tried creating a tx from the hodl address to my own new address. This is the one giving an error. Should the tx instead be paying from the 1... address? I sign with my Trezor, so it is using the private key for the 3... address. Not sure if it can sign from a 1... address.

I am currently testing this before the timelock expires. Soon I can test again after the timelock is reached. Is this maybe the only reason it gives an error? In any case, it would help greatly if the Timelock guide could detail the correct way to make a tx in this scenario.

Thanks for reading and any help here.

(btw - I also tried to do this on testnet but it seems the coinb.in tx creator cannot currently load inputs to spend from the bitcoin testnet. So I was blocked at that point. I don't know how to use the redeem script in some other way than on the coinb.in tx page)

junderw commented 5 years ago

The Transaction serialization for Electrum and Coinbin is different. This has been mentioned many times before in other issues.

Any issues with transactions that were not 100% created, signed, and broadcasted using coinbin are not supported, and any debugging should be done on your own.

If you have technical questions that deal with how a timelock script works in general you could ask that... but asking why mixing two different wallets with no guarantee to be compatible... are not compatible... would require someone who is familiar with coinbins source going over and becoming familiar with Electrum's source or vice versa.

You will get a quicker and more detailed reply if you avoid questions that require the answerer to do some footwork to find out what's wrong for you.

My suggestion is doing the footwork, figuring out a more fundamental difference between the parsers of both tools and if you run into questions on how coinbin works along that path, we can answer that and maybe electrum's community could answer questions on their's.

Or you can wait until a kind stranger (someone who is familiar with both coinbin and Electrum) comes along and gives you an answer................ which will take a looooong time...

neocogent commented 5 years ago

Thanks for your reply.

I did look further into it after my trouble trying to bridge between the two wallets. The reason I was trying to do this is because I wanted to find a way to use this tool to create a CLTV tx with my Trezor without being able to provide a privkey to Coinb.in (even if used offline). Electrum would have worked for that except by digging into the source I found it cannot handle any CLTV script at all. It does not have the code to recognize a non-standard script and sign it. Due to it's own code it sees this tx as being already signed when it is not. That got me confused as it said it was signed when indeed it wasn't and it allowed it to be broadcast.

Anyway, I've spent the last couple days working on a plugin for Electrum. I'm calling it Time Machine and it will allow creating and managing CLTV addresses and spending from them. I'm using Coinb.in to test and keep compatible the addresses between the two (though I think raw tx code will not be). I did get Coinb.in to work later but only when I signed the tx within Coinb.in. After signed the tx can be broadcast in Electrum (not that doing that is of any benefit since the priv key would still need to be exported to be used in Coinb.in).

So far I have been able to create CLTV addresses in my plugin and next will work on the code needed to sign a spend tx. I will try to keep it compatible so that users might bridge between the two when useful. I did quite a bit of reading and digging in to this script type and how to make it work. This issue prompted me to figure it out so maybe in future others will benefit from that.

OutCast3k commented 5 years ago

Hi there,

It seems a bug existed when building at transaction which prevented you spending from a timelocked address. Your funds are totally safe, the bug is in the creation of the transaction not the address.

I've just fixed it and issued a few updates.

Please try again with the latest update, all my tests seem to show its working.