Conflux originally used the same hex40 format address as Ethereum, but restricted the first 0x0 , 0x1 , and 0x8 are legal, and these three prefixes can be used to distinguish the types of addresses:

  • 0x0 built-in contract address
  • 0x1 ordinary external account address
  • 0x8 contract address

However, because the address formats are similar and they cannot be used with each other completely (because Conflux restricts a fixed prefix), it is very easy to mix with the Ethereum address, which leads to the loss of assets. To solve this problem, Conflux introduced a new Base32 format address CIP-37
This article will give a detailed introduction to the Conflux address.

Ethereum hex40 address

The Ethereum account private key is a 256-bit string (32 bytes), usually randomly generated.

18e14a7b6a307f426a94f8114701e7c8e774e7f9a47e2c2035db29a206321725

Then calculate the X and Y values corresponding to the private key by using the elliptic curve algorithm. 04 + X + Y is the public key (65 bytes)

04
50863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352
2cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6

Finally, perform Keccak-256 calculation on the public key ( does not contain the 04 prefix) to obtain the hash value, and take the last 20 bytes as the Ethereum address

1016f75c54c607f082ae6b0881fac0abeda21781

I.e. 0x1016f75c54c607f082ae6b0881fac0abeda21781

image.png

And EIP-55 161bab2ce20e54. Its implementation is very simple, that is, make a keccak256 hash on the address, and then align it by bit, and change the hash value of 161bab2ce20e55>=8 In uppercase:

image.png

should be noted that in the Solidity smart contract, it is required to use the checkSum format address

Conflux Base32 address

0x1 , except that the first address of the address is forced to be changed to 061bab2ce20e9e after the address is generated.

Then base32 encode the address starting with 0x1 to get the base32 format address currently used by Conflux:

cfx:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg

The addresses of the two formats are only different in encoding, but the information expressed is the same, and they can be converted between

Specific coding rules

The encoding uses 32 characters: abcdefghjkmnprstuvwxyz0123456789 (i, l, o, q removed)

Network prefix

Determine the network prefix based on networkId:

payload

Use the fixed 0 as the version byte, and then add the byte data of the hex40 address to construct payload , and then base32 encode the payload.

checksum

Construct data for calculating checksum:

Use the following method to calculate a 40-bit number and convert it to 8 base32 characters as a checksum

uint64_t PolyMod(const data &v) {
    uint64_t c = 1;
    for (uint8_t d : v) {
        uint8_t c0 = c >> 35;
        c = ((c & 0x07ffffffff) << 5) ^ d;

        if (c0 & 0x01) c ^= 0x98f2bc8e61;
        if (c0 & 0x02) c ^= 0x79b76d99e2;
        if (c0 & 0x04) c ^= 0xf33e5fb3c4;
        if (c0 & 0x08) c ^= 0xae2eabe2a8;
        if (c0 & 0x10) c ^= 0x1e4f43e470;
    }
    return c ^ 1;
}

Finally connect all the data together:

netprefix + ":" + payload + checksum

Optional address type information

The base32 address can contain an optional address type information, which does not participate in the checksum calculation. There are four address types as follows:

Usually addresses with type information are expressed in capital letters

CFX:TYPE.USER:AAKPBX01FZM1XP89CB7URF6YVYXH3GGX5E9HZ07B38

For specific address specifications, see CIP-37 specification

Base32 usage scenarios

Conflux-rust Starting from v1.1.1 all RPC methods involving addresses only accept addresses in base32 format. Portal has also been upgraded to display and accept addresses in the new format by default. The new address is required for the main scenes:

  • RPC interaction
  • Wallet transfer
  • Use SDK to develop applications

At present, has only one scenario that needs to use the hex40 checksum format address, that is, when developing the Solidity smart contract, only the hex40 checksum address can be used Solidity code

In addition, when interacting with contract methods, when passing parameters or returning results, the essence also requires the use of ABI-encoded hex40 addresses. However, when interacting with Conflux SDK, the SDK will automatically convert the address format, so it can be said that this scenario also uses base32 format addresses.

SDK address method and Scan address conversion tool

Each language SDK of Conflux provides two format address conversion methods. Officially developed JS, Go, Java, Python language SDK, and community-developed C++ SDK, etc.
Take js-sdk as an example:

const {format} = require('js-conflux-sdk');

const hexAddress = "0x12c0ced72d5579b3df107b0697948d267c98d3d9";
const base32Address = "cfx:aakpbx01fzm1xp89cb7urf6yvyxh3ggx5e9hz07b38";
const netId = 1029;

// hex to base32
format.address(hexAddress, netId);
// cfx:aakpbx01fzm1xp89cb7urf6yvyxh3ggx5e9hz07b38
format.hexAddress(base32Address);
// 0x12c0ced72d5579b3df107b0697948d267c98d3d9

In addition, JS-SDK also provides multiple address-related utilities methods

const {address} = require('js-conflux-sdk');
/*
{
  encodeCfxAddress: [Function: encode],
  decodeCfxAddress: [Function: decode],
  ethChecksumAddress: [Function: ethChecksumAddress],
  ethAddressToCfxAddress: [Function: ethAddressToCfxAddress],
  ADDRESS_TYPES: {
    USER: 'user',
    CONTRACT: 'contract',
    BUILTIN: 'builtin',
    NULL: 'null'
  },
  isValidCfxAddress: [Function: isValidCfxAddress],
  verifyCfxAddress: [Function: verifyCfxAddress],
  hasNetworkPrefix: [Function: hasNetworkPrefix],
  simplifyCfxAddress: [Function: simplifyCfxAddress],
  shortenCfxAddress: [Function: shortenCfxAddress],
  isZeroAddress: [Function: isZeroAddress],
  isInternalContractAddress: [Function: isInternalContractAddress],
  isValidHexAddress: [Function: isValidHexAddress],
  isValidCfxHexAddress: [Function: isValidCfxHexAddress]
}
*/

address.encodeCfxAddress(hexAddress, netId, true);
// CFX:TYPE.USER:AAKPBX01FZM1XP89CB7URF6YVYXH3GGX5E9HZ07B38
address.decodeCfxAddress(base32Address);
/*
{
  hexAddress: <Buffer 12 c0 ce d7 2d 55 79 b3 df 10 7b 06 97 94 8d 26 7c 98 d3 d9>,
  netId: 1029,
  type: 'user'
}
*/

In addition, on the Scan browser, a 161bab2ce213c1 address conversion tool conversion between the two formats.

image.png

bip44 coin number

Like Ethereum and Bitcoin, Conflux also follows the account system introduced by bip32, bip44, and bip39. That is, you can use mnemonic phrase to generate HD wallet.

For example, the derivation path of m/44'/60'/0'/0/0 wallet is: 061bab2ce21408 where 60 is the coin code of ETH.

Conflux's Coin code is 503 , and its derived path is: m/44'/503'/0'/0/0

0x1 compatible address generation tool

At present, only 0x1 starting with 061bab2ce21450 in the Ethereum network can also be used in the Conflux network. If you want an address to be used on two networks, you can try to generate some 0x1 starting with 061bab2ce21451. You can use js-conflux-sdk the cli tools cfxjs to generate:

$ npx cfxjs genEthCMPTaccount  
PrivateKey:  0x6c6faf9644eafe16211ad6a222f7e2a22eb3b10f3145a6226ef0b4c9ef618413
Address:  0x15d4b49ffd7a75a86901cdfce54d85548d3698dd

There is also a web tool , which can quickly find the index and private key of a 0x1 account from the mnemonic. safety, please disconnect the network and turn on the privacy mode .

image.png


Conflux中文社区
66 声望19 粉丝

Conflux网址:[链接]