Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
eac31b29
Commit
eac31b29
authored
Oct 11, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce external calls, looks cleaner
parent
f21f2179
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
14 deletions
+15
-14
Challenge.sol
contracts/Challenge.sol
+7
-14
MIPSMemory.sol
contracts/MIPSMemory.sol
+8
-0
No files found.
contracts/Challenge.sol
View file @
eac31b29
...
...
@@ -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 =
w
riteBytes32(startState, 0x30000000, parentHash);
startState =
w
riteBytes32(startState, 0x30000020, Lib_RLPReader.readBytes32(blockNp1[4]));
startState =
w
riteBytes32(startState, 0x30000040, bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))));
startState =
w
riteBytes32(startState, 0x30000060, Lib_RLPReader.readBytes32(blockNp1[1]));
startState =
w
riteBytes32(startState, 0x30000080, bytes32(Lib_RLPReader.readUint256(blockNp1[9])));
startState =
w
riteBytes32(startState, 0x300000a0, bytes32(Lib_RLPReader.readUint256(blockNp1[11])));
startState =
mem.W
riteBytes32(startState, 0x30000000, parentHash);
startState =
mem.W
riteBytes32(startState, 0x30000020, Lib_RLPReader.readBytes32(blockNp1[4]));
startState =
mem.W
riteBytes32(startState, 0x30000040, bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))));
startState =
mem.W
riteBytes32(startState, 0x30000060, Lib_RLPReader.readBytes32(blockNp1[1]));
startState =
mem.W
riteBytes32(startState, 0x30000080, bytes32(Lib_RLPReader.readUint256(blockNp1[9])));
startState =
mem.W
riteBytes32(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
...
...
contracts/MIPSMemory.sol
View file @
eac31b29
...
...
@@ -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;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment