Extracts function selectors and arguments from EVM bytecode
Project description
EVMole
EVMole is a powerful library that extracts information from Ethereum Virtual Machine (EVM) bytecode, including function selectors, arguments, and state mutability, even for unverified contracts.
Key Features
- Multi-language support: Available as JavaScript, Rust, and Python libraries.
- High accurancy and performance: Outperforms existing tools.
- Broad compatibility: Tested with both Solidity and Vyper compiled contracts.
- Lightweight: Clean codebase with minimal external dependencies.
- Unverified contract analysis: Extracts information even from unverified bytecode.
Usage
JavaScript
API documentation and usage examples (node, vite, webpack, parcel, esbuild)
$ npm i evmole
import { functionSelectors, functionArguments, functionStateMutability } from 'evmole'
const code = '0x6080604052348015600e575f80fd5b50600436106030575f3560e01c80632125b65b146034578063b69ef8a8146044575b5f80fd5b6044603f3660046046565b505050565b005b5f805f606084860312156057575f80fd5b833563ffffffff811681146069575f80fd5b925060208401356001600160a01b03811681146083575f80fd5b915060408401356001600160e01b0381168114609d575f80fd5b80915050925092509256'
console.log(functionSelectors(code)); // [ '2125b65b', 'b69ef8a8' ]
console.log(functionArguments(code, '2125b65b')); // 'uint32,address,uint224'
console.log(functionStateMutability(code, '2125b65b')); // 'pure'
Rust
Documentation is available on docs.rs
let code = hex::decode("6080604052348015600e575f80fd5b50600436106030575f3560e01c80632125b65b146034578063b69ef8a8146044575b5f80fd5b6044603f3660046046565b505050565b005b5f805f606084860312156057575f80fd5b833563ffffffff811681146069575f80fd5b925060208401356001600160a01b03811681146083575f80fd5b915060408401356001600160e01b0381168114609d575f80fd5b80915050925092509256").unwrap();
println!("{:x?} | {} | {}",
evmole::function_selectors(&code, 0),
evmole::function_arguments(&code, &[0x21, 0x25, 0xb6, 0x5b], 0),
evmole::function_state_mutability(&code, &[0x21, 0x25, 0xb6, 0x5b], 0),
);
// [[21, 25, b6, 5b], [b6, 9e, f8, a8]] | uint32,address,uint224 | pure
Python
$ pip install evmole --upgrade
from evmole import function_selectors, function_arguments, function_state_mutability
code = '0x6080604052348015600e575f80fd5b50600436106030575f3560e01c80632125b65b146034578063b69ef8a8146044575b5f80fd5b6044603f3660046046565b505050565b005b5f805f606084860312156057575f80fd5b833563ffffffff811681146069575f80fd5b925060208401356001600160a01b03811681146083575f80fd5b915060408401356001600160e01b0381168114609d575f80fd5b80915050925092509256'
print(function_selectors(code)) # ['2125b65b', 'b69ef8a8']
print(function_arguments(code, '2125b65b')) # uint32,address,uint224
print(function_state_mutability(code, '2125b65b')) # pure
Foundry
Foundy's cast uses the Rust implementation of EVMole
$ cast selectors $(cast code 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)
0x06fdde03
0x095ea7b3 address,uint256
0x18160ddd
0x23b872dd address,address,uint256
...
$ cast selectors --resolve $(cast code 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)
0x06fdde03 name()
0x095ea7b3 address,uint256 approve(address,uint256)
0x18160ddd totalSupply()
0x23b872dd address,address,uint256 transferFrom(address,address,uint256)
...
Benchmark
function selectors
FP/FN - False Positive/False Negative errors; smaller is better
Dataset | evmole rs · js · py | whatsabi | sevm | evmhound | heimdall | smpl | |
largest1k 1000 addresses 24427 functions |
FP addrs | 1 🥈 | 0 🥇 | 0 🥇 | 75 | 18 | 95 |
FN addrs | 0 🥇 | 0 🥇 | 0 🥇 | 40 | 111 | 9 | |
FP funcs | 192 🥈 | 0 🥇 | 0 🥇 | 720 | 600 | 749 | |
FN funcs | 0 🥇 | 0 🥇 | 0 🥇 | 191 | 147 | 12 | |
Time | 0.4s · 0.8s · 0.6s | 2.9s | 38s(*) | 0.5s | 341s(*) | 1.8s | |
random50k 50000 addresses 1171102 functions |
FP addrs | 1 🥇 | 43 | 1 | 693 | 3 | 4136 |
FN addrs | 9 🥇 | 11 | 36 | 2903 | 4708 | 77 | |
FP funcs | 3 🥇 | 51 | 3 | 10798 | 29 | 14652 | |
FN funcs | 10 🥇 | 12 | 587 | 3538 | 6098 | 96 | |
Time | 4.5s · 12s · 10s | 49s | 1427s(*) | 5.8s | 8576s(*) | 49s | |
vyper 780 addresses 21244 functions |
FP addrs | 0 🥇 | 30 | 0 | 19 | 0 | 185 |
FN addrs | 0 🥇 | 780 | 21 | 300 | 780 | 480 | |
FP funcs | 0 🥇 | 30 | 0 | 19 | 0 | 197 | |
FN funcs | 0 🥇 | 21244 | 336 | 8273 | 21244 | 12971 | |
Time | 0.4s · 0.7s · 0.5s | 2.2s | 60s(*) | 0.4s | 27s(*) | 1.1s |
function arguments
Errors - when at least 1 argument is incorrect: (uint256,string)
≠ (uint256,bytes)
Dataset | evmole rs · js · py | heimdall | smpl | |
largest1k 24427 functions |
Errors | 14.0% 🥇 3417 |
31.1% 7593 |
58.3% 14242 |
Time | 1.0s · 8.3s · 3.5s | 342s(*) | 0.7s | |
random50k 1171102 functions |
Errors | 4.5% 🥇 52777 |
19.4% 227612 |
54.9% 643213 |
Time | 23s · 263s · 104s | 8544s(*) | 9.7s | |
vyper 21244 functions |
Errors | 49.6% 🥇 10544 |
100.0% 21244 |
56.8% 12077 |
Time | 0.7s · 5.2s · 2.2s | 28s(*) | 0.5s |
function state mutability
Errors - Results are not equal (treating view
and pure
as equivalent to nonpayable
)
Errors strict - Results are strictly unequal (nonpayable
≠ view
). Some ABIs mark pure
/view
functions as nonpayable
, so not all strict errors indicate real issues.
Dataset | evmole rs · js · py | whatsabi | sevm | heimdall | smpl | |
largest1k 24427 functions |
Errors | 0.0% 🥇 0 |
68.1% 16623 |
2.1% 501 |
25.4% 6201 |
2.6% 643 |
Errors strict | 19.3% 🥇 4718 |
79.3% 19370 |
59.0% 14417 |
54.9% 13403 |
60.9% 14864 |
|
Time | 7.9s · 17s · 10s | 3.7s | 37s(*) | 339s(*) | 0.7s | |
random50k 1160861 functions |
Errors | 0.0% 🥇 35 |
30.2% 351060 |
0.3% 3887 |
11.6% 134195 |
2.2% 24961 |
Errors strict | 6.8% 🥇 78676 |
58.1% 674922 |
55.7% 647070 |
27.7% 321494 |
57.7% 670318 |
|
Time | 226s · 523s · 309s | 80s | 1709s(*) | 8151s(*) | 9.4s | |
vyper 21166 functions |
Errors | 0.5% 🥇 110 |
100.0% 21166 |
77.8% 16462 |
100.0% 21166 |
1.8% 390 |
Errors strict | 11.4% 🥇 2410 |
100.0% 21166 |
91.0% 19253 |
100.0% 21166 |
59.6% 12610 |
|
Time | 3.7s · 8.7s · 5.1s | 2.2s | 59s(*) | 28s(*) | 0.6s |
See benchmark/README.md for the methodology and commands to reproduce these results
versions: evmole v0.4.1; whatsabi v0.14.1; sevm v0.6.19; evm-hound-rs v0.1.4; heimdall-rs v0.8.4
(*): sevm and heimdall-rs are full decompilers, not limited to extracting function selectors
How it works
Short: Executes code with a custom EVM and traces CALLDATA usage.
Long: TODO
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for evmole-0.4.1-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03b39f4ec782145643358aa1105f4a1395596265403f612f5356c1f6773fdc94 |
|
MD5 | 9f308a074e556ad89d1f2d743620652c |
|
BLAKE2b-256 | d41fe86e794bf7ea520016646dfc5d2be1a66046170add4cccca12c78cfe2cc8 |
Hashes for evmole-0.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8935aeca158ea42b9841135338793d6caab7fcefaccd0b58f4a44f7d91fa9811 |
|
MD5 | 27d431cdc2a1b6c8305be4d53d84f9cf |
|
BLAKE2b-256 | 50ce190d42765b2932a46d36797f01e8dbb45569b224e8cc5b303560eba825ed |
Hashes for evmole-0.4.1-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88c5ddf0cc7bc429bad3eed152d54eb470a9084220f90dcbe6c5eb7d2ab431f7 |
|
MD5 | d245cc4fcce71a34c2dc31a6f01a0b6f |
|
BLAKE2b-256 | 5ecda877c99d704aaf3c3ad21b5732249a3535baea86fe2a5c49dea9660e2dcf |
Hashes for evmole-0.4.1-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c70be8f47a20c3a87472e4104bfe8f7d278cb5712184785ff28d32709bfe9c0 |
|
MD5 | 852022b7f22a283b72c27dafcdaaeb24 |
|
BLAKE2b-256 | 2ab553b96ae87ae7c98b432488ca1568c3c05192050f7baa2bdb7ba898e37ee3 |
Hashes for evmole-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd56879d9b3abf6cc2b1348ae21d948db84553cb93405982c03dc9142c8bb067 |
|
MD5 | acc0bfd1a57cd5541d5a161a16310850 |
|
BLAKE2b-256 | 3ca6cdab013a5ec442d1899ce5653d707ce762310e38659777032ab60243a614 |
Hashes for evmole-0.4.1-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65b831f7ef6a75e9d1e4eda908195793127e84d00faaaeeef0418766621803b3 |
|
MD5 | 99a3ddfe077413f2530969ea4b221cf7 |
|
BLAKE2b-256 | 72fdbd256f4c2dd1d598ac0551ea496e21c299ebbbba82f08a055ed800c54bfa |
Hashes for evmole-0.4.1-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d3e71dc8693b8420ca38c7747e166afaeb9122119d190362984d339ff6fd0be |
|
MD5 | 86e1a606f6883653d0fa7a1e339dd6c8 |
|
BLAKE2b-256 | 94749b1d9b7fbd85c34a5f4b0691202bbcab95041d0cbe33a93aac54548d9c1c |
Hashes for evmole-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb7bd061d727e5165d820ff991fc49bacbbf448ee25cbf121cc20682b2987c1f |
|
MD5 | 459d40786188f1c78c140b30edd947db |
|
BLAKE2b-256 | 190c7bfffd706124a865f2f4b53f9b47ff7b0b82663f22a63da9f0681a926225 |
Hashes for evmole-0.4.1-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f9edfe880ecfdc434de8c008fa960c0bb3aa3bce29919cc5b885d7b012a7d89 |
|
MD5 | fb75746ba9070babf413605f81959360 |
|
BLAKE2b-256 | f27256540eb459ef36383e9d02000cf53d5946a950e08c7f5b298c525478ddb3 |
Hashes for evmole-0.4.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 012ce5821e70eb5aba423e3aa3e656225a36b78aba6563556993ee3d958d1221 |
|
MD5 | e984147fadc3c6b5b4454497073cb2a7 |
|
BLAKE2b-256 | 8e7d853749667267a3a148fc19f10c9f605d1fce07a21b0b792e4792b1862e52 |
Hashes for evmole-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc712ca882d6dbb4e1af24c4b635fd3351d2b0d07fe82256820fda05a0fc2297 |
|
MD5 | 9cb2d74a2b922451cac8758c71848498 |
|
BLAKE2b-256 | b9f9e7324592c0c6c625149abaf0286f7d4d3c6a7c02f2226e2587877e5de613 |
Hashes for evmole-0.4.1-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9e71866238f6af51926b0a840d424e890bad859313d58aec1289b8fa42f711d |
|
MD5 | fa8179c3e172783c7728159f0ec02937 |
|
BLAKE2b-256 | 7e8b3b54f8e87feadedbc404f3a118a29e1f299fb800bdf42dfbe96ff98b4303 |