本目录包含轻客户端协议的英文规范与 TLA+ 规范草案,当前仍在持续完善中。轻客户端的实现可参考 Rust 和 Go。 轻客户端假定会先从可信来源完成一次初始化,获得可信的区块头和验证者集合。随后,轻客户端协议允许客户端通过向全节点网络请求并验证一组最小化数据,安全地更新其可信状态(这些全节点中至少有一个是正确的)。 轻客户端可分解为两个主要组件:
  • 提交验证 - 验证来自单个全节点(称为 primary)的已签名区块头及其关联的验证者集合变更
  • 攻击检测 - 跨多个全节点(称为 secondaries)验证提交,并检测冲突(即是否存在轻客户端攻击)
一旦检测到轻客户端攻击,轻客户端会向全节点提交证据,由全节点负责“问责”,也就是惩罚攻击者:
  • 问责 - 给定攻击证据,计算应对此负责的一组验证者

提交验证

英文规范 以时间属性 LCV-DIST-SAFE.1 和 LCV-DIST-LIVE.1 描述了轻客户端的提交验证问题。提交验证被假定运行在 Cosmos 故障模型之中,在该模型下,验证者中有超过 2/3 在某个时间段内是正确的,并且验证者集合在每个高度都可以任意变化。 这里还给出了一个轻客户端协议,包含为满足这些时间属性而必须对区块头、提交和验证者集合执行的全部检查,因此轻客户端可以持续与区块链保持同步。客户端可以利用可信与不可信验证者集合之间的重叠,跳过可能大量的中间区块头。当重叠不足时,可以使用二分例程找到一组能够提供所需重叠的最小区块头集合。 TLA+ 规范 ver. 001 是对客户端执行的提交验证协议的形式化描述,包含安全性与终止性,可使用 Apalache 进行模型检查。 更详细的 TLA+ 规范 轻客户端验证 ver. 003 目前正在同行评审中。 MC*.tla 文件为 TLA+ 规范 提供了具体参数,以便执行模型检查。例如,MC4_3_faulty.tla 包含了节点、高度、信任期、时钟漂移、主节点正确性以及故障进程比例的如下参数:
AllNodes == {"n1", "n2", "n3", "n4"}
TRUSTED_HEIGHT == 1
TARGET_HEIGHT == 3
TRUSTING_PERIOD == 1400     \* 某种时间单位下的信任期
CLOCK_DRIFT = 10            \* 我们假定本地时钟的漂移量
REAL_CLOCK_DRIFT = 3        \* 本地时钟实际的漂移量
IS_PRIMARY_CORRECT == FALSE
FAULTY_RATIO == <<1, 3>>    \* 故障验证者少于 1 / 3
要运行完整的一组实验,请将 apalache 和 apalache-tests 克隆到目录 $DIR 中,并执行以下命令:
$DIR/apalache-tests/scripts/mk-run.py --memlimit 28 002bmc-apalache-ok.csv $DIR/apalache . out
./out/run-all.sh
实验完成后,可以执行以下命令收集日志:
cd ./out
$DIR/apalache-tests/scripts/parse-logs.py --human .
results.csv 中的所有行都应报告为 Deadlock,这表示算法已经终止,且未发现任何不变式违反。 与 002bmc-apalache-ok.csv 类似,文件 003bmc-apalache-error.csv 指定了应当产生反例的一组实验:
$DIR/apalache-tests/scripts/mk-run.py --memlimit 28 003bmc-apalache-error.csv $DIR/apalache . out
./out/run-all.sh
results.csv 中的所有行都应报告为 Error。 下表汇总了轻客户端验证 version 001 的实验结果。相关 TLA+ 属性可见于 TLA+ 规范。实验运行于一台配备 32GB RAM 和 4 核 Intel® Xeon® CPU E5-2686 v4 @ 2.30GHz 的 AWS 实例上。我们用“✗=k”表示在深度 k 处报告了一个错误,用“✓<=k”表示截至深度 k 未报告任何错误。 实验结果 version 003 的实验结果将随后补充。

攻击检测

英文规范 定义了轻客户端攻击(以及它们与区块链分叉的区别),并描述了轻客户端如何通过与全节点网络通信来检测这些攻击的问题,其中至少有一个全节点是正确的。 该规范还包含一个检测协议,用于检查通过验证协议从 primary 获取的区块头是否与 secondaries 提供的对应区块头一致。如果不一致,协议会分析相关全节点的验证轨迹,并生成可提交给全节点的不当行为证据,以便惩罚存在故障的验证者。 TLA+ 规范 是对双对等节点检测协议的形式化描述,包含安全性与终止性,可使用 Apalache 进行模型检查。 LCD_MC*.tla 文件为 TLA+ 规范 提供了具体参数,以便运行模型检查器。例如,LCD_MC4_4_faulty.tla 包含了节点、高度、信任期、时钟漂移、节点正确性以及故障进程比例的如下参数:
AllNodes == {"n1", "n2", "n3", "n4"}
TRUSTED_HEIGHT == 1
TARGET_HEIGHT == 3
TRUSTING_PERIOD == 1400     \* 某种时间单位下的信任期
CLOCK_DRIFT = 10            \* 我们假定本地时钟的漂移量
REAL_CLOCK_DRIFT = 3        \* 本地时钟实际的漂移量
IS_PRIMARY_CORRECT == FALSE
IS_SECONDARY_CORRECT == FALSE
FAULTY_RATIO == <<1, 3>>    \* 故障验证者少于 1 / 3
要运行完整的一组实验,请将 apalache 和 apalache-tests 克隆到目录 $DIR 中,并执行以下命令:
$DIR/apalache-tests/scripts/mk-run.py --memlimit 28 004bmc-apalache-ok.csv $DIR/apalache . out
./out/run-all.sh
实验完成后,可以执行以下命令收集日志:
cd ./out
$DIR/apalache-tests/scripts/parse-logs.py --human .
results.csv 中的所有行都应报告为 Deadlock,这表示算法已经终止,且未发现任何不变式违反。 与 004bmc-apalache-ok.csv 类似,文件 005bmc-apalache-error.csv 指定了应当产生反例的一组实验:
$DIR/apalache-tests/scripts/mk-run.py --memlimit 28 005bmc-apalache-error.csv $DIR/apalache . out
./out/run-all.sh
results.csv 中的所有行都应报告为 Error。 详细实验结果将很快补充。

问责

英文规范 定义了全节点在接收到来自轻客户端的攻击证据后所执行的协议。特别地,该协议处理三类攻击:
  • lunatic
  • equivocation
  • amnesia
我们在英文规范的最后一部分中讨论过,非 lunatic 情况被定义为冲突区块具有相同的验证者集合。对于这些情况,借助 TLA+ 中的 Tendermint 共识 的计算机辅助分析表明,equivocation 和 amnesia 已覆盖全部非 lunatic 攻击。 TLA+ 规范 是该协议的形式化描述,包含安全性属性,可使用 Apalache 进行模型检查。 与其他规范类似,MC_5_3.tla 包含了运行模型检查器所需的具体参数。该规范可在数秒内完成检查。 tendermint-accountability
This directory contains work-in-progress English and TLA+ specifications for the Light Client protocol. Implementations of the light client can be found in Rust and Go. Light clients are assumed to be initialized once from a trusted source with a trusted header and validator set. The light client protocol allows a client to then securely update its trusted state by requesting and verifying a minimal set of data from a network of full nodes (at least one of which is correct). The light client is decomposed into two main components:
  • Commit Verification - verify signed headers and associated validator set changes from a single full node, called primary
  • Attack Detection - verify commits across multiple full nodes (called secondaries) and detect conflicts (ie. the existence of a lightclient attack)
In case a lightclient attack is detected, the lightclient submits evidence to a full node which is responsible for “accountability”, that is, punishing attackers:
  • Accountability - given evidence for an attack, compute a set of validators that are responsible for it.

Commit Verification

The English specification describes the light client commit verification problem in terms of the temporal properties LCV-DIST-SAFE.1 and LCV-DIST-LIVE.1. Commit verification is assumed to operate within the Cosmos Failure Model, where +2/3 of validators are correct for some time period and validator sets can change arbitrarily at each height. A light client protocol is also provided, including all checks that need to be performed on headers, commits, and validator sets to satisfy the temporal properties - so a light client can continuously synchronize with a blockchain. Clients can skip possibly many intermediate headers by exploiting overlap in trusted and untrusted validator sets. When there is not enough overlap, a bisection routine can be used to find a minimal set of headers that do provide the required overlap. The TLA+ specification ver. 001 is a formal description of the commit verification protocol executed by a client, including the safety and termination, which can be model checked with Apalache. A more detailed TLA+ specification of Light client verification ver. 003 is currently under peer review. The MC*.tla files contain concrete parameters for the TLA+ specification, in order to do model checking. For instance, MC4_3_faulty.tla contains the following parameters for the nodes, heights, the trusting period, the clock drifts, correctness of the primary node, and the ratio of the faulty processes:
AllNodes == {"n1", "n2", "n3", "n4"}
TRUSTED_HEIGHT == 1
TARGET_HEIGHT == 3
TRUSTING_PERIOD == 1400     \* the trusting period in some time units
CLOCK_DRIFT = 10            \* how much we assume the local clock is drifting
REAL_CLOCK_DRIFT = 3        \* how much the local clock is actually drifting
IS_PRIMARY_CORRECT == FALSE
FAULTY_RATIO == <<1, 3>>    \* < 1 / 3 faulty validators
To run a complete set of experiments, clone apalache and apalache-tests into a directory $DIR and run the following commands:
$DIR/apalache-tests/scripts/mk-run.py --memlimit 28 002bmc-apalache-ok.csv $DIR/apalache . out
./out/run-all.sh
After the experiments have finished, you can collect the logs by executing the following command:
cd ./out
$DIR/apalache-tests/scripts/parse-logs.py --human .
All lines in results.csv should report Deadlock, which means that the algorithm has terminated and no invariant violation was found. Similar to 002bmc-apalache-ok.csv, file 003bmc-apalache-error.csv specifies the set of experiments that should result in counterexamples:
$DIR/apalache-tests/scripts/mk-run.py --memlimit 28 003bmc-apalache-error.csv $DIR/apalache . out
./out/run-all.sh
All lines in results.csv should report Error. The following table summarizes the experimental results for Light client verification version 001. The TLA+ properties can be found in the TLA+ specification. The experiments were run in an AWS instance equipped with 32GB RAM and a 4-core Intel® Xeon® CPU E5-2686 v4 @ 2.30GHz CPU. We write “✗=k” when a bug is reported at depth k, and “✓<=k” when no bug is reported up to depth k. Experimental results The experimental results for version 003 are to be added.

Attack Detection

The English specification defines light client attacks (and how they differ from blockchain forks), and describes the problem of a light client detecting these attacks by communicating with a network of full nodes, where at least one is correct. The specification also contains a detection protocol that checks whether the header obtained from the primary via the verification protocol matches corresponding headers provided by the secondaries. If this is not the case, the protocol analyses the verification traces of the involved full nodes and generates evidence of misbehavior that can be submitted to a full node so that the faulty validators can be punished. The TLA+ specification is a formal description of the detection protocol for two peers, including the safety and termination, which can be model checked with Apalache. The LCD_MC*.tla files contain concrete parameters for the TLA+ specification, in order to run the model checker. For instance, LCD_MC4_4_faulty.tla contains the following parameters for the nodes, heights, the trusting period, the clock drifts, correctness of the nodes, and the ratio of the faulty processes:
AllNodes == {"n1", "n2", "n3", "n4"}
TRUSTED_HEIGHT == 1
TARGET_HEIGHT == 3
TRUSTING_PERIOD == 1400     \* the trusting period in some time units
CLOCK_DRIFT = 10            \* how much we assume the local clock is drifting
REAL_CLOCK_DRIFT = 3        \* how much the local clock is actually drifting
IS_PRIMARY_CORRECT == FALSE
IS_SECONDARY_CORRECT == FALSE
FAULTY_RATIO == <<1, 3>>    \* < 1 / 3 faulty validators
To run a complete set of experiments, clone apalache and apalache-tests into a directory $DIR and run the following commands:
$DIR/apalache-tests/scripts/mk-run.py --memlimit 28 004bmc-apalache-ok.csv $DIR/apalache . out
./out/run-all.sh
After the experiments have finished, you can collect the logs by executing the following command:
cd ./out
$DIR/apalache-tests/scripts/parse-logs.py --human .
All lines in results.csv should report Deadlock, which means that the algorithm has terminated and no invariant violation was found. Similar to 004bmc-apalache-ok.csv, file 005bmc-apalache-error.csv specifies the set of experiments that should result in counterexamples:
$DIR/apalache-tests/scripts/mk-run.py --memlimit 28 005bmc-apalache-error.csv $DIR/apalache . out
./out/run-all.sh
All lines in results.csv should report Error. The detailed experimental results are to be added soon.

Accountability

The English specification defines the protocol that is executed on a full node upon receiving attack evidence from a lightclient. In particular, the protocol handles three types of attacks
  • lunatic
  • equivocation
  • amnesia
We discussed in the last part of the English specification that the non-lunatic cases are defined by having the same validator set in the conflicting blocks. For these cases, computer-aided analysis of Tendermint Consensus in TLA+ shows that equivocation and amnesia capture all non-lunatic attacks. The TLA+ specification is a formal description of the protocol, including the safety property, which can be model checked with Apalache. Similar to the other specifications, MC_5_3.tla contains concrete parameters to run the model checker. The specification can be checked within seconds. tendermint-accountability