Skip to main content

Extracts function selectors and arguments from EVM bytecode

Project description

EVMole

npm PyPI license

Extracts function selectors and arguments from EVM bytecode, even for unverified contracts.

  • Python & JavaScript implementations
  • Clean code with zero dependencies
  • Faster and more accurate than other tools
  • Tested on Solidity and Vyper compiled contracts

Try it online

Usage

JavaScript

$ npm i evmole
import {functionSelectors} from 'evmole'
// Also supported: const e = require('evmole'); e.functionSelectors();

const code = '0x6080604052348015600e575f80fd5b50600436106030575f3560e01c80632125b65b146034578063b69ef8a8146044575b5f80fd5b6044603f3660046046565b505050565b005b5f805f606084860312156057575f80fd5b833563ffffffff811681146069575f80fd5b925060208401356001600160a01b03811681146083575f80fd5b915060408401356001600160e01b0381168114609d575f80fd5b80915050925092509256fea2646970667358221220fbd308f142157eaf0fdc0374a3f95f796b293d35c337d2d9665b76dfc69501ea64736f6c63430008170033'
console.log( functionSelectors(code) )
// Output(list): [ '2125b65b', 'b69ef8a8' ]

console.log( functionArguments(code, '2125b65b') )
// Output(str): 'uint32,address,uint224'

Python

$ pip install evmole --upgrade
from evmole import function_arguments, function_selectors

code = '0x6080604052348015600e575f80fd5b50600436106030575f3560e01c80632125b65b146034578063b69ef8a8146044575b5f80fd5b6044603f3660046046565b505050565b005b5f805f606084860312156057575f80fd5b833563ffffffff811681146069575f80fd5b925060208401356001600160a01b03811681146083575f80fd5b915060408401356001600160e01b0381168114609d575f80fd5b80915050925092509256fea2646970667358221220fbd308f142157eaf0fdc0374a3f95f796b293d35c337d2d9665b76dfc69501ea64736f6c63430008170033'
print( function_selectors(code) )
# Output(list): ['2125b65b', 'b69ef8a8']

print( function_arguments(code, '2125b65b') )
# Output(str): 'uint32,address,uint224'

See examples for more

Benchmark

function selectors

FP/FN - False Positive/False Negative errors; smaller is better

Dataset evmole-js (py) whatsabi evm-hound-rs simple
largest1k
1000 contracts
24427 functions
FP/FN contracts: 1 / 0 :1st_place_medal: 38 / 8 75 / 40 95 / 9
FP/FN functions: 192 / 0 :2nd_place_medal: :1st_place_medal: 38 / 8 :1st_place_medal: :2nd_place_medal: 720 / 191 749 / 12
Time: 1.6s (1.74s) 3.54s 1.1s 1.85s
random50k
50000 contracts
1171102 functions
FP/FN contracts: 1 / 9 :1st_place_medal: 251 / 31 693 / 2903 4136 / 77
FP/FN functions: 3 / 10 :1st_place_medal: 261 / 32 10798 / 3538 14652 / 96
Time: 18.81s (32.27s) 67.13s 11.95s 34.39s
vyper
780 contracts
21244 functions
FP/FN contracts: 0 / 0 :1st_place_medal: 178 / 780 19 / 300 185 / 480
FP/FN functions: 0 / 0 :1st_place_medal: 181 / 21244 19 / 8273 197 / 12971
Time: 1.42s (1.28s) 2.39s 0.97s 1.34s

function arguments

errors - when at least 1 argument is incorrect: (uint256,string) != (uint256,bytes); smaller is better

Dataset evmole-js (py) simple
largest1k
1000 contracts
24427 functions
errors: 15.1%, 3677 :1st_place_medal: 58.3%, 14242
Time: 6.84s (13.02s) 1.17s
random50k
50000 contracts
1171102 functions
errors: 5.4%, 63774 :1st_place_medal: 54.9%, 643213
Time: 185.03s (402.58s) 8.76s
vyper
780 contracts
21244 functions
errors: 52.3%, 11103 :1st_place_medal: 56.8%, 12077
Time: 7.77s (16.05s) 0.98s

See benchmark/README.md for the methodology and commands to reproduce these results

How it works

Short: Executes code with a custom EVM and traces CALLDATA usage.

Long: TODO

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

evmole-0.2.0.tar.gz (10.8 kB view hashes)

Uploaded Source

Built Distribution

evmole-0.2.0-py3-none-any.whl (11.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page