github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/spec/light-client/attacks/isolate-attackers_001_draft.md (about)

     1  <!-- markdown-link-check-disable -->
     2  
     3  # Lightclient Attackers Isolation
     4  
     5  > Warning: This is the beginning of an unfinished draft. Don't continue reading!
     6  
     7  Adversarial nodes may have the incentive to lie to a lightclient about the state of a Tendermint blockchain. An attempt to do so is called attack. Light client [verification][verification] checks incoming data by checking a so-called "commit", which is a forwarded set of signed messages that is (supposedly) produced during executing Tendermint consensus. Thus, an attack boils down to creating and signing Tendermint consensus messages in deviation from the Tendermint consensus algorithm rules.
     8  
     9  As Tendermint consensus and light client verification is safe under the assumption of more than 2/3 of correct voting power per block [[TMBC-FM-2THIRDS]][TMBC-FM-2THIRDS-link], this implies that if there was an attack then [[TMBC-FM-2THIRDS]][TMBC-FM-2THIRDS-link] was violated, that is, there is a block such that
    10  
    11  - validators deviated from the protocol, and
    12  - these validators represent more than 1/3 of the voting power in that block.
    13  
    14  In the case of an [attack][node-based-attack-characterization], the lightclient [attack detection mechanism][detection] computes data, so called evidence [[LC-DATA-EVIDENCE.1]][LC-DATA-EVIDENCE-link], that can be used
    15  
    16  - to proof that there has been attack [[TMBC-LC-EVIDENCE-DATA.1]][TMBC-LC-EVIDENCE-DATA-link] and
    17  - as basis to find the actual nodes that deviated from the Tendermint protocol.
    18  
    19  This specification considers how a full node in a Tendermint blockchain can isolate a set of attackers that launched the attack. The set should satisfy
    20  
    21  - the set does not contain a correct validator
    22  - the set contains validators that represent more than 1/3 of the voting power of a block that is still within the unbonding period
    23  
    24  # Outline
    25  
    26  **TODO** when preparing a version for broader review.
    27  
    28  # Part I - Basics
    29  
    30  For definitions of data structures used here, in particular LightBlocks [[LCV-DATA-LIGHTBLOCK.1]](https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/verification/verification_002_draft.md#lcv-data-lightblock1), cf. [Light Client Verification][verification].
    31  
    32  # Part II - Definition of the Problem
    33  
    34  The specification of the [detection mechanism][detection] describes
    35  
    36  - what is a light client attack,
    37  - conditions under which the detector will detect a light client attack,
    38  - and the format of the output data, called evidence, in the case an attack is detected. The format is defined in
    39  [[LC-DATA-EVIDENCE.1]][LC-DATA-EVIDENCE-link] and looks as follows
    40  
    41  ```go
    42  type LightClientAttackEvidence struct {
    43      ConflictingBlock   LightBlock
    44      CommonHeight       int64
    45  }
    46  ```
    47  
    48  The isolator is a function that gets as input evidence `ev`
    49  and a prefix of the blockchain `bc` at least up to height `ev.ConflictingBlock.Header.Height + 1`. The output is a set of *peerIDs* of validators.
    50  
    51  We assume that the full node is synchronized with the blockchain and has reached the height `ev.ConflictingBlock.Header.Height + 1`.
    52  
    53  #### **[FN-INV-Output.1]**
    54  
    55  When an output is generated it satisfies the following properties:
    56  
    57  - If
    58      - `bc[CommonHeight].bfttime` is within the unbonding period w.r.t. the time at the full node,
    59      - `ev.ConflictingBlock.Header != bc[ev.ConflictingBlock.Header.Height]`
    60      - Validators in `ev.ConflictingBlock.Commit` represent more than 1/3 of the voting power in `bc[ev.CommonHeight].NextValidators`
    61  - Then: A set of validators in `bc[CommonHeight].NextValidators` that
    62      - represent more than 1/3 of the voting power in `bc[ev.commonHeight].NextValidators`
    63      - signed Tendermint consensus messages for height `ev.ConflictingBlock.Header.Height` by violating the Tendermint consensus protocol.
    64  - Else: the empty set.
    65  
    66  # Part IV - Protocol
    67  
    68  Here we discuss how to solve the problem of isolating misbehaving processes. We describe the function `isolateMisbehavingProcesses` as well as all the helping functions below. In [Part V](#part-v---Completeness), we discuss why the solution is complete based on result from analysis with automated tools.
    69  
    70  ## Isolation
    71  
    72  ### Outline
    73  
    74  > Describe solution (in English), decomposition into functions, where communication to other components happens.
    75  
    76  #### **[LCAI-FUNC-MAIN.1]**
    77  
    78  ```go
    79  func isolateMisbehavingProcesses(ev LightClientAttackEvidence, bc Blockchain) []ValidatorAddress {
    80  
    81      reference := bc[ev.conflictingBlock.Header.Height].Header
    82      ev_header := ev.conflictingBlock.Header
    83  
    84      ref_commit := bc[ev.conflictingBlock.Header.Height + 1].Header.LastCommit // + 1 !!
    85      ev_commit := ev.conflictingBlock.Commit
    86  
    87      if violatesTMValidity(reference, ev_header) {
    88          // lunatic light client attack
    89          signatories := Signers(ev.ConflictingBlock.Commit)
    90          bonded_vals := Addresses(bc[ev.CommonHeight].NextValidators)
    91          return intersection(signatories,bonded_vals)
    92  
    93      }
    94      // If this point is reached the validator sets in reference and ev_header are identical
    95      else if RoundOf(ref_commit) == RoundOf(ev_commit) {
    96          // equivocation light client attack
    97          return intersection(Signers(ref_commit), Signers(ev_commit))
    98      }
    99      else {
   100          // amnesia light client attack
   101          return IsolateAmnesiaAttacker(ev, bc)
   102      }
   103  }
   104  ```
   105  
   106  - Implementation comment
   107      - If the full node has only reached height `ev.conflictingBlock.Header.Height` then `bc[ev.conflictingBlock.Header.Height + 1].Header.LastCommit` refers to the locally stored commit for this height. (This commit must be present by the precondition on `length(bc)`.)
   108      - We check in the precondition that the unbonding period is not expired. However, since time moves on, before handing the validators over Cosmos SDK, the time needs to be checked again to satisfy the contract which requires that only bonded validators are reported. This passing of validators to the SDK is out of scope of this specification.
   109  - Expected precondition
   110      - `length(bc) >= ev.conflictingBlock.Header.Height`
   111      - `ValidAndVerifiedUnbonding(bc[ev.CommonHeight], ev.ConflictingBlock) == SUCCESS`
   112      - `ev.ConflictingBlock.Header != bc[ev.ConflictingBlock.Header.Height]`
   113      - TODO: input light blocks pass basic validation
   114  - Expected postcondition
   115      - [[FN-INV-Output.1]](#FN-INV-Output1) holds
   116  - Error condition
   117      - returns an error if precondition is violated.
   118  
   119  ### Details of the Functions
   120  
   121  #### **[LCAI-FUNC-VVU.1]**
   122  
   123  ```go
   124  func ValidAndVerifiedUnbonding(trusted LightBlock, untrusted LightBlock) Result
   125  ```
   126  
   127  - Conditions are identical to [[LCV-FUNC-VALID.2]][LCV-FUNC-VALID.link] except the precondition "*trusted.Header.Time > now - trustingPeriod*" is substituted with
   128      - `trusted.Header.Time > now - UnbondingPeriod`
   129  
   130  #### **[LCAI-FUNC-NONVALID.1]**
   131  
   132  ```go
   133  func violatesTMValidity(ref Header, ev Header) boolean
   134  ```
   135  
   136  - Implementation remarks
   137      - checks whether the evidence header `ev` violates the validity property of Tendermint Consensus, by checking agains a reference header
   138  - Expected precondition
   139      - `ref.Height == ev.Height`
   140  - Expected postcondition
   141      - returns evaluation of the following disjunction  
   142      **[[LCAI-NONVALID-OUTPUT.1]]** ==  
   143      `ref.ValidatorsHash != ev.ValidatorsHash` or  
   144      `ref.NextValidatorsHash != ev.NextValidatorsHash` or  
   145      `ref.ConsensusHash != ev.ConsensusHash` or  
   146      `ref.AppHash != ev.AppHash` or  
   147      `ref.LastResultsHash != ev.LastResultsHash`
   148  
   149  ```go
   150  func IsolateAmnesiaAttacker(ev LightClientAttackEvidence, bc Blockchain) []ValidatorAddress
   151  ```
   152  
   153  - Implementation remarks
   154      **TODO:** What should we do here? Refer to the accountability doc?
   155  - Expected postcondition
   156      **TODO:** What should we do here? Refer to the accountability doc?
   157  
   158  ```go
   159  func RoundOf(commit Commit) []ValidatorAddress
   160  ```
   161  
   162  - Expected precondition
   163      - `commit` is well-formed. In particular all votes are from the same round `r`.
   164  - Expected postcondition
   165      - returns round `r` that is encoded in all the votes of the commit
   166  
   167  ```go
   168  func Signers(commit Commit) []ValidatorAddress
   169  ```
   170  
   171  - Expected postcondition
   172      - returns all validator addresses in `commit`
   173  
   174  ```go
   175  func Addresses(vals Validator[]) ValidatorAddress[]
   176  ```
   177  
   178  - Expected postcondition
   179      - returns all validator addresses in `vals`
   180  
   181  # Part V - Completeness
   182  
   183  As discussed in the beginning of this document, an attack boils down to creating and signing Tendermint consensus messages in deviation from the Tendermint consensus algorithm rules.
   184  The main function `isolateMisbehavingProcesses` distinguishes three kinds of wrongly signing messages, namely,
   185  
   186  - lunatic: signing invalid blocks
   187  - equivocation: double-signing valid blocks in the same consensus round
   188  - amnesia: signing conflicting blocks in different consensus rounds, without having seen a quorum of messages that would have allowed to do so.
   189  
   190  The question is whether this captures all attacks.
   191  First observe that the first checking in `isolateMisbehavingProcesses` is `violatesTMValidity`. It takes care of lunatic attacks. If this check passes, that is, if `violatesTMValidity` returns `FALSE` this means that [FN-NONVALID-OUTPUT] evaluates to false, which implies that `ref.ValidatorsHash = ev.ValidatorsHash`. Hence after `violatesTMValidity`, all the involved validators are the ones from the blockchain. It is thus sufficient to analyze one instance of Tendermint consensus with a fixed group membership (set of validators). Also it is sufficient to consider two different valid consensus values, that is, binary consensus.
   192  
   193  **TODO** we have analyzed Tendermint consensus with TLA+ and have accompanied Galois in an independent study of the protocol based on [Ivy proofs](https://github.com/tendermint/spec/tree/master/ivy-proofs).
   194  
   195  # References
   196  
   197  [[supervisor]] The specification of the light client supervisor.
   198  
   199  [[verification]] The specification of the light client verification protocol
   200  
   201  [[detection]] The specification of the light client attack detection mechanism.
   202  
   203  [supervisor]:
   204  https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/supervisor/supervisor_001_draft.md
   205  
   206  [verification]: https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/verification/verification_002_draft.md
   207  
   208  [detection]:
   209  https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/detection/detection_003_reviewed.md
   210  
   211  [LC-DATA-EVIDENCE-link]:
   212  https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/detection/detection_003_reviewed.md#lc-data-evidence1
   213  
   214  [TMBC-LC-EVIDENCE-DATA-link]:
   215  https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/detection/detection_003_reviewed.md#tmbc-lc-evidence-data1
   216  
   217  [node-based-attack-characterization]:
   218  https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/detection/detection_003_reviewed.md#node-based-characterization-of-attacks
   219  
   220  [TMBC-FM-2THIRDS-link]: https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/verification/verification_002_draft.md#tmbc-fm-2thirds1
   221  
   222  [LCV-FUNC-VALID.link]: https://github.com/tendermint/spec/blob/master/rust-spec/lightclient/verification/verification_002_draft.md#lcv-func-valid2