<h3>Short Answer</h3>
<p>Yes, but there's more than one.</p>
<h3>Long Answer</h3>
<p>Bitcoin scripts are a <strong>stack-based</strong> language. The 'separators' are the Bitcoin push-data-onto-stack instructions. There are <a href="https://en.bitcoin.it/wiki/Script#Constants" rel="nofollow noreferrer">multiple instructions to push data onto the stack</a>:</p>
<ul>
<li>OP_0, OP_1, OP_2, ...</li>
<li>0x01-0x75 (Yes, that's their real name)<br />
Push <em>opcode</em> bytes onto the stack<br />
This is most common - the average piece of data in Bitcoin is shorter than 75 bytes.</li>
<li>PUSHDATA1 - Read 1 byte, convert to int, read that many bytes</li>
<li>PUSHDATA2 - Read 2 bytes, convert to int, read that many bytes</li>
<li>PUSHDATA4 ...</li>
<li>OP_1NEGATE - Pushes -1 onto the stack. Somewhat use-impaired.</li>
</ul>
<p>There's a useful rule of thumb here, though it's not always correct. Take the first byte. Convert it to a number. Count that many bytes forward. That's a single piece of data. Repeat.</p>
<p>Let's work through an example. Let's find the elements of the input script for <a href="https://blockchain.info/tx/fd8f1af8eabf25b192fecae66b096d4a1f955422793490761e58e4c3edc1c88d" rel="nofollow noreferrer">this transaction.</a></p>
<blockquote>
<p>0100000001cce488677848b7a962f01a525d7cd78139a5be1ab75ead5b7336ba6f512d0388010000008b483045022100b65463abe3b5f79dbe9556180e60db4b6b3a6db7c43132e1e396e73023b34d2402206a412868470f8b83dc266a364b79e0a2acd0f5642181f7d0212c7ea608271a4a0141040ab8f88b419c62dba59d2e685bd3bc07367236d841abf3068b5886cd7a6c7297e721d42a41cb1bbd69ed684cc5d5c738d611d886c4493280b26637abad5603a5ffffffff0280f0fa02000000001976a914f593d5cfb3b74ac2988815cdf26c0420981385b788ac50d2a019000000001976a9148a0c13d08a36e68aa5294ca7e6f06a9946c3f1d588ac00000000</p>
</blockquote>
<p>Break it up, find the input script:</p>
<blockquote>
<p>version: 01000000<br />
inputs: 01<br />
hash: cce488677848b7a962f01a525d7cd78139a5be1ab75ead5b7336ba6f512d0388<br />
vout: 01000000<br />
input script len: 8b<br />
input script: 483045022100b65463abe3b5f79dbe9556180e60db4b6b3a6db7c43132e1e396e73023b34d2402206a412868470f8b83dc266a364b79e0a2acd0f5642181f7d0212c7ea608271a4a0141040ab8f88b419c62dba59d2e685bd3bc07367236d841abf3068b5886cd7a6c7297e721d42a41cb1bbd69ed684cc5d5c738d611d886c4493280b26637abad5603a5<br />
seq: ffffffff<br />
outputs: 02<br />
amount: 80f0fa0200000000<br />
output script len: 19<br />
output script: 76a914f593d5cfb3b74ac2988815cdf26c0420981385b788ac<br />
amount: 50d2a01900000000<br />
output script len: 19<br />
output script: 76a9148a0c13d08a36e68aa5294ca7e6f06a9946c3f1d588ac<br />
lock_time: 00000000</p>
</blockquote>
<p>Now, we know the first piece of data is 0x48 (72) bytes long.</p>
<blockquote>
<p>48...3045022100b65463abe3b5f79dbe9556180e60db4b6b3a6db7c43132e1e396e73023b34d2402206a412868470f8b83dc266a364b79e0a2acd0f5642181f7d0212c7ea608271a4a01...41040ab8f88b419c62dba59d2e685bd3bc07367236d841abf3068b5886cd7a6c7297e721d42a41cb1bbd69ed684cc5d5c738d611d886c4493280b26637abad5603a5</p>
</blockquote>
<p>The second part is 0x41 (65) bytes long:</p>
<blockquote>
<p>48...3045022100b65463abe3b5f79dbe9556180e60db4b6b3a6db7c43132e1e396e73023b34d2402206a412868470f8b83dc266a364b79e0a2acd0f5642181f7d0212c7ea608271a4a01...41...040ab8f88b419c62dba59d2e685bd3bc07367236d841abf3068b5886cd7a6c7297e721d42a41cb1bbd69ed684cc5d5c738d611d886c4493280b26637abad5603a5...</p>
</blockquote>

CC BY-SA 3.0
2014-10-20T12:11:28.773Z
Thank you very much, this was a very descriptive and clear answer!
morsecoder
CC BY-SA 3.0
2014-10-20T12:18:04.690Z
Just like you described, if I look into the hex of a standard scriptPubKey (such as "76a9143cfa95abbb8da05e2a597f5da9640b5ef3d39d6088ac") there is a 0x14 op code to say that we are pushing 20 bytes
morsecoder
CC BY-SA 3.0
2014-10-20T03:37:37.223Z
2014-10-20T03:37:37.223Z
2020-06-16T11:10:03.350Z
Nick ODell
<p>From the <a href="https://bitcoin.org/en/developer-guide#standard-transactions" rel="noreferrer">bitcoin developer page</a>, the format of the scripts used in P2SH transactions are as follows:</p>

<pre>
Pubkey script: OP_HASH160 &lt;Hash160(redeemScript)&gt; OP_EQUAL
Redeem script: &lt;OP_2&gt; &lt;pubkey&gt; &lt;pubkey&gt; &lt;pubkey&gt; &lt;OP_3&gt; OP_CHECKMULTISIG
Signature script: OP_0 &lt;sig&gt; &lt;sig&gt; &lt;redeemScript>
</pre>

<p>When coins that were previously sent to a P2SH script are spent, and so the concatenated scriptSig and scriptPubKey scripts are executed, the OP_HASH160 is calculated on the redeem script, which is part of the scriptSig. How is it denoted in the script which parts should be included in the redeemScript? That is, how is it denoted which parts should be hashed when OP_HASH160 gets executed? Obviously it can't be the whole scriptSig, because there are signatures contained, so how does the executor know what to hash? Is there some sort of a marker OP code?</p>

<p>Thanks!</p>

<script>
How to denote <serialized> script in P2SH transaction?
morsecoder
# How to denote <serialized> script in P2SH transaction?

(Asked by: username_0 on 2014-10-20)

From the [bitcoin developer page](https://bitcoin.org/en/developer-guide#standard-transactions), the format of the scripts used in P2SH transactions are as follows:

```

Pubkey script: OP_HASH160 <Hash160(redeemScript)> OP_EQUAL
Redeem script: <OP_2> <pubkey> <pubkey> <pubkey> <OP_3> OP_CHECKMULTISIG
Signature script: OP_0 <sig> <sig> <redeemScript>

```

When coins that were previously sent to a P2SH script are spent, and so the concatenated scriptSig and scriptPubKey scripts are executed, the OP\_HASH160 is calculated on the redeem script, which is part of the scriptSig. How is it denoted in the script which parts should be included in the redeemScript? That is, how is it denoted which parts should be hashed when OP\_HASH160 gets executed? Obviously it can't be the whole scriptSig, because there are signatures contained, so how does the executor know what to hash? Is there some sort of a marker OP code?

Thanks!

**Tags:** script


---

## 1 answers

### Answer by username_1 on 2014-10-20. Score: 4 | Accepted answer

### Short Answer

Yes, but there's more than one.

### Long Answer

Bitcoin scripts are a **stack-based** language. The 'separators' are the Bitcoin push-data-onto-stack instructions. There are [multiple instructions to push data onto the stack](https://en.bitcoin.it/wiki/Script#Constants):

* OP\_0, OP\_1, OP\_2, ...
* 0x01-0x75 (Yes, that's their real name)  
  Push *opcode* bytes onto the stack  
  This is most common - the average piece of data in Bitcoin is shorter than 75 bytes.
* PUSHDATA1 - Read 1 byte, convert to int, read that many bytes
* PUSHDATA2 - Read 2 bytes, convert to int, read that many bytes
* PUSHDATA4 ...
* OP\_1NEGATE - Pushes -1 onto the stack. Somewhat use-impaired.

There's a useful rule of thumb here, though it's not always correct. Take the first byte. Convert it to a number. Count that many bytes forward. That's a single piece of data. Repeat.

Let's work through an example. Let's find the elements of the input script for [this transaction.](https://blockchain.info/tx/fd8f1af8eabf25b192fecae66b096d4a1f955422793490761e58e4c3edc1c88d)

> 0100000001cce488677848b7a962f01a525d7cd78139a5be1ab75ead5b7336ba6f512d0388010000008b483045022100b65463abe3b5f79dbe9556180e60db4b6b3a6db7c43132e1e396e73023b34d2402206a412868470f8b83dc266a364b79e0a2acd0f5642181f7d0212c7ea608271a4a0141040ab8f88b419c62dba59d2e685bd3bc07367236d841abf3068b5886cd7a6c7297e721d42a41cb1bbd69ed684cc5d5c738d611d886c4493280b26637abad5603a5ffffffff0280f0fa02000000001976a914f593d5cfb3b74ac2988815cdf26c0420981385b788ac50d2a019000000001976a9148a0c13d08a36e68aa5294ca7e6f06a9946c3f1d588ac00000000

Break it up, find the input script:

> version: 01000000  
> inputs: 01  
> hash: cce488677848b7a962f01a525d7cd78139a5be1ab75ead5b7336ba6f512d0388  
> vout: 01000000  
> input script len: 8b  
> input script: 483045022100b65463abe3b5f79dbe9556180e60db4b6b3a6db7c43132e1e396e73023b34d2402206a412868470f8b83dc266a364b79e0a2acd0f5642181f7d0212c7ea608271a4a0141040ab8f88b419c62dba59d2e685bd3bc07367236d841abf3068b5886cd7a6c7297e721d42a41cb1bbd69ed684cc5d5c738d611d886c4493280b26637abad5603a5  
> seq: ffffffff  
> outputs: 02  
> amount: 80f0fa0200000000  
> output script len: 19  
> output script: 76a914f593d5cfb3b74ac2988815cdf26c0420981385b788ac  
> amount: 50d2a01900000000  
> output script len: 19  
> output script: 76a9148a0c13d08a36e68aa5294ca7e6f06a9946c3f1d588ac  
> lock\_time: 00000000

Now, we know the first piece of data is 0x48 (72) bytes long.

> 48...3045022100b65463abe3b5f79dbe9556180e60db4b6b3a6db7c43132e1e396e73023b34d2402206a412868470f8b83dc266a364b79e0a2acd0f5642181f7d0212c7ea608271a4a01...41040ab8f88b419c62dba59d2e685bd3bc07367236d841abf3068b5886cd7a6c7297e721d42a41cb1bbd69ed684cc5d5c738d611d886c4493280b26637abad5603a5

The second part is 0x41 (65) bytes long:

> 48...3045022100b65463abe3b5f79dbe9556180e60db4b6b3a6db7c43132e1e396e73023b34d2402206a412868470f8b83dc266a364b79e0a2acd0f5642181f7d0212c7ea608271a4a01...41...040ab8f88b419c62dba59d2e685bd3bc07367236d841abf3068b5886cd7a6c7297e721d42a41cb1bbd69ed684cc5d5c738d611d886c4493280b26637abad5603a5...

> **Comments:**
> **username_0**: Thank you very much, this was a very descriptive and clear answer!  
> **username_0**: Just like you described, if I look into the hex of a standard scriptPubKey (such as "76a9143cfa95abbb8da05e2a597f5da9640b5ef3d39d6088ac") there is a 0x14 op code to say that we are pushing 20 bytes  

---

