Bitcoin SPV Type Lock 约束(主网 btc-mainnet-v0.1.0)Bitcoin SPV Type Lock Constraints (mainnet btc-mainnet-v0.1.0)
来源:ckb-cell/ckb-bitcoin-spv-contracts @f3e3ba8(tag btc-mainnet-v0.1.0)contracts/ckb-bitcoin-spv-type-lock + ckb-bitcoin-spv verifier @a3c43fd · mainnet 0xa76e…741d (type)Source: ckb-cell/ckb-bitcoin-spv-contracts @f3e3ba8 (tag btc-mainnet-v0.1.0) contracts/ckb-bitcoin-spv-type-lock + ckb-bitcoin-spv verifier @a3c43fd · mainnet 0xa76e…741d (type)
RGB++ (UTXO Stack)
- GitHubGitHubgithub.com/utxostack/rgbpp
- XXx.com/utxostack
来源:Source: utxostack GitHub org profile (X); org website https://www.utxostack.network returned HTTP 402 to automated checks, so omitted
给 AI agent:For AI agents: btc_spv_type_lock.md · llms.txt
0 → 1 + n创建 SPV 实例Create an SPV instance
Inputs 输入Inputs
inputs[0]:任意inputs[0]: anyCellInput{ since, previous_output }
Outputs 输出Outputs
Info cellCell{ type: { codeHash: SPV_TYPE_LOCK, args: SpvTypeArgs }, data: SpvInfo { tip_client_id: 0 } }
Client cell × nCell{ type: same type,
data: SpvClient { id: 0..n-1, tip_block_hash, headers_mmr_root, target_adjust_info } }
witness[info]WitnessArgs{ output_type: SpvBootstrap { height, header 80B } }
args(SpvTypeArgs,34 字节)args (SpvTypeArgs, 34 bytes)
type_id32B
clients_count1B
flags1B
- type_id32B实例唯一 IDinstance id= blake2b(inputs[0] ‖ 输出数量 u64)= blake2b(inputs[0] ‖ output count u64)0x23
- clients_count1Bclient cell 数number of client cells输出数 = 1 + 它outputs = 1 + it0x22
- flags1B0x80 = 跳过难度 / PoW 检查0x80 = skip difficulty / PoW checks——
SpvClient data(113 字节)SpvClient data (113 bytes)
id1B
tip_block_hash32B
headers_mmr_root72B
target_adjust_info8B
- id1Bclient id0..n-1 环形0..n-1 ring0x32
- tip_block_hash32B最新 BTC 区块哈希(内部字节序)latest BTC block hash (internal byte order)= 最后一个 header 的 sha256d= sha256d of the last header0x7a
- headers_mmr_root72BHeaderDigest { min_height, max_height, partial_chain_work U256 LE, children_hash }MMR 增量证明incremental MMR proof0x71/0x72
- target_adjust_info8Bstart_time ‖ next_compact_target按难度周期更新updated per difficulty period0x7d
限制Constraints
- outputs本实例输出 ≥ 4、连续排列、数量 = 1 + clients_countinstance outputs ≥ 4, contiguous, count = 1 + clients_count0x20 / 0x21 / 0x22
- type_idblake2b(第一个 CellInput ‖ 输出数量 u64)blake2b(first CellInput ‖ output count u64)0x23
- info第一个输出 = SpvInfo,tip = 0first output = SpvInfo with tip 00x24 / 0x25
- clients都等于由 bootstrap 计算的 client,id 依次递增all equal the client derived from the bootstrap, ids increasing0x26–0x28
2 → 2更新:覆盖最旧的 clientUpdate: overwrite the oldest client
Inputs 输入Inputs
Info cellSpvInfo { tip_client_id: t }
Client cellSpvClient { id: next(t) } // oldest
Outputs 输出Outputs
Info cellSpvInfo { tip_client_id: next(t) }
Client cellSpvClient { id: next(t), tip_block_hash: new tip, … }
witness[info]WitnessArgs{ output_type: SpvUpdate { headers, new_headers_mmr_proof } }
cell_deps 中放当前 tip client(id = t);新 client 是在它上面接上 headers 的结果。The current tip client (id = t) goes in cell_deps; the new client is that client extended by the headers.
限制Constraints
- inputs / outputs各是一个 SpvInfo + 一个 SpvClient;输入 client id = next(t);输出 info = next(t)one SpvInfo + one SpvClient each; input client id = next(t); output info = next(t)0x30–0x35
- cell_deps恰一个本实例 client,id = texactly one client of this instance, id = t0x36–0x39
- headers非空;与 tip 连续;bits = 期望难度;PoW;MMR 证明;新 client 的 id、tip、高度、target_adjust_info 正确non-empty; continue the tip; bits = expected difficulty; PoW; MMR proof; new client id, tip, heights, target_adjust_info correct0x3a / 0x69–0x7d
m → m重组(m > 2)Reorg (m > 2)
Inputs 输入Inputs
Info cellSpvInfo { tip_client_id: t }
Client cells × (m−1)SpvClient { id ∈ {t, prev(t), …} }
Outputs 输出Outputs
Info cellSpvInfo { tip_client_id: oldest rolled-back id }
Client cells × (m−1)SpvClient { identical except id }
限制Constraints
- inputs一个 info + ≥ 2 个 client,id 是从 tip 往回连续的一段one info + ≥ 2 clients whose ids are a consecutive run back from tip0x41–0x47
- outputs同一组 id;所有 client 相同;info 指向最旧的那个same id set; all clients identical; info points at the oldest0x48–0x4d / 0x35
- chain work新 partial_chain_work > 旧 tipnew partial_chain_work > old tip0x40
- cell_deps / headerscell_dep 为分叉点 client;headers 同更新规则cell_dep is the fork-point client; headers follow the update rules0x4e–0x51 / 0x69–0x7d
部署与来源Deployments & source 已核验verified
源码source
ckb-cell/ckb-bitcoin-spv-contracts@f3e3ba84 · contracts/ckb-bitcoin-spv-type-lock/src · checksums.txt (tag btc-mainnet-v0.1.0 (= origin/production). sha256 of the mainnet code cell data 481b173ca6d264c4c447210fae466ef4a2f9d7a78f5d6fd07dda4d61cf1bf34c equals checksums.txt here (checksums are sha256, so check-deployments cannot match them; binary status set by hand). Verifier types: ckb-cell/ckb-bitcoin-spv @a3c43fd)
二进制核验binary check
已核验verified verified by hand via sha256 checksums.txt (check-deployments compares blake2b only and would rewrite this as unverified)
0x0a1d2402d7…6da7dbbf: sha256 481b173ca6d264c4c447210fae466ef4a2f9d7a78f5d6fd07dda4d61cf1bf34c of the code cell data is listed for build/release/ckb-bitcoin-spv-type-lock in checksums.txt at f3e3ba8
0x0a1d2402d7…6da7dbbf: sha256 481b173ca6d264c4c447210fae466ef4a2f9d7a78f5d6fd07dda4d61cf1bf34c of the code cell data is listed for build/release/ckb-bitcoin-spv-type-lock in checksums.txt at f3e3ba8
| 网络network | code_hash | cell_dep | type_id args | 数据哈希data hash | 部署交易deploy tx |
|---|---|---|---|---|---|
| mainnet | 0xa76e227da81b97d23deabf0d8964aa41c042f4bcf2db2b8bd873fe8521de741d type | 0x1dc9a53526…e7d8a2b8:0 code | 0xe58e5edfb4…52c97eb7 | 0x0a1d2402d7…6da7dbbf | 0x1dc9a53526…e7d8a2b8 #12576657 |
链上数据核对于 on-chain data checked 2026-11-06
版本:链上主网 code cell(0x1dc9a535…:0,type id 可升级,至今未升级)数据的 sha256 = 481b173c…,等于 tag btc-mainnet-v0.1.0(= origin/production = f3e3ba8)checksums.txt 中的 ckb-bitcoin-spv-type-lock。Version: the sha256 of the on-chain mainnet code cell data (0x1dc9a535…:0, type-id upgradable, never upgraded so far) is 481b173c…, equal to the ckb-bitcoin-spv-type-lock line in checksums.txt at tag btc-mainnet-v0.1.0 (= origin/production = f3e3ba8).
code hash 来源:RGB++ lock 配置 cell(0x04c5c3e6…:1)中的 btc_lc_type_hash = 0x00a2…c6f7,对应 cell_dep 0xd6b2fcb7…:1 的 type,其 code_hash 即本合约。Code hash source: btc_lc_type_hash in the RGB++ lock config cell (0x04c5c3e6…:1) is 0x00a2…c6f7, the type of cell_dep 0xd6b2fcb7…:1, whose code_hash is this script.
测试网未收录:BTC testnet3 实例 0xc8a3…6d28 当前二进制 sha256 043f7318… 不在任何 tag 的 checksums.txt 中;signet 实例 0x73d9…e25e = tag v0.2.0(启用了销毁且 flags 含义改变),与本页规则不同。Testnet not included: the BTC testnet3 instance 0xc8a3…6d28 currently runs a binary (sha256 043f7318…) not listed in any tag's checksums.txt; the signet instance 0x73d9…e25e is tag v0.2.0 (destroy enabled, flags redefined), whose rules differ from this page.
此版本 entry.rs 注释掉了销毁分支,所以 (n, 0) 走 UnknownOperation 0x10。This version comments out the destroy branch in entry.rs, so (n, 0) falls to UnknownOperation 0x10.
解码器会计算每个 header 的 sha256d、检查内部连续性、PoW 与新 tip;与 cell_dep 中 tip client 相关的部分(接续、期望难度、MMR、高度、target_adjust_info)无法检查。The decoder computes each header sha256d and checks internal continuity, PoW and the new tip; everything tied to the tip client in cell_deps (continuation, expected difficulty, MMR, heights, target_adjust_info) cannot be checked.
错误码(error.rs):0x01–0x05 syscall · 0x10 UnknownOperation · 0x20–0x28 创建 · 0x2f DestroyNotEnoughCells · 0x30–0x3a 更新 · 0x40–0x51 重组 · 0x60 + BootstrapError / UpdateError(0x69 EmptyHeaders · 0x6a UncontinuousHeaders · 0x6b Difficulty · 0x6c Pow · 0x71 Mmr · 0x72 HeadersMmrProof · 0x79 ClientId · 0x7a ClientTipBlockHash · 0x7b/0x7c 高度 · 0x7d ClientTargetAdjustInfo)Error codes (error.rs): 0x01–0x05 syscall · 0x10 UnknownOperation · 0x20–0x28 create · 0x2f DestroyNotEnoughCells · 0x30–0x3a update · 0x40–0x51 reorg · 0x60 + BootstrapError / UpdateError (0x69 EmptyHeaders · 0x6a UncontinuousHeaders · 0x6b Difficulty · 0x6c Pow · 0x71 Mmr · 0x72 HeadersMmrProof · 0x79 ClientId · 0x7a ClientTipBlockHash · 0x7b/0x7c heights · 0x7d ClientTargetAdjustInfo)
2026-11-19 上游审阅(非链上升级声明):主网 production 分支及 btc-mainnet-v0.1.0 仍为 f3e3ba8;master 新增销毁、testnet reset、操作分类和 verifier 变更,checksum 也不同,不能直接套到现有主网部署。2026-11-19 upstream review (not an on-chain upgrade claim): Mainnet production and btc-mainnet-v0.1.0 still point to f3e3ba8. Master adds destroy, testnet reset, operation-dispatch and verifier changes and has a different checksum; these must not be applied to the existing mainnet deployment.
code hash 来源:RGB++ lock 配置 cell(0x04c5c3e6…:1)中的 btc_lc_type_hash = 0x00a2…c6f7,对应 cell_dep 0xd6b2fcb7…:1 的 type,其 code_hash 即本合约。Code hash source: btc_lc_type_hash in the RGB++ lock config cell (0x04c5c3e6…:1) is 0x00a2…c6f7, the type of cell_dep 0xd6b2fcb7…:1, whose code_hash is this script.
测试网未收录:BTC testnet3 实例 0xc8a3…6d28 当前二进制 sha256 043f7318… 不在任何 tag 的 checksums.txt 中;signet 实例 0x73d9…e25e = tag v0.2.0(启用了销毁且 flags 含义改变),与本页规则不同。Testnet not included: the BTC testnet3 instance 0xc8a3…6d28 currently runs a binary (sha256 043f7318…) not listed in any tag's checksums.txt; the signet instance 0x73d9…e25e is tag v0.2.0 (destroy enabled, flags redefined), whose rules differ from this page.
此版本 entry.rs 注释掉了销毁分支,所以 (n, 0) 走 UnknownOperation 0x10。This version comments out the destroy branch in entry.rs, so (n, 0) falls to UnknownOperation 0x10.
解码器会计算每个 header 的 sha256d、检查内部连续性、PoW 与新 tip;与 cell_dep 中 tip client 相关的部分(接续、期望难度、MMR、高度、target_adjust_info)无法检查。The decoder computes each header sha256d and checks internal continuity, PoW and the new tip; everything tied to the tip client in cell_deps (continuation, expected difficulty, MMR, heights, target_adjust_info) cannot be checked.
错误码(error.rs):0x01–0x05 syscall · 0x10 UnknownOperation · 0x20–0x28 创建 · 0x2f DestroyNotEnoughCells · 0x30–0x3a 更新 · 0x40–0x51 重组 · 0x60 + BootstrapError / UpdateError(0x69 EmptyHeaders · 0x6a UncontinuousHeaders · 0x6b Difficulty · 0x6c Pow · 0x71 Mmr · 0x72 HeadersMmrProof · 0x79 ClientId · 0x7a ClientTipBlockHash · 0x7b/0x7c 高度 · 0x7d ClientTargetAdjustInfo)Error codes (error.rs): 0x01–0x05 syscall · 0x10 UnknownOperation · 0x20–0x28 create · 0x2f DestroyNotEnoughCells · 0x30–0x3a update · 0x40–0x51 reorg · 0x60 + BootstrapError / UpdateError (0x69 EmptyHeaders · 0x6a UncontinuousHeaders · 0x6b Difficulty · 0x6c Pow · 0x71 Mmr · 0x72 HeadersMmrProof · 0x79 ClientId · 0x7a ClientTipBlockHash · 0x7b/0x7c heights · 0x7d ClientTargetAdjustInfo)
2026-11-19 上游审阅(非链上升级声明):主网 production 分支及 btc-mainnet-v0.1.0 仍为 f3e3ba8;master 新增销毁、testnet reset、操作分类和 verifier 变更,checksum 也不同,不能直接套到现有主网部署。2026-11-19 upstream review (not an on-chain upgrade claim): Mainnet production and btc-mainnet-v0.1.0 still point to f3e3ba8. Master adds destroy, testnet reset, operation-dispatch and verifier changes and has a different checksum; these must not be applied to the existing mainnet deployment.