Commit 41b47702 authored by George Hotz's avatar George Hotz Committed by George Hotz

much more generic test, nothing hardcoded

parent a5069abc
......@@ -55,24 +55,29 @@ npx hardhat node --fork https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa44
# challenger is pretending the block 13284491 transition is the transition for 13284469
# this will conflict at the first step
rm -rf /tmp/cannon/*
mkdir -p /tmp/cannon /tmp/cannon_fault && rm -rf /tmp/cannon/* /tmp/cannon_fault/*
mipsevm/mipsevm
npx hardhat run scripts/deploy.js --network hosthat
cp /tmp/cannon/*.json /tmp/cannon_fault/
# compute the MIPS checkpoints
minigeth/go-ethereum 13284491 && mipsevm/mipsevm 13284491
# compute real MIPS checkpoint
minigeth/go-ethereum 13284469 && mipsevm/mipsevm 13284469
BLOCK=13284469 npx hardhat run scripts/challenge.js --network hosthat
# compute fake MIPS checkpoint (use a symlink to pretend)
BASEDIR=/tmp/cannon_fault minigeth/go-ethereum 13284491 && BASEDIR=/tmp/cannon_fault mipsevm/mipsevm 13284491
ln -s /tmp/cannon_fault/0_13284491 /tmp/cannon_fault/0_13284469
BASEDIR=/tmp/cannon_fault BLOCK=13284469 npx hardhat run scripts/challenge.js --network hosthat
# do binary search
for i in {1..23}
do
ID=0 BLOCK=13284491 CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
BASEDIR=/tmp/cannon_fault ID=0 BLOCK=13284469 CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
ID=0 BLOCK=13284469 npx hardhat run scripts/respond.js --network hosthat
done
# assert as challenger (fails)
ID=0 BLOCK=13284491 CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
BASEDIR=/tmp/cannon_fault ID=0 BLOCK=13284469 CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
# assert as defender (passes)
ID=0 BLOCK=13284469 npx hardhat run scripts/assert.js --network hosthat
......
......@@ -44,13 +44,17 @@ func main() {
fmt.Println("override node url", newNodeUrl)
oracle.SetNodeUrl(newNodeUrl)
}
basedir := os.Getenv("BASEDIR")
if len(basedir) == 0 {
basedir = "/tmp/cannon"
}
pkw := oracle.PreimageKeyValueWriter{}
pkwtrie := trie.NewStackTrie(pkw)
blockNumber, _ := strconv.Atoi(os.Args[1])
// TODO: get the chainid
oracle.SetRoot(fmt.Sprintf("/tmp/cannon/0_%d", blockNumber))
oracle.SetRoot(fmt.Sprintf("%s/0_%d", basedir, blockNumber))
oracle.PrefetchBlock(big.NewInt(int64(blockNumber)), true, nil)
oracle.PrefetchBlock(big.NewInt(int64(blockNumber)+1), false, pkwtrie)
hash, err := pkwtrie.Commit()
......
......@@ -19,9 +19,13 @@ func WriteCheckpoint(ram map[uint32](uint32), fn string, step int) {
func main() {
root := ""
target := -1
basedir := os.Getenv("BASEDIR")
if len(basedir) == 0 {
basedir = "/tmp/cannon"
}
if len(os.Args) > 1 {
blockNumber, _ := strconv.Atoi(os.Args[1])
root = fmt.Sprintf("/tmp/cannon/%d_%d", 0, blockNumber)
root = fmt.Sprintf("%s/%d_%d", basedir, 0, blockNumber)
}
if len(os.Args) > 2 {
target, _ = strconv.Atoi(os.Args[2])
......@@ -67,7 +71,7 @@ func main() {
// not ready for golden yet
LoadMappedFileUnicorn(mu, "mipigo/minigeth.bin", ram, 0)
if root == "" {
WriteCheckpoint(ram, "/tmp/cannon/golden.json", -1)
WriteCheckpoint(ram, fmt.Sprintf("%s/golden.json", basedir), -1)
fmt.Println("exiting early without a block number")
os.Exit(0)
}
......
const fs = require("fs")
const { deployed, getBlockRlp, getTrieNodesForCall } = require("../scripts/lib")
const { basedir, deployed, getBlockRlp, getTrieNodesForCall } = require("../scripts/lib")
async function main() {
let [c, m, mm] = await deployed()
......@@ -17,13 +17,16 @@ async function main() {
console.log(c.address, m.address, mm.address)
// TODO: move this to lib, it's shared with the test
let startTrie = JSON.parse(fs.readFileSync("/tmp/cannon/golden.json"))
/*const assertionRoot = "0x1111111111111111111111111111111111111111111111111111111111111111"
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_"+blockNumberN.toString()+"/checkpoint_final.json"))*/
let startTrie = JSON.parse(fs.readFileSync(basedir+"/golden.json"))
// we are submitting the (wrong) transition for block 13284469 as the attacker
const assertionRoot = "0xb0b8fc0cf929b8b7a1a31059e1dfb321e78ff0dfe5912d5c615beaf37ec608e7"
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_13284491/checkpoint_final.json"))
const assertionRootBinary = fs.readFileSync(basedir+"/0_"+blockNumberN.toString()+"/output")
var assertionRoot = "0x"
for (var i=0; i<32; i++) {
hex = assertionRootBinary[i].toString(16);
assertionRoot += ("0"+hex).slice(-2);
}
console.log("asserting root", assertionRoot)
let finalTrie = JSON.parse(fs.readFileSync(basedir+"/0_"+blockNumberN.toString()+"/checkpoint_final.json"))
let preimages = Object.assign({}, startTrie['preimages'], finalTrie['preimages']);
const finalSystemState = finalTrie['root']
......
......@@ -2,12 +2,14 @@ const fs = require("fs")
const rlp = require('rlp')
const child_process = require("child_process")
const basedir = process.env.BASEDIR == undefined ? "/tmp/cannon" : process.env.BASEDIR
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 startTrie = JSON.parse(fs.readFileSync(basedir+"/golden.json"))
let goldenRoot = startTrie["root"]
console.log("goldenRoot is", goldenRoot)
......@@ -49,7 +51,7 @@ function getBlockRlp(block) {
}
async function deployed() {
let addresses = JSON.parse(fs.readFileSync("/tmp/cannon/deployed.json"))
let addresses = JSON.parse(fs.readFileSync(basedir+"/deployed.json"))
const c = await ethers.getContractAt("Challenge", addresses["Challenge"])
const m = await ethers.getContractAt("MIPS", addresses["MIPS"])
const mm = await ethers.getContractAt("MIPSMemory", addresses["MIPSMemory"])
......@@ -106,7 +108,7 @@ async function getTrieNodesForCall(c, caddress, cdat, preimages) {
}
function getTrieAtStep(blockNumberN, step) {
const fn = "/tmp/cannon/0_"+blockNumberN.toString()+"/checkpoint_"+step.toString()+".json"
const fn = basedir+"/0_"+blockNumberN.toString()+"/checkpoint_"+step.toString()+".json"
if (!fs.existsSync(fn)) {
console.log("running mipsevm")
......@@ -133,4 +135,4 @@ async function writeMemory(mm, root, addr, data, bytes32=false) {
return root
}
module.exports = { deploy, deployed, getTrieNodesForCall, getBlockRlp, getTrieAtStep, writeMemory, MissingHashError }
module.exports = { basedir, deploy, deployed, getTrieNodesForCall, getBlockRlp, getTrieAtStep, writeMemory, MissingHashError }
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