EVM Engine
EVM Engine
Qiling supports Ethereum smart contract emulation via a custom EVM engine module.
Installation
1git clone https://github.com/qilingframework/qiling.git
2git checkout dev
3git submodule update --init
4pip3 install -e .[evm]
Execute Smart Contract Bytecode
1from qiling import Qiling
2
3ql = Qiling(archtype="evm")
4
5contract = "0x60606040..." # deployment bytecode
6
7# Optional: encode constructor parameters
8bal = ql.arch.evm.abi.convert(['uint256'], [20])
9contract = contract + bal
10
11# Create accounts
12user1 = ql.arch.evm.create_account(balance=100 * 10**18) # 100 ETH
13c1 = ql.arch.evm.create_account() # contract account
14
15# Build and send a transaction
16call_data = '0x...' # function selector + encoded args
17msg1 = ql.arch.evm.create_message(user1, c1, call_data)
18result = ql.run(code=msg1)
Debug Smart Contract Bytecode
1from qiling import Qiling
2
3ql = Qiling(archtype="evm")
4ql.debugger = True # opens debugger GUI in terminal
5
6contract = "0x60606040..."
7user1 = ql.arch.evm.create_account(balance=100 * 10**18)
8c1 = ql.arch.evm.create_account()
9
10msg0 = ql.arch.evm.create_message(user1, b'', code=contract, contract_address=c1)
11ql.run(code=msg0)
Set EVM Hard Fork
1from qiling.arch.evm.vm.evm import QlArchEVMEmulator
2from qiling.arch.evm.constants import BERLIN_FORK
3
4ql = Qiling(archtype="evm")
5ql.arch.evm = QlArchEVMEmulator(ql, fork_name=BERLIN_FORK)
Available fork constants are in qiling/arch/evm/constants.py.
Run Tests
1cd tests
2python3 ./test_evm.py