#assembly #push #bytecode #language #evm #assemble #intermediate

bin+lib evmil

An low-level immediate language for compiling to EVM bytecode

24 releases

0.4.5 Oct 26, 2023
0.4.4 Oct 26, 2023
0.4.0 Sep 19, 2023
0.3.3 Sep 11, 2023
0.1.0 Sep 3, 2022

#129 in Magic Beans

Download history 37/week @ 2024-02-18 4/week @ 2024-02-25 2/week @ 2024-03-10 129/week @ 2024-03-31

131 downloads per month

MIT/Apache

390KB
7.5K SLoC

Rust 5.5K SLoC // 0.2% comments Assembly 2K SLoC // 0.5% comments Shell 6 SLoC

Overview

This is a library and tool for working with EVM bytecode. The tool allows you to disassemble contracts into assembly language, and assemble them back again. The tool also supports a primitive intermediate language which can be compiled into bytecode.

Assembler / Disassembler

To illustrate the tool, we will first disassemble the bytecode contract 0x60006000511161000f5760016000525b. We can do this as follows:

evmil disassemble --code 0x60006000511161000f5760016000525b

This should produce the following output:

.code
        push 0x00
        push 0x00
        mload
        gt
        push 0x000f
        jumpi
        push 0x01
        push 0x00
        mstore
_0x000f:
        jumpdest

If we store this into a file test.asm, we can then assemble it back as follows:

evmil assemble test.asm

And we should see our original bytecode being output:

0x60006000511161000f5760016000525b

Finally, when writing assembly language we can use labels for simplicity. For example, the above could be rewritten as follows:

.code
        push 0x00
        push 0x00
        mload
        gt
        push lab
        jumpi
        push 0x01
        push 0x00
        mstore
lab:
        jumpdest

This just makes writing the assembly language a bit easier.

Dependencies

~3.5MB
~64K SLoC