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.

158 lines
10 KiB

  1. ---
  2. order: 3
  3. title: Application Requirements
  4. ---
  5. # Application Requirements
  6. This section specifies what Tendermint expects from the Application. It is structured as a set
  7. of formal requirement that can be used for testing and verification of the Application's logic.
  8. Let $p$ and $q$ be two different correct proposers in rounds $r_p$ and $r_q$ respectively, in height $h$.
  9. Let $s_{p,h-1}$ be $p$'s Application's state committed for height $h-1$.
  10. Let $v_p$ (resp. $v_q$) be the block that $p$'s (resp. $q$'s) Tendermint passes on to the Application
  11. via `RequestPrepareProposal` as proposer of round $r_p$ (resp $r_q$), height $h$, also known as the
  12. raw proposal.
  13. Let $v'_p$ (resp. $v'_q$) the possibly modified block $p$'s (resp. $q$'s) Application returns via
  14. `ResponsePrepareProposal` to Tendermint, also known as the prepared proposal.
  15. Process $p$'s prepared proposal can differ in two different rounds where $p$ is the proposer.
  16. * Requirement 1 [`PrepareProposal`, header-changes] When the blockchain is in same-block execution mode,
  17. $p$'s Application provides values for the following parameters in `ResponsePrepareProposal`:
  18. _AppHash_, _TxResults_, _ConsensusParams_, _ValidatorUpdates_. Provided values for
  19. _ConsensusParams_ and _ValidatorUpdates_ MAY be empty to denote that the Application
  20. wishes to keep the current values.
  21. Parameters _AppHash_, _TxResults_, _ConsensusParams_, and _ValidatorUpdates_ are used by Tendermint to
  22. compute various hashes in the block header that will finally be part of the proposal.
  23. * Requirement 2 [`PrepareProposal`, no-header-changes] When the blockchain is in next-block execution
  24. mode, $p$'s Application does not provide values for the following parameters in `ResponsePrepareProposal`:
  25. _AppHash_, _TxResults_, _ConsensusParams_, _ValidatorUpdates_.
  26. In practical terms, Requirements 1 and 2 imply that Tendermint will (a) panic if the Application is in
  27. same-block execution mode and _does_ _not_ provide values for
  28. _AppHash_, _TxResults_, _ConsensusParams_, and _ValidatorUpdates_, or
  29. (b) log an error if the Application is in next-block execution mode and _does_ provide values for
  30. _AppHash_, _TxResults_, _ConsensusParams_, or _ValidatorUpdates_ (the values provided will be ignored).
  31. * Requirement 3 [`PrepareProposal`, timeliness] If $p$'s Application fully executes prepared blocks in
  32. `PrepareProposal` and the network is in a synchronous period while processes $p$ and $q$ are in $r_p$, then
  33. the value of *TimeoutPropose* at $q$ must be such that $q$'s propose timer does not time out
  34. (which would result in $q$ prevoting *nil* in $r_p$).
  35. Full execution of blocks at `PrepareProposal` time stands on Tendermint's critical path. Thus,
  36. Requirement 3 ensures the Application will set a value for _TimeoutPropose_ such that the time it takes
  37. to fully execute blocks in `PrepareProposal` does not interfere with Tendermint's propose timer.
  38. * Requirement 4 [`PrepareProposal`, `ProcessProposal`, coherence]: For any two correct processes $p$ and $q$,
  39. if $q$'s Tendermint calls `RequestProcessProposal` on $v'_p$,
  40. $q$'s Application returns Accept in `ResponseProcessProposal`.
  41. Requirement 4 makes sure that blocks proposed by correct processes _always_ pass the correct receiving process's
  42. `ProcessProposal` check.
  43. On the other hand, if there is a deterministic bug in `PrepareProposal` or `ProcessProposal` (or in both),
  44. strictly speaking, this makes all processes that hit the bug byzantine. This is a problem in practice,
  45. as very often validators are running the Application from the same codebase, so potentially _all_ would
  46. likely hit the bug at the same time. This would result in most (or all) processes prevoting `nil`, with the
  47. serious consequences on Tendermint's liveness that this entails. Due to its criticality, Requirement 4 is a
  48. target for extensive testing and automated verification.
  49. * Requirement 5 [`ProcessProposal`, determinism-1]: `ProcessProposal` is a (deterministic) function of the current
  50. state and the block that is about to be applied. In other words, for any correct process $p$, and any arbitrary block $v'$,
  51. if $p$'s Tendermint calls `RequestProcessProposal` on $v'$ at height $h$,
  52. then $p$'s Application's acceptance or rejection **exclusively** depends on $v'$ and $s_{p,h-1}$.
  53. * Requirement 6 [`ProcessProposal`, determinism-2]: For any two correct processes $p$ and $q$, and any arbitrary block $v'$,
  54. if $p$'s (resp. $q$'s) Tendermint calls `RequestProcessProposal` on $v'$ at height $h$,
  55. then $p$'s Application accepts $v'$ if and only if $q$'s Application accepts $v'$.
  56. Note that this requirement follows from Requirement 5 and the Agreement property of consensus.
  57. Requirements 5 and 6 ensure that all correct processes will react in the same way to a proposed block, even
  58. if the proposer is Byzantine. However, `ProcessProposal` may contain a bug that renders the
  59. acceptance or rejection of the block non-deterministic, and therefore prevents processes hitting
  60. the bug from fulfilling Requirements 5 or 6 (effectively making those processes Byzantine).
  61. In such a scenario, Tendermint's liveness cannot be guaranteed.
  62. Again, this is a problem in practice if most validators are running the same software, as they are likely
  63. to hit the bug at the same point. There is currently no clear solution to help with this situation, so
  64. the Application designers/implementors must proceed very carefully with the logic/implementation
  65. of `ProcessProposal`. As a general rule `ProcessProposal` _should_ always accept the block.
  66. According to the Tendermint algorithm, a correct process can broadcast at most one precommit message in round $r$, height $h$.
  67. Since, as stated in the [Description](#description) section, `ResponseExtendVote` is only called when Tendermint
  68. is about to broadcast a non-`nil` precommit message, a correct process can only produce one vote extension in round $r$, height $h$.
  69. Let $e^r_p$ be the vote extension that the Application of a correct process $p$ returns via `ResponseExtendVote` in round $r$, height $h$.
  70. Let $w^r_p$ be the proposed block that $p$'s Tendermint passes to the Application via `RequestExtendVote` in round $r$, height $h$.
  71. * Requirement 7 [`ExtendVote`, `VerifyVoteExtension`, coherence]: For any two correct processes $p$ and $q$, if $q$ receives $e^r_p$
  72. from $p$ in height $h$, $q$'s Application returns Accept in `ResponseVerifyVoteExtension`.
  73. Requirement 7 constrains the creation and handling of vote extensions in a similar way as Requirement 4
  74. contrains the creation and handling of proposed blocks.
  75. Requirement 7 ensures that extensions created by correct processes _always_ pass the `VerifyVoteExtension`
  76. checks performed by correct processes receiving those extensions.
  77. However, if there is a (deterministic) bug in `ExtendVote` or `VerifyVoteExtension` (or in both),
  78. we will face the same liveness issues as described for Requirement 4, as Precommit messages with invalid vote
  79. extensions will be discarded.
  80. * Requirement 8 [`VerifyVoteExtension`, determinism-1]: `VerifyVoteExtension` is a (deterministic) function of
  81. the current state, the vote extension received, and the prepared proposal that the extension refers to.
  82. In other words, for any correct process $p$, and any arbitrary vote extension $e$, and any arbitrary
  83. block $w$, if $p$'s (resp. $q$'s) Tendermint calls `RequestVerifyVoteExtension` on $e$ and $w$ at height $h$,
  84. then $p$'s Application's acceptance or rejection **exclusively** depends on $e$, $w$ and $s_{p,h-1}$.
  85. * Requirement 9 [`VerifyVoteExtension`, determinism-2]: For any two correct processes $p$ and $q$,
  86. and any arbitrary vote extension $e$, and any arbitrary block $w$,
  87. if $p$'s (resp. $q$'s) Tendermint calls `RequestVerifyVoteExtension` on $e$ and $w$ at height $h$,
  88. then $p$'s Application accepts $e$ if and only if $q$'s Application accepts $e$.
  89. Note that this requirement follows from Requirement 8 and the Agreement property of consensus.
  90. Requirements 8 and 9 ensure that the validation of vote extensions will be deterministic at all
  91. correct processes.
  92. Requirements 8 and 9 protect against arbitrary vote extension data from Byzantine processes
  93. similarly to Requirements 5 and 6 and proposed blocks.
  94. Requirements 8 and 9 can be violated by a bug inducing non-determinism in
  95. `VerifyVoteExtension`. In this case liveness can be compromised.
  96. Extra care should be put in the implementation of `ExtendVote` and `VerifyVoteExtension` and,
  97. as a general rule, `VerifyVoteExtension` _should_ always accept the vote extension.
  98. * Requirement 10 [_all_, no-side-effects]: $p$'s calls to `RequestPrepareProposal`,
  99. `RequestProcessProposal`, `RequestExtendVote`, and `RequestVerifyVoteExtension` at height $h$ do
  100. not modify $s_{p,h-1}$.
  101. * Requirement 11 [`ExtendVote`, `FinalizeBlock`, non-dependency]: for any correct process $p$,
  102. and any vote extension $e$ that $p$ received at height $h$, the computation of
  103. $s_{p,h}$ does not depend on $e$.
  104. The call to correct process $p$'s `RequestFinalizeBlock` at height $h$, with block $v_{p,h}$
  105. passed as parameter, creates state $s_{p,h}$.
  106. Additionally,
  107. * in next-block execution mode, $p$'s `FinalizeBlock` creates a set of transaction results $T_{p,h}$,
  108. * in same-block execution mode, $p$'s `PrepareProposal` creates a set of transaction results $T_{p,h}$
  109. if $p$ was the proposer of $v_{p,h}$, otherwise `FinalizeBlock` creates $T_{p,h}$.
  110. >**TODO** I have left out all the "events" as they don't have any impact in safety or liveness
  111. >(same for consensus params, and validator set)
  112. * Requirement 12 [`FinalizeBlock`, determinism-1]: For any correct process $p$,
  113. $s_{p,h}$ exclusively depends on $s_{p,h-1}$ and $v_{p,h}$.
  114. * Requirement 13 [`FinalizeBlock`, determinism-2]: For any correct process $p$,
  115. the contents of $T_{p,h}$ exclusively depend on $s_{p,h-1}$ and $v_{p,h}$.
  116. Note that Requirements 12 and 13, combined with Agreement property of consensus ensure
  117. the Application state evolves consistently at all correct processes.
  118. Finally, notice that neither `PrepareProposal` nor `ExtendVote` have determinism-related
  119. requirements associated.
  120. Indeed, `PrepareProposal` is not required to be deterministic:
  121. * $v'_p$ may depend on $v_p$ and $s_{p,h-1}$, but may also depend on other values or operations.
  122. * $v_p = v_q \nRightarrow v'_p = v'_q$.
  123. Likewise, `ExtendVote` can also be non-deterministic:
  124. * $e^r_p$ may depend on $w^r_p$ and $s_{p,h-1}$, but may also depend on other values or operations.
  125. * $w^r_p = w^r_q \nRightarrow e^r_p = e^r_q$