Commit eac31b29 authored by George Hotz's avatar George Hotz

reduce external calls, looks cleaner

parent f21f2179
......@@ -12,6 +12,7 @@ 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);
}
contract Challenge {
......@@ -50,14 +51,6 @@ contract Challenge {
// memory helpers
function writeBytes32(bytes32 stateHash, uint32 addr, bytes32 val) internal view returns (bytes32) {
for (uint32 i = 0; i < 32; i += 4) {
uint256 tv = uint256(val>>(224-(i*8)));
stateHash = mem.WriteMemory(stateHash, addr+i, uint32(tv));
}
return stateHash;
}
// create challenge
uint256 public lastChallengeId = 0;
......@@ -100,12 +93,12 @@ contract Challenge {
// the first instruction executed in MIPS should be an access of startState
// parentblockhash, txhash, coinbase, unclehash, gaslimit, time
bytes32 startState = GlobalStartState;
startState = writeBytes32(startState, 0x30000000, parentHash);
startState = writeBytes32(startState, 0x30000020, Lib_RLPReader.readBytes32(blockNp1[4]));
startState = writeBytes32(startState, 0x30000040, bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))));
startState = writeBytes32(startState, 0x30000060, Lib_RLPReader.readBytes32(blockNp1[1]));
startState = writeBytes32(startState, 0x30000080, bytes32(Lib_RLPReader.readUint256(blockNp1[9])));
startState = writeBytes32(startState, 0x300000a0, bytes32(Lib_RLPReader.readUint256(blockNp1[11])));
startState = mem.WriteBytes32(startState, 0x30000000, parentHash);
startState = mem.WriteBytes32(startState, 0x30000020, Lib_RLPReader.readBytes32(blockNp1[4]));
startState = mem.WriteBytes32(startState, 0x30000040, bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))));
startState = mem.WriteBytes32(startState, 0x30000060, Lib_RLPReader.readBytes32(blockNp1[1]));
startState = mem.WriteBytes32(startState, 0x30000080, bytes32(Lib_RLPReader.readUint256(blockNp1[9])));
startState = mem.WriteBytes32(startState, 0x300000a0, bytes32(Lib_RLPReader.readUint256(blockNp1[11])));
// 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
......
......@@ -65,6 +65,14 @@ contract MIPSMemory {
return newstateHash;
}
function WriteBytes32(bytes32 stateHash, uint32 addr, bytes32 val) public pure returns (bytes32) {
for (uint32 i = 0; i < 32; i += 4) {
uint256 tv = uint256(val>>(224-(i*8)));
stateHash = WriteMemory(stateHash, addr+i, uint32(tv));
}
return stateHash;
}
// needed for preimage oracle
function ReadBytes32(bytes32 stateHash, uint32 addr) public view returns (bytes32) {
uint256 ret = 0;
......
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