Skip to main content

Extracts function selectors from EVM bytecode

Project description

EVMole

PyPI npm license

Extracts function selectors 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

Usage

JavaScript

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

const code = '0x6080604052600436106025575f3560e01c8063b69ef8a8146029578063d0e30db014604d575b5f80fd5b3480156033575f80fd5b50603b5f5481565b60405190815260200160405180910390f35b60536055565b005b345f8082825460639190606a565b9091555050565b80820180821115608857634e487b7160e01b5f52601160045260245ffd5b9291505056fea2646970667358221220354240f63068d555e9b817619001b0dff6ea630d137edc1a640dae8e3ebb959864736f6c63430008170033'
console.log( functionSelectors(code) )
// Output(list): [ 'b69ef8a8', 'd0e30db0' ]

Python

$ pip install evmole --upgrade
from evmole import function_selectors

code = '0x6080604052600436106025575f3560e01c8063b69ef8a8146029578063d0e30db014604d575b5f80fd5b3480156033575f80fd5b50603b5f5481565b60405190815260200160405180910390f35b60536055565b005b345f8082825460639190606a565b9091555050565b80820180821115608857634e487b7160e01b5f52601160045260245ffd5b9291505056fea2646970667358221220354240f63068d555e9b817619001b0dff6ea630d137edc1a640dae8e3ebb959864736f6c63430008170033'
print( function_selectors(code) )
# Output(list): ['b69ef8a8', 'd0e30db0']

See examples for more

Benchmark

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

Dataset simple whatsabi evmole-js (py)
largest1k
1000 contracts
24427 functions
FP/FN contracts: 95 / 9 38 / 8 1 / 0 :1st_place_medal:
FP/FN functions: 749 / 12 38 / 8 :1st_place_medal: :2nd_place_medal: 192 / 0 :2nd_place_medal: :1st_place_medal:
Time: 2.06s 3.8s 1.99s (2.09s) :rocket:
random50k
50000 contracts
1171102 functions
FP/FN contracts: 4136 / 77 251 / 31 1 / 9 :1st_place_medal:
FP/FN functions: 14652 / 96 261 / 32 3 / 10 :1st_place_medal:
Time: 32.3s 71.13s 25.63s (33.56s) :rocket:
vyper
780 contracts
21244 functions
FP/FN contracts: 185 / 480 178 / 780 0 / 0 :1st_place_medal:
FP/FN functions: 197 / 12971 181 / 21244 0 / 0 :1st_place_medal:
Time: 1.71s 2.52s 1.58s (1.8s) :rocket:

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.1.2.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

evmole-0.1.2-py3-none-any.whl (9.1 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