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.connectLoop_iff
Binders and hypotheses
- f : a record of seven Boolean script flags (p2sh, witness, taproot, dersig, cltv, csv, nulldummy).
- H∈N : the block height used for maturity, coin creation and BIP68.
- mtp:N→N : a median-time-past function by height (arbitrary).
- ltf∈N : the lock-time flags word.
- txs : a list of serialized transactions.
- u : a ledger (association list from outpoints to coins).
- fees∈Z, sigOps∈N : initial accumulators.
- undo : a block undo list (list of lists of coins), the initial undo accumulator.
- Hypothesis hpos : for every tx∈txs, 0≤valueOut(tx) (sum of its output values).
- Hypothesis hfees : 0≤fees.
The hypotheses and the binder undo do not appear in the right-hand side of the conclusion.
Conclusion
(∃st, connectLoop(f,H,mtp,ltf,⟨u,fees,sigOps,undo⟩,txs)=somest)⟺TxsSpec(f,H,mtp,ltf,u,fees,sigOps,txs).
Left side, unfolded
connectLoop on the empty list returns some of the current state. On tx::rest from state ⟨v,F,Σ,U⟩:
- Fee/undo step. If isCoinBase(tx) (exactly one input whose prevout is 32 zero bytes with index 232−1): (F,U) unchanged. Otherwise checkTxInputs(v,tx,H) must return somefee (every prevout present in v; for each input's coin c: not [coinbase and H−c.height<100 in natural subtraction], c.out.nValue∈[0,M], running sum in [0,M]; final valueIn≥valueOut(tx); valueIn−valueOut(tx)∈[0,M]; fee=valueIn−valueOut(tx); M=2.1⋅1015), else fail; then F+fee∈[0,M] else fail; then sequenceLocksOk(v,H,mtp,ltf,tx) else fail; new F:=F+fee, U:=U++[[accessCoin(v,i.prevout)∣i∈tx.vin]].
- Σ′:=Σ+txSigOpCost(f,v,tx); fail if Σ′>80000.
- If not coinbase and inputScriptsOk(f,v,tx) is false, fail.
- Continue on rest from ⟨updateCoins(v,tx,H),F′,Σ′,U′⟩.
Auxiliary meanings: sequenceLocksOk runs the BIP68 core calculation with version tx.versionmod232, flags ltfmod232, context ⟨H,mtp⟩ and inputs ⟨i.nSequencemod232,accessCoin(v,i.prevout).height⟩ (height 0 for a missing coin), returning whether the accumulated minimum height is <H and the accumulated minimum time is <mtp(H−1). txSigOpCost(f,v,tx)=4⋅legacySigOpCount(tx)+ (for non-coinbase) 4⋅∑ip2shSigOpCount if f.p2sh, plus ∑icountWitnessSigOps, all against the spent scriptPubKeys from accessCoin. inputScriptsOk(f,v,tx): for every index n<∣tx.vin∣, the full VerifyScript (with the Taproot handler) succeeds for input n, with the spent-outputs list [accessCoin(v,j.prevout).out∣j∈tx.vin], context ⟨f,tx,n,spent value⟩, the input's scriptSig, the coin's scriptPubKey and the input's witness. updateCoins(v,tx,H): remove the entries keyed by tx's prevouts (none for a coinbase), then add each spendable output i as ⟨tx.vouti,H,isCoinBase(tx)⟩ under ⟨txid(tx),i⟩, replacing an existing entry.
Right side, unfolded
TxsSpec(f,H,mtp,ltf,u,fees,sigOps,txs): true for []; for tx::rest from (v,F,Σ):
- isCoinBase(tx)=false⇒[TxInputsSpec(f,v,H,mtp,ltf,tx)∧F+feeOf(v,tx)≤M], where feeOf(v,tx)=valueIn(v,tx.vin)−valueOut(tx) with valueIn summing accessCoin values (dummy −1 if missing), and TxInputsSpec is: ∀i∈tx.vin,∃c,getCoin(v,i.prevout)=somec∧(c.isCoinbase=true⇒c.height+100≤H)∧0≤c.out.nValue≤M; valueIn(v,tx.vin)≤M; valueOut(tx)≤valueIn(v,tx.vin); satisfiesBIP68 (specification form: BIP68 not enabled, i.e. version mod232<2 or ltfmod232 even, or every input is disabled (bit 31) or — time-based (bit 22): mtp(c.height−1)+512⋅(seqmod216)≤mtp(H−1); height-based: c.height+(seqmod216)≤H — with natural subtraction in c.height−1 and H−1); and ∀n<∣tx.vin∣, the same full script verification as in inputScriptsOk equals true;
- Σ+txSigOpCost(f,v,tx)≤80000;
- TxsSpec on rest from (updateCoins(v,tx,H), F if coinbase else F+feeOf(v,tx), Σ+txSigOpCost(f,v,tx)).
Note that the right side imposes no lower bound on F+feeOf (the left requires F+fee≥0), which is where hfees and hpos enter.
Edge cases silently included
Empty txs (both sides trivially true); coinbase-shaped transactions anywhere in the list (no input checks either side); undo arbitrary and irrelevant to the right side; mtp arbitrary (e.g. non-monotone); 32-bit truncation of version, sequence and ltf; natural subtraction in maturity and in mtp(⋅−1); missing coins give value −1 and height 0 via accessCoin on both sides where it is used; duplicate keys in u (first match wins).
Confirmed by the moderator at approval.