You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: smart-contracts/filecoin-evm-runtime/address-types.md
+38-25Lines changed: 38 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,10 +11,10 @@ Filecoin has five address classes, and actors tend to have _multiple_ addresses.
11
11
12
12
The goal of using different types of addresses is to provide a robust address format that is scalable, easy to use, and reliable. These addresses encode information including:
13
13
14
-
* Network prefix: indicates the network the actor belongs to.
15
-
* Protocol indicator: identify the type and version of this address.
16
-
* Payload: identify the actor according to the protocol.
17
-
* Checksum: validate the address.
14
+
- Network prefix: indicates the network the actor belongs to.
15
+
- Protocol indicator: identify the type and version of this address.
16
+
- Payload: identify the actor according to the protocol.
17
+
- Checksum: validate the address.
18
18
19
19
Filecoin addresses can be represented either as raw bytes or a string. Raw bytes format will always be used on-chain. An address can also be encoded to a string, including a checksum and network prefix. The string format will never appear on-chain and is only for human-readable purposes.
20
20
@@ -26,17 +26,17 @@ Filecoin address can be broken down like this:
26
26
27
27
The network prefix is prepended to an address when encoding to a string. The network prefix indicates which network an address belongs to. Network prefixes never appear on-chain and are only used when encoding an address to a human-readable format.
28
28
29
-
*`f` - addresses on the Filecoin mainnet.
30
-
*`t` - addresses used on any Filecoin testnet.
29
+
-`f` - addresses on the Filecoin mainnet.
30
+
-`t` - addresses used on any Filecoin testnet.
31
31
32
32
The protocol indicator identifies the address type, which describes how a method should interpret the information in the `payload` field of an address.
33
33
34
-
*`0`: An ID address.
35
-
*`1`: A wallet address generated from a secp256k public key.
36
-
*`2`: An actor address.
37
-
*`3`: A wallet address generated from BLS public key.
38
-
*`4`: A delegated address for user-defined foreign actors:
39
-
*`410`: Ethereum-compatible address space managed by the Ethereum address manager (EAM). Each 410 address is equivalent to an 0x address.
34
+
-`0`: An ID address.
35
+
-`1`: A wallet address generated from a secp256k public key.
36
+
-`2`: An actor address.
37
+
-`3`: A wallet address generated from BLS public key.
38
+
-`4`: A delegated address for user-defined foreign actors:
39
+
-`410`: Ethereum-compatible address space managed by the Ethereum address manager (EAM). Each 410 address is equivalent to an 0x address.
40
40
41
41
Each address type is described below.
42
42
@@ -70,18 +70,18 @@ Public key addresses allow devices, like hardware wallets, to derive a valid Fil
70
70
71
71
Filecoin supports two types of public key addresses:
72
72
73
-
*[secp256k1 addresses](https://en.bitcoin.it/wiki/Secp256k1) that begin with the protocol indicator as `1`.
74
-
*[BLS addresses](https://en.wikipedia.org/wiki/BLS\_digital\_signature) that begin with the protocol indicator as `3`.
73
+
-[secp256k1 addresses](https://en.bitcoin.it/wiki/Secp256k1) that begin with the protocol indicator as `1`.
74
+
-[BLS addresses](https://en.wikipedia.org/wiki/BLS_digital_signature) that begin with the protocol indicator as `3`.
75
75
76
76
`t1iandfn6d...ddboqxbhoeva` - a testnet wallet address generated using secp256k1. `t3vxj34sbdr3...road7cbygq` - a testnet wallet address generated using BLS.
77
77
78
78
## Delegated addresses
79
79
80
80
Filecoin supports extensible, user-defined actor addresses through the `4` address class, introduced in [Filecoin Improvement Proposal (FIP) 0048](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0048.md). The `4` address class provides the following benefits to the network:
81
81
82
-
* Implement foreign addressing systems in Filecoin.
83
-
* A predictable addressing scheme to support interactions with addresses that do not yet exist on-chain.
84
-
* User-defined, programmable addressing systems without extensive changes and network upgrades.
82
+
- Implement foreign addressing systems in Filecoin.
83
+
- A predictable addressing scheme to support interactions with addresses that do not yet exist on-chain.
84
+
- User-defined, programmable addressing systems without extensive changes and network upgrades.
85
85
86
86
For example, a testnet delegated address using the Ethereum Addressing System is structured as follows:
87
87
@@ -137,23 +137,36 @@ Again, assume you have deployed a solidity smart contract on Filecoin Calibratio
137
137
138
138
When you try to invoke this smart contract on Filecoin using Ethereum tooling, you need to use your `0x5f6044198a16279f87d2839c998893858bbf8d9c` smart contract address.
139
139
140
-
### Converting to a 0x-style address
140
+
### Converting to a 0x-style Address
141
141
142
142
The Filecoin EVM runtime introduces support for `0x` Ethereum-style addresses. Filecoin addresses starting with either `f0` or `f410f` can be converted to the `0x` format as follows:
143
143
144
+

145
+
144
146
Addresses starting with `f0` can be converted to the `0x` format by:
145
147
146
-
* Extracting the `actor_id` (e.g., the `1234` in `f01234`).
147
-
* Hex encode with a `0xff` prefix: `sprintf("0xff0000000000000000000000%016x", actor_id)`.
148
+
- Extracting the `actor_id` (e.g., the `1234` in `f01234`).
149
+
- Hex encode with a `0xff` prefix: `sprintf("0xff0000000000000000000000%016x", actor_id)`.
148
150
149
151
Addresses starting with `f410f` address can be converted to the `0x` format by:
150
152
151
-
* Removing the `f410f` prefix.
152
-
* Decoding the remainder as base 32 (RFC 4648 without padding).
153
-
* Trim off the last 4 bytes. This is a _checksum_ that can optionally be verified, but that’s beyond the scope of this documentation.
154
-
* Assert that the remaining address is 20 bytes long.
155
-
* Hex-encode: `sprintf(0x%040x", actor_id)`.
153
+
- Removing the `f410f` prefix.
154
+
- Decoding the remainder as base 32 (RFC 4648 without padding).
155
+
- Trim off the last 4 bytes. This is a _checksum_ that can optionally be verified, but that’s beyond the scope of this documentation.
156
+
- Assert that the remaining address is 20 bytes long.
157
+
- Hex-encode: `sprintf(0x%040x", actor_id)`.
156
158
157
159
{% hint style="danger" %}
158
160
`f0` addresses are **not** re-org stable and should not be used until the chain has settled.
159
161
{% endhint %}
162
+
163
+
### Converting to a Filecoin Address
164
+
165
+
On the flip side, Ethereum-style addresses can be converted to a Filecoin address as follows:
166
+
167
+
Addresses starting with `0xff0000000000000000000000` can be converted to a Filecoin address by:
168
+
169
+
- Decoding the last 16 hex digits into a uint64
170
+
- Format the address as `f0${decimal(id)}` where decimal(id) is the decimal representation of the decoded actor ID.
0 commit comments