-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix transaction creation and signing #2
Comments
@ofek, @fyookball, @bjarnemagnussen, wanted to let you know about the bounty in case you were interested. Thank you for your help already. |
Since the segwit branch contains a lot of segwit soecific code I think that the cleanest way would be to start with ofek's bit branch and then change the signature generation algorithm found inside |
Ah, heh. I guess that makes more sense then. For me, I'm not worried about script hash, multisig, or anything like that. I appreciate your feedback. If no one jumps on this today I'll probably try that tomorrow. Thank you! |
Library is now based on the original bit. Will work from there. |
I tried to broadcast a transaction with electron-cash and it said FORKID had to be used. Understandable. I added that in and it says the same thing. Also with blockdozer it says I must use the FORKID. I am not sure if they are throwing a generic error message or if it's not working how I expect it to. Judging by some older testing, it seems like multiple error types are possible: https://bitcoin.stackexchange.com/questions/63340/cannot-make-valid-bitcoin-cash-transaction/63345 I know I need to make it BIP-143, I am first wondering how I can inspect the signature and whether these error codes are generic or specific and something else is wrong. |
I believe I've implemented in the logic. I am hardcoding sequence numbers as I don't know their purpose and everywhere I've seen has them set at 2^32. In e126766 I am able to generate transactions again. blockdozer says the SIGHASH_FORKID is bad, electron-cash says it's missing inputs. Deserializing in electron-cash looks just fine. I don't know if any good utilities to inspect signatures with. Would appreciate any help you can give. |
i took a look at your transaction.py and it seems to define SIGHASH_FORKID constant and then never uses it ? |
Thanks for taking a look. Yes, I have it defined as a stub. I will use it in the future but Python 3 doesn't have bitwise operations on bytes objects. Instead, I am setting 0x41 instead of 0x01 as the hash type. |
I now have just a CHECK(MULTI)SIG error which I am working through, looking at the spec closely. |
@bjarnemagnussen is this correct? https://github.com/bjarnemagnussen/bit/blob/segwit/bit/transaction.py#L444 I can see that you have scriptCode_len before scriptCode. That does not line up with the specification from what I can tell: https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki Not sure if there's a bug or if I am missing something. |
Pushed a couple small tweaks and am stopping for the night. No luck so far. Signature is still bad. I found the "official" Bitcoin Cash signature doc which looks identical to BIP-143 from what I can tell. https://github.com/Bitcoin-UAHF/spec/blob/master/replay-protected-sighash.md |
Hey @teran-mckinney. Regarding the //Edit2: Actually also using P2PKH I think you need the scriptCode_len. See this step-by-step but using the old signature scheme: https://bitcoin.stackexchange.com/questions/32628/redeeming-a-raw-transaction-step-by-step-example-required |
you could also create the same TX in electron cash and step through to see where your code diverges |
Thank you, to both of you. I'm narrowing down the only difference to the hashOuputs. The source is the same, the hash is different. I think there's some slight nuance I'm missing. |
It works!!! Thank you all for your help. You can see the stupid bug that was there. Real pain to debug. Took me a few days. I'm glad to have this working so I can start using Bitcoin Cash now. |
Implemented rest.bitcoin.com API support
Right now our inputs are all messed up. Outputs look kind of okay.
Here's a transaction generated from this script:
Output:
Deserialized:
That was deserialized as mainnet so the addresses are wrong.
I ported this over from https://github.com/bjarnemagnussen/bit/tree/segwit, which is in turn a fork of ofek's bit library.
I am also using electron-cash as a reference: https://github.com/fyookball/electrum/blob/cash/lib/transaction.py
And I should probably understand this better: https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki
I dont know if it would make more sense to start with the original bit or the bit segwit branch. I think we need BIP-143 signatures and a 0x41 hash type for pay to public hash.
I am really lost on this. Would hugely appreciate help on this.
If you can get this library working (getting send() to work, ultimately), I'll pay you $300 USD equivalent of BCH.
Thanks,
Teran
The text was updated successfully, but these errors were encountered: