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
e37f3c0b
Commit
e37f3c0b
authored
Oct 11, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check proof in AddMerkleState
parent
41bff486
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
24 deletions
+17
-24
Challenge.sol
contracts/Challenge.sol
+1
-22
MIPSMemory.sol
contracts/MIPSMemory.sol
+16
-2
No files found.
contracts/Challenge.sol
View file @
e37f3c0b
...
@@ -49,9 +49,6 @@ contract Challenge {
...
@@ -49,9 +49,6 @@ contract Challenge {
owner.transfer(address(this).balance);
owner.transfer(address(this).balance);
}
}
// memory helpers
// create challenge
// create challenge
uint256 public lastChallengeId = 0;
uint256 public lastChallengeId = 0;
...
@@ -103,10 +100,9 @@ contract Challenge {
...
@@ -103,10 +100,9 @@ contract Challenge {
// confirm the finalSystemHash asserts the state you claim (in $t0-$t7) and the machine is stopped
// 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
// you must load these proofs into MIPS before calling this
// we disagree at the end
// we disagree at the end
require(mem.ReadMemory(finalSystemState, 0xC0000080) == 0x5EAD0000, "machine is not stopped in final state (PC == 0x5EAD0000)");
require(mem.ReadMemory(finalSystemState, 0x30000800) == 0x1337f00d, "state is not outputted");
require(mem.ReadMemory(finalSystemState, 0x30000800) == 0x1337f00d, "state is not outputted");
require(mem.ReadBytes32(finalSystemState, 0x30000804) == assertionRoot, "you are claiming a different state root in machine");
require(mem.ReadBytes32(finalSystemState, 0x30000804) == assertionRoot, "you are claiming a different state root in machine");
require(mem.ReadMemory(finalSystemState, 0xC0000080) == 0x5EAD0000, "machine is not stopped in final state (PC == 0x5EAD0000)");
return newChallengeTrusted(startState, finalSystemState, stepCount);
return newChallengeTrusted(startState, finalSystemState, stepCount);
}
}
...
@@ -167,21 +163,4 @@ contract Challenge {
...
@@ -167,21 +163,4 @@ contract Challenge {
emit ChallengerWins(challengeId);
emit ChallengerWins(challengeId);
}
}
function HumiliateChallengerStateTransition(uint256 challengeId, bytes32 finalRiscState) external {
Chal storage c = challenges[challengeId];
require(c.challenger != address(0), "invalid challenge");
require(owner == msg.sender, "must be owner");
require(c.L + 1 == c.R, "binary search not finished");
// it's 0 if you agree with all attacker states except the final one
// in which case, you get a free pass to submit now
require(c.defendedState[c.R] == finalRiscState || c.defendedState[c.R] == bytes32(0), "must be consistent with state");
require(mips.Step(c.defendedState[c.L]) == finalRiscState, "wrong asserted state");
// consider the challenger mocked
// if they staked a bounty, you could claim it here
emit ChallengerLoses(challengeId);
}
}
}
contracts/MIPSMemory.sol
View file @
e37f3c0b
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
pragma solidity ^0.7.3;
pragma solidity ^0.7.3;
import "./lib/Lib_Keccak256.sol";
import "./lib/Lib_Keccak256.sol";
import "./lib/Lib_MerkleTrie.sol";
contract MIPSMemory {
contract MIPSMemory {
// This state is global
// This state is global
...
@@ -47,8 +48,21 @@ contract MIPSMemory {
...
@@ -47,8 +48,21 @@ contract MIPSMemory {
return Lib_Keccak256.get_hash(c);
return Lib_Keccak256.get_hash(c);
}
}
function AddMerkleState(bytes32 stateHash, uint32 addr, uint32 value, string calldata proof) public {
function tb(uint32 dat) internal returns (bytes memory) {
// TODO: check proof
bytes memory ret = new bytes(4);
ret[0] = bytes1(uint8(dat >> 24));
ret[1] = bytes1(uint8(dat >> 16));
ret[2] = bytes1(uint8(dat >> 8));
ret[3] = bytes1(uint8(dat >> 0));
return ret;
}
function AddMerkleState(bytes32 stateHash, uint32 addr, uint32 value, bytes calldata proof) public {
if (value == 0) {
require(Lib_MerkleTrie.verifyExclusionProof(tb(addr), proof, stateHash) == true, "couldn't verify 0 proof");
} else {
require(Lib_MerkleTrie.verifyInclusionProof(tb(addr), tb(value), proof, stateHash) == true, "couldn't verify non 0 proof");
}
state[stateHash][addr] = (1 << 32) | value;
state[stateHash][addr] = (1 << 32) | value;
}
}
...
...
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