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

Transaction verify not working. #172

Closed username1565 closed 5 years ago

username1565 commented 5 years ago
  1. https://coinb.in/#verify
  2. 010000000001a0860100000000001976a9145700e52bce4a0fceca7646a9614a46c2f364559f88ac00000000
  3. Submit Result: Unable to decode
  4. https://ttutdxh-nubits.github.io/cointoolkit/#verify
  5. Change mode - select BitCoin.
  6. 010000000001a0860100000000001976a9145700e52bce4a0fceca7646a9614a46c2f364559f88ac00000000
  7. press "Verify" button. Result: Success decoding raw transaction.

Source code: https://github.com/ttutdxh-nubits/cointoolkit


Also in coinbin-v1.2a from releases transaction verify working good, but in coinbin-v1.3 this is not working.

Fix this, please.


P.S.: You can fix this, using next code:

  1. coinbin.js:
    function decodeTransactionScript(){//...
    //if (decode.witness.length>=1) {
    if (typeof decode.witness !== 'undefined' /*exclude undefined for non-segwit transaction*/
    && decode.witness.length>=1) {
  2. coin.js:
    var obj = new coinjs.transaction();
    obj.version = readAsInt(4);
    //console.log(obj.version);
    //if(buffer[pos] == 0x00 && buffer[pos+1] == 0x01){
    if(obj.version!==1 /*or another identificator to exclude not segwit transaction*/
    && buffer[pos] == 0x00 && buffer[pos+1] == 0x01){
    // segwit transaction
username1565 commented 5 years ago

Also you can merge your code with this web-wallet: https://github.com/ttutdxh-nubits/cointoolkit and combine the functions, which is working there.

junderw commented 5 years ago

Didn't work on either.

_001

junderw commented 5 years ago

First of all, any tx with 0 inputs are invalid. Even coinbases have 1 dummy input... a 0 input count is an invalid transaction.

Second of all, Segwit uses the above fact to make an un-parseable transaction so that old nodes don't choke on a segwit transaction. They will see the input count is zero and not even attempt to parse the rest. (Remember, the C++ logic for Bitcoin Core parses bytes as they come in sequential order)

Sooo, if your site says "Verified" for an invalid transaction... your site is broken.

# READ AS NON-SEGWIT TX
# version
01000000
# input count = 0
00
# output count = 1
01
# first output satoshis count
a086010000000000
# first output scriptPubkey
1976a9145700e52bce4a0fceca7646a9614a46c2f364559f88ac
# TimeLock
00000000

# READ AS SEGWIT TX
# version
01000000
# SEGWIT MARKER
00
# SEGWIT FLAGS
01
# INPUT COUNT (=0xa0 =160 means we have to parse 160 inputs from now on.) 
a0
# first input prevTxid
860100000000001976a9145700e52bce4a0fceca7646a9614a46c2f364559f88
# first input prevTxOut (=0xac =172 meaning you are spending the 173rd output of the above txhash tx)
ac000000
# ScriptSig Length = 0
00
# Skip scriptSig parse
....
# nSequence....... is nowhere to be found
junderw commented 5 years ago

So wherever you got this tx data from is broken... it just made you a non-segwit transaction with 0 inputs, and Coinbin rightfully tried to say "oh ok, so it's a segwit tx then" and then choked on your transaction as soon as it found no nSequence for the first input... "Hey, your data just stopped suddenly... ok error time"

username1565 commented 5 years ago

Didn't work on either.

Just switch mode to "Bitcoin". decode_signed_raw_transaction Here you can decode this too: https://txid.io/wallet/#verify

How I got this transaction?

  1. Go here: https://username1565.github.io/brainwallet.github.io/#tx
  2. Private key: 5HsGGnRCbQ8hjjeL5Hi38vrMTzbSqzNtUjJ1JxF1qFwAzjV4KJ1
  3. Source Address: 18w2rtYxYse12po93P1dkf8QnW8DaYqRTD
  4. Destination Address: 18w2rtYxYse12po93P1dkf8QnW8DaYqRTD
  5. Amount: 0.001 BTC As result, Raw Transaction: 010000000001a0860100000000001976a9145700e52bce4a0fceca7646a9614a46c2f364559f88ac00000000

Of course, this is not segwit transaction, but brainwalletx is client-side and open source. Anyone can do fork and fix this or add support of segwit transactions.


P.S.: I just want to make myself, the correctly signed raw transactions, but on client-side, offline and in the browser, and then, when I'll be online I can do broadcast this tx to the miners, using online services, like this or this or just using coinb.in API for example, using some get-query, like this (TX decode failed).

But I don't see any web-wallet where I can do this correctly, and verify then. BrainwalletX being developed to support offline transactions, but this is still not perfect... For example, there, I cann't re-sign transaction to inject another signature, and I cann't see decoded scripts...

I don't understand segwit-innovations, but I think this may to be the backward compatible with the very first format of transactions...

junderw commented 5 years ago

Please read what I said:

The transaction you posted is an invalid format and can not be parsed by a proper application.

Any application that looks at that data and says "this is a valid transaction format" is wrong. The fact that is says "OK" when it SHOULD say "WRONG" means that the app is wrong.

Coinbin is correct here.

junderw commented 5 years ago

Here is the simplest English I can say:

This hex data:

"010000000001a0860100000000001976a9145700e52bce4a0fceca7646a9614a46c2f364559f88ac00000000"

is not a Bitcoin transaction.

Coinbin is right.

Brainwalletx and cointoolkit are wrong.

username1565 commented 5 years ago

@junderw Ok, thanks. If you have free time, you can do fork and rewrite this client-side applications, just for fun, and open the pull requests. Bitcoin documentation is very hard to read and understanding.