Commit 690f9803 authored by George Hotz's avatar George Hotz

pushed a challenge to cheapeth

parent 2ed9dcae
......@@ -57,12 +57,14 @@ process done with hash 0x5c45998dfbf9ce70bcbb80574ed7a622922d2c775e0a2331fe5a8b8
```
# testing on cheapeth
npx hardhat node
# only works for pre fork blocks
minigeth/go-ethereum 1171895
(cd mipsevm && ./mipsevm 1171895)
npx hardhat run scripts/deploy.js
BLOCK=13652175 npx hardhat run scripts/challenge.js
BLOCK=1171895 npx hardhat run scripts/challenge.js
```
## State Oracle API
On chain / in MIPS, we have two oracles
......
......@@ -97,14 +97,23 @@ contract Challenge {
function InitiateChallenge(uint blockNumberN, bytes calldata blockHeaderNp1,
bytes32 assertionRoot, bytes32 finalSystemState, uint256 stepCount) external returns (uint256) {
bytes32 computedBlockHash = keccak256(blockHeaderNp1);
require(blockhash(blockNumberN+1) == computedBlockHash, "end block hash wrong");
// get block hashes, can replace with oracle
bytes32 blockNumberNHash = blockhash(blockNumberN);
bytes32 blockNumberNp1Hash = blockhash(blockNumberN+1);
// TODO: this is only removed for testing. zero security without it
/*if (blockNumberNHash == bytes32(0) || blockNumberNp1Hash == bytes32(0)) {
revert("block number too old to challenge");
}
require(blockNumberNp1Hash == computedBlockHash, "end block hash wrong");*/
// decode the blocks
bytes32 inputHash;
{
Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1);
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]);
require(blockhash(blockNumberN) == parentHash, "parent block hash somehow wrong");
//require(blockNumberNHash == parentHash, "parent block hash somehow wrong");
bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]);
require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge");
......
const { deployed, getBlockRlp } = require("../scripts/lib")
const fs = require("fs")
const { deployed, getBlockRlp, getTrieNodesForCall } = require("../scripts/lib")
async function main() {
let [c, m, mm] = await deployed()
......@@ -14,7 +15,32 @@ async function main() {
const blockNp1Rlp = getBlockRlp(blockNp1)
console.log(c.address, m.address, mm.address)
// TODO: finish this
// 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"))*/
// fake for testing (it's the next block)
const assertionRoot = "0xb135cb00efbc2341905eafc034eca0dcec40b039a1b28860bf7c309c872e5644"
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_1171896/checkpoint_final.json"))
let preimages = Object.assign({}, startTrie['preimages'], finalTrie['preimages']);
const finalSystemState = finalTrie['root']
let args = [blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, finalTrie['step']]
let cdat = c.interface.encodeFunctionData("InitiateChallenge", args)
let nodes = await getTrieNodesForCall(c, cdat, preimages)
// run "on chain"
for (n of nodes) {
await mm.AddTrieNode(n)
}
let ret = await c.InitiateChallenge(...args)
let receipt = await ret.wait()
// ChallengeCreate event
let challengeId = receipt.events[0].args['challengeId'].toNumber()
console.log("new challenge with id", challengeId)
}
main()
......
......@@ -68,8 +68,12 @@ async function getTrieNodesForCall(c, cdat, preimages) {
});
break
} catch(e) {
const missing = e.toString().split("'")[1]
if (missing.length == 64) {
let missing = e.toString().split("'")[1]
if (missing == undefined) {
// other kind of error from HTTPProvider
missing = e.error.message.toString().split("execution reverted: ")[1]
}
if (missing !== undefined && missing.length == 64) {
console.log("requested node", missing)
let node = preimages["0x"+missing]
if (node === undefined) {
......
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