Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Buried deployments, script-verification flags by height, and the two exception blocks

Definition
BitcoinActivation

by pitimespi · Oct 26, 2026 · Mathlib 0df444a (Lean v4.33.1)

bitcoinbitcoin-mainnetconsensusformal-verificationscript-flagssoft-fork-activation

A buried deployment is one of HEIGHTINCB (BIP34), CLTV (BIP65), DERSIG (BIP66), CSV, SEGWIT, with mainnet activation heights 227,931227{,}931227,931, 388,381388{,}381388,381, 363,725363{,}725363,725, 419,328419{,}328419,328, 481,824481{,}824481,824 (deploymentHeight). activeAt(height, dep) holds when the deployment height is at most the block height, as DeploymentActiveAt; activeAfter(prevHeight, dep) holds when it is at most prevHeight +1+ 1+1, as DeploymentActiveAfter.

A flag set is a record of seven Booleans: p2sh, witness, taproot, dersig, cltv, csv, nulldummy. noFlags has none; baseFlags has p2sh, witness, taproot. A block's exception status is none, bip16Block (the hash-keyed P2SH violation) or taprootBlock (the hash-keyed Taproot violation); exceptionBase yields baseFlags, noFlags, and p2sh+witness respectively.

blockScriptFlags(height, exc) is GetBlockScriptFlags: the exception base, with dersig, cltv, csv, nulldummy each OR-ed with activeAt of DERSIG, CLTV, CSV, SEGWIT at the height. ScriptFlags.le is pointwise inclusion: every flag true in the first is true in the second.

LOCKTIME_VERIFY_SEQUENCE=1\mathrm{LOCKTIME\_VERIFY\_SEQUENCE} = 1LOCKTIME_VERIFY_SEQUENCE=1, and lockTimeFlags(height) is that value when CSV is active at the height and 000 otherwise, as nLockTimeFlags in ConnectBlock.

Formalization Note. The exception table is modeled by the three-valued classification rather than a hash lookup. Versionbits deployments are not modeled, since the pinned source consults none for mainnet consensus flags. Only Std is imported.

Definition code
import Std

namespace BitcoinActivation

/-! Transcription of the historical rule selection of Bitcoin Core at revision
`a773e1e33b349dc819b5a0edc1c7a4839dc73b48`: the buried deployment heights of `CMainParams`
(`kernel/chainparams.cpp`), `DeploymentActiveAt` / `DeploymentActiveAfter` for buried deployments
(`deploymentstatus.h`), `GetBlockScriptFlags` with the two `script_flag_exceptions`
(`validation.cpp`), and the `nLockTimeFlags` selection in `ConnectBlock`. -/

/-- `Consensus::BuriedDeployment`. -/
inductive BuriedDeployment where
  | heightInCB   -- BIP34
  | cltv         -- BIP65
  | derSig       -- BIP66
  | csv          -- BIP68/112/113
  | segwit       -- BIP141/143/147
  deriving DecidableEq, Repr

/-- `Consensus::Params::DeploymentHeight` at mainnet values. -/
def deploymentHeight : BuriedDeployment → Nat
  | .heightInCB => 227931
  | .cltv => 388381
  | .derSig => 363725
  | .csv => 419328
  | .segwit => 481824

/-- `DeploymentActiveAt(index, dep) = index.nHeight >= DeploymentHeight(dep)`. -/
def activeAt (height : Nat) (dep : BuriedDeployment) : Bool := decide (deploymentHeight dep ≤ height)

/-- `DeploymentActiveAfter(pindexPrev, dep) = pindexPrev->nHeight + 1 >= DeploymentHeight(dep)`. -/
def activeAfter (prevHeight : Nat) (dep : BuriedDeployment) : Bool :=
  decide (deploymentHeight dep ≤ prevHeight + 1)

/-- The consensus script-verification flags `GetBlockScriptFlags` can set. -/
structure ScriptFlags where
  p2sh : Bool
  witness : Bool
  taproot : Bool
  dersig : Bool
  cltv : Bool
  csv : Bool
  nulldummy : Bool
  deriving DecidableEq, Repr

/-- `SCRIPT_VERIFY_NONE`. -/
def noFlags : ScriptFlags := ⟨false, false, false, false, false, false, false⟩

/-- The default base `SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_TAPROOT`. -/
def baseFlags : ScriptFlags := ⟨true, true, true, false, false, false, false⟩

/-- `consensus.script_flag_exceptions`: the block is one of the two historical exceptions, or
not. The BIP16 exception (`00000000000002dc…9c22`) maps to `SCRIPT_VERIFY_NONE`; the Taproot
exception (`0000000000000000000f14c3…95ad`) maps to `SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS`. -/
inductive ScriptException where
  | none
  | bip16Block
  | taprootBlock
  deriving DecidableEq, Repr

/-- The flags the exception table yields, or the default base. -/
def exceptionBase : ScriptException → ScriptFlags
  | .none => baseFlags
  | .bip16Block => noFlags
  | .taprootBlock => ⟨true, true, false, false, false, false, false⟩

/-- `GetBlockScriptFlags(block_index)` at mainnet: the base (default or exception), then
`DERSIG`, `CHECKLOCKTIMEVERIFY`, `CHECKSEQUENCEVERIFY` and `NULLDUMMY` added when BIP66, BIP65,
CSV and SegWit respectively are active at the block's height. -/
def blockScriptFlags (height : Nat) (exc : ScriptException) : ScriptFlags :=
  let f := exceptionBase exc
  { f with
    dersig := f.dersig || activeAt height .derSig
    cltv := f.cltv || activeAt height .cltv
    csv := f.csv || activeAt height .csv
    nulldummy := f.nulldummy || activeAt height .segwit }

/-- Pointwise inclusion of flag sets: every rule enforced by the first is enforced by the second. -/
def ScriptFlags.le (a b : ScriptFlags) : Prop :=
  (a.p2sh = true → b.p2sh = true) ∧ (a.witness = true → b.witness = true) ∧
  (a.taproot = true → b.taproot = true) ∧ (a.dersig = true → b.dersig = true) ∧
  (a.cltv = true → b.cltv = true) ∧ (a.csv = true → b.csv = true) ∧
  (a.nulldummy = true → b.nulldummy = true)

/-- `consensus/consensus.h`: `LOCKTIME_VERIFY_SEQUENCE = (1 << 0)`. -/
def LOCKTIME_VERIFY_SEQUENCE : Nat := 1

/-- The `nLockTimeFlags` of `ConnectBlock`: `LOCKTIME_VERIFY_SEQUENCE` once CSV is active at the
block's height, else `0`. -/
def lockTimeFlags (height : Nat) : Nat :=
  if activeAt height .csv then LOCKTIME_VERIFY_SEQUENCE else 0

end BitcoinActivation
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: GetBlockScriptFlags, src/validation.cpp lines 2249-2288: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/validation.cpp#L2249; DeploymentActiveAt / DeploymentActiveAfter (buried), src/deploymentstatus.h; BuriedDeployment and DeploymentHeight, src/consensus/params.h; CMainParams BIP34Height, BIP65Height, BIP66Height, CSVHeight, SegwitHeight, script_flag_exceptions, src/kernel/chainparams.cpp; LOCKTIME_VERIFY_SEQUENCE, src/consensus/consensus.h; nLockTimeFlags in ConnectBlock, src/validation.cpp line 2478
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: Def_BitcoinActivation (all declarations)

Everything below lives in a single namespace, here called BitcoinActivation. There are thirteen declarations: two inductive types, one record type, and ten definitions. No theorem is stated in this file.


BuriedDeployment (inductive type). A finite type with exactly five distinct elements and nothing else. The five elements are named heightInCB\mathsf{heightInCB}heightInCB, cltv\mathsf{cltv}cltv, derSig\mathsf{derSig}derSig, csv\mathsf{csv}csv, and segwit\mathsf{segwit}segwit. The type comes with decidable equality (any two elements can be compared) and a printable representation. The comments next to the constructors mention BIP numbers, but those comments carry no formal content: an element of this type is just one of five labels.


deploymentHeight (function deploymentHeight:BuriedDeployment→N\mathsf{deploymentHeight} : \mathsf{BuriedDeployment} \to \mathbb{N}deploymentHeight:BuriedDeployment→N). A total function from the five labels to natural numbers, given by the table

deploymentHeight(heightInCB)=227931,deploymentHeight(cltv)=388381,deploymentHeight(derSig)=363725,deploymentHeight(csv)=419328,deploymentHeight(segwit)=481824.\begin{aligned} \mathsf{deploymentHeight}(\mathsf{heightInCB}) &= 227931,\\ \mathsf{deploymentHeight}(\mathsf{cltv}) &= 388381,\\ \mathsf{deploymentHeight}(\mathsf{derSig}) &= 363725,\\ \mathsf{deploymentHeight}(\mathsf{csv}) &= 419328,\\ \mathsf{deploymentHeight}(\mathsf{segwit}) &= 481824. \end{aligned}deploymentHeight(heightInCB)deploymentHeight(cltv)deploymentHeight(derSig)deploymentHeight(csv)deploymentHeight(segwit)​=227931,=388381,=363725,=419328,=481824.​

Note that the numeric order of these values (227931<363725<388381<419328<481824227931 < 363725 < 388381 < 419328 < 481824227931<363725<388381<419328<481824) is not the order in which the constructors are listed: derSig\mathsf{derSig}derSig (363725363725363725) is numerically below cltv\mathsf{cltv}cltv (388381388381388381) although cltv\mathsf{cltv}cltv is listed first.


activeAt (function activeAt:N→BuriedDeployment→B\mathsf{activeAt} : \mathbb{N} \to \mathsf{BuriedDeployment} \to \mathbb{B}activeAt:N→BuriedDeployment→B, where B={true,false}\mathbb{B} = \{\mathsf{true}, \mathsf{false}\}B={true,false}). For a natural number hhh ("height") and a label ddd, activeAt(h,d)\mathsf{activeAt}(h, d)activeAt(h,d) is the Boolean value (not a proposition) that is true\mathsf{true}true exactly when deploymentHeight(d)≤h\mathsf{deploymentHeight}(d) \le hdeploymentHeight(d)≤h and false\mathsf{false}false otherwise. In particular the comparison is non-strict: at h=deploymentHeight(d)h = \mathsf{deploymentHeight}(d)h=deploymentHeight(d) itself the value is true\mathsf{true}true. Heights are natural numbers, so h=0h = 0h=0 is allowed (giving false\mathsf{false}false for every label, since every tabulated height is positive) and no negative height exists.


activeAfter (function activeAfter:N→BuriedDeployment→B\mathsf{activeAfter} : \mathbb{N} \to \mathsf{BuriedDeployment} \to \mathbb{B}activeAfter:N→BuriedDeployment→B). For a natural number ppp ("previous height") and a label ddd, activeAfter(p,d)\mathsf{activeAfter}(p, d)activeAfter(p,d) is the Boolean value that is true\mathsf{true}true exactly when deploymentHeight(d)≤p+1\mathsf{deploymentHeight}(d) \le p + 1deploymentHeight(d)≤p+1, and false\mathsf{false}false otherwise. Here p+1p + 1p+1 is ordinary natural-number successor (no wrap-around). Nothing in the definition relates it to activeAt\mathsf{activeAt}activeAt; it is defined directly by the inequality.


ScriptFlags (record type). A record with exactly seven Boolean fields, in this order: p2sh\mathsf{p2sh}p2sh, witness\mathsf{witness}witness, taproot\mathsf{taproot}taproot, dersig\mathsf{dersig}dersig, cltv\mathsf{cltv}cltv, csv\mathsf{csv}csv, nulldummy\mathsf{nulldummy}nulldummy. A value of this type is therefore a 7-tuple of Booleans, and two values are equal exactly when all seven fields agree. Equality is decidable and values are printable. Below, a value is written as a tuple ⟨p2sh,witness,taproot,dersig,cltv,csv,nulldummy⟩\langle \mathsf{p2sh}, \mathsf{witness}, \mathsf{taproot}, \mathsf{dersig}, \mathsf{cltv}, \mathsf{csv}, \mathsf{nulldummy}\rangle⟨p2sh,witness,taproot,dersig,cltv,csv,nulldummy⟩ in that field order, with T\mathsf{T}T for true\mathsf{true}true and F\mathsf{F}F for false\mathsf{false}false.


noFlags (constant of type ScriptFlags\mathsf{ScriptFlags}ScriptFlags). The record with all seven fields false\mathsf{false}false:

noFlags=⟨F,F,F,F,F,F,F⟩.\mathsf{noFlags} = \langle \mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F}\rangle .noFlags=⟨F,F,F,F,F,F,F⟩.

baseFlags (constant of type ScriptFlags\mathsf{ScriptFlags}ScriptFlags). The record whose first three fields are true\mathsf{true}true and whose last four are false\mathsf{false}false:

baseFlags=⟨T,T,T,F,F,F,F⟩,\mathsf{baseFlags} = \langle \mathsf{T},\mathsf{T},\mathsf{T},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F}\rangle,baseFlags=⟨T,T,T,F,F,F,F⟩,

i.e. p2sh=witness=taproot=true\mathsf{p2sh} = \mathsf{witness} = \mathsf{taproot} = \mathsf{true}p2sh=witness=taproot=true and dersig=cltv=csv=nulldummy=false\mathsf{dersig} = \mathsf{cltv} = \mathsf{csv} = \mathsf{nulldummy} = \mathsf{false}dersig=cltv=csv=nulldummy=false.


ScriptException (inductive type). A finite type with exactly three distinct elements, named none\mathsf{none}none, bip16Block\mathsf{bip16Block}bip16Block, and taprootBlock\mathsf{taprootBlock}taprootBlock, with decidable equality and a printable representation. Important: none\mathsf{none}none here is an ordinary constructor of this three-element type — it is not the "absent value" of an option type. Writing .none\mathsf{.none}.none in later statements picks this element. The docstring mentions two block hashes, but no hash appears in the formal content; the type is just three labels.


exceptionBase (function exceptionBase:ScriptException→ScriptFlags\mathsf{exceptionBase} : \mathsf{ScriptException} \to \mathsf{ScriptFlags}exceptionBase:ScriptException→ScriptFlags). A total function on the three labels:

exceptionBase(none)=baseFlags=⟨T,T,T,F,F,F,F⟩,exceptionBase(bip16Block)=noFlags=⟨F,F,F,F,F,F,F⟩,exceptionBase(taprootBlock)=⟨T,T,F,F,F,F,F⟩.\begin{aligned} \mathsf{exceptionBase}(\mathsf{none}) &= \mathsf{baseFlags} = \langle \mathsf{T},\mathsf{T},\mathsf{T},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F}\rangle,\\ \mathsf{exceptionBase}(\mathsf{bip16Block}) &= \mathsf{noFlags} = \langle \mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F}\rangle,\\ \mathsf{exceptionBase}(\mathsf{taprootBlock}) &= \langle \mathsf{T},\mathsf{T},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F},\mathsf{F}\rangle . \end{aligned}exceptionBase(none)exceptionBase(bip16Block)exceptionBase(taprootBlock)​=baseFlags=⟨T,T,T,F,F,F,F⟩,=noFlags=⟨F,F,F,F,F,F,F⟩,=⟨T,T,F,F,F,F,F⟩.​

So the taprootBlock\mathsf{taprootBlock}taprootBlock case has p2sh\mathsf{p2sh}p2sh and witness\mathsf{witness}witness true, taproot\mathsf{taproot}taproot false, and the remaining four fields false.


blockScriptFlags (function blockScriptFlags:N→ScriptException→ScriptFlags\mathsf{blockScriptFlags} : \mathbb{N} \to \mathsf{ScriptException} \to \mathsf{ScriptFlags}blockScriptFlags:N→ScriptException→ScriptFlags). For a natural number hhh and a label eee, let f=exceptionBase(e)f = \mathsf{exceptionBase}(e)f=exceptionBase(e) (one of the three records above). Then blockScriptFlags(h,e)\mathsf{blockScriptFlags}(h, e)blockScriptFlags(h,e) is the record obtained from fff by keeping the fields p2sh\mathsf{p2sh}p2sh, witness\mathsf{witness}witness, taproot\mathsf{taproot}taproot exactly as in fff, and replacing the other four fields by a Boolean OR with an activation test:

dersig:=f.dersig∨activeAt(h,derSig)=f.dersig∨[ 363725≤h ],cltv:=f.cltv∨activeAt(h,cltv)=f.cltv∨[ 388381≤h ],csv:=f.csv∨activeAt(h,csv)=f.csv∨[ 419328≤h ],nulldummy:=f.nulldummy∨activeAt(h,segwit)=f.nulldummy∨[ 481824≤h ],\begin{aligned} \mathsf{dersig} &:= f.\mathsf{dersig} \lor \mathsf{activeAt}(h, \mathsf{derSig}) &&= f.\mathsf{dersig} \lor [\,363725 \le h\,],\\ \mathsf{cltv} &:= f.\mathsf{cltv} \lor \mathsf{activeAt}(h, \mathsf{cltv}) &&= f.\mathsf{cltv} \lor [\,388381 \le h\,],\\ \mathsf{csv} &:= f.\mathsf{csv} \lor \mathsf{activeAt}(h, \mathsf{csv}) &&= f.\mathsf{csv} \lor [\,419328 \le h\,],\\ \mathsf{nulldummy} &:= f.\mathsf{nulldummy} \lor \mathsf{activeAt}(h, \mathsf{segwit}) &&= f.\mathsf{nulldummy} \lor [\,481824 \le h\,], \end{aligned}dersigcltvcsvnulldummy​:=f.dersig∨activeAt(h,derSig):=f.cltv∨activeAt(h,cltv):=f.csv∨activeAt(h,csv):=f.nulldummy∨activeAt(h,segwit)​​=f.dersig∨[363725≤h],=f.cltv∨[388381≤h],=f.csv∨[419328≤h],=f.nulldummy∨[481824≤h],​

where [ P ][\,P\,][P] denotes the Boolean truth value of the decidable inequality PPP and ∨\lor∨ is Boolean OR. Since in all three values of exceptionBase\mathsf{exceptionBase}exceptionBase the fields dersig,cltv,csv,nulldummy\mathsf{dersig}, \mathsf{cltv}, \mathsf{csv}, \mathsf{nulldummy}dersig,cltv,csv,nulldummy are false\mathsf{false}false, these four fields of the result are in fact exactly [ 363725≤h ][\,363725 \le h\,][363725≤h], [ 388381≤h ][\,388381 \le h\,][388381≤h], [ 419328≤h ][\,419328 \le h\,][419328≤h], [ 481824≤h ][\,481824 \le h\,][481824≤h] regardless of eee; the dependence on eee is only through the first three fields (p2sh\mathsf{p2sh}p2sh, witness\mathsf{witness}witness, taproot\mathsf{taproot}taproot), which are copied from exceptionBase(e)\mathsf{exceptionBase}(e)exceptionBase(e) and never altered by the height. Note also that the label heightInCB\mathsf{heightInCB}heightInCB and its height 227931227931227931 are not consulted by this function at all. The definition is total: every natural hhh (including 000) and every eee yields a record.


ScriptFlags.le (binary relation le:ScriptFlags→ScriptFlags→Prop\mathsf{le} : \mathsf{ScriptFlags} \to \mathsf{ScriptFlags} \to \mathsf{Prop}le:ScriptFlags→ScriptFlags→Prop). For records a,ba, ba,b, the proposition le(a,b)\mathsf{le}(a, b)le(a,b) is the conjunction of seven implications, one per field in the fixed order:

(a.p2sh=true⇒b.p2sh=true)  ∧  (a.witness=true⇒b.witness=true)  ∧  (a.taproot=true⇒b.taproot=true)  ∧  (a.dersig=true⇒b.dersig=true)  ∧  (a.cltv=true⇒b.cltv=true)  ∧  (a.csv=true⇒b.csv=true)  ∧  (a.nulldummy=true⇒b.nulldummy=true).\begin{aligned} &(a.\mathsf{p2sh} = \mathsf{true} \Rightarrow b.\mathsf{p2sh} = \mathsf{true}) \;\land\; (a.\mathsf{witness} = \mathsf{true} \Rightarrow b.\mathsf{witness} = \mathsf{true}) \;\land\;\\ &(a.\mathsf{taproot} = \mathsf{true} \Rightarrow b.\mathsf{taproot} = \mathsf{true}) \;\land\; (a.\mathsf{dersig} = \mathsf{true} \Rightarrow b.\mathsf{dersig} = \mathsf{true}) \;\land\;\\ &(a.\mathsf{cltv} = \mathsf{true} \Rightarrow b.\mathsf{cltv} = \mathsf{true}) \;\land\; (a.\mathsf{csv} = \mathsf{true} \Rightarrow b.\mathsf{csv} = \mathsf{true}) \;\land\;\\ &(a.\mathsf{nulldummy} = \mathsf{true} \Rightarrow b.\mathsf{nulldummy} = \mathsf{true}). \end{aligned}​(a.p2sh=true⇒b.p2sh=true)∧(a.witness=true⇒b.witness=true)∧(a.taproot=true⇒b.taproot=true)∧(a.dersig=true⇒b.dersig=true)∧(a.cltv=true⇒b.cltv=true)∧(a.csv=true⇒b.csv=true)∧(a.nulldummy=true⇒b.nulldummy=true).​

Each implication is a one-directional implication between the propositions "this Boolean field equals true\mathsf{true}true"; nothing is asserted when the field of aaa is false\mathsf{false}false. This is a proposition, not a Boolean, and it is not declared as an instance of any order-theoretic class; it is just a named predicate on pairs of records.


LOCKTIME_VERIFY_SEQUENCE (constant of type N\mathbb{N}N). The natural number 111. The docstring mentions a bit shift, but the definition is literally the numeral 111.


lockTimeFlags (function lockTimeFlags:N→N\mathsf{lockTimeFlags} : \mathbb{N} \to \mathbb{N}lockTimeFlags:N→N). For a natural number hhh,

lockTimeFlags(h)={LOCKTIME_VERIFY_SEQUENCE=1if activeAt(h,csv)=true, i.e. if 419328≤h,0otherwise, i.e. if h<419328.\mathsf{lockTimeFlags}(h) = \begin{cases} \mathsf{LOCKTIME\_VERIFY\_SEQUENCE} = 1 & \text{if } \mathsf{activeAt}(h, \mathsf{csv}) = \mathsf{true}, \text{ i.e. if } 419328 \le h,\\ 0 & \text{otherwise, i.e. if } h < 419328. \end{cases}lockTimeFlags(h)={LOCKTIME_VERIFY_SEQUENCE=10​if activeAt(h,csv)=true, i.e. if 419328≤h,otherwise, i.e. if h<419328.​

The branch condition is the Boolean activeAt(h,csv)\mathsf{activeAt}(h, \mathsf{csv})activeAt(h,csv) used as a condition; the result is a natural number that is always either 000 or 111.

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

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 26, 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