Commit 6c0d0df5 authored by George Hotz's avatar George Hotz

mipsevm builds golden

parent 05db1a9b
......@@ -3,20 +3,26 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"strconv"
uc "github.com/unicorn-engine/unicorn/bindings/go/unicorn"
)
func WriteCheckpoint(ram map[uint32](uint32), root string, step int) {
func WriteCheckpoint(ram map[uint32](uint32), fn string) {
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/cannon/%d_%d", 0, 13284469)
root := ""
if len(os.Args) > 1 {
blockNumber, _ := strconv.Atoi(os.Args[1])
root = fmt.Sprintf("/tmp/cannon/%d_%d", 0, blockNumber)
}
// step 1, generate the checkpoints every million steps using unicorn
ram := make(map[uint32](uint32))
......@@ -25,20 +31,26 @@ func main() {
// this can be raised to 10,000,000 if the files are too large
if step%10000000 == 0 {
SyncRegs(mu, ram)
WriteCheckpoint(ram, root, step)
fn := fmt.Sprintf("%s/checkpoint_%d.json", root, step)
WriteCheckpoint(ram, fn)
}
lastStep = step
})
ZeroRegisters(ram)
// not ready for golden yet
LoadMappedFileUnicorn(mu, "../mipigo/minigeth.bin", ram, 0)
WriteCheckpoint(ram, root, -1)
LoadMappedFileUnicorn(mu, "mipigo/minigeth.bin", ram, 0)
WriteCheckpoint(ram, "/tmp/cannon/golden.json")
if root == "" {
fmt.Println("exiting early without a block number")
os.Exit(0)
}
LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0x30000000)
mu.Start(0, 0x5ead0004)
SyncRegs(mu, ram)
WriteCheckpoint(ram, root, lastStep)
WriteCheckpoint(ram, fmt.Sprintf("%s/checkpoint_%d.json", root, lastStep))
// step 2 (optional), validate each 1 million chunk in EVM
......
......@@ -9,6 +9,7 @@ async function main() {
"MIPSMemory": mm.address,
}
console.log("deployed", json)
fs.writeFileSync("/tmp/cannon/deployed.json", JSON.stringify(json))
}
main()
......
const goldenRoot = "0x1f6285b6d372ee187815a8580d1af3ab348cea34abbee18a8e13272454a4c4af"
const fs = require("fs")
async function deploy() {
const MIPS = await ethers.getContractFactory("MIPS")
const m = await MIPS.deploy()
const mm = await ethers.getContractAt("MIPSMemory", await m.m())
let startTrie = JSON.parse(fs.readFileSync("/tmp/cannon/golden.json"))
let goldenRoot = startTrie["root"]
console.log("goldenRoot is", goldenRoot)
const Challenge = await ethers.getContractFactory("Challenge")
const c = await Challenge.deploy(m.address, goldenRoot)
......
......@@ -2,9 +2,6 @@ const { expect } = require("chai")
const fs = require("fs")
const { deploy } = require("../scripts/lib")
// golden minigeth.bin hash
const goldenRoot = "0x1f6285b6d372ee187815a8580d1af3ab348cea34abbee18a8e13272454a4c4af"
describe("Challenge contract", function () {
beforeEach(async function () {
[c, m, mm] = await deploy()
......@@ -23,13 +20,14 @@ describe("Challenge contract", function () {
const blockNp1Rlp = blockNp1.header.serialize()
const assertionRoot = "0x9e0261efe4509912b8862f3d45a0cb8404b99b239247df9c55871bd3844cebbd"
const finalSystemState = "0xf02b4450a07d492c17b4b554851f0dcb12192e2439a507b12fcea8f801a596a6"
let startTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_13284469/checkpoint_-1.json"))
let startTrie = JSON.parse(fs.readFileSync("/tmp/cannon/golden.json"))
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_13284469/checkpoint_85059435.json"))
const finalSystemState = finalTrie['root']
while (1) {
try {
// TODO: make this eth call?
// needs something like InitiateChallengeWithTrieNodes
await c.InitiateChallenge(blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, 1)
break
} catch(e) {
......
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