ANYONECANPAY signs only the signed input
ProvedBitcoinSig.sigHashLegacy_anyoneCanPayWith the SIGHASH_ANYONECANPAY bit set, the legacy hash of two transactions that agree on version, outputs, lock time and on the prevout and sequence of the signed input is the same, whatever their other inputs.
import Definitions.Def_BitcoinSig open BitcoinSig BitcoinSer
theorem BitcoinSig.sigHashLegacy_anyoneCanPay (scriptCode : Bytes) (tx tx' : Tx) (nIn hashType : Nat)
(hacp : hashType &&& BitcoinSig.SIGHASH_ANYONECANPAY ≠ 0)
(h1 : tx'.version = tx.version) (h2 : tx'.vout = tx.vout) (h3 : tx'.nLockTime = tx.nLockTime)
(h4 : (tx'.vin.getD nIn ⟨⟨[], 0⟩, [], 0, []⟩).prevout = (tx.vin.getD nIn ⟨⟨[], 0⟩, [], 0, []⟩).prevout)
(h5 : (tx'.vin.getD nIn ⟨⟨[], 0⟩, [], 0, []⟩).nSequence = (tx.vin.getD nIn ⟨⟨[], 0⟩, [], 0, []⟩).nSequence) :
BitcoinSig.sigHashLegacy scriptCode tx' nIn hashType = BitcoinSig.sigHashLegacy scriptCode tx nIn hashType := 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: BitcoinSig.sigHashLegacy_anyoneCanPay
Binders and hypothesis. Universally quantified over: a byte string ; two transactions and ; natural numbers (an input index) and (an unbounded natural number, not restricted to a byte). Write for the default input (empty prevout hash, prevout index 0, empty scriptSig, sequence 0, no witness), and for the -th input of or if . Five hypotheses:
- : (bitwise AND on natural numbers; the
SIGHASH_ANYONECANPAYbit is set); - : ;
- : (the output lists are equal as lists);
- : ;
- : ;
- : . Nothing is assumed about the number of inputs of either transaction, about other inputs, or about scriptSigs and witnesses.
Conclusion.
Unfolding. sigHashLegacy is uint256One (the byte 1 followed by 31 zeros) if and ; otherwise it is the double SHA-256 of serSigTx followed by the 4 little-endian bytes of . The special-case test depends only on , and the output list, which equates, so both sides take the same branch. In the hashing branch, serSigTx with the ANYONECANPAY bit set serializes: the 4-byte version; the compact size ; exactly one input record, which is serSigInput at index (because of the bit, the loop index is overridden by ): serOutPoint of the prevout of (hash bytes, then 4-byte index), then — since the index equals — serScriptCode (the script code with OP_CODESEPARATOR instructions removed, prefixed by its compact size), then the 4-byte sequence of ; then the compact size of and the output records, where is if , if , else , and each record is serTxOut of output (or of if in SINGLE mode or if is out of range); then the 4-byte lock time. Every quantity consulted — version, the chosen input's prevout and sequence, the output list, the lock time, and the common , , — is equated by the hypotheses, so the serializations and hence the hashes coincide.
Edge cases. If is out of range for one or both transactions, / compare against the default input's empty hash and zero sequence, and the serialized outpoint of the default is only 4 zero bytes. Hash types such as (ANYONECANPAY with low bits ) or fall into the "all outputs" treatment. values above are permitted by the binder.
What is not said. The statement does not say anything when the ANYONECANPAY bit is clear (then other inputs' prevouts and sequences matter). It does not say that the hypotheses are necessary for equality of hashes. It does not say the two transactions have the same number of inputs or the same inputs other than input , and does not need to. It does not mention scriptSigs or witnesses at all. It does not say that the common hash is a hash of anything "meaningful", nor that it differs from uint256One. It does not involve the witness-v0 signature hash.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.