<blockquote>
  <p>Alice creates her digital signature that contains transcation info like id etc.</p>
</blockquote>

<p>The digital signature only applies to certain inputs and outputs within the transaction, depending on the <code>SIGHASH</code> type. The default is <code>SIGHASH_ALL</code>, in which case all inputs and outputs are signed by every participant in the transaction (where one participant equals the required keys for an input). It is possible that all participants are actually the same key (or set of keys for a multisig address).</p>

<blockquote>
  <p>She encrypts the signature with her private key.</p>
</blockquote>

<p>Nothing is encrypted. The signature is over plaintext data, and the signature is serialized into the tx as is. There is no encryption anywhere.</p>

<blockquote>
  <p>She creates scriptPubKey and scriptSig, she has the Bitcoin-Adress of Bob.</p>
</blockquote>

<p>The scriptPubKey is created prior to the signing, as it is part of the unsigned transaction in the <code>vout</code>. The scriptSig is created using the signature and the public key (when spending a pay-to-pubkey-hash input), or the redeem script (when spending a pay-to-script-hash input). For segwit addresses, the signature and witness program are not serialize within the input, but are added to a special witness field in the transaction.</p>

<blockquote>
  <p>The node extracs Bob's Bitcoin Adress from Alice's signature</p>
</blockquote>

<p>Bob's address is part of the <code>vout</code> set in the transaction. It is not included in the signature. In certain SIGHASH types, the output is signed and verified by the signature, but it is not included in it.</p>

<blockquote>
  <p>a Miner picks this transcation from the mempool.</p>
</blockquote>

<p>Every node maintains its own mempool. The correct flow would be:</p>

<ul>
<li>The transaction makes its way across the p2p network to the miner's node</li>
<li>The miner's node verifies the transaction</li>
<li>If valid, the tx is added to that node's mempool</li>
<li>The tx may make its way into the block template being mined at some point, depending on the fee.</li>
</ul>

<blockquote>
  <p>he creates a Merkle-Tree of several transactions, puts it in a block. Uses SHA-256(Blockhash+nonce) and tries to mine.</p>
</blockquote>

<p>Only the merkle tree root is added to the block header.</p>

<p>The hashing operations are performed on the block header, which contains the nonce.</p>

<p>The merkle tree is not stored anywhere. When needed, it is constructed from the list of transactions in the block.</p>

CC BY-SA 4.0
2018-08-05T13:59:50.053Z
2018-08-05T13:59:50.053Z
Raghav Sood
<p>As far as I understood, a transaction works like this:</p>

<p>Alice wants to send 5 BTC to Bob. Alice creates her digital signature that contains transcation info like id etc. She encrypts the signature with her private key. She creates scriptPubKey and scriptSig, she has the Bitcoin-Adress of Bob. </p>

<p>This transaction has to be verified by nodes. A node checks this transaction. He checks if Alice really has 5 BTC by checking her input. If it's ok, then all is fine. The node additionally checks Alice's digital signature. The node extracs Bob's Bitcoin Adress from Alice's signature. If it's ok, the Node puts the transaction to the mempool.</p>

<p>Nothing was mined until here. Now, due to the broadcast system and p2p network of Bitcoin, a Miner picks this transcation from the mempool.</p>

<p>What does he do now? Does he assume, that the transaction is valid or does he check the transaction again ?</p>

<p>If he does not check the transaction again, and assumes, that the transcation is valid, he creates a Merkle-Tree of several transactions, puts it in a block. Uses SHA-256(Blockhash+nonce) and tries to mine.</p>

<p>Is that right, what I've understood so far or did I make a mistake ?</p>

<blockchain>
Understanding how validation of a transaction works
Blnpwr
# Understanding how validation of a transaction works

(Asked by: username_0 on 2018-08-05)

As far as I understood, a transaction works like this:

Alice wants to send 5 BTC to Bob. Alice creates her digital signature that contains transcation info like id etc. She encrypts the signature with her private key. She creates scriptPubKey and scriptSig, she has the Bitcoin-Adress of Bob.

This transaction has to be verified by nodes. A node checks this transaction. He checks if Alice really has 5 BTC by checking her input. If it's ok, then all is fine. The node additionally checks Alice's digital signature. The node extracs Bob's Bitcoin Adress from Alice's signature. If it's ok, the Node puts the transaction to the mempool.

Nothing was mined until here. Now, due to the broadcast system and p2p network of Bitcoin, a Miner picks this transcation from the mempool.

What does he do now? Does he assume, that the transaction is valid or does he check the transaction again ?

If he does not check the transaction again, and assumes, that the transcation is valid, he creates a Merkle-Tree of several transactions, puts it in a block. Uses SHA-256(Blockhash+nonce) and tries to mine.

Is that right, what I've understood so far or did I make a mistake ?

**Tags:** blockchain


---

## 1 answers

### Answer by username_1 on 2018-08-05. Score: 3 | Accepted answer

> Alice creates her digital signature that contains transcation info like id etc.

The digital signature only applies to certain inputs and outputs within the transaction, depending on the `SIGHASH` type. The default is `SIGHASH_ALL`, in which case all inputs and outputs are signed by every participant in the transaction (where one participant equals the required keys for an input). It is possible that all participants are actually the same key (or set of keys for a multisig address).

> She encrypts the signature with her private key.

Nothing is encrypted. The signature is over plaintext data, and the signature is serialized into the tx as is. There is no encryption anywhere.

> She creates scriptPubKey and scriptSig, she has the Bitcoin-Adress of Bob.

The scriptPubKey is created prior to the signing, as it is part of the unsigned transaction in the `vout`. The scriptSig is created using the signature and the public key (when spending a pay-to-pubkey-hash input), or the redeem script (when spending a pay-to-script-hash input). For segwit addresses, the signature and witness program are not serialize within the input, but are added to a special witness field in the transaction.

> The node extracs Bob's Bitcoin Adress from Alice's signature

Bob's address is part of the `vout` set in the transaction. It is not included in the signature. In certain SIGHASH types, the output is signed and verified by the signature, but it is not included in it.

> a Miner picks this transcation from the mempool.

Every node maintains its own mempool. The correct flow would be:

* The transaction makes its way across the p2p network to the miner's node
* The miner's node verifies the transaction
* If valid, the tx is added to that node's mempool
* The tx may make its way into the block template being mined at some point, depending on the fee.

> he creates a Merkle-Tree of several transactions, puts it in a block. Uses SHA-256(Blockhash+nonce) and tries to mine.

Only the merkle tree root is added to the block header.

The hashing operations are performed on the block header, which contains the nonce.

The merkle tree is not stored anywhere. When needed, it is constructed from the list of transactions in the block.


---

