4

How are smart contract addresses (those that start with KT1) computed?

I would like to know whether CHAIN_ID is somehow used in its computation, or it is possible to have two KT1 contracts with identical addresses on different chains.

3 Answers 3

10

In case someone needs precise calculations.

Say, you have an operation group hash onvsLP3JFZia2mzZKWaFuFkWg2L5p3BDUhzh5Kr6CiDDN3rtQ1D and an origination index 0 which is increased for every origination operation in the group including internal operations. In order to calculate originated contract hash you need to do:

  1. Base58 decode (with checksum) the opg hash (34 bytes)
  2. Remove 2-byte prefix (32 bytes)
  3. Convert index (int32) to bytes (4 bytes)
  4. Concatenate opg hash and index bytes (36 bytes)
  5. Take Blake2b hash with digest size=20 (20 bytes)
  6. Prepend 3-byte prefix \002\090\121
  7. Base58 encode (with checksum)

In the result you get KT1UvfyLytrt71jh63YV4Yex5SmbNXpWHxtg

When you call run_code RPC endpoint a dummy contract is originated. Its address is calculated the same way, but a zero opg hash (\x00 32 times) is used. For every CREATE_CONTRACT instruction the origination index is increased.

The dummy originated contract address is thus always KT1Mjjcb6tmSsLm7Cb3DSQszePjfchPM4Uxm

7

KT1 addresses are computed from origination nonce. The origination nonce is made of operation hash (the operation that creates the origination) and its index (the index starts from 0 and it gets incremented for each origination in the operation).

The operation hash depends on block header of the branch where it was included.The CHAIN_ID depends on genesis block hash.

So on chains with different CHAIN_IDs the block hashes will differ, because they depend on their predecessors, and so you should never get the same KT1 addresses.

-1

You have a good answer. If you want to learn more see these threads.

https://www.reddit.com/r/tezos/comments/91tis3/multiple_kt1_addresses

https://www.reddit.com/r/tezos/comments/9mxtkp/what_is_the_difference_between_manager_address/

Difference between tz1 and KT1 addresses

Difference between tz1 and KT1 addresses

1
  • 2
    Thank's for participating here. You should include excerpts and/or a summary from those sources as a text instead of posting links. Those external sources might change and then won't help future visitors of this question see the answer that was given on that day.
    – XTZST2O
    Commented Dec 31, 2019 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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