Commit 7c3b3af0 authored by George Hotz's avatar George Hotz

allow mipsevm to use both unicorn and the evm

parent 20d6c36d
...@@ -34,6 +34,6 @@ jobs: ...@@ -34,6 +34,6 @@ jobs:
cd mipsevm cd mipsevm
go build go build
- name: Generate checkpoints for 13284469 - name: Generate checkpoints for 13284469
run: mipsevm/mipsevm 13284469 run: cd mipsevm && ./mipsevm 13284469
- name: Run test challenge - name: Run test challenge
run: npx hardhat test test/challenge_test.js run: npx hardhat test test/challenge_test.js
...@@ -26,39 +26,56 @@ func main() { ...@@ -26,39 +26,56 @@ func main() {
if len(os.Args) > 2 { if len(os.Args) > 2 {
target, _ = strconv.Atoi(os.Args[2]) target, _ = strconv.Atoi(os.Args[2])
} }
evm := false
if len(os.Args) > 3 && os.Args[3] == "evm" {
evm = true
}
// step 1, generate the checkpoints every million steps using unicorn // step 1, generate the checkpoints every million steps using unicorn
ram := make(map[uint32](uint32)) ram := make(map[uint32](uint32))
lastStep := 0 lastStep := 1
mu := GetHookedUnicorn(root, ram, func(step int, mu uc.Unicorn, ram map[uint32](uint32)) { if evm {
// this can be raised to 10,000,000 if the files are too large ZeroRegisters(ram)
if step%10000000 == 0 || step == target { LoadMappedFile("../mipigo/minigeth.bin", ram, 0)
SyncRegs(mu, ram) WriteCheckpoint(ram, "/tmp/cannon/golden.json", -1)
fn := fmt.Sprintf("%s/checkpoint_%d.json", root, step) LoadMappedFile(fmt.Sprintf("%s/input", root), ram, 0x30000000)
WriteCheckpoint(ram, fn, step) RunWithRam(ram, target-1, 0, nil)
if step == target { lastStep += target - 1
// done fn := fmt.Sprintf("%s/checkpoint_%d.json", root, lastStep)
mu.RegWrite(uc.MIPS_REG_PC, 0x5ead0004) WriteCheckpoint(ram, fn, lastStep)
} else {
mu := GetHookedUnicorn(root, ram, func(lstep int, mu uc.Unicorn, ram map[uint32](uint32)) {
step := lstep + 1
// this can be raised to 10,000,000 if the files are too large
if step%10000000 == 0 || step == target {
SyncRegs(mu, ram)
fn := fmt.Sprintf("%s/checkpoint_%d.json", root, step)
WriteCheckpoint(ram, fn, step)
if step == target {
// done
mu.RegWrite(uc.MIPS_REG_PC, 0x5ead0004)
}
} }
lastStep = step
})
ZeroRegisters(ram)
// not ready for golden yet
LoadMappedFileUnicorn(mu, "../mipigo/minigeth.bin", ram, 0)
WriteCheckpoint(ram, "/tmp/cannon/golden.json", -1)
if root == "" {
fmt.Println("exiting early without a block number")
os.Exit(0)
} }
lastStep = step
})
ZeroRegisters(ram) // TODO: this is actually step 0->1. Renumber as appropriate
// not ready for golden yet LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0x30000000)
LoadMappedFileUnicorn(mu, "mipigo/minigeth.bin", ram, 0)
WriteCheckpoint(ram, "/tmp/cannon/golden.json", -1)
if root == "" {
fmt.Println("exiting early without a block number")
os.Exit(0)
}
// TODO: this is actually step 0->1. Renumber as appropriate mu.Start(0, 0x5ead0004)
LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0x30000000) SyncRegs(mu, ram)
}
mu.Start(0, 0x5ead0004)
SyncRegs(mu, ram)
if target == -1 { if target == -1 {
WriteCheckpoint(ram, fmt.Sprintf("%s/checkpoint_final.json", root), lastStep) WriteCheckpoint(ram, fmt.Sprintf("%s/checkpoint_final.json", root), lastStep)
} }
......
...@@ -20,7 +20,7 @@ func check(err error) { ...@@ -20,7 +20,7 @@ func check(err error) {
} }
} }
var steps int = 1 var steps int = 0
var heap_start uint64 = 0 var heap_start uint64 = 0
func WriteBytes(fd int, bytes []byte) { func WriteBytes(fd int, bytes []byte) {
......
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