<p>If the output value was only constrained by their sum being smaller than that of the inputs, you could e.g. set one output to a negative value and create new money in a second output.</p>
<p>You can also do more creative stuff:
I think the rule might have been introduced as a response to the <a href="https://en.bitcoin.it/wiki/Value_overflow_incident" rel="nofollow noreferrer">value overflow incident</a> on 2010-08-15. A transaction in a (now invalid) block at height 74638 created outputs that were so large that their sum overflowed into the permitted range. The transaction created 2×92.2 billion bitcoins.</p>
<p>The code fix for the value overflow incident can be found in this <a href="https://github.com/bitcoin/bitcoin/commit/d4c6b90ca3f9b47adb1b2724a0c3514f80635c84#diff-118fcbaaba162ba17933c7893247df3aR1013" rel="nofollow noreferrer">commit</a>. The code for this rule can be found in <a href="https://github.com/bitcoin/bitcoin/blob/c46f1ce75196860c8b036d2965faac7db3aa4414/src/consensus/tx_check.cpp#L30" rel="nofollow noreferrer">src/consensus/tx_check.cpp</a>. The <code>CheckTransaction()</code> function checks consensus rules that don't require any knowledge of the current chainstate.</p>

CC BY-SA 4.0
2021-03-22T15:36:27.340Z
2022-06-24T14:08:26.197Z
2022-06-24T14:08:26.197Z
Murch
<p>In the 'tx messages' section for <a href="https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages" rel="nofollow noreferrer">protocol rules</a> we have</p>
<blockquote>
<ol start="4">
<li>Each output value, as well as the total, must be in legal money range</li>
</ol>
</blockquote>
<blockquote>
<ol start="12">
<li>For each input, if the referenced output does not exist (e.g. never existed or has already been spent), reject this transaction</li>
</ol>
</blockquote>
<p>If my understanding is correct, rule 4 will confirm 0 &lt;= output, sum of outputs &lt;= 21,000,000, and rule 12 is checking that each input is in the UTXO set. I am having a hard time seeing why rule 4 is necessary, it seems like other rules - such as rule 12 - would already invalidate a transaction that was not in legal range. No one could ever have &gt; 21,000,000 bitcoin so there could never be utxos for more 21,000,000.</p>
<p>Also, where can I find the code for these checks in the <a href="https://github.com/bitcoin/bitcoin" rel="nofollow noreferrer">source code</a>.</p>

CC BY-SA 4.0
2021-03-22T16:04:17.357Z
There's no real reason for the rule to exist, other than that there had been an integer overflow incident in the past.
Claris
<bitcoin-core-development><protocol><transaction-verification><consensus><output>
Why does the value range of outputs need to be restricted?
Prince M
# Why does the value range of outputs need to be restricted?

(Asked by: username_0 on 2021-03-22)

In the 'tx messages' section for [protocol rules](https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages) we have

> 4. Each output value, as well as the total, must be in legal money range

> 12. For each input, if the referenced output does not exist (e.g. never existed or has already been spent), reject this transaction

If my understanding is correct, rule 4 will confirm 0 <= output, sum of outputs <= 21,000,000, and rule 12 is checking that each input is in the UTXO set. I am having a hard time seeing why rule 4 is necessary, it seems like other rules - such as rule 12 - would already invalidate a transaction that was not in legal range. No one could ever have > 21,000,000 bitcoin so there could never be utxos for more 21,000,000.

Also, where can I find the code for these checks in the [source code](https://github.com/bitcoin/bitcoin).

**Tags:** bitcoin-core-development, protocol, transaction-verification, consensus, output

> **Comments:**
> **username_1**: There's no real reason for the rule to exist, other than that there had been an integer overflow incident in the past.  

---

## 1 answers

### Answer by username_2 on 2021-03-22. Score: 2 | Accepted answer

If the output value was only constrained by their sum being smaller than that of the inputs, you could e.g. set one output to a negative value and create new money in a second output.

You can also do more creative stuff:
I think the rule might have been introduced as a response to the [value overflow incident](https://en.bitcoin.it/wiki/Value_overflow_incident) on 2010-08-15. A transaction in a (now invalid) block at height 74638 created outputs that were so large that their sum overflowed into the permitted range. The transaction created 2×92.2 billion bitcoins.

The code fix for the value overflow incident can be found in this [commit](https://github.com/bitcoin/bitcoin/commit/d4c6b90ca3f9b47adb1b2724a0c3514f80635c84#diff-118fcbaaba162ba17933c7893247df3aR1013). The code for this rule can be found in [src/consensus/tx\_check.cpp](https://github.com/bitcoin/bitcoin/blob/c46f1ce75196860c8b036d2965faac7db3aa4414/src/consensus/tx_check.cpp#L30). The `CheckTransaction()` function checks consensus rules that don't require any knowledge of the current chainstate.


---

