Snowbridge: Support bridging native ETH#6855
Conversation
7a76da6 to
dd51d23
Compare
|
The approach looks good! |
|
Will approve once you've implemented the emulated test that verifies the full BH->AH path. |
| /// Tests the full cycle of eth transfers: | ||
| /// - sending a token to AssetHub | ||
| /// - returning the token to Ethereum | ||
| #[test] | ||
| fn send_eth_asset_from_asset_hub_to_ethereum_and_back() { |
There was a problem hiding this comment.
Is Rococo deprecated so we may need to add new features/tests to Westend instead?
There was a problem hiding this comment.
Yeah agree, I did not want to change all our test boilerplate in this PR to keep it focused. But I think we need to in a separate PR.
There was a problem hiding this comment.
yes, this test (and others) needs to move to westend - can be followup PR, but pls do it
| type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent; | ||
| type RuntimeOrigin = <AssetHubRococo as Chain>::RuntimeOrigin; | ||
|
|
||
| let _issued_event = RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { |
There was a problem hiding this comment.
why the the underscore prepended to the variable name?
There was a problem hiding this comment.
The assert_expected_events! macro does not "use" the variable from the perspective of the compiler. I think the token is copied into the macro body, so it leaves this variable unused. Using underscore silences the warning.
| ) | ||
| .unwrap(); | ||
|
|
||
| let _burned_event = RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { |
There was a problem hiding this comment.
ditto, why the underscore?
There was a problem hiding this comment.
Commented above.
...arachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs
Outdated
Show resolved
Hide resolved
| match inner_location.unpack() { | ||
| (0, [AccountKey20 { network, key }]) if self.network_matches(network) => | ||
| Some((H160(*key), *amount)), | ||
| (0, []) => Some((H160([0; 20]), *amount)), |
There was a problem hiding this comment.
Add comment for this case explaining why what we are trying to do here, for example, UnlockNativeToken command supports unlocking ether if token address is NULL.
There was a problem hiding this comment.
Convert it to/from { parents: 2, interior: X1(GlobalConsensus(Ethereum{chain_id: 1})) } when encountered
Could we use location { parents: 2, interior: X2[GlobalConsensus(Ethereum{chain_id: 1}),AccountKey20 { network: None, key: H160::zero().into() }] } to represent Ether?
To be consistent with other ERC20 assets, then I would assume there is no need for this branch.
There was a problem hiding this comment.
This is a good point. But I think using the base { parents: 2, interior: X1(GlobalConsensus(Ethereum{chain_id: 1})) } is more intuitive so I prefer the current version. But lets discuss @vgeddes
| 2, | ||
| [GlobalConsensus(network), AccountKey20 { network: None, key: token.into() }], | ||
| ) | ||
| if token == H160([0; 20]) { |
There was a problem hiding this comment.
Add a comment here explaining that a token address of 0x00... is equivalent to native ether.
Co-authored-by: Vincent Geddes <117534+vgeddes@users.noreply.github.com>
bkchr
left a comment
There was a problem hiding this comment.
Not a XCM expert, left one DQ otherwise it looks reasonable.
| // If the token is `0x0000000000000000000000000000000000000000` then return the location of | ||
| // native Ether. | ||
| if token == H160([0; 20]) { | ||
| Location::new(2, [GlobalConsensus(network)]) |
There was a problem hiding this comment.
DQ: Don't we need to check here that network == Ethereum(chain_id: 1)?
There was a problem hiding this comment.
I saw that too and checked if it needs validation, it doesn't: convert_token_address() is internal fn called by convert_register_token() or convert_send_token() which are converting Ethereum commands into XCM programs, somewhere above on the callstack the source was already validated as being Ethereum and the only thing that varies here is the Ethereum chain_id (testnet or prod).
Maybe for clarity and hardening this helper function should take only chain_id and hardcode Ethereum as network:
- fn convert_token_address(network: NetworkId, token: H160) -> Location {
+ fn convert_token_address(chain_id: u64, token: H160) -> Location {There was a problem hiding this comment.
Hey thanks for setting the label. So the chain_id comes directly from the message encoded on the solidity side, where it is taken from the on-chain variable block.chainid
- Passed in here:
- From message body here:
- Decoded here:
polkadot-sdk/bridges/snowbridge/pallets/inbound-queue/src/lib.rs
Lines 279 to 280 in 1059be7
- Encoded in solidity here, taken directly from the block: https://github.com/Snowfork/snowbridge/blob/20a804669e0da59cff01b09588e16f1267d98862/contracts/src/SubstrateTypes.sol#L81
So it does not need to be validated explicitly. It will be validated implicitly by message verification through the light client.
|
Created backport PR for
Please cherry-pick the changes locally and resolve any conflicts. git fetch origin backport-6855-to-stable2407
git worktree add --checkout .worktree/backport-6855-to-stable2407 backport-6855-to-stable2407
cd .worktree/backport-6855-to-stable2407
git reset --hard HEAD^
git cherry-pick -x 4059282fc7b6ec965cc22a9a0df5920a4f3a4101
git push --force-with-lease |
|
Created backport PR for
Please cherry-pick the changes locally and resolve any conflicts. git fetch origin backport-6855-to-stable2409
git worktree add --checkout .worktree/backport-6855-to-stable2409 backport-6855-to-stable2409
cd .worktree/backport-6855-to-stable2409
git reset --hard HEAD^
git cherry-pick -x 4059282fc7b6ec965cc22a9a0df5920a4f3a4101
git push --force-with-lease |
|
hmm, any way to trigger the backport bot after the PR was merged? cc @EgorPopelyaev L.E.: Nevermind, bot picked it up automatically 💪 |
Changes:
1. Use the 0x0000000000000000000000000000000000000000 token address as
Native ETH.
2. Convert it to/from `{ parents: 2, interior:
X1(GlobalConsensus(Ethereum{chain_id: 1})) }` when encountered.
Onchain changes:
This will require a governance request to register native ETH (with the
above location) in the foreign assets pallet and make it sufficient.
Related solidity changes:
Snowfork/snowbridge#1354
TODO:
- [x] Emulated Tests
---------
Co-authored-by: Vincent Geddes <117534+vgeddes@users.noreply.github.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Bastian Köcher <info@kchr.de>
(cherry picked from commit 4059282)
|
Successfully created backport PR for |
| use sp_core::U256; | ||
| use sp_std::vec; | ||
|
|
||
| pub fn make_send_native_eth_message() -> InboundQueueFixture { |
Backport #6855 into `stable2409` from alistair-singh. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> --------- Co-authored-by: Alistair Singh <alistair.singh7@gmail.com> Co-authored-by: Adrian Catangiu <adrian@parity.io>
Backport #6855 into `stable2412` from alistair-singh. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> --------- Co-authored-by: Alistair Singh <alistair.singh7@gmail.com> Co-authored-by: Adrian Catangiu <adrian@parity.io>
* master: Snowbridge: Support bridging native ETH (#6855) adding warning when using default substrateWeight in production (#7046) release: unset SKIP_WASM_BUILD (#7074) fix typos (#7068) Fix defensive! macro to be used in umbrella crates (#7069) rewrite some flaky zombienet polkadot tests to zombienet-sdk (#6757) Implement NetworkRequest for litep2p (#7073) migrate pallet-node-authorization to use umbrella crate (#7040)
Changes:
{ parents: 2, interior: X1(GlobalConsensus(Ethereum{chain_id: 1})) }when encountered.Onchain changes:
This will require a governance request to register native ETH (with the above location) in the foreign assets pallet and make it sufficient.
Related solidity changes: Snowfork/snowbridge#1354
TODO: