Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

CheckTransaction characterized

Proved
BitcoinBlock.checkTransaction_iff

by 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][0, \mathrm{MAX\_MONEY}][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 sorry
Source
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

  • txtxtx : a serialized transaction: version ∈N\in \mathbb{N}∈N, a list tx.vintx.\mathrm{vin}tx.vin of inputs (each with prevout ⟨hash bytes,n∈N⟩\langle \text{hash bytes}, n \in \mathbb{N}\rangle⟨hash bytes,n∈N⟩, scriptSig bytes, sequence ∈N\in \mathbb{N}∈N, witness stack), a list tx.vouttx.\mathrm{vout}tx.vout of outputs (each with value ∈Z\in \mathbb{Z}∈Z and scriptPubKey bytes), and lock time ∈N\in \mathbb{N}∈N.

There are no hypotheses.

Conclusion

checkTransaction(tx)=true  ⟺  TxSpec(tx).\mathrm{checkTransaction}(tx) = \mathrm{true} \iff \mathrm{TxSpec}(tx).checkTransaction(tx)=true⟺TxSpec(tx).

Left side, unfolded

checkTransaction(tx)\mathrm{checkTransaction}(tx)checkTransaction(tx) is the Boolean conjunction of:

  1. tx.vintx.\mathrm{vin}tx.vin is non-empty;
  2. tx.vouttx.\mathrm{vout}tx.vout is non-empty;
  3. ∣serTx(false,tx)∣⋅4≤4 000 000|\mathrm{serTx}(\mathrm{false}, tx)| \cdot 4 \le 4\,000\,000∣serTx(false,tx)∣⋅4≤4000000, where serTx(false,tx)\mathrm{serTx}(\mathrm{false},tx)serTx(false,tx) is the witness-free serialization (4-byte version modulo 2322^{32}232, compact-size-prefixed inputs, compact-size-prefixed outputs, 4-byte lock time modulo 2322^{32}232);
  4. outputsLoop(tx.vout,0)\mathrm{outputsLoop}(tx.\mathrm{vout}, 0)outputsLoop(tx.vout,0) returns a value: scanning outputs in order with accumulator starting at 000, fail if an output value is <0<0<0, fail if it is >2 100 000 000 000 000> 2\,100\,000\,000\,000\,000>2100000000000000, fail if the new accumulator acc+v\mathit{acc} + vacc+v is outside [0,2.1⋅1015][0, 2.1\cdot 10^{15}][0,2.1⋅1015], else continue; success returns the final accumulator;
  5. the list of prevouts of tx.vintx.\mathrm{vin}tx.vin has no duplicates;
  6. if isCoinBase(tx)\mathrm{isCoinBase}(tx)isCoinBase(tx) (i.e. tx.vintx.\mathrm{vin}tx.vin is a single input whose prevout hash is 32 zero bytes and whose index is 429496729542949672954294967295): the scriptSig length of the head of tx.vintx.\mathrm{vin}tx.vin (default input with empty scriptSig if the list were empty) satisfies 2≤ℓ≤1002 \le \ell \le 1002≤ℓ≤100; otherwise every input of txtxtx has a non-null prevout (prevout hash ≠32\ne 32=32 zero bytes or index ≠4294967295\ne 4294967295=4294967295).

Right side, unfolded

TxSpec(tx)\mathrm{TxSpec}(tx)TxSpec(tx) is the conjunction:

  • tx.vin≠[ ]tx.\mathrm{vin} \ne [\,]tx.vin=[];
  • tx.vout≠[ ]tx.\mathrm{vout} \ne [\,]tx.vout=[];
  • ∣serTx(false,tx)∣⋅4≤4 000 000|\mathrm{serTx}(\mathrm{false},tx)|\cdot 4 \le 4\,000\,000∣serTx(false,tx)∣⋅4≤4000000;
  • for every output ooo of txtxtx, 0≤o.nValue≤2 100 000 000 000 0000 \le o.\mathrm{nValue} \le 2\,100\,000\,000\,000\,0000≤o.nValue≤2100000000000000;
  • valueOut(tx)≤2 100 000 000 000 000\mathrm{valueOut}(tx) \le 2\,100\,000\,000\,000\,000valueOut(tx)≤2100000000000000, where valueOut(tx)=∑o∈tx.vouto.nValue\mathrm{valueOut}(tx) = \sum_{o \in tx.\mathrm{vout}} o.\mathrm{nValue}valueOut(tx)=∑o∈tx.vout​o.nValue (an integer sum, 000 for no outputs);
  • the prevouts of tx.vintx.\mathrm{vin}tx.vin are pairwise distinct;
  • isCoinBase(tx)=true⇒\mathrm{isCoinBase}(tx) = \mathrm{true} \RightarrowisCoinBase(tx)=true⇒ for every input iii of txtxtx, 2≤∣i.scriptSig∣≤1002 \le |i.\mathrm{scriptSig}| \le 1002≤∣i.scriptSig∣≤100;
  • isCoinBase(tx)=false⇒\mathrm{isCoinBase}(tx) = \mathrm{false} \RightarrowisCoinBase(tx)=false⇒ for every input iii of txtxtx, outPointNull(i.prevout)=false\mathrm{outPointNull}(i.\mathrm{prevout}) = \mathrm{false}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).

Human review
  • Endorsed by Shuze Chen · Oct 27, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 27, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me