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.

345 lines
14 KiB

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