Skip to content

Ethereum Transact Xcm#733

Closed
tgmichel wants to merge 15 commits intopolkadot-evm:masterfrom
moonbeam-foundation:transact-xcm
Closed

Ethereum Transact Xcm#733
tgmichel wants to merge 15 commits intopolkadot-evm:masterfrom
moonbeam-foundation:transact-xcm

Conversation

@tgmichel
Copy link
Copy Markdown
Contributor

This PR introduces a new transact_xcm dispatchable.

Co-authored by @girazoki

Relates to

@nanocryk 's paritytech/polkadot#5657

Motivation

  • Enable Transact Xcm to pallet-ethereum.
  • Store Xcm Ethereum transactions as part of the Ethereum block.

Origin and account

The origin parachain A can send a Transact Xcm to Frontier-enabled parachain B using a MultiLocation origin extended with a DescendOrigin instruction. The resultant Hash for this MultiLocation is the sender's controlled account in parachain B. This way, the sender's controlled account in parachain B is as-if it was the only possible derivation from the sender's controlled account in parachain A.

  • A new XcmEthereumTransaction variant is added to RawOrigin and we ensure this to be the origin when allowing calls to the new dispatchable.
  • Derived account is privatekey-less and thus only meant to be used as the origin through Xcm.

Check and validate

Multiple Xcm fragments are part of the same inherent extrinsic, and current UncheckedExtrinsic::check and CheckedExtrinsic::validate implementations - which are part of transaction pool submission and validation - will not be executed.

Ethereum Xcm transactions are instead validated directly within the dispatchable body using the same logic as the rest of the existing code paths.

Xcm payload to transaction conversion

transact_xcm input contains all the data necessary to perform a conversion to ethereum::TransactionV2 type.

pub struct EthereumXcmTransactionV1 {
	/// Gas limit to be consumed by EVM execution.
	pub gas_limit: U256,
	/// Fee configuration of choice.
	pub fee_payment: EthereumXcmFee,
	/// Either a Call (the callee, account or contract address) or Create (currently unsupported).
	pub action: TransactionAction,
	/// Value to be transfered.
	pub value: U256,
	/// Input data for a contract call.
	pub input: Vec<u8>,
	/// Map of addresses to be pre-paid to warm storage.
	pub access_list: Option<Vec<(H160, Vec<H256>)>>,
}

EthereumXcmFee is a custom enum meant to provide two options to build the message in the origin chain:

  • ManualEthereumXcmFee: fee is know in advance, and can be used to build Legacy, EIP2930 and EIP1559 transaction types.
  • AutoEthereumXcmFee: fee is not known in advance, and allows to choose from Low, Medium and High pre-configured gas fees. We introduce this option because cross-chain messages will be processed in a future unknown block, and users might want to execute the transaction using the (potentially congestion-based) on-chain fee rate.

The EthereumXcmTransaction is converted to a TransactionV2, populating signature fields with bogus data. We can do this because we assume:
1. recover_signer is not needed - which is part of promoting an UncheckedExtrinsic to a CheckedExtrinsic.
2. We already know the parachain A sender controls the derived account in parachain B.
3. Current chain id is used.
4. The next nonce for the derived account will be used to execute the transaction.

Restrictions

Currently we deliberately disabled TransactionAction::Create. The reasons are:

  • Input data for contract creation likely exceeds allowed Xcm size.
  • We don't see a practical use case for it anyways.

tgmichel and others added 15 commits June 15, 2022 17:01
(cherry picked from commit c0a6fab)
(cherry picked from commit 83e503b)
(cherry picked from commit 4adc37e)
(cherry picked from commit b683911)

# Conflicts:
#	frame/ethereum/src/lib.rs
(cherry picked from commit cce4c61)
(cherry picked from commit 55eb01b)
(cherry picked from commit dcc01ce)
(cherry picked from commit 6d6713f)
(cherry picked from commit df7d606)
(cherry picked from commit f83e027)
(cherry picked from commit b8043b3)
(cherry picked from commit f3d73cd)
(cherry picked from commit 8afb33f)
@tgmichel
Copy link
Copy Markdown
Contributor Author

Closing by now. #741 does some minor refactor so external code can interface with pallet-ethereum.

@tgmichel tgmichel closed this Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants