1

When I try to push a raw Bitcoin transaction via the blockchain.info API I get the following error message:

Script resulted in a non-true stack: []

Transaction should send 0.001 Bitcoins with a 0.0005 fee from 1CBzN3YW4h7XRwb5sjpmBSEPmVPa9wHPgD to 1KAsr5RcApYG1Rk9uLwsHTXvwsyD1FVyFy.

unsigned transaction:

01000000
01
88802ffe48d0f9d2867495e933b1477094ce017f5d6e4204e40f1040ab805c16
00000000
19
76a9147abd6d64781930ee9abfaa75b0976b45ce9b93ba88ac
ffffffff
01
a086010000000000
19
76a914c75073b564d6ebce3d5d12d59ab20d44bd10f69f88ac
00000000
01000000

signed transaction:

01000000
01
88802ffe48d0f9d2867495e933b1477094ce017f5d6e4204e40f1040ab805c16
00000000
8b
483045022100FA512B36C030BAD0868E2679E1B29E32CCE0099DA086F8FD82010DFFF61B79BA02206C00220683E448C29CCE73FCD7F3CD74E3F76582C07F2F0B436EF247C2D2523F014104a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2da
ffffffff
01
a086010000000000
19
76a914c75073b564d6ebce3d5d12d59ab20d44bd10f69f88ac
00000000

Does anyone has an idea why the transaction is incorrect?

  • Can you provide the crediting transaction it spends in hex format? Preferably without the line breaks you are using on the other ones? I'm guessing it fails in the interpreter some how? – Chris Stewart Sep 2 '16 at 14:17
  • Do you mean the output which will be spent? Hex of the unspent output is: 76a9147abd6d64781930ee9abfaa75b0976b45ce9b93ba88ac, script: OP_DUP OP_HASH160 7abd6d64781930ee9abfaa75b0976b45ce9b93ba OP_EQUALVERIFY OP_CHECKSIG. – tkorwin Sep 2 '16 at 15:57
1

something is wrong in your scriptSig

the publicKey in your script is

04a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2daf 

but it does not match the address https://blockchain.info/address/1CBzN3YW4h7XRwb5sjpmBSEPmVPa9wHPgD which is the output of https://blockchain.info/tx/165c80ab40100fe404426e5d7f01ce947047b133e9957486d2f9d048fe2f8088

Are you sure that you are signing with the private key of 1CBzN3YW4h7XRwb5sjpmBSEPmVPa9wHPgD?

  • 1
    Correct public key is: 04a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2da. There was an extra 'f' at the end which should have been at the line below: 'ffffffff'. – tkorwin Sep 2 '16 at 15:46
1

I was able to push the transaction after signing it via the https://coinb.in/#sign.

It looks like I am generating incorrect signatures.

1

I used the following code to produce a correct signature:

public String sign(String msg, BigInteger d) throws IOException {
    ECDSASigner signer = new ECDSASigner();
    X9ECParameters params = SECNamedCurves.getByName("secp256k1");
    ECDomainParameters ecDomainParameters = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());
    ECPrivateKeyParameters ecPrivateKeyParameters = new ECPrivateKeyParameters(d, ecDomainParameters);
    signer.init(true, ecPrivateKeyParameters);
    BigInteger[] sigs = signer.generateSignature(DatatypeConverter.parseHexBinary(msg));
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DERSequenceGenerator seq = new DERSequenceGenerator(byteArrayOutputStream);
    seq.addObject(new DERInteger(sigs[0]));
    seq.addObject(new DERInteger(sigs[1]));
    seq.close();
    byte[] bytes = byteArrayOutputStream.toByteArray();
    return DatatypeConverter.printHexBinary(bytes);

}

1

I entered your unsigned raw transaction into file, and ran through these steps:

1.) create the unsigned raw tx and double hash

printf "010000000188802ffe48d0f9d2867495e933b1477094ce017f5d6e4204e40f1040ab805c16000000001976a9147abd6d64781930ee9abfaa75b0976b45ce9b93ba88acffffffff01a0860100000000001976a914c75073b564d6ebce3d5d12d59ab20d44bd10f69f88ac0000000001000000" > tmp_urtx.txt
xxd -r -p <tmp_urtx.txt >tmp_urtx.hex
# if no xxd (OpenBSD, FreeBSD ...), then this:
# result=$( cat tmp_urtx.txt | sed 's/[[:xdigit:]]\{2\}/\\x&/g' )
# printf $result > tmp_urtx.hex
openssl dgst -binary -sha256 >tmp_sha256.hex <tmp_urtx.hex
openssl dgst -binary -sha256 >tmp_dsha256.hex <tmp_sha256.hex
xxd -ps tmp_dsha256.hex | tr -d "\n" > tx_hash.txt
xxd -r -p <tx_hash.txt >tx_hash.hex

2.) create the pubkey.pem

echo 3056301006072a8648ce3d020106052b8104000a034200 > pubkey.txt
echo 04a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2da >> pubkey.txt
xxd -r -p <pubkey.txt | openssl pkey -pubin -inform der >pubkey.pem
openssl asn1parse -in pubkey.pem

3.) create the signature file

echo 3045022100FA512B36C030BAD0868E2679E1B29E32CCE0099DA086F8FD82010DFFF61B79BA02206C00220683E448C29CCE73FCD7F3CD74E3F76582C07F2F0B436EF247C2D2523F > tx_sig.txt
xxd -r -p <tx_sig.txt >tx_sig.hex

4.) verify all together

openssl pkeyutl <tx_hash.hex -verify -pubin -inkey pubkey.pem -sigfile tx_sig.hex

--> Signature Verification Failure

5.) conclusion

as it doesn't match, the link between privkey, signature and pubkey seems to be incorrect. I double checked the signature, it looks correct though:

#########################################################
### procedure to strictly check DER-encoded signature ###
#########################################################
Minimum and maximum size constraints                        - ok
scriptsig always starts with 0x30                           - ok
length 138 chars is less than actual sig length (142 chars) - ok
       (hex 0x45, decimal 69, 138 chars)
length of R coordinate (66) >= 0                            - ok
length of S coordinate (64) >= 0                            - ok
S-Value is within scriptsig boundaries                      - ok
Make sure the R & S length covers the entire signature      - ok
S-value must be smaller than N/2                            - ok
strictly check DER-encoded signature                        - ok
#########################################################

Maybe double check between priv and pubkeys? (compressed and uncompressed?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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