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.
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:
\002\090\121
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
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_ID
s the block hashes will differ, because they depend on their predecessors, and so you should never get the same KT1 addresses.
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/