• Stars
    star
    341
  • Rank 120,037 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ethereum Virtual Machine (EVM) disassembler and assembler

pyevmasm

Build Status

PyPI version Slack Status

pyevmasm is an assembler and disassembler library for the Ethereum Virtual Machine (EVM). It includes a commandline utility and a Python API.

CLI Examples with evmasm

evmasm is a commandline utility that uses pyevmasm to assemble or disassemble EVM:

usage: evmasm [-h] (-a | -d | -t) [-bi] [-bo] [-i [INPUT]] [-o [OUTPUT]] [-f FORK]

pyevmasm the EVM assembler and disassembler

optional arguments:
  -h, --help            show this help message and exit
  -a, --assemble        Assemble EVM instructions to opcodes
  -d, --disassemble     Disassemble EVM to opcodes
  -t, --print-opcode-table
                        List supported EVM opcodes
  -bi, --binary-input   Binary input mode (-d only)
  -bo, --binary-output  Binary output mode (-a only)
  -i [INPUT], --input [INPUT]
                        Input file, default=stdin
  -o [OUTPUT], --output [OUTPUT]
                        Output file, default=stdout
  -f FORK, --fork FORK  Fork, default: byzantium. Possible: frontier,
                        homestead, tangerine_whistle, spurious_dragon,
                        byzantium, constantinople, serenity. Also an unsigned
                        block number is accepted to select the fork.

Disassembling the preamble of compiled contract:

$ echo -n "608060405260043610603f57600035" | evmasm -d
00000000: PUSH1 0x80
00000002: PUSH1 0x40
00000004: MSTORE
00000005: PUSH1 0x4
00000007: CALLDATASIZE
00000008: LT
00000009: PUSH1 0x3f
0000000b: JUMPI
0000000c: PUSH1 0x0
0000000e: CALLDATALOAD

Python API Examples

>>> from pyevmasm import instruction_tables, disassemble_hex, disassemble_all, assemble_hex
>>> instruction_table = instruction_tables['byzantium']
>>> instruction_table[20]
Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
>>> instruction_table['EQ']
Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
>>> instrs = list(disassemble_all(binascii.unhexlify('608060405260043610603f57600035')))
>>> instrs.insert(1, instruction_table['JUMPI'])
>>> a = assemble_hex(instrs)
>>> a
'0x60805760405260043610603f57600035'
>>> print(disassemble_hex(a))
PUSH1 0x80
JUMPI
PUSH1 0x40
MSTORE
...
>>> assemble_hex('PUSH1 0x40\nMSTORE\n')
'0x604052'

Installation

Python >=2.7 or Python >=3.3 is required.

Install the latest stable version using pip:

pip install pyevmasm

Or, install the library from source:

git clone https://github.com/trailofbits/pyevmasm
cd pyevmasm
python setup.py install --user

Documentation

https://pyevmasm.readthedocs.io

New issues, feature requests, and contributions are welcome. Join us in #ethereum channel on the Empire Hacking Slack to discuss Ethereum security tool development.

More Repositories

1

slither

Static Analyzer for Solidity and Vyper
Python
4,971
star
2

echidna

Ethereum smart contract fuzzer
Solidity
2,551
star
3

not-so-smart-contracts

Examples of Solidity security issues
Solidity
2,097
star
4

building-secure-contracts

Guidelines and training material to write secure smart contracts
Solidity
2,069
star
5

evm-opcodes

Ethereum opcodes and instruction reference
1,270
star
6

awesome-ethereum-security

A curated list of awesome Ethereum security references
1,256
star
7

ethersplay

EVM dissassembler
Python
816
star
8

solc-select

Manage and switch between Solidity compiler versions
Python
723
star
9

blockchain-security-contacts

Directory of security contacts for blockchain companies
395
star
10

rattle

evm binary static analysis
Python
348
star
11

etheno

Simplify Ethereum security analysis and testing
Python
330
star
12

ida-evm

IDA Processor Module for the Ethereum Virtual Machine (EVM)
Python
297
star
13

medusa

Parallelized, coverage-guided, mutational Solidity smart contract fuzzing, powered by go-ethereum
Go
254
star
14

properties

Pre-built security properties for common Ethereum operations
Solidity
237
star
15

amarna

Amarna is a static-analyzer and linter for the Cairo programming language.
Python
147
star
16

crytic-compile

Abstraction layer for smart contract build systems
Python
137
star
17

caracal

Static Analyzer for Starknet smart contracts
Cairo
124
star
18

slither-action

Shell
121
star
19

evm_cfg_builder

EVM CFG recovery
Python
110
star
20

optik

Optik is a set of symbolic execution tools that assist smart-contract fuzzers
Python
89
star
21

echidna-streaming-series

A 6-part series on how to use Echidna on real-world codebases
Solidity
88
star
22

roundme

Rust
85
star
23

tayt

StarkNet smart contract fuzzer
Python
75
star
24

fuzz-utils

A tool to automatically generate Foundry unit test cases from Echidna and Medusa failed properties
Solidity
75
star
25

diffusc

Experimental tool to ease the review of smart contracts upgrades
Solidity
69
star
26

tealer

Static Analyzer for Teal
Python
61
star
27

echidna-action

GitHub Action to run Echidna, the Ethereum smart contract fuzzer
Shell
58
star
28

fluxture

A crawling framework for blockchains and peer-to-peer systems
Python
46
star
29

attacknet

Tool and testing methodology for subjecting blockchain devnets to simulated network and side channel attacks
Go
43
star
30

secureum-medusa

Solidity
42
star
31

echidna-spearbit-demo

Example code for testing using Echidna explained during the Spearbit presentation
Solidity
38
star
32

slither-docs-action

Write documentation for your code in pull requests using Slither and OpenAI.
TypeScript
36
star
33

echidna-parade

Python
28
star
34

solana-lints

Lints based on the Sealevel Attacks
Rust
28
star
35

contract-explorer

Visual Studio Code integration for Slither, a Solidity static analysis framework
TypeScript
28
star
36

whipstaff

A specification of the CBC Casper consensus protocols written in TLA+ and PlusCal (transpiled to TLA+)
TLA
20
star
37

trailofbits-security

The Trail of Bits Truffle Security Toolbox
JavaScript
20
star
38

damn-vulnerable-defi-echidna

Solidity
13
star
39

amarna-action

Github action for the Amarna static analyzer
Shell
10
star
40

cloudexec

A general purpose foundation for cloud-based fuzzing and mutation testing jobs
Go
10
star
41

medusa-geth

A go-ethereum fork enabling additional testing capabilities for medusa
10
star
42

slightly-smarter-contracts

Python
7
star
43

slither-docs-demo

A demo on how to use the slither-docs actions (https://github.com/crytic/slither-docs-action)
Solidity
7
star
44

vscode-starknet-explorer

StarkNet support extension for VSCode. Visualize StarkNet contracts: view storage variables, external and view functions, and events.
TypeScript
6
star
45

solc

4
star
46

embark-contract-info

embark-contract-info
JavaScript
3
star
47

fuzz-vs-fv

TypeScript
3
star
48

addressarrayutils_demo

Demonstration for using echidna to test a Solidity library
Solidity
2
star
49

remix-plugin-8000

JavaScript
2
star
50

ethdam

1
star
51

slither-lsp

Python
1
star