<p>There are no checks specifically on OP_RETURN. There is a standardness rule, which is that they must embed up to 40 bytes of data. Of course, if you're mining your own blocks, you can ignore standardness rules.</p>

<p>There is a rule against scripts more than 10 kilobytes long, but since there's no limit on the number of outputs you can create, that's not a meaningful restriction.</p>

<p>However, this isn't a very good way to attack the network. It costs roughly $1000 of electricity to make a block. (You recoup some of that from the Bitcoins you get, of course.) It would take <a href="http://www.wolframalpha.com/input/?i=%241000%2F%281+MB+*+10000+%2F%28GB*month%2F%240.08%29%29+in+years" rel="nofollow">104 years</a> for 10000 nodes storing your block to cost more than mining it costed you in the first place.</p>

CC BY-SA 3.0
2015-02-03T22:16:25.510Z
2015-02-03T23:22:43.130Z
2015-02-03T23:22:43.130Z
Nick ODell
<p>10,000 bytes.  See Bitcoin Core source code: <a href="https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/script.h#L31-L32" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/script.h#L31-L32</a>
<a href="https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/interpreter.cpp#L299-L300" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/interpreter.cpp#L299-L300</a></p>
<p>Note that the <code>EvalScript</code> function only runs when someone tries to spend a script, so it doesn't apply to unspendable outputs like OP_RETURN.  In that case, the consensus rules allow you to include as much data as you want in the output up to the maximum block weight limit.  Bitcoin Core has long placed much more restrictive limits on what transactions it'll relay and mine when they contain OP_RETURN outputs, so we rarely see transactions exceeding those limits.</p>

CC BY-SA 3.0
2015-02-03T21:52:06.987Z
It was right under my nose :)
morsecoder
CC BY-SA 4.0
2015-02-03T21:51:18.093Z
2021-04-24T20:22:16.617Z
2021-04-24T20:22:16.617Z
David A. Harding
<p>Previous research:</p>

<ul>
<li><a href="https://bitcoin.stackexchange.com/questions/25290/transactions-maximum-size">Transaction&#39;s maximum size</a></li>
<li><a href="https://bitcoin.stackexchange.com/questions/1823/what-is-the-maximum-size-of-a-transaction">What is the maximum size of a transaction?</a></li>
<li><a href="https://github.com/bitcoin/bitcoin/blob/v0.10.0rc3/src/main.h#L57-L58" rel="noreferrer">The maximum size of a <strong>standard transaction</strong> is 100k bytes</a>.</li>
</ul>

<p><strong>Are there any consensus rules that prohibit scripts from being too large?</strong> I know each individual element of a script has to be less than 520 bytes, as <a href="https://github.com/bitcoin/bitcoin/blob/v0.10.0rc3/src/script/script.h#L18" rel="noreferrer">shown here</a>, but a script could still have many many individual elements and create an extremely large block.</p>

<p>For example, a malicious miner wants to make the blockchain as big as possible and creates a coinbase transaction with a particular output that has the <code>OP_RETURN</code> opcode followed by enough data to make their block just less than the 1 MB limit. <em>Will the malicious miner's block, in which 99% of the block data is encoded into a dummy <code>OP_RETURN</code> output, be accepted or rejected?</em></p>

CC BY-SA 3.0
2015-06-16T04:36:44.947Z
stack elements of a txout script need not be less than 520 bytes - [there are examples](http://blockexplorer.com/tx/77822fd6663c665104119cb7635352756dfc50da76a92d417ec1a12c518fad69) in the live blockchain of stack elements larger than this. however i think that the MAX_SCRIPT_ELEMENT_SIZE criteria you mention [will prevent this txout from ever being spent](https://github.com/bitcoin/bitcoin/blob/e5f1f5a26399c7d36fa8e2c29ec411eea49b0a4c/src/script/interpreter.cpp#L272)
mulllhausen
<script><consensus><op-return>
Is there a maximum size of a scriptSig/scriptPubKey?
morsecoder
# Is there a maximum size of a scriptSig/scriptPubKey?

(Asked by: username_0 on 2015-02-03)

Previous research:

* [Transaction's maximum size](https://bitcoin.stackexchange.com/questions/25290/transactions-maximum-size)
* [What is the maximum size of a transaction?](https://bitcoin.stackexchange.com/questions/1823/what-is-the-maximum-size-of-a-transaction)
* [The maximum size of a **standard transaction** is 100k bytes](https://github.com/bitcoin/bitcoin/blob/v0.10.0rc3/src/main.h#L57-L58).

**Are there any consensus rules that prohibit scripts from being too large?** I know each individual element of a script has to be less than 520 bytes, as [shown here](https://github.com/bitcoin/bitcoin/blob/v0.10.0rc3/src/script/script.h#L18), but a script could still have many many individual elements and create an extremely large block.

For example, a malicious miner wants to make the blockchain as big as possible and creates a coinbase transaction with a particular output that has the `OP_RETURN` opcode followed by enough data to make their block just less than the 1 MB limit. *Will the malicious miner's block, in which 99% of the block data is encoded into a dummy `OP_RETURN` output, be accepted or rejected?*

**Tags:** script, consensus, op-return

> **Comments:**
> **username_1**: stack elements of a txout script need not be less than 520 bytes - [there are examples](http://blockexplorer.com/tx/77822fd6663c665104119cb7635352756dfc50da76a92d417ec1a12c518fad69) in the live blockchain of stack elements larger than this. however i think that the MAX_SCRIPT_ELEMENT_SIZE criteria you mention [will prevent this txout from ever being spent](https://github.com/bitcoin/bitcoin/blob/e5f1f5a26399c7d36fa8e2c29ec411eea49b0a4c/src/script/interpreter.cpp#L272)  

---

## 2 answers

### Answer by username_3 on 2015-02-03. Score: 12 | Accepted answer

10,000 bytes. See Bitcoin Core source code: <https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/script.h#L31-L32>
<https://github.com/bitcoin/bitcoin/blob/v0.17.0/src/script/interpreter.cpp#L299-L300>

Note that the `EvalScript` function only runs when someone tries to spend a script, so it doesn't apply to unspendable outputs like OP\_RETURN. In that case, the consensus rules allow you to include as much data as you want in the output up to the maximum block weight limit. Bitcoin Core has long placed much more restrictive limits on what transactions it'll relay and mine when they contain OP\_RETURN outputs, so we rarely see transactions exceeding those limits.

> **Comments:**
> **username_0**: It was right under my nose :)  

---

### Answer by username_2 on 2015-02-03. Score: 2

There are no checks specifically on OP\_RETURN. There is a standardness rule, which is that they must embed up to 40 bytes of data. Of course, if you're mining your own blocks, you can ignore standardness rules.

There is a rule against scripts more than 10 kilobytes long, but since there's no limit on the number of outputs you can create, that's not a meaningful restriction.

However, this isn't a very good way to attack the network. It costs roughly $1000 of electricity to make a block. (You recoup some of that from the Bitcoins you get, of course.) It would take [104 years](http://www.wolframalpha.com/input/?i=%241000%2F%281+MB+*+10000+%2F%28GB*month%2F%240.08%29%29+in+years) for 10000 nodes storing your block to cost more than mining it costed you in the first place.


---

