Skip to content

Commit 4723e7c

Browse files
authored
Merge pull request #2284 from XORS-eng/address-types-update
ethereum address conversion addition
2 parents 456a593 + 773778b commit 4723e7c

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed
110 KB
Loading

smart-contracts/filecoin-evm-runtime/address-types.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Filecoin has five address classes, and actors tend to have _multiple_ addresses.
1111

1212
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:
1313

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.
1818

1919
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.
2020

@@ -26,17 +26,17 @@ Filecoin address can be broken down like this:
2626

2727
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.
2828

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.
3131

3232
The protocol indicator identifies the address type, which describes how a method should interpret the information in the `payload` field of an address.
3333

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.
4040

4141
Each address type is described below.
4242

@@ -70,18 +70,18 @@ Public key addresses allow devices, like hardware wallets, to derive a valid Fil
7070

7171
Filecoin supports two types of public key addresses:
7272

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`.
7575

7676
`t1iandfn6d...ddboqxbhoeva` - a testnet wallet address generated using secp256k1. `t3vxj34sbdr3...road7cbygq` - a testnet wallet address generated using BLS.
7777

7878
## Delegated addresses
7979

8080
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:
8181

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.
8585

8686
For example, a testnet delegated address using the Ethereum Addressing System is structured as follows:
8787

@@ -137,23 +137,36 @@ Again, assume you have deployed a solidity smart contract on Filecoin Calibratio
137137

138138
When you try to invoke this smart contract on Filecoin using Ethereum tooling, you need to use your `0x5f6044198a16279f87d2839c998893858bbf8d9c` smart contract address.
139139

140-
### Converting to a 0x-style address
140+
### Converting to a 0x-style Address
141141

142142
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:
143143

144+
![Filecoin to Ethereum Address Conversion](../../.gitbook/assets/ethereum-address-conversion.png)
145+
144146
Addresses starting with `f0` can be converted to the `0x` format by:
145147

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)`.
148150

149151
Addresses starting with `f410f` address can be converted to the `0x` format by:
150152

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)`.
156158

157159
{% hint style="danger" %}
158160
`f0` addresses are **not** re-org stable and should not be used until the chain has settled.
159161
{% 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.
171+
172+
Otherwise, it maps to f410f…

0 commit comments

Comments
 (0)