diff --git a/contracts/Challenge.sol b/contracts/Challenge.sol index da73a4b5f63aab80eb851cd35d66d3eafe42c6f8..f4c3c0ea3858e522c53f7db82ad13aa74b4e825c 100644 --- a/contracts/Challenge.sol +++ b/contracts/Challenge.sol @@ -4,15 +4,15 @@ pragma solidity ^0.7.3; import "./lib/Lib_RLPReader.sol"; interface IMIPS { - function Step(bytes32 stateHash) external view returns (bytes32); + function Step(bytes32 stateHash) external returns (bytes32); function m() external pure returns (IMIPSMemory); } interface IMIPSMemory { function ReadMemory(bytes32 stateHash, uint32 addr) external view returns (uint32); function ReadBytes32(bytes32 stateHash, uint32 addr) external view returns (bytes32); - function WriteMemory(bytes32 stateHash, uint32 addr, uint32 val) external pure returns (bytes32); - function WriteBytes32(bytes32 stateHash, uint32 addr, bytes32 val) external pure returns (bytes32); + function WriteMemory(bytes32 stateHash, uint32 addr, uint32 val) external returns (bytes32); + function WriteBytes32(bytes32 stateHash, uint32 addr, bytes32 val) external returns (bytes32); } contract Challenge { @@ -87,7 +87,6 @@ contract Challenge { // load starting info into the input oracle // we both agree at the beginning - // the first instruction executed in MIPS should be an access of startState bytes32 txhash = Lib_RLPReader.readBytes32(blockNp1[4]); bytes32 coinbase = bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))); bytes32 unclehash = Lib_RLPReader.readBytes32(blockNp1[1]); @@ -98,9 +97,8 @@ contract Challenge { bytes32 startState = GlobalStartState; startState = mem.WriteBytes32(startState, 0xB0000000, inputHash); - // confirm the finalSystemHash asserts the state you claim (in $t0-$t7) and the machine is stopped - // you must load these proofs into MIPS before calling this - // we disagree at the end + // confirm the finalSystemHash asserts the state you claim and the machine is stopped + // you must load these trie nodes into MIPSMemory before calling this require(mem.ReadMemory(finalSystemState, 0xC0000080) == 0x5EAD0000, "machine is not stopped in final state (PC == 0x5EAD0000)"); require(mem.ReadMemory(finalSystemState, 0xB0000800) == 0x1337f00d, "state is not outputted"); require(mem.ReadBytes32(finalSystemState, 0xB0000804) == assertionRoot, "you are claiming a different state root in machine"); diff --git a/hardhat.config.js b/hardhat.config.js index a797a72a9a261007c7613d60ddaf03deeab4d0d0..bc72ae2849ec12d167fd2a0806a0692f90e7015f 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -3,7 +3,7 @@ */ require("@nomiclabs/hardhat-ethers"); -//require("hardhat-gas-reporter"); +require("hardhat-gas-reporter"); module.exports = { solidity: { diff --git a/mipigo/.gitignore b/mipigo/.gitignore index 8298b61d0f6dd07c7150aa034c5bfb11d333c234..dde24b177ebf531c3c0bd052bf64c435c218ce15 100644 --- a/mipigo/.gitignore +++ b/mipigo/.gitignore @@ -3,4 +3,4 @@ go-ethereum sysroot test/test minigeth -minigeth.bin +/minigeth.bin diff --git a/mipigo/golden/minigeth.bin b/mipigo/golden/minigeth.bin new file mode 100644 index 0000000000000000000000000000000000000000..3682c0803ba12ae6784475766b5198a1ef227610 Binary files /dev/null and b/mipigo/golden/minigeth.bin differ diff --git a/mipsevm/main.go b/mipsevm/main.go index 53c6b9a6149e911c13f85dcf5ff990af4710eb80..b2e9cca7e104d9fb40131a7e012f58e4586619c4 100644 --- a/mipsevm/main.go +++ b/mipsevm/main.go @@ -31,7 +31,7 @@ func main() { }) ZeroRegisters(ram) - LoadMappedFileUnicorn(mu, "../mipigo/minigeth.bin", ram, 0) + LoadMappedFileUnicorn(mu, "../mipigo/golden/minigeth.bin", ram, 0) LoadMappedFileUnicorn(mu, fmt.Sprintf("%s/input", root), ram, 0xB0000000) mu.Start(0, 0x5ead0004) diff --git a/test/challenge_test.js b/test/challenge_test.js new file mode 100644 index 0000000000000000000000000000000000000000..316909d9e0e0224191d25eeb633318c4c54be805 --- /dev/null +++ b/test/challenge_test.js @@ -0,0 +1,16 @@ +const { expect } = require("chai"); + +describe("Challenge contract", function () { + beforeEach(async function () { + // this mips can be reused for other challenges + const MIPS = await ethers.getContractFactory("MIPS") + const m = await MIPS.deploy() + + const Challenge = await ethers.getContractFactory("Challenge") + // golden minigeth.bin hash + c = await Challenge.deploy(m.address, "0x9c15aa86416a3a9d3b15188fc9f9be59626c1f83a33e5d63b58ca1bf0f8cef71") + }) + it("challenge contract deploys", async function() { + console.log("Challenge deployed at", c.address) + }) +}) \ No newline at end of file