CheckTransaction characterized
ProvedBitcoinBlock.checkTransaction_iffby pitimespi · Oct 26, 2026 · Mathlib 0df444a (Lean v4.33.1)
bip30bip34bitcoinbitcoin-mainnetblock-validationconnectblockconsensusformal-verificationundo
checkTransaction tx = true iff TxSpec tx: non-empty inputs and outputs, stripped size within the limit, every output value in [0,MAX_MONEY] and the total at most MAX_MONEY, distinct prevouts, the coinbase script-length rule, and no null prevout for a non-coinbase.
Deprecated. Superseded by BitcoinBlockV2.checkTransaction_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.
Preamble
import Definitions.Def_BitcoinBlock
import Definitions.Def_BitcoinSer
Formal statement
theorem BitcoinBlock.checkTransaction_iff (tx : BitcoinSer.Tx) :
BitcoinBlock.checkTransaction tx = true ↔ BitcoinBlock.TxSpec tx := by sorrySource
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: AcceptBlockHeader, CheckBlockHeader, ContextualCheckBlockHeader, CheckBlock, CheckMerkleRoot, CheckWitnessMalleation, ContextualCheckBlock, ConnectBlock, GetBlockScriptFlags, IsBIP30Repeat, IsBIP30Unspendable, UpdateCoins, DisconnectBlock, ApplyTxInUndo, src/validation.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/validation.cpp; CheckTransaction (consensus/tx_check.cpp); IsFinalTx, GetLegacySigOpCount, GetP2SHSigOpCount, GetTransactionSigOpCost, CheckTxInputs (consensus/tx_verify.cpp); CScript::GetSigOpCount, IsUnspendable (script/script.cpp, script.h); CountWitnessSigOps (script/interpreter.cpp); AddCoin, SpendCoin, AddCoins (coins.cpp); GetBlockProof (chain.cpp); GetWitnessCommitmentIndex, GetBlockWeight (consensus/validation.h); CMainParams (kernel/chainparams.cpp)
Read-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.checkTransaction_iff
Binders
- tx : a serialized transaction: version ∈N, a list tx.vin of inputs (each with prevout ⟨hash bytes,n∈N⟩, scriptSig bytes, sequence ∈N, witness stack), a list tx.vout of outputs (each with value ∈Z and scriptPubKey bytes), and lock time ∈N.
There are no hypotheses.
Conclusion
checkTransaction(tx)=true⟺TxSpec(tx).
Left side, unfolded
checkTransaction(tx) is the Boolean conjunction of:
- tx.vin is non-empty;
- tx.vout is non-empty;
- ∣serTx(false,tx)∣⋅4≤4000000, where serTx(false,tx) is the witness-free serialization (4-byte version modulo 232, compact-size-prefixed inputs, compact-size-prefixed outputs, 4-byte lock time modulo 232);
- outputsLoop(tx.vout,0) returns a value: scanning outputs in order with accumulator starting at 0, fail if an output value is <0, fail if it is >2100000000000000, fail if the new accumulator acc+v is outside [0,2.1⋅1015], else continue; success returns the final accumulator;
- the list of prevouts of tx.vin has no duplicates;
- if isCoinBase(tx) (i.e. tx.vin is a single input whose prevout hash is 32 zero bytes and whose index is 4294967295): the scriptSig length of the head of tx.vin (default input with empty scriptSig if the list were empty) satisfies 2≤ℓ≤100; otherwise every input of tx has a non-null prevout (prevout hash =32 zero bytes or index =4294967295).
Right side, unfolded
TxSpec(tx) is the conjunction:
- tx.vin=[];
- tx.vout=[];
- ∣serTx(false,tx)∣⋅4≤4000000;
- for every output o of tx, 0≤o.nValue≤2100000000000000;
- valueOut(tx)≤2100000000000000, where valueOut(tx)=∑o∈tx.vouto.nValue (an integer sum, 0 for no outputs);
- the prevouts of tx.vin are pairwise distinct;
- isCoinBase(tx)=true⇒ for every input i of tx, 2≤∣i.scriptSig∣≤100;
- isCoinBase(tx)=false⇒ for every input i of tx, outPointNull(i.prevout)=false.
Edge cases silently included
Empty input or output lists (both sides false); the left checks every running partial sum while the right checks each value and the total; the coinbase scriptSig bound is on the head input (left) versus all inputs (right), the two coinciding because a coinbase has exactly one input; hash bytes of arbitrary length are allowed (a prevout hash is "null" only when it is exactly 32 zero bytes).
View graph
Confirmed by the moderator at approval.