<blockquote>
  <p>I see in the bitcoin wiki there is something called "script" which compiles down to some bytecode to be run by a very very basic virtual machine.</p>
</blockquote>

<p>Script is a stack-based language that is used to <strong>validate input and output scripts in transactions</strong>. Script is purposely designed to lack Turing-completeness (no loops) so that it is deterministic in nature. (No infinite loops, etc). An input/output is considered to be "valid" when the top stack item is true (or 0x01).</p>

<blockquote>
  <p>Does this mean that each block is actually just a string/array of bytes when it comes in and is processed by a node?</p>
</blockquote>

<p>Bitcoin nodes validate transactions, Bitcoin miners compute blocks in accordance with the Proof-of-Work model defined in the Bitcoin protocol. That being said, yes, technically the <em>raw</em> block data is an array of hexadecimal bytes. When miners begin mining the block, they are <em>only hashing</em> the header of the block (first 80 bytes) which includes the following information:</p>

<p><code>nVersion|hashPrevBlock|hashMerkleRoot|Time|Bits|Nonce</code></p>

<p>They can get away with doing this because the <code>hashMerkleRoot</code> value is a reference to the hash of all the transactions in the block they are mining. These transactions have been validated by nodes.</p>

<p>In Bitcoin-core you can specify serialization as the second parameter in the <code>getblock</code> command. By default it will nicely display the data in a JSON like output, although it is really a long hexadecimal output.</p>

<hr>

<p>Example:</p>

<p><code>getblock 00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09 0</code></p>

<p>Output: <code>010000007de867cc8adc5cc8fb6b898ca4462cf9fd66...</code></p>

CC BY-SA 4.0
2018-10-28T21:08:03.207Z
2018-10-28T21:08:03.207Z
Mason Ticehurst
<p>A block consists of a header, and then a number of serialised transactions. The block header contains no script, it only contains data such as the merkle root of the transactions in the block (so the header commits to the list of transactions), nonce, version number, etc. Note that a block isn't encoded with JSON, it has its own serialisation format which you can find in most developer documentation (e.g. <a href="https://bitcoin.org/en/developer-reference#block-headers" rel="nofollow noreferrer">here</a>)</p>

<p>The script is contained only inside transactions themselves, specifically to dictate the spending condition of an output. An output will have a scriptPubKey which holds the outputs script (usually of a specific form like P2PKH, P2SH) and the input when it's spent will contain a scriptSig which contains the spending script. In segregated witness transactions, the scriptSig will be empty and the script will instead be in the witness section of the transaction, but it's still the same principle. </p>

<p>Block verification takes a number of steps such as validation of the proof of work, validation that the timestamp is ok, that the coinbase transaction is ok, that all the other transactions are ok, etc etc.</p>

CC BY-SA 4.0
2018-10-28T20:58:29.997Z
2018-10-28T20:58:29.997Z
meshcollider
<p>I see in the bitcoin wiki there is something called "script" which compiles down to some bytecode to be run by a very very basic virtual machine.
Does this mean that each block is actually just a string/array of bytes when it comes in and is processed by a node?
so a block in its "true" format would look something like [0x01, 0x04, 0x0f, 0xa1.... etc. ?</p>

<p>and then the node that recieves the block just puts the bytes into the interpreter to be run by the bitcoin VM?</p>

<p>which is correct? a block is pure bytecode or JSON? what would a bitcoincore node understand when receiving a new block?</p>

CC BY-SA 4.0
2018-10-28T21:07:08.627Z
... and the wiki gives some detailed view on the checks happening: https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages
pebwindkraft
<script><transaction-verification><validation><block-validity>
How are blocks verified?
Shazzad Kabir
# How are blocks verified?

(Asked by: username_0 on 2018-10-28)

I see in the bitcoin wiki there is something called "script" which compiles down to some bytecode to be run by a very very basic virtual machine.
Does this mean that each block is actually just a string/array of bytes when it comes in and is processed by a node?
so a block in its "true" format would look something like [0x01, 0x04, 0x0f, 0xa1.... etc. ?

and then the node that recieves the block just puts the bytes into the interpreter to be run by the bitcoin VM?

which is correct? a block is pure bytecode or JSON? what would a bitcoincore node understand when receiving a new block?

**Tags:** script, transaction-verification, validation, block-validity

> **Comments:**
> **username_1**: ... and the wiki gives some detailed view on the checks happening: https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages  

---

## 2 answers

### Answer by username_3 on 2018-10-28. Score: 4 | Accepted answer

A block consists of a header, and then a number of serialised transactions. The block header contains no script, it only contains data such as the merkle root of the transactions in the block (so the header commits to the list of transactions), nonce, version number, etc. Note that a block isn't encoded with JSON, it has its own serialisation format which you can find in most developer documentation (e.g. [here](https://bitcoin.org/en/developer-reference#block-headers))

The script is contained only inside transactions themselves, specifically to dictate the spending condition of an output. An output will have a scriptPubKey which holds the outputs script (usually of a specific form like P2PKH, P2SH) and the input when it's spent will contain a scriptSig which contains the spending script. In segregated witness transactions, the scriptSig will be empty and the script will instead be in the witness section of the transaction, but it's still the same principle.

Block verification takes a number of steps such as validation of the proof of work, validation that the timestamp is ok, that the coinbase transaction is ok, that all the other transactions are ok, etc etc.


---

### Answer by username_2 on 2018-10-28. Score: 0

> I see in the bitcoin wiki there is something called "script" which compiles down to some bytecode to be run by a very very basic virtual machine.

Script is a stack-based language that is used to **validate input and output scripts in transactions**. Script is purposely designed to lack Turing-completeness (no loops) so that it is deterministic in nature. (No infinite loops, etc). An input/output is considered to be "valid" when the top stack item is true (or 0x01).

> Does this mean that each block is actually just a string/array of bytes when it comes in and is processed by a node?

Bitcoin nodes validate transactions, Bitcoin miners compute blocks in accordance with the Proof-of-Work model defined in the Bitcoin protocol. That being said, yes, technically the *raw* block data is an array of hexadecimal bytes. When miners begin mining the block, they are *only hashing* the header of the block (first 80 bytes) which includes the following information:

`nVersion|hashPrevBlock|hashMerkleRoot|Time|Bits|Nonce`

They can get away with doing this because the `hashMerkleRoot` value is a reference to the hash of all the transactions in the block they are mining. These transactions have been validated by nodes.

In Bitcoin-core you can specify serialization as the second parameter in the `getblock` command. By default it will nicely display the data in a JSON like output, although it is really a long hexadecimal output.

---

Example:

`getblock 00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09 0`

Output: `010000007de867cc8adc5cc8fb6b898ca4462cf9fd66...`


---

