In the 'tx messages' section for protocol rules we have
- Each output value, as well as the total, must be in legal money range
- 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.