<p>I was able to push the transaction after signing it via the <a href="https://coinb.in/#sign" rel="nofollow">https://coinb.in/#sign</a>.</p>

<p>It looks like I am generating incorrect signatures.</p>

CC BY-SA 3.0
2016-09-02T18:18:24.200Z
2016-09-02T18:18:24.200Z
tkorwin
<p>I used the following code to produce a correct signature:</p>

<pre><code>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);
</code></pre>

<p>}</p>

CC BY-SA 3.0
2016-09-04T16:28:25.577Z
2016-09-04T16:28:25.577Z
tkorwin
<p>I entered your unsigned raw transaction into file, and ran through these steps:</p>

<p>1.) create the unsigned raw tx and double hash</p>

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

<p>2.) create the pubkey.pem</p>

<pre><code>echo 3056301006072a8648ce3d020106052b8104000a034200 &gt; pubkey.txt
echo 04a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2da &gt;&gt; pubkey.txt
xxd -r -p &lt;pubkey.txt | openssl pkey -pubin -inform der &gt;pubkey.pem
openssl asn1parse -in pubkey.pem
</code></pre>

<p>3.) create the signature file</p>

<pre><code>echo 3045022100FA512B36C030BAD0868E2679E1B29E32CCE0099DA086F8FD82010DFFF61B79BA02206C00220683E448C29CCE73FCD7F3CD74E3F76582C07F2F0B436EF247C2D2523F &gt; tx_sig.txt
xxd -r -p &lt;tx_sig.txt &gt;tx_sig.hex
</code></pre>

<p>4.) verify all together</p>

<pre><code>openssl pkeyutl &lt;tx_hash.hex -verify -pubin -inkey pubkey.pem -sigfile tx_sig.hex
</code></pre>

<p><strong>--> Signature Verification Failure</strong></p>

<p>5.) conclusion</p>

<p>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:</p>

<pre><code>#########################################################
### 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) &gt;= 0                            - ok
length of S coordinate (64) &gt;= 0                            - ok
S-Value is within scriptsig boundaries                      - ok
Make sure the R &amp; S length covers the entire signature      - ok
S-value must be smaller than N/2                            - ok
strictly check DER-encoded signature                        - ok
#########################################################
</code></pre>

<p>Maybe double check between priv and pubkeys? (compressed and uncompressed?)</p>

CC BY-SA 3.0
2016-11-16T12:19:41.120Z
2016-11-16T12:19:41.120Z
pebwindkraft
<p>something is wrong in your scriptSig</p>

<p>the publicKey in your script is </p>

<pre><code>04a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2daf 
</code></pre>

<p>but it does not match the address <a href="https://blockchain.info/address/1CBzN3YW4h7XRwb5sjpmBSEPmVPa9wHPgD" rel="nofollow">https://blockchain.info/address/1CBzN3YW4h7XRwb5sjpmBSEPmVPa9wHPgD</a> which is the output of <a href="https://blockchain.info/tx/165c80ab40100fe404426e5d7f01ce947047b133e9957486d2f9d048fe2f8088" rel="nofollow">https://blockchain.info/tx/165c80ab40100fe404426e5d7f01ce947047b133e9957486d2f9d048fe2f8088</a></p>

<p>Are you sure that you are signing with the private key of 1CBzN3YW4h7XRwb5sjpmBSEPmVPa9wHPgD?</p>

CC BY-SA 3.0
2016-09-02T15:46:06.327Z
Correct public key is: 04a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2da. There was an extra 'f' at the end which should have been at the line below: 'ffffffff'.
tkorwin
CC BY-SA 3.0
2016-09-02T14:33:44.537Z
2016-09-02T14:33:44.537Z
amaclin
<p>When I try to push a raw Bitcoin transaction via the blockchain.info API I get the following error message:</p>

<blockquote>
  <p>Script resulted in a non-true stack: []</p>
</blockquote>

<p>Transaction should send 0.001 Bitcoins with a 0.0005 fee from 1CBzN3YW4h7XRwb5sjpmBSEPmVPa9wHPgD to 1KAsr5RcApYG1Rk9uLwsHTXvwsyD1FVyFy.</p>

<p>unsigned transaction:</p>

<pre><code>01000000
01
88802ffe48d0f9d2867495e933b1477094ce017f5d6e4204e40f1040ab805c16
00000000
19
76a9147abd6d64781930ee9abfaa75b0976b45ce9b93ba88ac
ffffffff
01
a086010000000000
19
76a914c75073b564d6ebce3d5d12d59ab20d44bd10f69f88ac
00000000
01000000
</code></pre>

<p>signed transaction:</p>

<pre><code>01000000
01
88802ffe48d0f9d2867495e933b1477094ce017f5d6e4204e40f1040ab805c16
00000000
8b
483045022100FA512B36C030BAD0868E2679E1B29E32CCE0099DA086F8FD82010DFFF61B79BA02206C00220683E448C29CCE73FCD7F3CD74E3F76582C07F2F0B436EF247C2D2523F014104a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2da
ffffffff
01
a086010000000000
19
76a914c75073b564d6ebce3d5d12d59ab20d44bd10f69f88ac
00000000
</code></pre>

<p>Does anyone has an idea why the transaction is incorrect?</p>

CC BY-SA 3.0
2016-09-02T14:17:30.220Z
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
CC BY-SA 3.0
2016-09-02T15:57:49.960Z
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
<transactions><script><signature><raw-transaction><raw-data>
Generate and push raw Bitcoin transaction
tkorwin
# Generate and push raw Bitcoin transaction

(Asked by: username_0 on 2016-09-02)

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?

**Tags:** transactions, script, signature, raw-transaction, raw-data

> **Comments:**
> **username_1**: 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?  
> **username_0**: 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.  

---

## 4 answers

### Answer by username_0 on 2016-09-02. Score: 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.


---

### Answer by username_0 on 2016-09-04. Score: 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);

```

}


---

### Answer by username_2 on 2016-11-16. Score: 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?)


---

### Answer by username_3 on 2016-09-02. Score: 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?

> **Comments:**
> **username_0**: Correct public key is: 04a75429241bc8c83e0a1c615155e9b984880f16d39b09b28eef464139fb84d8ff507a5d482e8f41cdb5a762436515d310f16b208bdce4ddfb8a30a7236d36a2da. There was an extra 'f' at the end which should have been at the line below: 'ffffffff'.  

---

