Commit ac204c7e authored by George Hotz's avatar George Hotz

wow, preimage oracle was so easy to write

parent 0154de17
......@@ -43,11 +43,30 @@ contract MIPS {
}
function ReadMemory(bytes32 stateHash, uint32 addr) public view returns (uint32) {
require(addr & 3 == 0, "read memory must be 32-bit aligned");
// zero register is always 0
if (addr == REG_OFFSET) {
// zero register is always 0
return 0;
}
require(addr & 3 == 0, "read memory must be 32-bit aligned");
// MMIO preimage oracle
if (addr >= 0x31000000 && addr < 0x32000000) {
bytes32 pihash = ReadBytes32(stateHash, 0x30001000);
if (addr == 0x31000000) {
return uint32(preimage[pihash].length);
}
uint offset = addr-0x31000004;
uint8 a0 = uint8(preimage[pihash][offset]);
uint8 a1 = uint8(preimage[pihash][offset+1]);
uint8 a2 = uint8(preimage[pihash][offset+2]);
uint8 a3 = uint8(preimage[pihash][offset+3]);
return (uint32(a0) << 24) |
(uint32(a1) << 16) |
(uint32(a2) << 8) |
(uint32(a3) << 0);
}
uint64 ret = state[stateHash][addr];
require((ret >> 32) == 1, "memory was not initialized");
return uint32(ret);
......
......@@ -30,7 +30,6 @@ heap_start = 0x20000000 # 0x20000000-0x30000000
# output oracle @ 0x30000800
# preimage oracle (write) @ 0x30001000
# preimage oracle (read) @ 0x31000000-0x32000000 (16 MB)
# preimage oracle (trigger) @ 0x32000000 (returns size)
brk_start = 0x40000000 # 0x40000000-0x80000000
......
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