broadcasting error for raw bitcoin transaction testnet

0

I am trying to create a raw transaction and send it to the testnet. I am using testnet keys and here is the simplified readable output from my script:

decoded private key:  efd0171bc0e1a973c75d97cdf38ecccfb2e70227a23cfcdadfed8d9dd1f198c6dc

testnet private ky =  d0171bc0e1a973c75d97cdf38ecccfb2e70227a23cfcdadfed8d9dd1f198c6dc

Receiver public key:   a4842eed5a2c6fd7b71a238632f268d5831dacc0

out1Script:  76a914a4842eed5a2c6fd7b71a238632f268d5831dacc088ac
out1 script length in bytes =  25

My public key:  2431e05399f655c52f2e7ab6227837c94d450312
out2Script:  76a9142431e05399f655c52f2e7ab6227837c94d45031288ac
out2 script length in bytes =  25

Message to sign:  f1c7146e665f9b59a6cce31526d85abb2d76859ba13219e9f8cf8e0d51051e45

my pub k without 04 part added:  be13acda02dc89ebd1ab87030750b694563c7dac7ebc53b541178e6d04cda33215d712406ff8b705607312d5fea471e9855dbcb963efb63a54e7efeb36382881
pub k len:  128 that is 64 byte long

signatureeeee:  30450221008eaa588a4037a1cd87115853ad28fc215b0ba2cfa7b1327675563bbd971939e302204d245c9092f0c28f3f31ad1bcccb4aef5c7fe718d2a20c39a94358eb8b61845c
signature lenght:  142

verify signatureeeee with pub key without '04' added that is derived directly from private key:  True

wif pub ky:  2431e05399f655c52f2e7ab6227837c94d450312
pub ky from pr ky:  be13acda02dc89ebd1ab87030750b694563c7dac7ebc53b541178e6d04cda33215d712406ff8b705607312d5fea471e9855dbcb963efb63a54e7efeb36382881

sigscript:  4830450221008eaa588a4037a1cd87115853ad28fc215b0ba2cfa7b1327675563bbd971939e302204d245c9092f0c28f3f31ad1bcccb4aef5c7fe718d2a20c39a94358eb8b61845c014104be13acda02dc89ebd1ab87030750b694563c7dac7ebc53b541178e6d04cda33215d712406ff8b705607312d5fea471e9855dbcb963efb63a54e7efeb36382881
sigscript lennn:  278
pubky len in sigscript:  65

Formatting of real transaction:

version------------------- 01000000
transaction used---------- 01
transaction out Hex------ 245d84ae31c473495d2ba9b3a57b44196d634acf8a8d689960550345422a01fd
transaction out index----- 00000000
signing script size------- 8b
sigScript----------------- 4830450221008eaa588a4037a1cd87115853ad28fc215b0ba2cfa7b1327675563bbd971939e302204d245c9092f0c28f3f31ad1bcccb4aef5c7fe718d2a20c39a94358eb8b61845c014104be13acda02dc89ebd1ab87030750b694563c7dac7ebc53b541178e6d04cda33215d712406ff8b705607312d5fea471e9855dbcb963efb63a54e7efeb36382881

-----sigscript formatting----

sig size---- 48

signature--- 30450221008eaa588a4037a1cd87115853ad28fc215b0ba2cfa7b1327675563bbd971939e302204d245c9092f0c28f3f31ad1bcccb4aef5c7fe718d2a20c39a94358eb8b61845c

how this script applies----- 01

pub ky len--- 41

pub key-- 04be13acda02dc89ebd1ab87030750b694563c7dac7ebc53b541178e6d04cda33215d712406ff8b705607312d5fea471e9855dbcb963efb63a54e7efeb36382881

this pub key is 65 byte long dueto '04' added
---end sigscript formatting----

sequence------------------ ffffffff
no. of out trxn----------- 02
out1 value---------------- 00c4090000000000
out1 script len----------- 19
out1 Script--------------- 76a914a4842eed5a2c6fd7b71a238632f268d5831dacc088ac
out2 value---------------- c0cf6a0000000000
out2 script len----------- 19
out2 script--------------- 76a9142431e05399f655c52f2e7ab6227837c94d45031288ac
lock time----------------- 00000000

Transaction of hex string:

0100000001245d84ae31c473495d2ba9b3a57b44196d634acf8a8d689960550345422a01fd000000008b4830450221008eaa588a4037a1cd87115853ad28fc215b0ba2cfa7b1327675563bbd971939e302204d245c9092f0c28f3f31ad1bcccb4aef5c7fe718d2a20c39a94358eb8b61845c014104be13acda02dc89ebd1ab87030750b694563c7dac7ebc53b541178e6d04cda33215d712406ff8b705607312d5fea471e9855dbcb963efb63a54e7efeb36382881ffffffff0200c40900000000001976a914a4842eed5a2c6fd7b71a238632f268d5831dacc088acc0cf6a00000000001976a9142431e05399f655c52f2e7ab6227837c94d45031288ac00000000

I am using transaction in hex string to broadcast using https://live.blockcypher.com/btc-testnet/pushtx/ which shows this error:

Error validating transaction: Error running script for input 0 referencing fd012a424503556099688d8acf4a636d19447ba5b3a92b5d4973c431ae845d24 at 0: Script was NOT verified successfully..

The 0 index in that transaction is:

OP_DUP OP_HASH160 2431e05399f655c52f2e7ab6227837c94d450312 OP_EQUALVERIFY OP_CHECKSIG

tried broadcasting using: https://testnet.blockexplorer.com/tx/send which shows this error:

16: mandatory-script-verify-flag-failed (Script evaluated without error but finished with a false/empty top stack element). Code:-26

When I decode the transaction using: https://live.blockcypher.com/btc-testnet/decodetx/ it shows:

{
    "addresses": [
        "mipLNRZc9oo2fKFzhfwJVNy1t29VsqHRvS", 
        "mvWqTmhjEyMkymTm4VMFWLPQhzGwo6RPGM"
    ], 
    "block_height": -1, 
    "block_index": -1, 
    "confirmations": 0, 
    "double_spend": false, 
    "fees": 6499, 
    "hash": "28aa9b738ec668c62280c7d7cb19c1b907ec10427050902609a54264774c77ca", 
    "inputs": [
        {
            "addresses": [
                "mipLNRZc9oo2fKFzhfwJVNy1t29VsqHRvS"
            ], 
            "age": 1489541, 
            "output_index": 0, 
            "output_value": 7646499, 
            "prev_hash": "fd012a424503556099688d8acf4a636d19447ba5b3a92b5d4973c431ae845d24", 
            "script": "4830450221008eaa588a4037a1cd87115853ad28fc215b0ba2cfa7b1327675563bbd971939e302204d245c9092f0c28f3f31ad1bcccb4aef5c7fe718d2a20c39a94358eb8b61845c014104be13acda02dc89ebd1ab87030750b694563c7dac7ebc53b541178e6d04cda33215d712406ff8b705607312d5fea471e9855dbcb963efb63a54e7efeb36382881", 
            "script_type": "pay-to-pubkey-hash", 
            "sequence": 4294967295
        }
], 
    "outputs": [
        {
            "addresses": [
                "mvWqTmhjEyMkymTm4VMFWLPQhzGwo6RPGM"
            ], 
            "script": "76a914a4842eed5a2c6fd7b71a238632f268d5831dacc088ac", 
            "script_type": "pay-to-pubkey-hash", 
            "value": 640000
        }, 
        {
            "addresses": [
                "mipLNRZc9oo2fKFzhfwJVNy1t29VsqHRvS"
            ], 
            "script": "76a9142431e05399f655c52f2e7ab6227837c94d45031288ac", 
            "script_type": "pay-to-pubkey-hash", 
            "value": 7000000
        }
    ], 
    "preference": "low", 
    "received": "2019-05-02T00:31:23.148760954Z", 
    "relayed_by": "54.162.99.128", 
    "size": 258, 
    "total": 7640000, 
    "ver": 1, 
    "vin_sz": 1, 
    "vout_sz": 2
}

So far what I have found is there some sort of confusion in sigscript part because the address where coins are sent is :2431e05399f655c52f2e7ab6227837c94d450312 which is '04' added to the pub key and applied sha256 to this new key and then ripemd160, but signature can only be verified with the pubkey without the 04 part.

So now, I am not sure how to proceed further. If anyone needs the code to look I am happy to provide it.

bish

Posted 2019-05-02T06:30:01.333

Reputation: 1

Answers

0

Your signature is OK. So, something is wrong with your digest calculation

static void test_sig ( )
{
  const MyKey32 priv ( QByteArray::fromHex ( "d0171bc0e1a973c75d97cdf38ecccfb2e70227a23cfcdadfed8d9dd1f198c6dc" ) );
  const MyByteArray pub ( priv.getPublicKeyClassic ( ) );
  const MyByteArray sig ( QByteArray::fromHex ( "30450221008eaa588a4037a1cd87115853ad28fc215b0ba2cfa7b1327675563bbd971939e302204d245c9092f0c28f3f31ad1bcccb4aef5c7fe718d2a20c39a94358eb8b61845c" ) );
  const MyKey32 digest ( QByteArray::fromHex ( "f1c7146e665f9b59a6cce31526d85abb2d76859ba13219e9f8cf8e0d51051e45" ) );

  qDebug ( ) << "priv=" << priv.toHex ( ).constData ( );
  qDebug ( ) << "pub=" << pub.toHex ( ).constData ( );
  qDebug ( ) << "verify result=" << ( digest.verify ( pub, sig ) ? "passed" : "failed" );
}

Output:

priv= d0171bc0e1a973c75d97cdf38ecccfb2e70227a23cfcdadfed8d9dd1f198c6dc
pub= 04be13acda02dc89ebd1ab87030750b694563c7dac7ebc53b541178e6d04cda33215d712406ff8b705607312d5fea471e9855dbcb963efb63a54e7efeb36382881
verify result= passed

amaclin

Posted 2019-05-02T06:30:01.333

Reputation: 5 763

but how is signature is digest calculation is wrong my signature creating code: signing_ky = ecdsa.SigningKey.from_string(my_orgi_hexed_prk, curve = ecdsa.SECP256k1) verifying_ky = signing_ky.get_verifying_key() signature = signing_ky.sign_digest(hased_raw_tx, sigencode=ecdsa.util.sigencode_der_canonize)bish 2019-05-02T23:47:46.680

also the error occurs when i am trying to broadcast the the transaction . really appreciate the helpbish 2019-05-02T23:57:23.180

How did you get the digest (message to sign)? in other words, show me the hex of your hased_raw_txamaclin 2019-05-03T03:10:58.320

02298b9f5c206560aa45a3f61bc01b546834111dc1402f0374e54bb6ca0eb89abish 2019-05-03T05:59:33.613

that one was when i run the script again with modification but this is the one from question above: f1c7146e665f9b59a6cce31526d85abb2d76859ba13219e9f8cf8e0d51051e45bish 2019-05-03T06:00:48.747

How did you get the digest f1c714...? in other words, show me the hex of your hased_raw_txamaclin 2019-05-03T06:18:36.130

hased_raw_tx = hashlib.sha256(hashlib.sha256(raw_tx).digest()).digest()bish 2019-05-03T06:29:41.167

OMG! what is raw_tx here?amaclin 2019-05-03T07:05:08.020

raw_tx = ( version

        + tx_in_count
        + reversed_prv_tx_id
        + index
        + sigScript_raw_size
        + sigScript_raw
        + sequence
        + tx_out_count
        + tx_out_value
        + tx_out_pubScript_size
        + tx_out_pubScript
        + tx_out2_value
        + tx_out2_scriptLen
        + tx_out2_script
        + lock_time          
        + (1).to_bytes(4, byteorder="little", signed=False)  #hash code
)
bish 2019-05-08T05:01:14.200

this is the raw tx raw_tx = 0100000001c24bb420c9f9aa54fc54af79e6081759312a83f72776ae3bf0838576b0233a8b000000001976a914a4842eed5a2c6fd7b71a238632f268d5831dacc088acffffffff025c937400000000001976a9142431e05399f655c52f2e7ab6227837c94d45031288ac5a000000000000001976a914a4842eed5a2c6fd7b71a238632f268d5831dacc088ac0000000001000000bish 2019-05-08T05:01:28.600

this whole code works if i create only one output but it doesnt work if output 2 is added to the real transactionbish 2019-05-08T05:02:20.007

your rawtx has digest 7a14a699e884980fc842da703dfd8117d9ec3c4d9b57f2f38f19ed6b32913a1d but not f1c7146e665f9b59a6cce31526d85abb2d76859ba13219e9f8cf8e0d51051e45amaclin 2019-05-08T12:44:57.377