github.com/cosmos/cosmos-sdk@v0.50.10/docs/architecture/adr-016-validator-consensus-key-rotation.md (about)

     1  # ADR 016: Validator Consensus Key Rotation
     2  
     3  ## Changelog
     4  
     5  * 2019 Oct 23: Initial draft
     6  * 2019 Nov 28: Add key rotation fee
     7  
     8  ## Context
     9  
    10  Validator consensus key rotation feature has been discussed and requested for a long time, for the sake of safer validator key management policy (e.g. https://github.com/tendermint/tendermint/issues/1136). So, we suggest one of the simplest form of validator consensus key rotation implementation mostly onto Cosmos SDK.
    11  
    12  We don't need to make any update on consensus logic in Tendermint because Tendermint does not have any mapping information of consensus key and validator operator key, meaning that from Tendermint point of view, a consensus key rotation of a validator is simply a replacement of a consensus key to another.
    13  
    14  Also, it should be noted that this ADR includes only the simplest form of consensus key rotation without considering multiple consensus keys concept. Such multiple consensus keys concept shall remain a long term goal of Tendermint and Cosmos SDK.
    15  
    16  ## Decision
    17  
    18  ### Pseudo procedure for consensus key rotation
    19  
    20  * create new random consensus key.
    21  * create and broadcast a transaction with a `MsgRotateConsPubKey` that states the new consensus key is now coupled with the validator operator with signature from the validator's operator key.
    22  * old consensus key becomes unable to participate on consensus immediately after the update of key mapping state on-chain.
    23  * start validating with new consensus key.
    24  * validators using HSM and KMS should update the consensus key in HSM to use the new rotated key after the height `h` when `MsgRotateConsPubKey` committed to the blockchain.
    25  
    26  ### Considerations
    27  
    28  * consensus key mapping information management strategy
    29      * store history of each key mapping changes in the kvstore.
    30      * the state machine can search corresponding consensus key paired with given validator operator for any arbitrary height in a recent unbonding period.
    31      * the state machine does not need any historical mapping information which is past more than unbonding period.
    32  * key rotation costs related to LCD and IBC
    33      * LCD and IBC will have traffic/computation burden when there exists frequent power changes
    34      * In current Tendermint design, consensus key rotations are seen as power changes from LCD or IBC perspective
    35      * Therefore, to minimize unnecessary frequent key rotation behavior, we limited maximum number of rotation in recent unbonding period and also applied exponentially increasing rotation fee
    36  * limits
    37      * a validator cannot rotate its consensus key more than `MaxConsPubKeyRotations` time for any unbonding period, to prevent spam.
    38      * parameters can be decided by governance and stored in genesis file.
    39  * key rotation fee
    40      * a validator should pay `KeyRotationFee` to rotate the consensus key which is calculated as below
    41      * `KeyRotationFee` = (max(`VotingPowerPercentage` *100, 1)* `InitialKeyRotationFee`) * 2^(number of rotations in `ConsPubKeyRotationHistory` in recent unbonding period)
    42  * evidence module
    43      * evidence module can search corresponding consensus key for any height from slashing keeper so that it can decide which consensus key is supposed to be used for given height.
    44  * abci.ValidatorUpdate
    45      * tendermint already has ability to change a consensus key by ABCI communication(`ValidatorUpdate`).
    46      * validator consensus key update can be done via creating new + delete old by change the power to zero.
    47      * therefore, we expect we even do not need to change tendermint codebase at all to implement this feature.
    48  * new genesis parameters in `staking` module
    49      * `MaxConsPubKeyRotations` : maximum number of rotation can be executed by a validator in recent unbonding period. default value 10 is suggested(11th key rotation will be rejected)
    50      * `InitialKeyRotationFee` : the initial key rotation fee when no key rotation has happened in recent unbonding period. default value 1atom is suggested(1atom fee for the first key rotation in recent unbonding period)
    51  
    52  ### Workflow
    53  
    54  1. The validator generates a new consensus keypair.
    55  2. The validator generates and signs a `MsgRotateConsPubKey` tx with their operator key and new ConsPubKey
    56  
    57      ```go
    58      type MsgRotateConsPubKey struct {
    59          ValidatorAddress  sdk.ValAddress
    60          NewPubKey         crypto.PubKey
    61      }
    62      ```
    63  
    64  3. `handleMsgRotateConsPubKey` gets `MsgRotateConsPubKey`, calls `RotateConsPubKey` with emits event
    65  4. `RotateConsPubKey`
    66      * checks if `NewPubKey` is not duplicated on `ValidatorsByConsAddr`
    67      * checks if the validator is does not exceed parameter `MaxConsPubKeyRotations` by iterating `ConsPubKeyRotationHistory`
    68      * checks if the signing account has enough balance to pay `KeyRotationFee`
    69      * pays `KeyRotationFee` to community fund
    70      * overwrites `NewPubKey` in `validator.ConsPubKey`
    71      * deletes old `ValidatorByConsAddr`
    72      * `SetValidatorByConsAddr` for `NewPubKey`
    73      * Add `ConsPubKeyRotationHistory` for tracking rotation
    74  
    75      ```go
    76      type ConsPubKeyRotationHistory struct {
    77          OperatorAddress         sdk.ValAddress
    78          OldConsPubKey           crypto.PubKey
    79          NewConsPubKey           crypto.PubKey
    80          RotatedHeight           int64
    81      }
    82      ```
    83  
    84  5. `ApplyAndReturnValidatorSetUpdates` checks if there is `ConsPubKeyRotationHistory` with `ConsPubKeyRotationHistory.RotatedHeight == ctx.BlockHeight()` and if so, generates 2 `ValidatorUpdate` , one for a remove validator and one for create new validator
    85  
    86      ```go
    87      abci.ValidatorUpdate{
    88          PubKey: cmttypes.TM2PB.PubKey(OldConsPubKey),
    89          Power:  0,
    90      }
    91  
    92      abci.ValidatorUpdate{
    93          PubKey: cmttypes.TM2PB.PubKey(NewConsPubKey),
    94          Power:  v.ConsensusPower(),
    95      }
    96      ```
    97  
    98  6. at `previousVotes` Iteration logic of `AllocateTokens`,  `previousVote` using `OldConsPubKey` match up with `ConsPubKeyRotationHistory`, and replace validator for token allocation
    99  7. Migrate `ValidatorSigningInfo` and `ValidatorMissedBlockBitArray` from `OldConsPubKey` to `NewConsPubKey`
   100  
   101  * Note : All above features shall be implemented in `staking` module.
   102  
   103  ## Status
   104  
   105  Proposed
   106  
   107  ## Consequences
   108  
   109  ### Positive
   110  
   111  * Validators can immediately or periodically rotate their consensus key to have better security policy
   112  * improved security against Long-Range attacks (https://nearprotocol.com/blog/long-range-attacks-and-a-new-fork-choice-rule) given a validator throws away the old consensus key(s)
   113  
   114  ### Negative
   115  
   116  * Slash module needs more computation because it needs to lookup corresponding consensus key of validators for each height
   117  * frequent key rotations will make light client bisection less efficient
   118  
   119  ### Neutral
   120  
   121  ## References
   122  
   123  * on tendermint repo : https://github.com/tendermint/tendermint/issues/1136
   124  * on cosmos-sdk repo : https://github.com/cosmos/cosmos-sdk/issues/5231
   125  * about multiple consensus keys : https://github.com/tendermint/tendermint/issues/1758#issuecomment-545291698