<p>Every Bitcoin in existence today exists as an unspent transaction output (UTXO) on the Bitcoin blockchain. That is, the output of an existing confirmed transaction that has not yet been consumed as the input of some other transaction.</p>

<p>Coinbase has a collection of UTXOs that represent the Bitcoins that they hold. When you tell Coinbase to make a Bitcoin payment to someone from your wallet, they choose one or more of those UTXOs to make the payment with.</p>

<p>They then form a chunk of data that claims those UTXOs and creates a new UTXO giving the Bitcoins to the recipient and one giving any change back to them. It's that chunk of data that they sign with the key for each UTXO they are spending with that payment.</p>

<p>Once the transaction is confirmed, the new UTXO for the recipient is the Bitcoins you sent them. When they see that UTXO appear on the blockchain, they know you paid them. They can then form a transaction that spends that UTXO to transfer those Bitcoins to someone else.</p>

CC BY-SA 3.0
2016-05-12T08:12:03.317Z
2016-05-12T08:12:03.317Z
David Schwartz
<p>A <code>coin</code> is described by 3 things. </p>

<ul>
<li>The outpoint: the <code>txid</code> and output index in the creating transaction. Explicitly identifies coins being spent </li>
<li>The amount</li>
<li>The scriptPubKey</li>
</ul>

<p>To spend a coin, you create a transaction specifying the outpoint as an input. You specify some destinations (known as outputs). The <code>scriptPubKey</code> often requires you to provide a signature authenticating the spend. </p>

<p>ECDSA specifies to take <code>h = H(m) mod n</code>, where H(m) is a hashing algorithm, and use this data to calculate a signature by a private key. Your question is, what is <code>m</code>?</p>

<p><code>m</code> (the data being signed) is a transaction serialized according to SIGHASH flags which determine what parts are committed to in the signature. </p>

<ul>
<li>SIGHASH_ALL commits the entire transaction as 'data', so if any of that data changes (someone adds an input, or changes a destination), the signature is rendered invalid. </li>
<li>SIGHASH_NONE captures everything <em>but</em> the outputs (the output index is resized to zero). This ensures the signature is valid so long as the inputs remain the same. The outputs can be changed at will. </li>
<li>SIGHASH_SINGLE captures an input and an output. Anything else can change without rendering the signature invalid. </li>
<li>SIGHASH_ANYONECANPAY can be applied on top of the other sighash types. Only one input is signed (yours), and the outputs. </li>
</ul>

<p>The SIGHASH flags are appended to the signature, which allows others to repeat the procedure done while signing. </p>

<p>There are some other modifications: 
  - input scripts are set to zero, since signatures can't sign themselves. 
  - the <code>txout.scriptPubKey</code> is added as the <code>txin.scriptSig</code> for this vin (the part since the last OP_CODESEPARATOR)
  - at the very end, the <code>hashTypeCode</code> (4-byte sighash flag) is appended</p>

<p>For more detail on this process, read over this page and the image: <a href="https://en.bitcoin.it/wiki/OP_CHECKSIG" rel="nofollow">https://en.bitcoin.it/wiki/OP_CHECKSIG</a></p>

<p>Segregated witness includes a modification to how <code>m</code> is derived. See BIP 143: <a href="https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki" rel="nofollow">https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki</a></p>

CC BY-SA 3.0
2016-05-12T15:42:20.663Z
2016-05-12T15:42:20.663Z
karimkorun
<p>I was reading about the math behind bitcoins in this <a href="http://www.coindesk.com/math-behind-bitcoin/" rel="nofollow">article</a>, and one thing I can't seem to wrap my head around is how the said algorithm is used to sign "data". What exactly is this "data"? Is it my bitcoin? If so, how exactly is a bitcoin represented in terms of data? Say I have 5 bitcoins in my Coinbase wallet that I want to send my friend. How would that translate to the whole "gaining the private key and signing your data with it" process as described in the article?</p>

<p>Sorry if this is too novice a question, I'm new to cryptography concepts. Thanks in advance!</p>

<private-key><signature><cryptography><ecdsa>
Signing data with ECDSA
Prithaj Nath
# Signing data with ECDSA

(Asked by: username_0 on 2016-05-12)

I was reading about the math behind bitcoins in this [article](http://www.coindesk.com/math-behind-bitcoin/), and one thing I can't seem to wrap my head around is how the said algorithm is used to sign "data". What exactly is this "data"? Is it my bitcoin? If so, how exactly is a bitcoin represented in terms of data? Say I have 5 bitcoins in my Coinbase wallet that I want to send my friend. How would that translate to the whole "gaining the private key and signing your data with it" process as described in the article?

Sorry if this is too novice a question, I'm new to cryptography concepts. Thanks in advance!

**Tags:** private-key, signature, cryptography, ecdsa


---

## 2 answers

### Answer by username_1 on 2016-05-12. Score: 1

Every Bitcoin in existence today exists as an unspent transaction output (UTXO) on the Bitcoin blockchain. That is, the output of an existing confirmed transaction that has not yet been consumed as the input of some other transaction.

Coinbase has a collection of UTXOs that represent the Bitcoins that they hold. When you tell Coinbase to make a Bitcoin payment to someone from your wallet, they choose one or more of those UTXOs to make the payment with.

They then form a chunk of data that claims those UTXOs and creates a new UTXO giving the Bitcoins to the recipient and one giving any change back to them. It's that chunk of data that they sign with the key for each UTXO they are spending with that payment.

Once the transaction is confirmed, the new UTXO for the recipient is the Bitcoins you sent them. When they see that UTXO appear on the blockchain, they know you paid them. They can then form a transaction that spends that UTXO to transfer those Bitcoins to someone else.


---

### Answer by username_2 on 2016-05-12. Score: 1

A `coin` is described by 3 things.

* The outpoint: the `txid` and output index in the creating transaction. Explicitly identifies coins being spent
* The amount
* The scriptPubKey

To spend a coin, you create a transaction specifying the outpoint as an input. You specify some destinations (known as outputs). The `scriptPubKey` often requires you to provide a signature authenticating the spend.

ECDSA specifies to take `h = H(m) mod n`, where H(m) is a hashing algorithm, and use this data to calculate a signature by a private key. Your question is, what is `m`?

`m` (the data being signed) is a transaction serialized according to SIGHASH flags which determine what parts are committed to in the signature.

* SIGHASH\_ALL commits the entire transaction as 'data', so if any of that data changes (someone adds an input, or changes a destination), the signature is rendered invalid.
* SIGHASH\_NONE captures everything *but* the outputs (the output index is resized to zero). This ensures the signature is valid so long as the inputs remain the same. The outputs can be changed at will.
* SIGHASH\_SINGLE captures an input and an output. Anything else can change without rendering the signature invalid.
* SIGHASH\_ANYONECANPAY can be applied on top of the other sighash types. Only one input is signed (yours), and the outputs.

The SIGHASH flags are appended to the signature, which allows others to repeat the procedure done while signing.

There are some other modifications:
- input scripts are set to zero, since signatures can't sign themselves.
- the `txout.scriptPubKey` is added as the `txin.scriptSig` for this vin (the part since the last OP\_CODESEPARATOR)
- at the very end, the `hashTypeCode` (4-byte sighash flag) is appended

For more detail on this process, read over this page and the image: <https://en.bitcoin.it/wiki/OP_CHECKSIG>

Segregated witness includes a modification to how `m` is derived. See BIP 143: <https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki>


---

