CheckTxInputs characterized
ProvedBitcoinBlock.checkTxInputs_iffcheckTxInputs u tx H succeeds iff every input spends an existing coin with value in range that is mature if a coinbase (), the input total is in range, the outputs do not exceed it, and the fee is in range; the returned value is valueIn − valueOut.
Deprecated. Superseded by BitcoinBlockV2.checkTxInputs_iff (revision 2 of the block mission): the p2shSigOpCount of this revision counted every push of scriptSig instead of only the redeem script, over-counting P2SH sigops; the V2 declarations carry the corrected definition.
import Definitions.Def_BitcoinBlock import Definitions.Def_BitcoinSer
theorem BitcoinBlock.checkTxInputs_iff (u : Ledger) (tx : BitcoinSer.Tx) (H : Nat) :
((∃ fee, BitcoinBlock.checkTxInputs u tx H = some fee) ↔
(∀ i ∈ tx.vin, ∃ c, BitcoinBlock.getCoin u i.prevout = some c ∧
(c.isCoinbase = true → c.height + COINBASE_MATURITY ≤ H) ∧ 0 ≤ c.out.nValue ∧ c.out.nValue ≤ MAX_MONEY) ∧
BitcoinBlock.valueIn u tx.vin ≤ MAX_MONEY ∧ BitcoinBlock.valueOut tx ≤ BitcoinBlock.valueIn u tx.vin ∧
BitcoinBlock.valueIn u tx.vin - BitcoinBlock.valueOut tx ≤ MAX_MONEY) ∧
(∀ fee, BitcoinBlock.checkTxInputs u tx H = some fee → fee = BitcoinBlock.feeOf u tx) := by sorryRead-back
What the Lean code literally says, in plain math · claude-fable-5-1 (independent sub-agent, blind: Lean code + auditor instructions only)
Read-back: BitcoinBlock.checkTxInputs_iff
Binders
- : a ledger, i.e. a list of pairs where is an outpoint and is a coin with an output (value , scriptPubKey), , a Boolean. Keys need not be distinct.
- : a serialized transaction (version, inputs , outputs , lock time).
- : the spend height.
There are no hypotheses.
Conclusion
The conclusion is a conjunction of two parts.
Part 1 (an equivalence):
with (MAX_MONEY) and = COINBASE_MATURITY.
Part 2 (an implication, for all fees):
Definitions unfolded
- : the coin of the first entry of whose key equals , or none.
- : if present, else the dummy coin (value ).
- over .
- over (a missing coin contributes ).
- .
- : if some input's prevout has no coin in , none; otherwise run the input loop over with accumulator : for each input, look up its coin (none fail); if the coin is a coinbase and (natural-number subtraction, so when ) then fail; let ; if or then fail; else continue with . If the loop fails, none. Otherwise with the final accumulator: none if ; none if ; else .
So Part 1 says: the executable check succeeds exactly when every input's prevout is present in with a coin that is mature if coinbase () and whose value lies in , the total input value (as computed with the dummy default, which is irrelevant when all coins exist) is at most , the outputs do not exceed the inputs, and the difference is at most . Part 2 says any fee returned equals .
Edge cases silently included
Empty (left: loop trivially succeeds with , so success iff and ; right: the universal clause is vacuous and the same three inequalities remain); negative output values are not excluded here, so can exceed (hence the last conjunct is not redundant); duplicate keys in (first match wins); coins with (natural subtraction yields , so a coinbase coin from the "future" fails, consistent with failing); duplicate prevouts within are not excluded and each is counted separately in .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.