1

In the 'tx messages' section for protocol rules we have

  1. Each output value, as well as the total, must be in legal money range
  1. 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.

3
  • 1
    Hi Prince M, a vague title like "tx protocol rules" makes it hard for other users to assess from the topic overview what your topic is about. I edited it, trying to capture the gist of your question. Please feel free to amend it if you have a better.
    – Murch
    Mar 22 at 15:47
  • I agree with your edit, thanks for your kind note explaining it!
    – Prince M
    Mar 22 at 15:50
  • There's no real reason for the rule to exist, other than that there had been an integer overflow incident in the past.
    – Claris
    Mar 22 at 16:04
2

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 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 original code fix for the value overflow incident can be found here: https://github.com/bitcoin/bitcoin/commit/d4c6b90ca3f9b47adb1b2724a0c3514f80635c84#diff-118fcbaaba162ba17933c7893247df3aR1013

The code for this rule can be found in src/consensus/tx_check.cpp here. The CheckTransaction() function checks consensus rules that don't require any knowledge of the current chainstate.

2
  • Thanks, and can you point me to where in the source code these rules are coded?
    – Prince M
    Mar 22 at 16:14
  • 1
    @PrinceM: In case you didn't see, zow added an edit to my answer that points out the specific code section.
    – Murch
    Mar 22 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.