AIFeed

实用量子安全比特币

Translation(model translation, not the source's own text)

仓库文件导航

题图
题图

Practical Quantum Safe Bitcoin

本仓库包含论文 Practical Quantum Safe Bitcoin、其实现与基准测试记录,以及其数学结果的 Lean 形式化。论文构建了两个实用量子安全比特币(PQSB)实例:Legacy PQSB(论文中称 PQSB-legacy),依赖传统 Bitcoin Script;以及 SegWit PQSB(PQSB-segwit),支持 SegWit v0。它们带来三项改进:

  • 更快的签名。在 124 位经典伪造目标下,Legacy PQSB 需要约 2^28.7 次期望签名尝试。在该级别下,三十次花费在一块 RTX 5090 上的求解器中平均耗时 0.76 秒。使用优化后的求解器,估计在 MacBook M3 的 GPU 上约需 24 秒,而此前构建上五次花费耗时 10 到 23 秒(按更快构建的速率约 9 到 21 秒),在带有 SHA 扩展的四颗 x86 核心上约需 41 秒。该级别下的一次花费已在主网区块 978,560 中被挖出。
  • 签名时间与抗伪造性之间的权衡。将 Legacy PQSB 的伪造目标提高到约 132 位需要约 2^35.2 次签名尝试:在一块 RTX 5090 上期望约 9 秒,而此前构建上三次花费耗时 8 到 20 秒;在 M3 的 GPU 上约需 12 分钟。Legacy PQSB 共有七个级别,从 92 位到 140 位;SegWit PQSB 有六个级别,从 64 位到 95 位。
  • SegWit 兼容性与内存池传播。SegWit PQSB 符合标准 P2WSH 中继限制,因此任何节点都会中继其花费。在 80 位经典伪造目标下,它需要约 2^31.8 次签名尝试:在一块 RTX 5090 上约需一秒,而十次 regtest 花费耗时 0.09 到 2.21 秒;在 M3 的 GPU 上约需 72 秒,而两次花费分别耗时 75 和 78 秒。一次 91 位的花费已在主网区块 978653 中被挖出,一次 88 位的已在主网区块 978,542 中被挖出;一次 80 位的在区块 978,456 中。

下面的级别表给出了每种设置的数值,BENCHMARKS.md 给出了哪些是实测、哪些是估计。计算成本与比特币交易手续费是分开的。

入门:PQSB 构建器

构建器会引导你以任一模式完成一次花费:选择 SegWit 或 Legacy PQSB、主网或 regtest,以及一个安全级别及其在你硬件上的预期签名时间;然后设置金库的密钥、为金库注资并花费它。每次支付都需要一组新的密钥,因此构建器会为每次支付新建一个金库,并维护一个列表。它既以浏览器页面的形式提供,也以终端中相同的步骤提供,两者都在你自己的机器上运行 pqai-btc-everything/implementation-app/ 中的命令。

你需要 Python 3.12 或更高版本(无需额外包)、用于求解器的 C 编译器,以及用于校验每笔交易的共识库的 Rust。在 Windows 上,请在 WSL2(Ubuntu 24.04 或更高版本)中运行所有内容:构建脚本和工具期望 Linux 或 macOS。在 Ubuntu(或 WSL2)上,sudo apt install git build-essential 可提供 git 和 C 编译器,rustup 可安装 Rust。构建一次,然后从 implementation-app 中运行下面所有内容:


        git clone https://github.com/EspressoSystems/PQSB.git
cd PQSB/pqai-btc-everything/implementation-app
solver/build.sh                           # 求解器:CPU 构建,Apple 芯片上使用 Metal,找到 nvcc 时使用 CUDA
(cd verifier && cargo build --release)    # Bitcoin Core 的共识库
      

文章标题:Practical Quantum Safe Bitcoin

正文: 在装有 NVIDIA GPU 时,只要 nvcc(CUDA 编译器)在 PATH 上,solver/build.sh 也会构建 GPU solver、search,此后这些工具便使用它而不是 CPU。在 Linux 上,安装 NVIDIA 的 CUDA toolkit。在 Windows 上,你已有的 NVIDIA 驱动即可供 WSL2 使用:只在 WSL2 内从 NVIDIA 的 WSL-Ubuntu 仓库安装 toolkit(添加该仓库后执行 sudo apt install cuda-toolkit),绝不要安装 Linux 驱动。然后把 /usr/local/cuda/bin 加入 PATH,再次运行 solver/build.sh。nvidia-smi 会显示 GPU 及其驱动所支持的最新 CUDA 版本;toolkit 不得比它更新。

在浏览器中:


        python3 tools/pqsb_app.py                 # opens the page on 127.0.0.1 and prints its address
      

在终端中:


        python3 tools/pqsb_cli.py                 # asks each step in turn; q quits, and running it again goes on where it stopped
      

先在 regtest 上试。安装 Bitcoin Core 后,在页面上选择 Regtest,给它存放 bitcoind 的文件夹,然后启动 regtest 节点:它的玩耍币钱包会为 vault 付款并为你挖出交易。在终端中:


        BITCOIN_BIN=/path/to/bitcoin/bin python3 tools/pqsb_cli.py --regtest
      

新 vault 在 SegWit 下从 80 bits 起步,在 Legacy 下从 124 bits 起步,表格中任何级别都可选择;对于有真实价值的 SegWit,请选择 80 bits 或更高。docs/pqsb-app.md 对两者都有完整说明。

Explorer

explorer 会在你自己的 Bitcoin Core 节点的区块中找出 Bitcoin 主网上每一笔 PQSB 交易,校验每一笔花费(脚本模型、Bitcoin Core 的共识库、中继限制、T 的长度、pins),并把它们显示在一个仅读取 JSON 索引的静态页面上。节点的 RPC 始终留在 localhost;页面从不与它通信。


        cd pqai-btc-everything/implementation-app
python3 -m qsb2 scan --follow --mempool       # from block 978,243 to the tip, then each new block; writes explorer/index.json
python3 -m http.server -d explorer 8000       # the page, explorer/index.html, at http://127.0.0.1:8000/
      

docs/explorer.md 涵盖节点的配置、把扫描器作为服务运行,以及发布页面。

What is here

pathwhat it is
Paper/introspection-pqsb.pdf论文,Practical Quantum Safe Bitcoin ;其 LaTeX 源码为 Paper/introspection-pqsb.tex ,附 Paper/references.bib
Paper/introspection-lean/论文的内省签名框架的 Lean 4 开发
pqsb-lean/Lean 4 形式化:论文的计数、工作与伪造界及其参数数值的机器校验证明
pqai-btc-everything/实现与基准测试存档
pqai-btc-everything/BENCHMARKS.md对照论文数值的基准测试,每一项都标记为实测、估计或来自论文
pqai-btc-everything/benchmarks/RTX 5090 和 MacBook M3 的报告,以及论文中每种设置在各机器速率下的结果
pqai-btc-everything/implementation-app/带 builder 的实现:两种锁(带 pins 的 SegWit PQSB)、含两者 GPU 搜索的 solver、页面和 CLI
pqai-btc-everything/implementation-main/较早的快照:两种锁,其中 SegWit PQSB 的锁不带 pins、P2WSH solver、测试,以及该锁在主网上的花费
pqai-btc-everything/implementation-cuda/含面向 NVIDIA GPU 的 Legacy PQSB GPU 搜索的快照
pqai-btc-everything/implementation-metal/含面向 Apple 芯片的较早 Metal 构建的快照;M3 的 GPU 数值来自 implementation-app/ 中较晚的构建

Experimental software

这是实验性软件。不要把它用于你承受不起损失的币。

  • 这里的一切都未经审计。
  • 伪造数值依赖于我们的安全论证以及 docs/security.md 中的假设。pqsb-lean/ 校验的是论文的数学,而非脚本:脚本本身没有任何证明经过机器校验。
  • Legacy PQSB 的列表选择没有 clamp;每一次被接受的花费都会选中已披露的条目,这是一个论证,由测试检验,而非证明。
  • 脚本、密钥生成或 lock.json 处理中的错误可能永久丢失币。
  • 此演示中秘密以明文存储,因此不应被用于保护大额资金。

先在 regtest 上运行每一步,然后再锁定小额资金。

锁及其等级

等级是经典伪造工作量,以比特为单位:持有一次花费的 openings 的伪造者每次尝试的成功概率至多为 2^-level。签名者的尝试次数是找到一次花费的期望尝试次数。时间是在 implementation-app/ 的优化求解器于各机器上测得的速率下的期望时间;BENCHMARKS.md 给出了测得的各次花费,其中大部分运行于之前的构建上。

SegWit PQSB:带 pins 的 P2WSH 锁(docs/pins.md)。花费是标准的:任何节点都会中继它。

该表是可能设置的一个子集:在 7 到 10 个位置、1 到 6 个 pins 以及最多 127 个 commitments 上的搜索在 P2WSH 的限制内找到了许多布局,而这些是其中一些在其等级下需要最少尝试次数的布局。等级 87 和 95 使用 8 个位置和 6 个 pins:大约略低于 88 和 96,而尝试次数只有四分之一。

levelpositionscommitmentspinslengths of Tbytessigner's triesRTX 5090MacBook M3, GPU4 x86 cores
64979458, 8 × 591,9852^15.79under a secondunder a secondunder a second
72979457, 8 × 591,9852^23.79under a secondunder a secondunder a second
80979456, 8 × 591,9852^31.79under a second73 s88 s
87888655, 7 × 592,1762^37.7959 s77 min94 min
88979455, 8 × 591,9852^39.794 min5.2 hours6.3 hours
95888655, 58, 6 × 592,1762^45.794.2 hours14 days17 days

每个脚本有 201 个操作。一次花费在 9 个位置时约为 1,060 vB,在 8 个位置时约为 1,076 vB。各列在 RTX 5090 上每秒进行 4.05 亿次尝试(在等级 80、无 pins 的锁上超过 2^35 次尝试),在 M3 的 GPU 上为 5120 万次(等级 72 时 2^30 次尝试;带 pins 的锁在等级 80 的两次花费测得 5160 万次),在带有 SHA 扩展和 AVX-512 的 Intel Xeon 的四个核心上为 4210 万次(等级 64):见 implementation-app/ 中的 docs/opt-cuda.md、docs/bench-macbook-metal.md 和 docs/opt-cpu.md。第一个 SegWit PQSB,即无 pins 的 P2WSH 锁(docs/p2wsh.md),已不再构建。

Legacy PQSB:具有四个组件的 legacy 锁(docs/legacy.md)。一个 nonce 组件和三个 subset 组件作用于一个秘密列表,每个组件都有自己的已提交标量向量。两笔交易都是非标准的,直接发送给矿工。

levelDlist, openingsscalarssigner's triesRTX 5090MacBook M3, GPU4 x86 cores
9257, 57, 57, 57206; 4, 4, 430, 37, 40, 432^19.80under a secondunder a secondunder a second
10056, 57, 57, 57206; 4, 4, 430, 37, 40, 432^26.11under a second1 s2 s
10856, 56, 57, 57206; 4, 4, 430, 37, 40, 432^27.25under a second7 s11 s
11656, 56, 56, 57206; 4, 4, 430, 37, 40, 432^28.05under a second14 s24 s
12456, 56, 56, 56206; 4, 4, 430, 37, 40, 432^28.71under a second24 s41 s
13255, 56, 56, 56222; 4, 4, 448, 26, 26, 272^35.159 s12 min20 min
14056, 56, 55, 55230; 3, 4, 528, 29, 30, 282^41.2714 min17 hours28 hours

每个脚本有 198 或 199 个操作,9,987 到 10,000 字节。每一列使用优化构建在 level 124 测得的组件速率:在 RTX 5090 上每秒 43.4 亿次 nonce 尝试和约 6 亿次子集尝试,在 M3 的 GPU 上为 5330 万次和约 1200 万次,在 x86 核心上为 3340 万次和约 700 万次。

手动运行实现

上面的构建器会为你运行这些相同的命令。以下命令在上述构建之后,在 pqai-btc-everything/implementation-app/ 中运行:


        cd pqai-btc-everything/implementation-app
python3 tests/run.py                      # the quick tests, about a minute
python3 tests/pins.py                     # SegWit PQSB's lock with pins, and its mainnet spend; about a minute
python3 -m qsb2 count                     # every lock: bytes, operations, figures, times
python3 -m qsb2 check-mainnet             # the spends of the first P2WSH lock on mainnet, rebuilt and checked from public data
      

当 verifier/ 构建完成后,花费命令会在写入每一笔花费之前,对其运行 Bitcoin Core 的共识库。构建它。

首先在 regtest 上。将 Bitcoin Core 的 bitcoind 放在 BITCOIN_BIN 中,演示会构建一个锁、为其注资、找到花费、检查它,并在一个私有 regtest 节点上挖出它:


        export BITCOIN_BIN=/path/to/bitcoin/bin
python3 -m qsb2 p2wsh demo --level 64 --real        # SegWit PQSB at its real lengths: a second on a CPU
python3 -m qsb2 legacy demo --level 124 --D 58     # Legacy PQSB at a low-work length: seconds
python3 -m qsb2 legacy demo --level 124 --D 56     # Legacy PQSB at its real lengths: seconds on a GPU
python3 tests/run.py --regtest                      # every demo the tests run
      

要锁定真实币,请遵循实现 README 中的“How to spend”。

秘密与一次性使用。lock.json 保存秘密。它以西元 600 权限写入;切勿提交或发送它。一个锁只能花费一次。工具会拒绝第二次不同的花费,那会暴露更多开口。

Lean 形式化


        cd pqsb-lean
lake exe cache get    # prebuilt Mathlib
lake build
      

pqsb-lean/README.md 将论文的每个结果映射到其 Lean 定理。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Hacker News
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗