Skip to content

Instantly share code, notes, and snippets.

@Saw-mon-and-Natalie
Created July 30, 2022 20:37
Show Gist options
  • Save Saw-mon-and-Natalie/43413cdbf43e0905865976373bbbe9f5 to your computer and use it in GitHub Desktop.
Save Saw-mon-and-Natalie/43413cdbf43e0905865976373bbbe9f5 to your computer and use it in GitHub Desktop.

Cell Division - a self mutating smart contract

Deployed contract on Goerli : 0xE29ff6DA321397d10819DD9579dbcdcf817fF862

Runtime bytecode (30 bytes):

0x68601e8060093d393df35952383d59396009380160173d828234f050f0ff
# ▇ => ▇ + ▇
# Minimal runtime bytecode for a contract that mutates
# into two child contracts and then self-destructs
# 1st child contract receives the call value
# 2nd child contract recevies the remaining balance
# author: Saw-mon and Natalie
# constructor payload for the spawned contract
# ┏━━━━━━━━━━━━━━━━━━━ push1 RUNTIME_BYTECODE_LEN # L
# ┃ ┏━━━━━━━━━━━━━━━ dup1 # L L
# ┃ ┃ ┏━━━━━━━━━━━━━ push1 RUNTIME_BYTECODE_OFFSET # O L L
# ┃ ┃ ┃ ┏━━━━━━━━━ returndatasize # 0 O L L
# ┃ ┃ ┃ ┃ ┏━━━━━━━ codecopy # L
# ┃ ┃ ┃ ┃ ┃ ┏━━━━━ returndatasize # 0 L
# ┃ ┃ ┃ ┃ ┃ ┃ ┏━━━ return
push9 0x601e8060093d393df3
# ┗┻╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍ The only important byte that varies.
msize
mstore # mem = 000...000 601e8060093d393df3
# = 000...000 spawned constructor payload
# copy the runtime bytecode after the constructor code in mem
codesize # cs
returndatasize # 0 cs
msize # 0x20 0 cs
codecopy # mem = 000...000 601e8060093d393df3 RUNTIME_BYTECODE
# --- stack ---
push1 9 # 9
codesize # cs 9
add # cs+9 = CS = total codesize in memory
push1 23 # 23 CS
returndatasize # 0 23 CS
dup3 # CS 0 23 CS
dup3 # 23 CS 0 23 CS
callvalue # v 23 CS 0 23 CS
create # addr1 0 23 CS
pop # 0 23 CS
create # addr2
selfdestruct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment