Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substrate EVM #3927

Merged
merged 24 commits into from Nov 3, 2019

Conversation

@sorpaas
Copy link
Member

sorpaas commented Oct 26, 2019

This implements an EVM execution module in SRML, to allow unmodified EVM code to be executed in a Substrate-based blockchains.

Execution Lifecycle

Accounts that the EVM can touch are stored in srml_evm::Accounts. Users can use call Module::deposit_balance and Module::withdraw_balance to transfer balance from normal balances module into the EVM module. There's one-to-one correspondence of balances account and EVM external accounts, defined via Trait::ConvertAccountId.

Once balance is in, users can then use Module::call and Module::create to execute normal EVM transactions, which corresponds to Ethereum message call transactions and contract creation transactions.

Compatibility

The module should be able to produce nearly identical result as running on Ethereum mainnet, including gas cost and balance changes. Observable behaviors by the contract that might be different include:

  • Block hashes. We use the system module to fetch block hashes. The available length may not be 256, but depends on the configuration of the system module.
  • Difficulty and coinbase. This value does not quite make sense in this module, and is currently hard coded to zero.

I think we currently don't aim to make unobservable behaviors, such as state root, to be the same. We also don't aim to follow the exact same transaction / receipt format. However, given one Ethereum transaction and one Substrate balances user private key, one should be able to convert any Ethereum transaction into a transaction compatible to use in this module.

The gas configurations are currently hard-coded to Istanbul hard fork. It can later be expanded to support earlier hard fork configurations.

EVM Engine

The current underlying EVM engine is SputnikVM. The engine is overhauled so that it's modular. One of the important reasons for this is that in the future we'll want to allow users to swap out components like gasometer, and inject their own customized ones.

Status

TODOs before this PR can be merged:

  • Remove all TODO comments in code.
  • Make sure gasometer compliance with Ethereum.
  • Fix issues regarding EVM version support.
  • Precompile interface and custom system call support.
  • Refactoring duplicate code of call/create.

Improvements that can be done, but maybe better in a future PR:

  • More customization. Allow selecting gasometer and gas cost configurations.
  • Performance. The current substate merging/reverting logic can be optimized a lot.
sorpaas added 2 commits Oct 26, 2019
Cargo.toml Outdated Show resolved Hide resolved
sorpaas added 5 commits Oct 26, 2019
@sorpaas sorpaas marked this pull request as ready for review Oct 31, 2019
}

fn chain_id(&self) -> U256 {
U256::one()

This comment has been minimized.

Copy link
@pepyakin

pepyakin Oct 31, 2019

Contributor

Can we actually pass runtime_io::chain_id() here?

This comment has been minimized.

Copy link
@xlc

xlc Oct 31, 2019

Contributor

@pepyakin I did a quick search, looks like runtime_io::chain_id is hardcoded to return 42?shouldn't it be configurable in chain spec?

This comment has been minimized.

Copy link
@pepyakin

pepyakin Oct 31, 2019

Contributor

That's a good question which unfortunately I cannot answer. It seems that it should though!

This comment has been minimized.

Copy link
@xlc

xlc Nov 1, 2019

Contributor
srml/evm/src/lib.rs Outdated Show resolved Hide resolved
srml/evm/src/lib.rs Outdated Show resolved Hide resolved
srml/evm/src/lib.rs Outdated Show resolved Hide resolved
srml/evm/src/lib.rs Outdated Show resolved Hide resolved
let bvalue = U256::from(UniqueSaturatedInto::<u64>::unique_saturated_into(value));
let address = T::ConvertAccountId::convert_account_id(sender);
Accounts::mutate(&address, |account| {
account.balance += bvalue;

This comment has been minimized.

Copy link
@xlc

xlc Oct 31, 2019

Contributor

will it be more performant if the account balance is moved to its own storage? otherwise this will unnecessarily read and write Account::code which can be large.

This comment has been minimized.

Copy link
@sorpaas

sorpaas Oct 31, 2019

Author Member

I moved code to its own storage. I'm currently still keeping balance and nonce in one place because they're usually changed together.

srml/evm/src/lib.rs Outdated Show resolved Hide resolved
srml/evm/src/lib.rs Outdated Show resolved Hide resolved
srml/evm/src/lib.rs Outdated Show resolved Hide resolved
srml/evm/src/lib.rs Outdated Show resolved Hide resolved
srml/evm/src/backend.rs Outdated Show resolved Hide resolved
sorpaas and others added 12 commits Oct 31, 2019
Co-Authored-By: Xiliang Chen <xlchen1291@gmail.com>
Co-Authored-By: Xiliang Chen <xlchen1291@gmail.com>
srml/evm/src/backend.rs Outdated Show resolved Hide resolved
@sorpaas sorpaas merged commit 1d5cae9 into master Nov 3, 2019
10 checks passed
10 checks passed
continuous-integration/gitlab-cargo-check-benches Build stage: test; status: success
Details
continuous-integration/gitlab-cargo-check-subkey Build stage: test; status: success
Details
continuous-integration/gitlab-check-line-width Build stage: test; status: success
Details
continuous-integration/gitlab-check-runtime Build stage: test; status: success
Details
continuous-integration/gitlab-check-web-wasm Build stage: test; status: success
Details
continuous-integration/gitlab-check_warnings Build stage: build; status: success
Details
continuous-integration/gitlab-node-exits Build stage: test; status: success
Details
continuous-integration/gitlab-test-linux-stable Build stage: test; status: success
Details
continuous-integration/gitlab-test-linux-stable-int Build stage: test; status: success
Details
continuous-integration/gitlab-test-srml-staking Build stage: test; status: success
Details
@sorpaas sorpaas deleted the sp-evm branch Nov 3, 2019
@soc1c soc1c referenced this pull request Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.