Light Client Verification
Light Client Verification
The light client implements a read operation of a [header][#cmbc-header1] from the [blockchain][cmbc-seq1], by communicating with full nodes. As some full nodes may be faulty, this functionality must be implemented in a fault-tolerant way.
In a Cosmos blockchain, the validator set may change with every new block. The staking and unbonding mechanism induces a [security model][CMBC-FM-2THIRDS-link]: starting at time Time of the [header][#cmbc-header1], more than two-thirds of the next validators of a new block are correct for the duration of TrustedPeriod. The fault-tolerant read operation is designed for this security model.
The challenge addressed here is that the light client might have a block of height h1 and needs to read the block of height h2 greater than h1. Checking all headers of heights from h1 to h2 might be too costly (e.g., in terms of energy for mobile devices). This specification tries to reduce the number of intermediate blocks that need to be checked, by exploiting the guarantees provided by the [security model][cmbc-fm-2thirds1].
Status
This document is thoroughly reviewed, and the protocol has been formalized in TLA+ and model checked.
Issues that need to be addressed
As it is part of the larger light node, its data structures and functions interact with the fork detection functionality of the light client. As a result of the work on Pull Request 479 we established the need for an update in the data structures in Issue 499. This will not change the verification logic, but it will record information about verification that can be used in fork detection (in particular in computing more efficiently the proof of fork).
Outline
-
Part I: Introduction of relevant terms of the Cosmos blockchain.
-
Part II: Introduction of the problem addressed by the Lightclient Verification protocol.
- Verification Informal Problem statement: For the general audience, that is, engineers who want to get an overview over what the component is doing from a bird's eye view.
- Sequential Problem statement: Provides a mathematical definition of the problem statement in its sequential form, that is, ignoring the distributed aspect of the implementation of the blockchain.
-
Part III: Distributed aspects of the light client, system assumptions and temporal logic specifications.
-
Incentives: how faulty full nodes may benefit from misbehaving and how correct full nodes benefit from cooperating.
-
Computational Model: timing and correctness assumptions.
-
Distributed Problem Statement: temporal properties that formalize safety and liveness properties in the distributed setting.
-
-
Part IV: Specification of the protocols.
-
Definitions: Describes inputs, outputs, variables used by the protocol, auxiliary functions
-
Core Verification: gives an outline of the solution, and details of the functions used (with preconditions, postconditions, error conditions).
-
Liveness Scenarios: when the light client makes progress depends heavily on the changes in the validator sets of the blockchain. We discuss some typical scenarios.
-
-
Part V: The above parts focus on a common case where the last verified block has height h1 and the requested height h2 satisfies h2 > h1. For IBC, there are scenarios where this might not be the case. In this part, we provide some preliminaries for supporting this. As not all details of the IBC requirements are clear by now, we do not provide a complete specification at this point. We mark with "Open Question" points that need to be addressed in order to finalize this specification. It should be noted that the technically most challenging case is the one specified in Part IV.
In this document we quite extensively use tags in order to be able to reference assumptions, invariants, etc. in future communication. In these tags we frequently use the following short forms:
- CMBC: Cosmos blockchain
- SEQ: for sequential specifications
- LCV: Lightclient Verification
- LIVE: liveness
- SAFE: safety
- FUNC: function
- INV: invariant
- A: assumption
Part I - Cosmos Blockchain
Header Fields necessary for the Light Client
[CMBC-HEADER.1]
A set of blockchain transactions is stored in a data structure called block, which contains a field called header. (The data structure block is defined [here][block]). As the header contains hashes to the relevant fields of the block, for the purpose of this specification, we will assume that the blockchain is a list of headers, rather than a list of blocks.
[CMBC-HASH-UNIQUENESS.1]
We assume that every hash in the header identifies the data it hashes. Therefore, in this specification, we do not distinguish between hashes and the data they represent.
[CMBC-HEADER-FIELDS.1]
A header contains the following fields:
Height: non-negative integerTime: time (integer)LastBlockID: HashvalueLastCommitDomainCommitValidators: DomainValNextValidators: DomainValData: DomainTXAppState: DomainAppLastResults: DomainRes
[CMBC-SEQ.1]
The Cosmos blockchain is a list chain of headers.
[CMBC-VALIDATOR-PAIR.1]
Given a full node, a validator pair is a pair (peerID, voting_power), where
- peerID is the PeerID (public key) of a full node,
- voting_power is an integer (representing the full node's voting power in a certain consensus instance).
In the Golang implementation the data type for validator pair is called
Validator
[CMBC-VALIDATOR-SET.1]
A validator set is a set of validator pairs. For a validator set vs, we write TotalVotingPower(vs) for the sum of the voting powers of its validator pairs.
[CMBC-VOTE.1]
A vote contains a prevote or precommit message sent and signed by
a validator node during the execution of [consensus][arXiv]. Each
message contains the following fields
Type: prevote or precommitHeight: positive integerRounda positive integerBlockIDa Hashvalue of a block (not necessarily a block of the chain)
[CMBC-COMMIT.1]
A commit is a set of precommit message.
Cosmos Failure Model
[CMBC-AUTH-BYZ.1]
We assume the authenticated Byzantine fault model in which no node (faulty or correct) may break digital signatures, but otherwise, no additional assumption is made about the internal behavior of faulty nodes. That is, faulty nodes are only limited in that they cannot forge messages.
[CMBC-TIME-PARAMS.1]
A Cosmos blockchain has the following configuration parameters:
- unbondingPeriod: a time duration.
- trustingPeriod: a time duration smaller than unbondingPeriod.
[CMBC-CORRECT.1]
We define a predicate correctUntil(n, t), where n is a node and t is a time point. The predicate correctUntil(n, t) is true if and only if the node n follows all the protocols (at least) until time t.
[CMBC-FM-2THIRDS.1]
If a block h is in the chain, then there exists a subset CorrV of h.NextValidators, such that:
- TotalVotingPower(CorrV) > 2/3 TotalVotingPower(h.NextValidators); cf. [CMBC-VALIDATOR-SET.1]
- For every validator pair (n,p) in CorrV, it holds correctUntil(n, h.Time + trustingPeriod); cf. [CMBC-CORRECT.1]
The definition of correct [[CMBC-CORRECT.1]][CMBC-CORRECT-link] refers to realtime, while it is used here with Time and trustingPeriod, which are "hardware times". We do not make a distinction here.
[CMBC-CORR-FULL.1]
Every correct full node locally stores a prefix of the current list of headers from [[CMBC-SEQ.1]][CMBC-SEQ-link].
What the Light Client Checks
From [CMBC-FM-2THIRDS.1] we directly derive the following observation:
[CMBC-VAL-CONTAINS-CORR.1]
Given a (trusted) block tb of the blockchain, a given set of full nodes N contains a correct node at a real-time t, if
- t - trustingPeriod < tb.Time < t
- the voting power in tb.NextValidators of nodes in N is more than 1/3 of TotalVotingPower(tb.NextValidators)
The following describes how a commit for a given block b must look like.
[CMBC-SOUND-DISTR-POSS-COMMIT.1]
For a block b, each element pc of PossibleCommit(b) satisfies:
- pc contains only votes (cf. [CMBC-VOTE.1]) by validators from b.Validators
- the sum of the voting powers in pc is greater than 2/3 TotalVotingPower(b.Validators)
- and there is an r such that each vote v in pc satisfies
- v.Type = precommit
- v.Height = b.Height
- v.Round = r
- v.blockID = hash(b)
The following property comes from the validity of the [consensus][arXiv]: A correct validator node only sends
prevoteorprecommit, ifBlockIDof the new (to-be-decided) block is equal to the hash of the last block.
[CMBC-VAL-COMMIT.1]
If for a block b, a commit c
- contains at least one validator pair (v,p) such that v is a correct validator node, and
- is contained in PossibleCommit(b)
then the block b is on the blockchain.
Context of this document
In this document we specify the light client verification component, called Core Verification. The Core Verification communicates with a full node. As full nodes may be faulty, it cannot trust the received information, but the light client has to check whether the header it receives coincides with the one generated by Tendermint consensus.
The two properties [[CMBC-VAL-CONTAINS-CORR.1]][CMBC-VAL-CONTAINS-CORR-link] and [[CMBC-VAL-COMMIT]][CMBC-VAL-COMMIT-link] formalize the checks done by this specification: Given a trusted block tb and an untrusted block ub with a commit cub, one has to check that cub is in PossibleCommit(ub), and that cub contains a correct node using tb.
Part II - Sequential Definition of the Verification Problem
Verification Informal Problem statement
Given a height targetHeight as an input, the Verifier eventually stores a header h of height targetHeight locally. This header h is generated by the Cosmos [blockchain][block]. In particular, a header that was not generated by the blockchain should never be stored.
Sequential Problem statement
[LCV-SEQ-LIVE.1]
The Verifier gets as input a height targetHeight, and eventually stores the header of height targetHeight of the blockchain.
[LCV-SEQ-SAFE.1]
The Verifier never stores a header which is not in the blockchain.
Part III - Light Client as Distributed System
Incentives
Faulty full nodes may benefit from lying to the light client, by making the light client accept a block that deviates (e.g., contains additional transactions) from the one generated by Tendermint consensus. Users using the light client might be harmed by accepting a forged header.
The [fork detector][fork-detector] of the light client may help the correct full nodes to understand whether their header is a good one. Hence, in combination with the light client detector, the correct full nodes have the incentive to respond. We can thus base liveness arguments on the assumption that correct full nodes reliably talk to the light client.
Computational Model
[LCV-A-PEER.1]
The verifier communicates with a full node called primary. No assumption is made about the full node (it may be correct or faulty).
[LCV-A-COMM.1]
Communication between the light client and a correct full node is reliable and bounded in time. Reliable communication means that messages are not lost, not duplicated, and eventually delivered. There is a (known) end-to-end delay Delta, such that if a message is sent at time t then it is received and processes by time t + Delta. This implies that we need a timeout of at least 2 Delta for remote procedure calls to ensure that the response of a correct peer arrives before the timeout expires.
[LCV-A-TFM.1]
The Cosmos blockchain satisfies the Cosmos failure model [[CMBC-FM-2THIRDS.1]][CMBC-FM-2THIRDS-link].
[LCV-A-VAL.1]
The system satisfies [[CMBC-AUTH-BYZ.1]][CMBC-Auth-Byz-link] and [[CMBC-FM-2THIRDS.1]][CMBC-FM-2THIRDS-link]. Thus, there is a blockchain that satisfies the soundness requirements (that is, the validation rules in [[block]]).
Distributed Problem Statement
Two Kinds of Termination
We do not assume that primary is correct. Under this assumption no protocol can guarantee the combination of the sequential properties. Thus, in the (unreliable) distributed setting, we consider two kinds of termination (successful and failure) and we will specify below under what (favorable) conditions Core Verification ensures to terminate successfully, and satisfy the requirements of the sequential problem statement:
[LCV-DIST-TERM.1]
Core Verification either terminates successfully or it terminates with failure.
Design choices
[LCV-DIST-STORE.1]
Core Verification has a local data structure called LightStore that contains light blocks (that contain a header). For each light block we record whether it is verified.
[LCV-DIST-PRIMARY.1]
Core Verification has a local variable primary that contains the PeerID of a full node.
[LCV-DIST-INIT.1]
LightStore is initialized with a header trustedHeader that was correctly generated by the Tendermint consensus. We say trustedHeader is verified.
Temporal Properties
[LCV-DIST-SAFE.1]
It is always the case that every verified header in LightStore was generated by an instance of Tendermint consensus.
[LCV-DIST-LIVE.1]
From time to time, a new instance of Core Verification is called with a height targetHeight greater than the height of any header in LightStore. Each instance must eventually terminate.
- If
- the primary is correct (and locally has the block of targetHeight), and
- LightStore always contains a verified header whose age is less than the
trusting period,
then Core Verification adds a verified header hd with height targetHeight to LightStore and it terminates successfully
These definitions imply that if the primary is faulty, a header may or may not be added to LightStore. In any case, [LCV-DIST-SAFE.1] must hold. The invariant [LCV-DIST-SAFE.1] and the liveness requirement [LCV-DIST-LIVE.1] allow that verified headers are added to LightStore whose height was not passed to the verifier (e.g., intermediate headers used in bisection; see below). Note that for liveness, initially having a trustedHeader within the trustinPeriod is not sufficient. However, as this specification will leave some freedom with respect to the strategy in which order to download intermediate headers, we do not give a more precise liveness specification here. After giving the specification of the protocol, we will discuss some liveness scenarios below.
Solving the sequential specification
This specification provides a partial solution to the sequential specification. The Verifier solves the invariant of the sequential part
[LCV-DIST-SAFE.1] => [LCV-SEQ-SAFE.1]
In the case the primary is correct, and there is a recent header in LightStore, the verifier satisfies the liveness requirements.
⋀ primary is correct
⋀ always ∃ verified header in LightStore. header.Time > now - trustingPeriod
⋀ [LCV-A-Comm.1] ⋀ (
( [[CMBC-CorrFull.1]][CMBC-CorrFull-link] ⋀
[LCV-DIST-LIVE.1] )
⟹ [LCV-SEQ-LIVE.1]
)
Part IV - Light Client Verification Protocol
We provide a specification for Light Client Verification. The local
code for verification is presented by a sequential function
VerifyToTarget to highlight the control flow of this functionality.
We note that if a different concurrency model is considered for
an implementation, the sequential flow of the function may be
implemented with mutexes, etc. However, the light client verification
is partitioned into three blocks that can be implemented and tested
independently:
FetchLightBlockis called to download a light block (header) of a given height from a peer.ValidAndVerifiedis a local code that checks the header.Scheduledecides which height to try to verify next. We keep this underspecified as different implementations (currently in Goland and Rust) may implement different optimizations here. We just provide necessary conditions on how the height may evolve.
Definitions
Data Types
The core data structure of the protocol is the LightBlock.
[LCV-DATA-LIGHTBLOCK.1]
type LightBlock struct {
Header Header
Commit Commit
Validators ValidatorSet
}
[LCV-DATA-LIGHTSTORE.1]
LightBlocks are stored in a structure which stores all LightBlock from initialization or received from peers.
type LightStore struct {
...
}
Each LightBlock is in one of the following states:
type VerifiedState int
const (
StateUnverified = iota + 1
StateVerified
StateFailed
StateTrusted
)
Only the detector module sets a lightBlock state to
StateTrustedand only if it wasStateVerifiedbefore.
The LightStore exposes the following functions to query stored LightBlocks.
[LCV-FUNC-GET.1]
func (ls LightStore) Get(height Height) (LightBlock, bool)
- Expected postcondition
- returns a LightBlock at a given height or false in the second argument if the LightStore does not contain the specified LightBlock.
[LCV-FUNC-LATEST-VERIF.1]
func (ls LightStore) LatestVerified() LightBlock
- Expected postcondition
- returns the highest light block whose state is
StateVerifiedorStateTrusted
- returns the highest light block whose state is
[LCV-FUNC-UPDATE.2]
func (ls LightStore) Update(lightBlock LightBlock,
verifiedState VerifiedState
verifiedBy Height)
- Expected postcondition
- The state of the LightBlock is set to verifiedState.
Excerpt (19997 of 43993 characters). Read the whole page on CometBFT specification ↗