Inspiration

What it does

Running ethereum bytecode in eosio smart contract

How I built it

There are two related repositories:

https://github.com/learnforpractice/eos-with-evm

https://github.com/learnforpractice/evm4eosio

The source code in evm4eosio/evm4eos will used to generate a wasm file named ethereum_vm.wasm that can be deploy to a eosio based network.

The same source code in evm4eosio/evm4eos will also generate a shared library named evm4eos which will used to implement intrinsic functions.

The source code have three API functions:

int evm_execute(const char *raw_trx, size_t raw_trx_size, const char *sender_address, size_t sender_address_size);

int evm_get_account_id(uint64_t account, const char* arbitrary_string, size_t arbitrary_string_size, char* hash, size_t hash_size);

int evm_recover_key(const uint8_t* sig, uint32_t sig_size, const uint8_t* _message, uint32t _message_len, uint8t* serialized_public_key, uint32_t _serializedpublic_key_size);

evm_execute and evm_get_account_id implemented in evm4eosio/evm4eos/main.cpp

evm_recover_key implemented in evm4eosio/libdevcrypto/Common.cpp

These functions can be configured to implemented as intrinsic functions which can be called by wasm code or compile directly in WASM bytecode with the following cmake variables to improve performance.

USE_INTRINSIC_EVM_EXECUTE

USE_INTRINSIC_EVM_GET_ACCOUNT_ID

USE_INTRINSIC_EVM_RECOVER_KEY

The source code of https://github.com/learnforpractice/eos-with-evm is a fork of eosio source code that have the above three intrinsic function implemented.

Challenges I ran into

Compile EVM source code to WASM

Accomplishments that I'm proud of

Abstracting vm api functions from eosio which allow compile C++ smart contract to native code without changes.

What I learned

Security > Usability > Maintainability > Simplicity > Performance

What's next for evm4eos

Bug Fixes & Continue to improve evm performance and some other things.

Built With

  • aleth
  • boost
  • eosio
  • ethash
  • secp256k1
Share this project:

Updates

posted an update

Update smart contract build Instruction

Build

git clone --branch evm2wasm https://github.com/learnforpractice/evm4eosio evm4eosio --recursive
cd evm4eosio
mkdir build
cd build

To improve the performance of evm, there are three variables that can be configured to whether use intrinsic evm api or not. These intrinsic EVM API need a nodeos build from eos-with-evm to run.

USE_INTRINSIC_EVM_RECOVER_KEY
USE_INTRINSIC_EVM_EXECUTE
USE_INTRINSIC_EVM_GET_ACCOUNT_ID

Build With No Use Of Intrinsic EVM API

cmake ..
make -j$(nproc)

Build To Use Intrinsic EVM API evm_recovery_key

cmake -DUSE_INTRINSIC_EVM_RECOVER_KEY=TRUE ..
make -j$(nproc)

Build To Use Intrinsic EVM API evm_execute

cmake -DUSE_INTRINSIC_EVM_EXECUTE=TRUE ..
make -j$(nproc)

Build To Use Intrinsic EVM API evm_get_account_id

cmake -DUSE_INTRINSIC_EVM_GET_ACCOUNT_ID=TRUE ..
make -j$(nproc)

Log in or sign up for Devpost to join the conversation.