Skip to content

Address, Shard Key, Chain Id, Shard Id

zgw edited this page Jan 25, 2019 · 1 revision

A QuarkChain address is 24 bytes instead of 20 bytes as specified in Ethereum. The first 20 bytes which is called RECIPIENT are generated the same way as an Ethereum address. The next 4 bytes encode a FULL_SHARD_KEY where the leading 2 bytes is a CHAIN_ID matching the id of one of the chains in the network and the other two bytes is SHARD_KEY which shall be randomly generated when a new address is created.

For example, the following is a QuarkChain address.

0x68fB978BF0e4c69bA338D4Fa5A4e5EAA88438AA80002D4aA

where RECIPIENT=68fB978BF0e4c69bA338D4Fa5A4e5EAA88438AA8 , FULL_SHARD_KEY=0002D4aA, CHAIN_ID=2, SHARD_KEY=D4aA.

QuarkChain network consists of a certain number of chains and each chain has a number of shards (SHARD_SIZE) which is always a power of 2. To find the shard an address belongs to, first we identify the chain based on CHAIN_ID then locate the shard

SHARD_ID = SHARD_KEY & (SHARD_SIZE - 1)

With the same function you can build addresses of the same recipient for different chains and shards. This will allow a single recipient to receive tokens in any shard.

Another concept in QuarkChain is called FULL_SHARD_ID, which is defined as

FULL_SHARD_ID = (CHAIN_ID << 16) + SHARD_SIZE + SHARD_ID

By supplying a FULL_SHARD_ID, we can identify a unique shard regardless of sharding state (pre/post reshard).

Note that addresses used in an EVM smart contract are still 20 bytes (the recipient in QuarkChain) as the execution scope of a smart contract cannot go beyond the shard it belongs to.