3

The RPC GET /chains/<chain_id>/chain_id returns:

'the chain unique identifier'

How is this identifier computed?

2
  • 3
    Possible duplicate of How do I base58 encode the chain ID using Python?
    – Ezy
    Feb 19 '19 at 22:40
  • The answers in the "using Python" version of the question :( do not seem to answer the general question... So I will attempt to answer this one.
    – Tom
    Feb 27 '19 at 16:52
5

The chain_id is computed from the genesis block hash as follows.

First, in pseudocode:

tezosB58CheckEncode('Net',
  firstFourBytes(
    blake2b(msg = tezosB58CheckDecode('B', genesisBlockHash),
            size = 32)))

In detail:

  1. Take the genesis block hash. For example, in mainnet, this is "BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2".

  2. Base58Check-decode the block hash. The prefix bytes for blocks "B" are [1, 52] (in decimal), as you can see by doing git grep B\( in tezos.git. This gives us 0x8fcf233671b6a04fcf679d2a381c2544ea6c1ea29ba6157776ed8424c7ccd00b.

  3. Compute the BLAKE2B hash (size 32) of the block hash bytes. We get 0x7a06a7709ff405d1791d856c52a3c55246e03ec913599b813ec2977398afb3be. Take only the first four bytes, 0x7a06a770.

  4. Base58Check-encode these four bytes with the "Net" prefix [87, 82, 0] (git grep Net\(). We get "NetXdQprcVkpaWU".

For a protocol update test chain, I believe the 'genesis' block will be the block in the main chain from which the test chain was forked.

You can find this computation defined in lib_crypto/chain_id.ml and then used as Chain_id.of_block_hash in various places (e.g. lib_shell/state.ml, lib_shell/chain_validator.ml, lib_storage/context.ml).

1
  • thanks for your answer! could you provide if possible for reference a source for this information ?
    – Ezy
    Mar 1 '19 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.