Commit 19580c2f authored by George Hotz's avatar George Hotz

challenge test, will fail until i put in the trie nodes

parent 2c47146a
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
pragma solidity ^0.7.3; pragma solidity ^0.7.3;
import "./lib/Lib_RLPReader.sol"; import "./lib/Lib_RLPReader.sol";
import "hardhat/console.sol";
interface IMIPS { interface IMIPS {
function Step(bytes32 stateHash) external returns (bytes32); function Step(bytes32 stateHash) external returns (bytes32);
...@@ -75,24 +76,28 @@ contract Challenge { ...@@ -75,24 +76,28 @@ contract Challenge {
function InitiateChallenge(uint blockNumberN, bytes calldata blockHeaderNp1, function InitiateChallenge(uint blockNumberN, bytes calldata blockHeaderNp1,
bytes32 assertionRoot, bytes32 finalSystemState, uint256 stepCount) external returns (uint256) { bytes32 assertionRoot, bytes32 finalSystemState, uint256 stepCount) external returns (uint256) {
require(blockhash(blockNumberN+1) == keccak256(blockHeaderNp1), "end block hash wrong"); bytes32 computedBlockHash = keccak256(blockHeaderNp1);
require(blockhash(blockNumberN+1) == computedBlockHash, "end block hash wrong");
// decode the blocks // decode the blocks
Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1); bytes32 inputHash;
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]); {
require(blockhash(blockNumberN) == parentHash, "parent block hash somehow wrong"); Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1);
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]);
bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]); require(blockhash(blockNumberN) == parentHash, "parent block hash somehow wrong");
require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge");
bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]);
// load starting info into the input oracle require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge");
// we both agree at the beginning
bytes32 txhash = Lib_RLPReader.readBytes32(blockNp1[4]); // load starting info into the input oracle
bytes32 coinbase = bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))); // we both agree at the beginning
bytes32 unclehash = Lib_RLPReader.readBytes32(blockNp1[1]); bytes32 txhash = Lib_RLPReader.readBytes32(blockNp1[4]);
bytes32 gaslimit = bytes32(Lib_RLPReader.readUint256(blockNp1[9])); bytes32 coinbase = bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2])));
bytes32 time = bytes32(Lib_RLPReader.readUint256(blockNp1[11])); bytes32 unclehash = Lib_RLPReader.readBytes32(blockNp1[1]);
bytes32 inputHash = keccak256(abi.encodePacked(parentHash, txhash, coinbase, unclehash, gaslimit, time)); bytes32 gaslimit = bytes32(Lib_RLPReader.readUint256(blockNp1[9]));
bytes32 time = bytes32(Lib_RLPReader.readUint256(blockNp1[11]));
inputHash = keccak256(abi.encodePacked(parentHash, txhash, coinbase, unclehash, gaslimit, time));
}
bytes32 startState = GlobalStartState; bytes32 startState = GlobalStartState;
startState = mem.WriteBytes32(startState, 0xB0000000, inputHash); startState = mem.WriteBytes32(startState, 0xB0000000, inputHash);
......
const { expect } = require("chai"); const { expect } = require("chai");
// golden minigeth.bin hash
const goldenRoot = "0x9c15aa86416a3a9d3b15188fc9f9be59626c1f83a33e5d63b58ca1bf0f8cef71"
describe("Challenge contract", function () { describe("Challenge contract", function () {
beforeEach(async function () { beforeEach(async function () {
// this mips can be reused for other challenges // this mips can be reused for other challenges
...@@ -7,10 +10,28 @@ describe("Challenge contract", function () { ...@@ -7,10 +10,28 @@ describe("Challenge contract", function () {
const m = await MIPS.deploy() const m = await MIPS.deploy()
const Challenge = await ethers.getContractFactory("Challenge") const Challenge = await ethers.getContractFactory("Challenge")
// golden minigeth.bin hash c = await Challenge.deploy(m.address, goldenRoot)
c = await Challenge.deploy(m.address, "0x9c15aa86416a3a9d3b15188fc9f9be59626c1f83a33e5d63b58ca1bf0f8cef71")
}) })
it("challenge contract deploys", async function() { it("challenge contract deploys", async function() {
console.log("Challenge deployed at", c.address) console.log("Challenge deployed at", c.address)
}) })
it("initiate challenge", async function() {
// TODO: is there a better way to get the "HardhatNetworkProvider"?
const hardhat = network.provider._wrapped._wrapped._wrapped._wrapped._wrapped
const blockchain = hardhat._node._blockchain
// get data
const blockNumberN = (await ethers.provider.getBlockNumber())-1;
const blockNp1 = blockchain._data._blocksByNumber.get(blockNumberN+1)
const blockNp1Rlp = blockNp1.header.serialize()
const assertionRoot = "0x1337133713371337133713371337133713371337133713371337133713371337"
// TODO: compute a valid one of these
const finalSystemState = "0x1337133713371337133713371337133713371337133713371337133713371337"
await c.InitiateChallenge(blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, 1)
//const blockHeaderNp1 = getBlockRlp(await ethers.provider.getBlock(blockNumberN+1));
//console.log(blockNumberN, blockHeaderNp1);
})
}) })
\ No newline at end of file
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