You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

347 lines
14 KiB

  1. <!-- markdown-link-check-disable -->
  2. # Requirements for Fork Detection in the IBC Context
  3. ## What you need to know about IBC
  4. In the following, I distilled what I considered relevant from
  5. <https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics>
  6. ### Components and their interface
  7. #### Tendermint Blockchains
  8. > I assume you know what that is.
  9. #### An IBC/Tendermint correspondence
  10. | IBC Term | Tendermint-RS Spec Term | Comment |
  11. |----------|-------------------------| --------|
  12. | `CommitmentRoot` | AppState | app hash |
  13. | `ConsensusState` | Lightblock | not all fields are there. NextValidator is definitly needed |
  14. | `ClientState` | latest light block + configuration parameters (e.g., trusting period + `frozenHeight` | NextValidators missing; what is `proofSpecs`?|
  15. | `frozenHeight` | height of fork | set when a fork is detected |
  16. | "would-have-been-fooled" | light node fork detection | light node may submit proof of fork to IBC component to halt it |
  17. | `Height` | (no epochs) | (epoch,height) pair in lexicographical order (`compare`) |
  18. | `Header` | ~signed header | validatorSet explicit (no hash); nextValidators missing |
  19. | `Evidence` | t.b.d. | definition unclear "which the light client would have considered valid". Data structure will need to change |
  20. | `verify` | `ValidAndVerified` | signature does not match perfectly (ClientState vs. LightBlock) + in `checkMisbehaviourAndUpdateState` it is unclear whether it uses traces or goes to h1 and h2 in one step |
  21. #### Some IBC links
  22. - [QueryConsensusState](https://github.com/cosmos/cosmos-sdk/blob/2651427ab4c6ea9f81d26afa0211757fc76cf747/x/ibc/02-client/client/utils/utils.go#L68)
  23. #### Required Changes in ICS 007
  24. - `assert(height > 0)` in definition of `initialise` doesn't match
  25. definition of `Height` as *(epoch,height)* pair.
  26. - `initialise` needs to be updated to new data structures
  27. - `clientState.frozenHeight` semantics seem not totally consistent in
  28. document. E.g., `min` needs to be defined over optional value in
  29. `checkMisbehaviourAndUpdateState`. Also, if you are frozen, why do
  30. you accept more evidence.
  31. - `checkValidityAndUpdateState`
  32. - `verify`: it needs to be clarified that checkValidityAndUpdateState
  33. does not perform "bisection" (as currently hinted in the text) but
  34. performs a single step of "skipping verification", called,
  35. `ValidAndVerified`
  36. - `assert (header.height > clientState.latestHeight)`: no old
  37. headers can be installed. This might be OK, but we need to check
  38. interplay with misbehavior
  39. - clienstState needs to be updated according to complete data
  40. structure
  41. - `checkMisbehaviourAndUpdateState`: as evidence will contain a trace
  42. (or two), the assertion that uses verify will need to change.
  43. - ICS 002 states w.r.t. `queryChainConsensusState` that "Note that
  44. retrieval of past consensus states by height (as opposed to just the
  45. current consensus state) is convenient but not required." For
  46. Tendermint fork detection, this seems to be a necessity.
  47. - `Header` should become a lightblock
  48. - `Evidence` should become `LightNodeProofOfFork` [LCV-DATA-POF.1]
  49. - `upgradeClientState` what is the semantics (in particular what is
  50. `height` doing?).
  51. - `checkMisbehaviourAndUpdateState(cs: ClientState, PoF:
  52. LightNodeProofOfFork)` needs to be adapted
  53. #### Handler
  54. A blockchain runs a **handler** that passively collects information about
  55. other blockchains. It can be thought of a state machine that takes
  56. input events.
  57. - the state includes a lightstore (I guess called `ConsensusState`
  58. in IBC)
  59. - The following function is used to pass a header to a handler
  60. ```go
  61. type checkValidityAndUpdateState = (Header) => Void
  62. ```
  63. For Tendermint, it will perform
  64. `ValidandVerified`, that is, it does the trusting period check and the
  65. +1/3 check (+2/3 for sequential headers).
  66. If it verifies a header, it adds it to its lightstore,
  67. if it does not pass verification it drops it.
  68. Right now it only accepts a header more recent then the latest
  69. header,
  70. and drops older
  71. ones or ones that could not be verified.
  72. > The above paragraph captures what I believe what is the current
  73. logic of `checkValidityAndUpdateState`. It may be subject to
  74. change. E.g., maintain a lightstore with state (unverified, verified)
  75. - The following function is used to pass "evidence" (this we
  76. will need to make precise eventually) to a handler
  77. ```go
  78. type checkMisbehaviourAndUpdateState = (bytes) => Void
  79. ```
  80. We have to design this, and the data that the handler can use to
  81. check that there was some misbehavior (fork) in order react on
  82. it, e.g., flagging a situation and
  83. stop the protocol.
  84. - The following function is used to query the light store (`ConsensusState`)
  85. ```go
  86. type queryChainConsensusState = (height: uint64) => ConsensusState
  87. ```
  88. #### Relayer
  89. - The active components are called **relayer**.
  90. - a relayer contains light clients to two (or more?) blockchains
  91. - the relayer send headers and data to the handler to invoke
  92. `checkValidityAndUpdateState` and
  93. `checkMisbehaviourAndUpdateState`. It may also query
  94. `queryChainConsensusState`.
  95. - multiple relayers may talk to one handler. Some relayers might be
  96. faulty. We assume existence of at least single correct relayer.
  97. ## Informal Problem Statement: Fork detection in IBC
  98. ### Relayer requirement: Evidence for Handler
  99. - The relayer should provide the handler with
  100. "evidence" that there was a fork.
  101. - The relayer can read the handler's consensus state. Thus the relayer can
  102. feed the handler precisely the information the handler needs to detect a
  103. fork.
  104. What is this
  105. information needs to be specified.
  106. - The information depends on the verification the handler does. It
  107. might be necessary to provide a bisection proof (list of
  108. lightblocks) so that the handler can verify based on its local
  109. lightstore a header *h* that is conflicting with a header *h'* in the
  110. local lightstore, that is, *h != h'* and *h.Height = h'.Height*
  111. ### Relayer requirement: Fork detection
  112. Let's assume there is a fork at chain A. There are two ways the
  113. relayer can figure that out:
  114. 1. as the relayer contains a light client for A, it also includes a fork
  115. detector that can detect a fork.
  116. 2. the relayer may also detect a fork by observing that the
  117. handler for chain A (on chain B)
  118. is on a different branch than the relayer
  119. - in both detection scenarios, the relayer should submit evidence to
  120. full nodes of chain A where there is a fork. As we assume a fullnode
  121. has a complete list of blocks, it is sufficient to send "Bucky's
  122. evidence" (<https://github.com/tendermint/tendermint/issues/5083>),
  123. that is,
  124. - two lightblocks from different branches +
  125. - a lightblock (perhaps just a height) from which both blocks
  126. can be verified.
  127. - in the scenario 2., the relayer must feed the A-handler (on chain B)
  128. a proof of a fork on A so that chain B can react accordingly
  129. ### Handler requirement
  130. - there are potentially many relayers, some correct some faulty
  131. - a handler cannot trust the information provided by the relayer,
  132. but must verify
  133. (Доверя́й, но проверя́й)
  134. - in case of a fork, we accept that the handler temporarily stores
  135. headers (tagged as verified).
  136. - eventually, a handler should be informed
  137. (`checkMisbehaviourAndUpdateState`)
  138. by some relayer that it has
  139. verified a header from a fork. Then the handler should do what is
  140. required by IBC in this case (stop?)
  141. ### Challenges in the handler requirement
  142. - handlers and relayers work on different lightstores. In principle
  143. the lightstore need not intersect in any heights a priori
  144. - if a relayer sees a header *h* it doesn't know at a handler (`queryChainConsensusState`), the
  145. relayer needs to
  146. verify that header. If it cannot do it locally based on downloaded
  147. and verified (trusted?) light blocks, it might need to use
  148. `VerifyToTarget` (bisection). To call `VerifyToTarget` we might keep
  149. *h* in the lightstore. If verification fails, we need to download the
  150. "alternative" header of height *h.Height* to generate evidence for
  151. the handler.
  152. - we have to specify what precisely `queryChainConsensusState`
  153. returns. It cannot be the complete lightstore. Is the last header enough?
  154. - we would like to assume that every now and then (smaller than the
  155. trusting period) a correct relayer checks whether the handler is on a
  156. different branch than the relayer.
  157. And we would like that this is enough to achieve
  158. the Handler requirement.
  159. - here the correctness argument would be easy if a correct relayer is
  160. based on a light client with a *trusted* state, that is, a light
  161. client who never changes its opinion about trusted. Then if such a
  162. correct relayer checks-in with a handler, it will detect a fork, and
  163. act in time.
  164. - if the light client does not provide this interface, in the case of
  165. a fork, we need some assumption about a correct relayer being on a
  166. different branch than the handler, and we need such a relayer to
  167. check-in not too late. Also
  168. what happens if the relayer's light client is forced to roll-back
  169. its lightstore?
  170. Does it have to re-check all handlers?
  171. ## On the interconnectedness of things
  172. In the broader discussion of so-called "fork accountability" there are
  173. several subproblems
  174. - Fork detection
  175. - Evidence creation and submission
  176. - Isolating misbehaving nodes (and report them for punishment over abci)
  177. ### Fork detection
  178. The preliminary specification ./detection.md formalizes the notion of
  179. a fork. Roughly, a fork exists if there are two conflicting headers
  180. for the same height, where both are supported by bonded full nodes
  181. (that have been validators in the near past, that is, within the
  182. trusting period). We distinguish between *fork on the chain* where two
  183. conflicting blocks are signed by +2/3 of the validators of that
  184. height, and a *light client fork* where one of the conflicting headers
  185. is not signed by +2/3 of the current height, but by +1/3 of the
  186. validators of some smaller height.
  187. In principle everyone can detect a fork
  188. - ./detection talks about the Tendermint light client with a focus on
  189. light nodes. A relayer runs such light clients and may detect
  190. forks in this way
  191. - in IBC, a relayer can see that a handler is on a conflicting branch
  192. - the relayer should feed the handler the necessary information so
  193. that it can halt
  194. - the relayer should report the fork to a full node
  195. ### Evidence creation and submission
  196. - the information sent from the relayer to the handler could be called
  197. evidence, but this is perhaps a bad idea because the information sent to a
  198. full node can also be called evidence. But this evidence might still
  199. not be enough as the full node might need to run the "fork
  200. accountability" protocol to generate evidence in the form of
  201. consensus messages. So perhaps we should
  202. introduce different terms for:
  203. - proof of fork for the handler (basically consisting of lightblocks)
  204. - proof of fork for a full node (basically consisting of (fewer) lightblocks)
  205. - proof of misbehavior (consensus messages)
  206. ### Isolating misbehaving nodes
  207. - this is the job of a full node.
  208. - might be subjective in the future: the protocol depends on what the
  209. full node believes is the "correct" chain. Right now we postulate
  210. that every full node is on the correct chain, that is, there is no
  211. fork on the chain.
  212. - The full node figures out which nodes are
  213. - lunatic
  214. - double signing
  215. - amnesic; **using the challenge response protocol**
  216. - We do not punish "phantom" validators
  217. - currently we understand a phantom validator as a node that
  218. - signs a block for a height in which it is not in the
  219. validator set
  220. - the node is not part of the +1/3 of previous validators that
  221. are used to support the header. Whether we call a validator
  222. phantom might be subjective and depend on the header we
  223. check against. Their formalization actually seems not so
  224. clear.
  225. - they can only do something if there are +1/3 faulty validators
  226. that are either lunatic, double signing, or amnesic.
  227. - abci requires that we only report bonded validators. So if a
  228. node is a "phantom", we would need the check whether the node is
  229. bonded, which currently is expensive, as it requires checking
  230. blocks from the last three weeks.
  231. - in the future, with state sync, a correct node might be
  232. convinced by faulty nodes that it is in the validator set. Then
  233. it might appear to be "phantom" although it behaves correctly
  234. ## Next steps
  235. > The following points are subject to my limited knowledge of the
  236. > state of the work on IBC. Some/most of it might already exist and we
  237. > will just need to bring everything together.
  238. - "proof of fork for a full node" defines a clean interface between
  239. fork detection and misbehavior isolation. So it should be produced
  240. by protocols (light client, the relayer). So we should fix that
  241. first.
  242. - Given the problems of not having a light client architecture spec,
  243. for the relayer we should start with this. E.g.
  244. - the relayer runs light clients for two chains
  245. - the relayer regularly queries consensus state of a handler
  246. - the relayer needs to check the consensus state
  247. - this involves local checks
  248. - this involves calling the light client
  249. - the relayer uses the light client to do IBC business (channels,
  250. packets, connections, etc.)
  251. - the relayer submits proof of fork to handlers and full nodes
  252. > the list is definitely not complete. I think part of this
  253. > (perhaps all) is
  254. > covered by what Anca presented recently.
  255. We will need to define what we expect from these components
  256. - for the parts where the relayer talks to the handler, we need to fix
  257. the interface, and what the handler does
  258. - we write specs for these components.