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
Asset Hub natively uses Polkadot's 32-byte account system but provides interoperability with Ethereum's 20-byte addresses through an automatic conversion system. When interacting with smart contracts:
7045
+
Asset Hub natively utilizes Polkadot's 32-byte account system while providing interoperability with Ethereum's 20-byte addresses through an automatic conversion system. When interacting with smart contracts:
7046
7046
7047
-
- Ethereum-compatible wallets (like MetaMask) can use their familiar 20-byte addresses
7048
-
- Polkadot accounts continue using their native 32-byte format
7047
+
- Ethereum-compatible wallets (like MetaMask) can use their familiar 20-byte addresses.
7048
+
- Polkadot accounts continue using their native 32-byte format.
7049
7049
- The Asset Hub chain automatically handles conversion between the two formats behind the scenes:
7050
7050
7051
-
- 20-byte Ethereum addresses are padded with `0xEE` bytes to create valid 32-byte Polkadot accounts
7052
-
- 32-byte Polkadot accounts can optionally register a mapping to a 20-byte address for Ethereum compatibility
7051
+
- 20-byte Ethereum addresses are padded with `0xEE` bytes to create valid 32-byte Polkadot accounts.
7052
+
- 32-byte Polkadot accounts can optionally register a mapping to a 20-byte address for Ethereum compatibility.
7053
7053
7054
7054
This dual-format approach enables Asset Hub to maintain compatibility with Ethereum tooling while fully integrating with the Polkadot ecosystem.
7055
7055
@@ -7064,58 +7064,65 @@ The platform handles two distinct address formats:
7064
7064
7065
7065
The [`AccountId32Mapper`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/struct.AccountId32Mapper.html){target=\_blank} implementation in [`pallet_revive`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/index.html){target=\_blank} handles the core address conversion logic. For converting a 20-byte Ethereum address to a 32-byte Polkadot address, the pallet uses a simple concatenation approach:
7066
7066
7067
-
- [**Core mechanism**](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_fallback_account_id){target=\_blank} - takes a 20-byte Ethereum address and extends it to 32 bytes by adding twelve `0xEE` bytes at the end. The key benefits of this approach are:
7068
-
- Able to fully revert, allowing a smooth transition back to the Ethereum format
7069
-
- Provides clear identification of Ethereum-controlled accounts through the `0xEE` suffix pattern
7070
-
- Maintains cryptographic security with a `2^96` difficulty for pattern reproduction
7067
+
- [**Core mechanism**](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_fallback_account_id){target=\_blank} : takes a 20-byte Ethereum address and extends it to 32 bytes by adding twelve `0xEE` bytes at the end. The key benefits of this approach are:
7068
+
- Able to fully revert, allowing a smooth transition back to the Ethereum format.
7069
+
- Provides clear identification of Ethereum-controlled accounts through the `0xEE` suffix pattern.
7070
+
- Maintains cryptographic security with a `2^96` difficulty for pattern reproduction.
7071
7071
7072
7072
### Polkadot to Ethereum Mapping
7073
7073
7074
-
The conversion from 32-byte to 20-byte addresses is handled through a stateful mapping system implemented in the [`AddressMapper`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html){target=\_blank} trait. The core functionality includes:
7074
+
The conversion from 32-byte Polkadot accounts to 20-byte Ethereum addresses is more complex than the reverse direction due to the lossy nature of the conversion. The [`AccountId32Mapper`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/struct.AccountId32Mapper.html){target=\_blank} handles this through two distinct approaches:
7075
7075
7076
-
- Address conversion in both directions
7077
-
- Account registration and management
7078
-
- Mapping status verification
7076
+
- **For Ethereum-derived accounts** : The system uses the [`is_eth_derived`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/fn.is_eth_derived.html){target=\_blank} function to detect accounts that were originally Ethereum addresses (identified by the `0xEE` suffix pattern). For these accounts, the conversion strips the last 12 bytes to recover the original 20-byte Ethereum address.
7077
+
7078
+
- **For native Polkadot accounts** : Since these accounts utilize the whole 32-byte space and weren't derived from Ethereum addresses, direct truncation would result in lost information. Instead, the system:
7079
+
1. Hashes the entire 32-byte account using Keccak-256.
7080
+
2. Takes the last 20 bytes of the hash to create the Ethereum address.
7081
+
3. This ensures a deterministic mapping while avoiding simple truncation.
7082
+
7083
+
The conversion process is implemented through the [`to_address`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_address){target=\_blank} function, which automatically detects the account type and applies the appropriate conversion method.
7084
+
7085
+
**Stateful Mapping for Reversibility** : Since the conversion from 32-byte to 20-byte addresses is inherently lossy, the system provides an optional stateful mapping through the [`OriginalAccount`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/type.OriginalAccount.html){target=\_blank} storage. When a Polkadot account registers a mapping (via the [`map`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.map){target=\_blank} function), the system stores the original 32-byte account ID, enabling the [`to_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_account_id){target=\_blank} function to recover the exact original account rather than falling back to a default conversion.
7079
7086
7080
7087
## Account Registration
7081
7088
7082
7089
The registration process is implemented through the [`map`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.map){target=\_blank} function. This process involves:
7083
7090
7084
-
- Checking if the account is already mapped
7085
-
- Calculating and collecting required deposits based on data size
7086
-
- Storing the address suffix for future reference
7087
-
- Managing the currency holds for security
7091
+
- Checking if the account is already mapped.
7092
+
- Calculating and collecting required deposits based on data size.
7093
+
- Storing the address suffix for future reference.
7094
+
- Managing the currency holds for security.
7088
7095
7089
7096
## Fallback Accounts
7090
7097
7091
7098
The fallback mechanism is integrated into the [`to_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_account_id){target=\_blank} function. It provides a safety net for address conversion by:
7092
7099
7093
-
- First, attempting to retrieve stored mapping data
7094
-
- Falling back to the default conversion method if no mapping exists
7095
-
- Maintaining consistency in address representation
7100
+
- First, attempting to retrieve stored mapping data.
7101
+
- Falling back to the default conversion method if no mapping exists.
7102
+
- Maintaining consistency in address representation.
7096
7103
7097
7104
## Contract Address Generation
7098
7105
7099
7106
The system supports two methods for generating contract addresses:
- Uses the deployer address, initialization code, input data, and salt
7109
-
- Enables predictable address generation for advanced use cases
7115
+
- Uses the deployer address, initialization code, input data, and salt.
7116
+
- Enables predictable address generation for advanced use cases.
7110
7117
7111
7118
## Security Considerations
7112
7119
7113
7120
The address mapping system maintains security through several design choices evident in the implementation:
7114
7121
7115
-
- The stateless mapping requires no privileged operations, as shown in the [`to_fallback_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_fallback_account_id){target=\_blank} implementation
7116
-
- The stateful mapping requires a deposit managed through the [`Currency`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/pallet/trait.Config.html#associatedtype.Currency){target=\_blank} trait
7117
-
- Mapping operations are protected against common errors through explicit checks
7118
-
- The system prevents double-mapping through the [`ensure!(!Self::is_mapped(account_id))`](https://github.com/paritytech/polkadot-sdk/blob/stable2412/substrate/frame/revive/src/address.rs#L125){target=\_blank} check
7122
+
- The stateless mapping requires no privileged operations, as shown in the [`to_fallback_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_fallback_account_id){target=\_blank} implementation.
7123
+
- The stateful mapping requires a deposit managed through the [`Currency`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/pallet/trait.Config.html#associatedtype.Currency){target=\_blank} trait.
7124
+
- Mapping operations are protected against common errors through explicit checks.
7125
+
- The system prevents double-mapping through the [`ensure!(!Self::is_mapped(account_id))`](https://github.com/paritytech/polkadot-sdk/blob/stable2412/substrate/frame/revive/src/address.rs#L125){target=\_blank} check.
7119
7126
7120
7127
All source code references are from the [`address.rs`](https://github.com/paritytech/polkadot-sdk/blob/stable2412/substrate/frame/revive/src/address.rs){target=\_blank} file in the Revive pallet of the Polkadot SDK repository.
Asset Hub natively uses Polkadot's 32-byte account system but provides interoperability with Ethereum's 20-byte addresses through an automatic conversion system. When interacting with smart contracts:
11627
+
Asset Hub natively utilizes Polkadot's 32-byte account system while providing interoperability with Ethereum's 20-byte addresses through an automatic conversion system. When interacting with smart contracts:
11628
11628
11629
-
- Ethereum-compatible wallets (like MetaMask) can use their familiar 20-byte addresses
11630
-
- Polkadot accounts continue using their native 32-byte format
11629
+
- Ethereum-compatible wallets (like MetaMask) can use their familiar 20-byte addresses.
11630
+
- Polkadot accounts continue using their native 32-byte format.
11631
11631
- The Asset Hub chain automatically handles conversion between the two formats behind the scenes:
11632
11632
11633
-
- 20-byte Ethereum addresses are padded with `0xEE` bytes to create valid 32-byte Polkadot accounts
11634
-
- 32-byte Polkadot accounts can optionally register a mapping to a 20-byte address for Ethereum compatibility
11633
+
- 20-byte Ethereum addresses are padded with `0xEE` bytes to create valid 32-byte Polkadot accounts.
11634
+
- 32-byte Polkadot accounts can optionally register a mapping to a 20-byte address for Ethereum compatibility.
11635
11635
11636
11636
This dual-format approach enables Asset Hub to maintain compatibility with Ethereum tooling while fully integrating with the Polkadot ecosystem.
11637
11637
@@ -11646,58 +11646,65 @@ The platform handles two distinct address formats:
11646
11646
11647
11647
The [`AccountId32Mapper`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/struct.AccountId32Mapper.html){target=\_blank} implementation in [`pallet_revive`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/index.html){target=\_blank} handles the core address conversion logic. For converting a 20-byte Ethereum address to a 32-byte Polkadot address, the pallet uses a simple concatenation approach:
11648
11648
11649
-
- [**Core mechanism**](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_fallback_account_id){target=\_blank} - takes a 20-byte Ethereum address and extends it to 32 bytes by adding twelve `0xEE` bytes at the end. The key benefits of this approach are:
11650
-
- Able to fully revert, allowing a smooth transition back to the Ethereum format
11651
-
- Provides clear identification of Ethereum-controlled accounts through the `0xEE` suffix pattern
11652
-
- Maintains cryptographic security with a `2^96` difficulty for pattern reproduction
11649
+
- [**Core mechanism**](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_fallback_account_id){target=\_blank} : takes a 20-byte Ethereum address and extends it to 32 bytes by adding twelve `0xEE` bytes at the end. The key benefits of this approach are:
11650
+
- Able to fully revert, allowing a smooth transition back to the Ethereum format.
11651
+
- Provides clear identification of Ethereum-controlled accounts through the `0xEE` suffix pattern.
11652
+
- Maintains cryptographic security with a `2^96` difficulty for pattern reproduction.
11653
11653
11654
11654
### Polkadot to Ethereum Mapping
11655
11655
11656
-
The conversion from 32-byte to 20-byte addresses is handled through a stateful mapping system implemented in the [`AddressMapper`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html){target=\_blank} trait. The core functionality includes:
11656
+
The conversion from 32-byte Polkadot accounts to 20-byte Ethereum addresses is more complex than the reverse direction due to the lossy nature of the conversion. The [`AccountId32Mapper`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/struct.AccountId32Mapper.html){target=\_blank} handles this through two distinct approaches:
11657
11657
11658
-
- Address conversion in both directions
11659
-
- Account registration and management
11660
-
- Mapping status verification
11658
+
- **For Ethereum-derived accounts** : The system uses the [`is_eth_derived`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/fn.is_eth_derived.html){target=\_blank} function to detect accounts that were originally Ethereum addresses (identified by the `0xEE` suffix pattern). For these accounts, the conversion strips the last 12 bytes to recover the original 20-byte Ethereum address.
11659
+
11660
+
- **For native Polkadot accounts** : Since these accounts utilize the whole 32-byte space and weren't derived from Ethereum addresses, direct truncation would result in lost information. Instead, the system:
11661
+
1. Hashes the entire 32-byte account using Keccak-256.
11662
+
2. Takes the last 20 bytes of the hash to create the Ethereum address.
11663
+
3. This ensures a deterministic mapping while avoiding simple truncation.
11664
+
11665
+
The conversion process is implemented through the [`to_address`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_address){target=\_blank} function, which automatically detects the account type and applies the appropriate conversion method.
11666
+
11667
+
**Stateful Mapping for Reversibility** : Since the conversion from 32-byte to 20-byte addresses is inherently lossy, the system provides an optional stateful mapping through the [`OriginalAccount`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/type.OriginalAccount.html){target=\_blank} storage. When a Polkadot account registers a mapping (via the [`map`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.map){target=\_blank} function), the system stores the original 32-byte account ID, enabling the [`to_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_account_id){target=\_blank} function to recover the exact original account rather than falling back to a default conversion.
11661
11668
11662
11669
## Account Registration
11663
11670
11664
11671
The registration process is implemented through the [`map`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.map){target=\_blank} function. This process involves:
11665
11672
11666
-
- Checking if the account is already mapped
11667
-
- Calculating and collecting required deposits based on data size
11668
-
- Storing the address suffix for future reference
11669
-
- Managing the currency holds for security
11673
+
- Checking if the account is already mapped.
11674
+
- Calculating and collecting required deposits based on data size.
11675
+
- Storing the address suffix for future reference.
11676
+
- Managing the currency holds for security.
11670
11677
11671
11678
## Fallback Accounts
11672
11679
11673
11680
The fallback mechanism is integrated into the [`to_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_account_id){target=\_blank} function. It provides a safety net for address conversion by:
11674
11681
11675
-
- First, attempting to retrieve stored mapping data
11676
-
- Falling back to the default conversion method if no mapping exists
11677
-
- Maintaining consistency in address representation
11682
+
- First, attempting to retrieve stored mapping data.
11683
+
- Falling back to the default conversion method if no mapping exists.
11684
+
- Maintaining consistency in address representation.
11678
11685
11679
11686
## Contract Address Generation
11680
11687
11681
11688
The system supports two methods for generating contract addresses:
- Uses the deployer address, initialization code, input data, and salt
11691
-
- Enables predictable address generation for advanced use cases
11697
+
- Uses the deployer address, initialization code, input data, and salt.
11698
+
- Enables predictable address generation for advanced use cases.
11692
11699
11693
11700
## Security Considerations
11694
11701
11695
11702
The address mapping system maintains security through several design choices evident in the implementation:
11696
11703
11697
-
- The stateless mapping requires no privileged operations, as shown in the [`to_fallback_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_fallback_account_id){target=\_blank} implementation
11698
-
- The stateful mapping requires a deposit managed through the [`Currency`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/pallet/trait.Config.html#associatedtype.Currency){target=\_blank} trait
11699
-
- Mapping operations are protected against common errors through explicit checks
11700
-
- The system prevents double-mapping through the [`ensure!(!Self::is_mapped(account_id))`](https://github.com/paritytech/polkadot-sdk/blob/stable2412/substrate/frame/revive/src/address.rs#L125){target=\_blank} check
11704
+
- The stateless mapping requires no privileged operations, as shown in the [`to_fallback_account_id`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/trait.AddressMapper.html#tymethod.to_fallback_account_id){target=\_blank} implementation.
11705
+
- The stateful mapping requires a deposit managed through the [`Currency`](https://paritytech.github.io/polkadot-sdk/master/pallet_revive/pallet/trait.Config.html#associatedtype.Currency){target=\_blank} trait.
11706
+
- Mapping operations are protected against common errors through explicit checks.
11707
+
- The system prevents double-mapping through the [`ensure!(!Self::is_mapped(account_id))`](https://github.com/paritytech/polkadot-sdk/blob/stable2412/substrate/frame/revive/src/address.rs#L125){target=\_blank} check.
11701
11708
11702
11709
All source code references are from the [`address.rs`](https://github.com/paritytech/polkadot-sdk/blob/stable2412/substrate/frame/revive/src/address.rs){target=\_blank} file in the Revive pallet of the Polkadot SDK repository.
0 commit comments