Commit 55b44daa authored by George Hotz's avatar George Hotz

checkpoint writer works

parent 6ec16006
#!/bin/bash
git clone https://github.com/geohot/unicorn.git -b dev unicorn2
cd unicorn2
cmake . -DUNICORN_ARCH=mips -DCMAKE_BUILD_TYPE=Debug
#cmake . -DUNICORN_ARCH=mips -DCMAKE_BUILD_TYPE=Debug
cmake . -DUNICORN_ARCH=mips -DCMAKE_BUILD_TYPE=Release
make -j8
......@@ -7,28 +7,33 @@ import (
uc "github.com/unicorn-engine/unicorn/bindings/go/unicorn"
)
func WriteCheckpoint(ram map[uint32](uint32), root string, step int) {
trieroot := RamToTrie(ram)
dat := TrieToJson(trieroot)
fn := fmt.Sprintf("%s/checkpoint_%d.json", root, step)
fmt.Printf("writing %s len %d with root %s\n", fn, len(dat), trieroot)
ioutil.WriteFile(fn, dat, 0644)
}
func main() {
root := fmt.Sprintf("/tmp/eth/%d", 13284469)
// step 1, generate the checkpoints every million steps using unicorn
ram := make(map[uint32](uint32))
ZeroRegisters(ram)
lastStep := 0
mu := GetHookedUnicorn(root, ram, func(step int, mu uc.Unicorn, ram map[uint32](uint32)) {
if step%1000000 == 0 {
trieroot := RamToTrie(ram)
dat := TrieToJson(trieroot)
fn := fmt.Sprintf("%s/checkpoint_%d.json", root, step)
fmt.Printf("writing %s len %d\n", fn, len(dat))
ioutil.WriteFile(fn, dat, 0644)
WriteCheckpoint(ram, root, step)
}
lastStep = step
})
check(mu.MemMap(0, 0x80000000))
ZeroRegisters(ram)
LoadMappedFileUnicorn(mu, "../mipigo/minigeth.bin", ram, 0)
LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0xB0000000)
mu.Start(0, 0x5ead0004)
WriteCheckpoint(ram, root, lastStep)
// step 2 (optional), validate each 1 million chunk in EVM
......
......@@ -155,6 +155,7 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u
}, 0, 0x80000000)
}
check(mu.MemMap(0, 0x80000000))
return mu
}
......@@ -173,8 +174,6 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
//mu.MemMap(0x5ead0000, 0x1000)
//mu.MemWrite(0xdead0000, []byte{0x08, 0x10, 0x00, 0x00})
check(mu.MemMap(0, 0x80000000))
// program
dat, _ := ioutil.ReadFile(fn)
mu.MemWrite(0, dat)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment