Skip to content

Instantly share code, notes, and snippets.

@karmacoma-eth
Last active March 18, 2023 18:28
Show Gist options
  • Save karmacoma-eth/220b58b7cd32d649fa1a15e70b6d8bff to your computer and use it in GitHub Desktop.
Save karmacoma-eth/220b58b7cd32d649fa1a15e70b6d8bff to your computer and use it in GitHub Desktop.
EVM quine
# quine.etk
# ⬜ => ⬜
# A quine is a computer program which takes no input and produces a copy of its own source code as its only output.
# 0x80...f3 is the compiled code excluding the push16 instruction (from dup1 to return)
push16 0x8060801b17606f5953600152602136f3
# --- stack ---
dup1 # code code
push1 128 # 128 code code
shl # code0000 code
or # codecode
# (6f is push16)
push1 0x6f # 6f codecode
msize # offset=0 6f codecode
mstore8 # codecode
# mem = [6f]
push1 1 # 1 codecode
mstore # mem = [6fcodecode]
push1 33 # size
calldatasize # offset=0 size
# (by definition, a quine takes no input so calldatasize is 0)
return # out = [6fcodecode]
# $ eas quine.etk
# 6f8060801b17606f5953600152602136f38060801b17606f5953600152602136f3
#
# $ evm --code $(eas quine.etk) run | cut -dx -f2
# 6f8060801b17606f5953600152602136f38060801b17606f5953600152602136f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment