Received HTLC, revocation path
ProvedBitcoinHtlc.received_revocationAs offered_revocation, for the received script.
import Definitions.Def_BitcoinHtlc import Definitions.Def_BitcoinScript open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinHtlc.received_revocation (f : Flags) (o : Oracle) (revHash remoteKey localKey payHash pk sig : Bytes) (expiry : Int)
(hrev : revHash.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) (hrem : remoteKey.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
(hloc : localKey.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE) (hpay : payHash.length ≤ BitcoinScript.MAX_SCRIPT_ELEMENT_SIZE)
(hd : expiry.natAbs < 2 ^ 32) (hb : o.hash160 pk = revHash) :
BitcoinScript.evalScript f o [pk, sig] (BitcoinHtlc.receivedScript revHash remoteKey localKey payHash expiry) =
(o.checkSig sig pk).map (fun ok => [BitcoinScript.boolBytes ok]) := 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: BitcoinHtlc.received_revocation
Statement. Let be any flag set, any oracle, any six byte strings and any integer, under the hypotheses , , , (bounding only the four script parameters; and are unbounded), (absolute value) and . The theorem asserts
i.e. the interpreter run on the initial stack ( on top) and the received script yields exactly when , and yields the one-element stack (that is or ) when . The signature is checked against the stack element itself; the expiry does not appear on the right-hand side.
Definitions unfolded
Basic notions used throughout. A byte is an 8-bit word and a byte string (written ) is a finite list of bytes; denotes the length of a byte string . The constant is the interpreter's maximum size of one stack element. A flag set consists of three Booleans , , . An oracle is an arbitrary structure supplying eight functions with no constraints whatsoever on their behaviour: (so in particular is any function from byte strings to byte strings, not necessarily RIPEMD160SHA256, not necessarily 20-byte-valued), (first argument the signature, second the public key; the value represents a script-aborting failure, a verdict ), and . Stacks are lists written top element first. is: false for the empty string; for a one-byte string , true iff and ; for with non-empty, true iff or (so a string of zero bytes whose last byte is is false). and (the empty string). The script-number encoding of an integer is: if ; otherwise the little-endian bytes of with no trailing zero byte, then, if the last of those bytes has its top bit () set, an extra byte (for ) or (for ) is appended, and otherwise, for , the top bit of the last byte is set. For example and . The decoding ("script number of at most bytes, non-minimal encodings allowed") is if , and otherwise of the little-endian value of with the top bit of the last byte read as a sign (the empty string decodes to ).
The number push / . For an integer , is the single opcode with byte value when or (so is the opcode , is the opcode , i.e. OP_2), and otherwise it is the data push of (so is the push of the one-byte string , and is the push of the empty string). is the byte-level form: the one opcode byte in the first case, and otherwise, where is the canonical push encoding of a byte string : if ; if ; if ; and otherwise.
The two witness scripts as instruction lists. Writing for the data push of the byte string , the offered script , for byte strings (the "revocation hash"), (the "remote key"), (the "local key") and (the "payment hash"), all four being completely unconstrained parameters (any byte strings, not necessarily 20 bytes, not necessarily hashes of anything), is the 26-instruction list
where is and OP_2 is , the opcode byte . The received script additionally takes an integer (the "expiry", any integer, possibly negative or zero) and is the 28-instruction list
where is the opcode if or , and the data push of otherwise (the empty push when ; a push carrying a sign bit when ).
The interpreter . This is the transcription of Bitcoin Core's legacy EvalScript: starting from the state (main stack , empty alt stack, empty condition stack, operation count ), it processes the instructions of in order and returns ("script failure") or of the final main stack. One instruction is processed as follows. A data push of fails if ; otherwise is pushed onto the main stack when every entry of the condition stack is true (otherwise the state is unchanged), and the step fails if the main and alt stacks then hold more than elements together. An opcode is "counted" when (OP_16); a counted opcode fails if the count already equals , and otherwise increments the count; any of the fifteen disabled opcodes (OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_INVERT, OP_AND, OP_OR, OP_XOR, OP_2MUL, OP_2DIV, OP_MUL, OP_DIV, OP_MOD, OP_LSHIFT, OP_RSHIFT) fails even when not executed; then, if every entry of the condition stack is true ("executing") or is one of OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF (any byte from to inclusive, which also includes the bytes and , for which execution fails), the opcode is executed and the 1000-element stack bound re-checked; an unexecuted opcode leaves the state alone. After the last instruction the run fails if the condition stack is non-empty. The executed opcodes relevant here behave as follows (with "fail" meaning ): OP_1…OP_16 push (so OP_2 pushes ; these are not counted); OP_DUP fails on an empty stack and otherwise duplicates the top; OP_DROP fails on an empty stack and otherwise removes the top; OP_SWAP fails with fewer than two elements and otherwise exchanges the top two; OP_SIZE fails on an empty stack and otherwise pushes above the unchanged top; OP_HASH160 fails on an empty stack and otherwise replaces the top by ; OP_EQUAL fails with fewer than two elements and otherwise pops the top two (top) and and pushes (byte-string equality), while OP_EQUALVERIFY pops them and fails unless ; OP_IF (resp. OP_NOTIF), when executing, fails on an empty stack and otherwise pops the top and pushes (resp. its negation) onto the condition stack, and when not executing pushes false onto the condition stack without touching the main stack; OP_ELSE fails on an empty condition stack and otherwise negates its top; OP_ENDIF fails on an empty condition stack and otherwise pops it; OP_CHECKSIG fails with fewer than two elements and otherwise pops (top) and , fails if , and pushes if it is ; OP_CHECKLOCKTIMEVERIFY is a no-op if is false, and otherwise fails on an empty stack, decodes the top as (failing if it has more than bytes), fails if the value is negative or is false, and otherwise leaves the state unchanged (the operand stays on the stack); OP_CHECKMULTISIG fails on an empty stack and otherwise pops decoded as (failing if undecodable, negative or ), adds the value to the operation count (failing if that exceeds ), takes exactly that many keys from the stack (failing if too few), pops decoded as (failing if undecodable, negative or ), takes exactly that many signatures (failing if too few), computes (failing if it is ), then pops one more element (failing if the stack is empty), fails if is true and is non-empty, and finally pushes of the loop's verdict.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.