Latest commit

History

183 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

pyevmasm

Build Status

PyPI versionSlack 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 selectthe 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 >=3.10 is required.

Install the latest stable version using pip:

pip install pyevmasm

Or, install the library from source:

git clone https://github.com/crytic/pyevmasm
cd pyevmasm
pip install .

For development (requires uv):

uv sync --group dev
uv run pytest

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.

About

Ethereum Virtual Machine (EVM) disassembler and assembler

Topics

Resources

Security policy

Stars

386 stars

Watchers

19 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); })();
Skip to content

Latest commit

History

183 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

pyevmasm

Build Status

PyPI versionSlack 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 selectthe 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 >=3.10 is required.

Install the latest stable version using pip:

pip install pyevmasm

Or, install the library from source:

git clone https://github.com/crytic/pyevmasm
cd pyevmasm
pip install .

For development (requires uv):

uv sync --group dev
uv run pytest

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.

About

Ethereum Virtual Machine (EVM) disassembler and assembler

Topics

Resources

Security policy

Stars

386 stars

Watchers

19 watching

Forks

Releases

Packages

Used by

Contributors

Languages