Explore the series

Building an EVM from scratch part 1 - the execution context

Building an EVM from scratch part 2 - branching instructions

Building an EVM from scratch part 3 - calldata and the function dispatcher

๐ŸŸฉ๐ŸŸฉ๐ŸŸฉ๐ŸŸฉ๐ŸŸฉ๐ŸŸฉ๐ŸŸฉ๐ŸŸจโฌœโฌœ 108/142 instructions implemented


It all started with this tweet:

https://twitter.com/0x796/status/1615640000904691714

Talk about a nerd-snipe. As someone who wrote an EVM for fun, I didnโ€™t consider EVM disassembly to be particularly challenging, but it turns out that this contract did indeed trick commonly used disassemblers to error out.

Weโ€™re going to build a basic disassembler, and progressively make it better until it can reliably work on arbitrary bytecode. Along the way, I collected some guidelines that I believe every disassembler should follow to become more robust:

๐Ÿ“œ Donโ€™t interpret data as code

๐Ÿ“œ Donโ€™t interpret code as data

๐Ÿ“œ Disassembling should be exactly reversible

๐Ÿ“œ When in doubt, ask โ€œwhat would the EVM do?โ€