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:
cd mipsevm
go build
- name: Generate checkpoints for 13284469
run: mipsevm/mipsevm 13284469
run: cd mipsevm && ./mipsevm 13284469
- name: Run test challenge
run: npx hardhat test test/challenge_test.js
......@@ -26,39 +26,56 @@ func main() {
if len(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
ram := make(map[uint32](uint32))
lastStep := 0
mu := GetHookedUnicorn(root, ram, func(step int, mu uc.Unicorn, ram map[uint32](uint32)) {
// 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 := 1
if evm {
ZeroRegisters(ram)
LoadMappedFile("../mipigo/minigeth.bin", ram, 0)
WriteCheckpoint(ram, "/tmp/cannon/golden.json", -1)
LoadMappedFile(fmt.Sprintf("%s/input", root), ram, 0x30000000)
RunWithRam(ram, target-1, 0, nil)
lastStep += target - 1
fn := fmt.Sprintf("%s/checkpoint_%d.json", root, lastStep)
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)
// 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)
}
// TODO: this is actually step 0->1. Renumber as appropriate
LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0x30000000)
// TODO: this is actually step 0->1. Renumber as appropriate
LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0x30000000)
mu.Start(0, 0x5ead0004)
SyncRegs(mu, ram)
}
mu.Start(0, 0x5ead0004)
SyncRegs(mu, ram)
if target == -1 {
WriteCheckpoint(ram, fmt.Sprintf("%s/checkpoint_final.json", root), lastStep)
}
......
......@@ -20,7 +20,7 @@ func check(err error) {
}
}
var steps int = 1
var steps int = 0
var heap_start uint64 = 0
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