github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/cmd/checkpoint-admin/README.md (about)

     1  ## Checkpoint-admin
     2  
     3  Checkpoint-admin is a tool for updating checkpoint oracle status. It provides a series of functions including deploying checkpoint oracle contract, signing for new checkpoints, and updating checkpoints in the checkpoint oracle contract.
     4  
     5  ### Checkpoint
     6  
     7  In the LES protocol, there is an important concept called checkpoint. In simple terms, whenever a certain number of blocks are generated on the blockchain, a new checkpoint is generated which contains some important information such as
     8  
     9  * Block hash at checkpoint
    10  * Canonical hash trie root at checkpoint
    11  * Bloom trie root at checkpoint
    12  
    13  *For a more detailed introduction to checkpoint, please see the LES [spec](https://github.com/ethereum/devp2p/blob/master/caps/les.md).*
    14  
    15  Using this information, light clients can skip all historical block headers when synchronizing data and start synchronization from this checkpoint. Therefore, as long as the light client can obtain some latest and correct checkpoints, the amount of data and time for synchronization will be greatly reduced.
    16  
    17  However, from a security perspective, the most critical step in a synchronization algorithm based on checkpoints is to determine whether the checkpoint used by the light client is correct. Otherwise, all blockchain data synchronized based on this checkpoint may be wrong. For this we provide two different ways to ensure the correctness of the checkpoint used by the light client.
    18  
    19  #### Hardcoded checkpoint
    20  
    21  There are several hardcoded checkpoints in the [source code](https://github.com/kisexp/xdchain/blob/master/params/config.go#L38) of the go-ethereum project. These checkpoints are updated by go-ethereum developers when new versions of software are released. Because light client users trust Geth developers to some extent, hardcoded checkpoints in the code can also be considered correct.
    22  
    23  #### Checkpoint oracle
    24  
    25  Hardcoded checkpoints can solve the problem of verifying the correctness of checkpoints (although this is a more centralized solution). But the pain point of this solution is that developers can only update checkpoints when a new version of software is released. In addition, light client users usually do not keep the Geth version they use always up to date. So hardcoded checkpoints used by users are generally stale. Therefore, it still needs to download a large amount of blockchain data during synchronization.
    26  
    27  Checkpoint oracle is a more flexible solution. In simple terms, this is a smart contract that is deployed on the blockchain. The smart contract records several designated trusted signers. Whenever enough trusted signers have issued their signatures for the same checkpoint, it can be considered that the checkpoint has been authenticated by the signers. Checkpoints authenticated by trusted signers can be considered correct.
    28  
    29  So this way, even without updating the software version, as long as the trusted signers regularly update the checkpoint in oracle on time, the light client can always use the latest and verified checkpoint for data synchronization.
    30  
    31  ### Usage
    32  
    33  Checkpoint-admin is a command line tool designed for checkpoint oracle. Users can easily deploy contracts and update checkpoints through this tool.
    34  
    35  #### Install
    36  
    37  ```shell
    38  go get github.com/kisexp/xdchain/cmd/checkpoint-admin
    39  ```
    40  
    41  #### Deploy
    42  
    43  Deploy checkpoint oracle contract. `--signers` indicates the specified trusted signer, and `--threshold` indicates the minimum number of signatures required by trusted signers to update a checkpoint.
    44  
    45  ```shell
    46  checkpoint-admin deploy --rpc <NODE_RPC_ENDPOINT> --clef <CLEF_ENDPOINT> --signer <SIGNER_TO_SIGN_TX> --signers <TRUSTED_SIGNER_LIST> --threshold 1
    47  ```
    48  
    49  It is worth noting that checkpoint-admin only supports clef as a signer for transactions and plain text(checkpoint). For more clef usage, please see the clef [tutorial](https://geth.ethereum.org/docs/clef/tutorial) .
    50  
    51  #### Sign
    52  
    53  Checkpoint-admin provides two different modes of signing. You can automatically obtain the current stable checkpoint and sign it interactively, and you can also use the information provided by the command line flags to sign checkpoint offline.
    54  
    55  **Interactive mode**
    56  
    57  ```shell
    58  checkpoint-admin sign --clef <CLEF_ENDPOINT> --signer <SIGNER_TO_SIGN_CHECKPOINT> --rpc <NODE_RPC_ENDPOINT>
    59  ```
    60  
    61  *It is worth noting that the connected Geth node can be a fullnode or a light client. If it is fullnode, you must enable the LES protocol. E.G. add `--light.serv 50` to the startup command line flags*.
    62  
    63  **Offline mode**
    64  
    65  ```shell
    66  checkpoint-admin sign --clef <CLEF_ENDPOINT> --signer <SIGNER_TO_SIGN_CHECKPOINT> --index <CHECKPOINT_INDEX> --hash <CHECKPOINT_HASH> --oracle <CHECKPOINT_ORACLE_ADDRESS>
    67  ```
    68  
    69  *CHECKPOINT_HASH is obtained based on this [calculation method](https://github.com/kisexp/xdchain/blob/master/params/config.go#L251).*
    70  
    71  #### Publish
    72  
    73  Collect enough signatures from different trusted signers for the same checkpoint and submit them to oracle to update the "authenticated" checkpoint in the contract.
    74  
    75  ```shell
    76  checkpoint-admin publish --clef <CLEF_ENDPOINT> --rpc <NODE_RPC_ENDPOINT> --signer <SIGNER_TO_SIGN_TX> --index <CHECKPOINT_INDEX> --signatures <CHECKPOINT_SIGNATURE_LIST>
    77  ```
    78  
    79  #### Status query
    80  
    81  Check the latest status of checkpoint oracle.
    82  
    83  ```shell
    84  checkpoint-admin status --rpc <NODE_RPC_ENDPOINT>
    85  ```
    86  
    87  ### Enable checkpoint oracle in your private network
    88  
    89  Currently, only the Ethereum mainnet and the default supported test networks (ropsten, rinkeby, goerli) activate this feature. If you want to activate this feature in your private network, you can overwrite the relevant checkpoint oracle settings through the configuration file after deploying the oracle contract.
    90  
    91  * Get your node configuration file `geth dumpconfig OTHER_COMMAND_LINE_OPTIONS > config.toml`
    92  * Edit the configuration file and add the following information
    93  
    94  ```toml
    95  [Eth.CheckpointOracle]
    96  Address = CHECKPOINT_ORACLE_ADDRESS
    97  Signers = [TRUSTED_SIGNER_1, ..., TRUSTED_SIGNER_N]
    98  Threshold = THRESHOLD
    99  ```
   100  
   101  * Start geth with the modified configuration file
   102  
   103  *In the private network, all fullnodes and light clients need to be started using the same checkpoint oracle settings.*