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.

1 Answer 1

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
12
  • 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
    May 2, 2019 at 23:47
  • also the error occurs when i am trying to broadcast the the transaction . really appreciate the help
    – bish
    May 2, 2019 at 23:57
  • How did you get the digest (message to sign)? in other words, show me the hex of your hased_raw_tx
    – amaclin
    May 3, 2019 at 3:10
  • 02298b9f5c206560aa45a3f61bc01b546834111dc1402f0374e54bb6ca0eb89a
    – bish
    May 3, 2019 at 5:59
  • that one was when i run the script again with modification but this is the one from question above: f1c7146e665f9b59a6cce31526d85abb2d76859ba13219e9f8cf8e0d51051e45
    – bish
    May 3, 2019 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.