<p>Found the error!</p>

<p>I am using OpenSSL library and was signing using the function: <code>ECDSA_Sign</code></p>

<p>The parameter <code>unsigned int *siglen</code> passed to this function is supposed to be filled with signature length. I was using the signature(parameter sig) and the length from parameter siglen to serialize the data. Turns out, although the signature being generated was always 72 bytes, the siglen parameter was filled seemingly randomly with 70, 71 or 72. And hence the number of bytes of signature that was being copied into my txn was not correct. Interestingly, if I call <code>ECDSA_size(key)</code> after making call to <code>ECDSA_Sign()</code>, i would get correct <code>72</code> value back.</p>

<p>AAAAh! Has anyone experienced this issue before with <code>ECDSA_Sign</code>? I haven't found anything on google yet.</p>

<p>But successfully posted the raw signed transaction using blockcypher's web tool/api.</p>

CC BY-SA 3.0
2018-03-04T05:32:40.033Z
Can you elaborate on how you solved the issue?
Maros
CC BY-SA 3.0
2017-02-17T03:29:50.920Z
2017-02-17T03:29:50.920Z
Tuhina Singh
<p>I have created a raw transaction and am now trying to push the hex format into testnet3. I have used following two ways and both are giving me two different errors, first one:</p>

<pre><code>curl -d '{"hex":"TX_HASH"}' http://tbtc.blockr.io/api/v1/tx/push
</code></pre>

<p>I get this error:</p>

<pre><code>{"status":"fail","data":"Could not push your transaction!","code":500,"message":"Did you sign your transaction?"}
</code></pre>

<p>and second one using this link: </p>

<p><a href="https://test.webbtc.com/relay_tx" rel="nofollow noreferrer">https://test.webbtc.com/relay_tx</a></p>

<p>gives me this error:</p>

<pre><code>Testnet3 - Error - Request took too long.
</code></pre>

<p>Not sure if signature is really the problem here. I used decode api from blockr.io to check my message - it seems well formed and is 226 bytes in length. I played around with fee wondering if that was an issue, but I think i have ruled that out as well.</p>

<p>I have also checked the validity of signature in the code (inspired by <a href="http://davidederosa.com/basic-blockchain-programming/" rel="nofollow noreferrer">David De Rosa's guide</a>).
Any tips on how can I verify the validity of my transaction?</p>

<p>Thanks.</p>

<p>Edit: Now I am getting this very descriptive error message from blockr:</p>

<pre><code>{"status":"error","data":"NULL","message":"It's looking like you may have taken a wrong turn. Don't worry... it happens to the best of us.","code":404}
</code></pre>

<p>Wish these guys didn't employ their sense of humour in error messages :(</p>

<p>used blockcypher api to push the raw transaction. This is the error message I get:</p>

<pre><code>Error sending transaction: Error running script for input 0 referencing 87ce205d61e4bf63c0bcc42db1a58c36a2cac0048df32e470f3dc1bd39741367 at 0: Script was NOT verified successfully..
</code></pre>

<p>After signing the transaction, I checked for signature verification using <code>ECDSA_verify(0,digest, sizeof(digest), sig, sig_len, key)</code> and this function call returns <code>1</code> - So I assumed my signature is correct. Am I wrong in assuming this? Am I missing something big here?</p>

CC BY-SA 3.0
2017-02-16T09:56:11.140Z
What are you passing as digest?
Pieter Wuille
CC BY-SA 3.0
2017-02-16T13:36:31.360Z
Can you provide the serialized tx in order to check the correctness?
sr_gi
<transactions><testnet><raw-transaction><transaction-verification>
Bitcoin testnet3: unable to push/publish raw transaction: how to verify validity of transaction?
Tuhina Singh
# Bitcoin testnet3: unable to push/publish raw transaction: how to verify validity of transaction?

(Asked by: username_0 on 2017-02-16)

I have created a raw transaction and am now trying to push the hex format into testnet3. I have used following two ways and both are giving me two different errors, first one:

```
curl -d '{"hex":"TX_HASH"}' http://tbtc.blockr.io/api/v1/tx/push

```

I get this error:

```
{"status":"fail","data":"Could not push your transaction!","code":500,"message":"Did you sign your transaction?"}

```

and second one using this link:

<https://test.webbtc.com/relay_tx>

gives me this error:

```
Testnet3 - Error - Request took too long.

```

Not sure if signature is really the problem here. I used decode api from blockr.io to check my message - it seems well formed and is 226 bytes in length. I played around with fee wondering if that was an issue, but I think i have ruled that out as well.

I have also checked the validity of signature in the code (inspired by [David De Rosa's guide](http://davidederosa.com/basic-blockchain-programming/)).
Any tips on how can I verify the validity of my transaction?

Thanks.

Edit: Now I am getting this very descriptive error message from blockr:

```
{"status":"error","data":"NULL","message":"It's looking like you may have taken a wrong turn. Don't worry... it happens to the best of us.","code":404}

```

Wish these guys didn't employ their sense of humour in error messages :(

used blockcypher api to push the raw transaction. This is the error message I get:

```
Error sending transaction: Error running script for input 0 referencing 87ce205d61e4bf63c0bcc42db1a58c36a2cac0048df32e470f3dc1bd39741367 at 0: Script was NOT verified successfully..

```

After signing the transaction, I checked for signature verification using `ECDSA_verify(0,digest, sizeof(digest), sig, sig_len, key)` and this function call returns `1` - So I assumed my signature is correct. Am I wrong in assuming this? Am I missing something big here?

**Tags:** transactions, testnet, raw-transaction, transaction-verification

> **Comments:**
> **username_1**: What are you passing as digest?  
> **username_2**: Can you provide the serialized tx in order to check the correctness?  

---

## 1 answers

### Answer by username_0 on 2017-02-17. Score: 1 | Accepted answer

Found the error!

I am using OpenSSL library and was signing using the function: `ECDSA_Sign`

The parameter `unsigned int *siglen` passed to this function is supposed to be filled with signature length. I was using the signature(parameter sig) and the length from parameter siglen to serialize the data. Turns out, although the signature being generated was always 72 bytes, the siglen parameter was filled seemingly randomly with 70, 71 or 72. And hence the number of bytes of signature that was being copied into my txn was not correct. Interestingly, if I call `ECDSA_size(key)` after making call to `ECDSA_Sign()`, i would get correct `72` value back.

AAAAh! Has anyone experienced this issue before with `ECDSA_Sign`? I haven't found anything on google yet.

But successfully posted the raw signed transaction using blockcypher's web tool/api.

> **Comments:**
> **username_3**: Can you elaborate on how you solved the issue?  

---

