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
312aad6d
Commit
312aad6d
authored
Mar 09, 2022
by
Nicolas "Norswap" Laurent
Committed by
norswap
Mar 17, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use natspec consistently + add challenge top-level description
parent
b1cf7a64
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
26 deletions
+31
-26
Challenge.sol
contracts/Challenge.sol
+31
-26
No files found.
contracts/Challenge.sol
View file @
312aad6d
...
@@ -4,38 +4,48 @@ pragma experimental ABIEncoderV2;
...
@@ -4,38 +4,48 @@ pragma experimental ABIEncoderV2;
import "./lib/Lib_RLPReader.sol";
import "./lib/Lib_RLPReader.sol";
/// @notice MIPS virtual machine interface
interface IMIPS {
interface IMIPS {
// Given a MIPS state hash (includes code & registers), execute the next instruction and returns
//
/ @notice
Given a MIPS state hash (includes code & registers), execute the next instruction and returns
// the update state hash.
//
/
the update state hash.
function Step(bytes32 stateHash) external returns (bytes32);
function Step(bytes32 stateHash) external returns (bytes32);
// Returns the associated MIPS memory contract.
//
/ @notice
Returns the associated MIPS memory contract.
function m() external pure returns (IMIPSMemory);
function m() external pure returns (IMIPSMemory);
}
}
/// @notice MIPS memory (really "state", including registers and memory-mapped I/O)
interface IMIPSMemory {
interface IMIPSMemory {
// Adds a `(hash(anything) => anything)` entry to the mapping that underpins all the Merkle tries
/// @notice Adds a `(hash(anything) => anything)` entry to the mapping that underpins all the
// that this contract deals with (where "state hash" = Merkle root of such a trie).
/// Merkle tries that this contract deals with (where "state hash" = Merkle root of such
// Here, `anything` is supposed to be node data in such a trie.
/// a trie).
/// @param anything node data to add to the trie
function AddTrieNode(bytes calldata anything) external;
function AddTrieNode(bytes calldata anything) external;
function ReadMemory(bytes32 stateHash, uint32 addr) external view returns (uint32);
function ReadMemory(bytes32 stateHash, uint32 addr) external view returns (uint32);
function ReadBytes32(bytes32 stateHash, uint32 addr) external view returns (bytes32);
function ReadBytes32(bytes32 stateHash, uint32 addr) external view returns (bytes32);
// Write 32 bits at the given address and returns the updated state hash.
//
/ @notice
Write 32 bits at the given address and returns the updated state hash.
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 val) external returns (bytes32);
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 val) external returns (bytes32);
// Write 32 bytes at the given address and returns the updated state hash.
//
/ @notice
Write 32 bytes at the given address and returns the updated state hash.
function WriteBytes32(bytes32 stateHash, uint32 addr, bytes32 val) external returns (bytes32);
function WriteBytes32(bytes32 stateHash, uint32 addr, bytes32 val) external returns (bytes32);
}
}
/// @notice Implementation of the challenge game, which allows a challenger to challenge an L1 block
/// by asserting a different state root for the transition implied by the block's
/// transactions. The challenger plays against a defender (the owner of this contract),
/// which we assume acts honestly. The challenger and the defender perform a binary search
/// over the execution trace of the fault proof program (in this case minigeth), in order
/// to determine a single execution step that they disagree on, at which point that step
/// can be executed on-chain in order to determine if the challenge is valid.
contract Challenge {
contract Challenge {
address payable immutable owner;
address payable immutable owner;
IMIPS immutable mips;
IMIPS immutable mips;
IMIPSMemory immutable mem;
IMIPSMemory immutable mem;
// State hash of the fault proof program's initial MIPS state.
//
/ @notice
State hash of the fault proof program's initial MIPS state.
bytes32 immutable globalStartState;
bytes32 immutable globalStartState;
constructor(IMIPS _mips, bytes32 _globalStartState) {
constructor(IMIPS _mips, bytes32 _globalStartState) {
...
@@ -60,21 +70,12 @@ contract Challenge {
...
@@ -60,21 +70,12 @@ contract Challenge {
uint256 blockNumberN;
uint256 blockNumberN;
}
}
mapping(uint256 => ChallengeData) challenges;
// Allow sending money to the contract (without calldata).
receive() external payable {}
// Allows the owner to withdraw funds from the contract.
function withdraw() external {
require(msg.sender == owner, "not owner");
(bool sent, ) = owner.call{value: address(this).balance}("");
require(sent, "Failed to send Ether");
}
/// @notice ID if the last created challenged, incremented for new challenge IDs.
/// @notice ID if the last created challenged, incremented for new challenge IDs.
uint256 public lastChallengeId = 0;
uint256 public lastChallengeId = 0;
/// @notice Maps challenge IDs to challenge data.
mapping(uint256 => ChallengeData) challenges;
/// @notice Emitted when a new challenge is created.
/// @notice Emitted when a new challenge is created.
event ChallengeCreated(uint256 challengeId);
event ChallengeCreated(uint256 challengeId);
...
@@ -161,11 +162,6 @@ contract Challenge {
...
@@ -161,11 +162,6 @@ contract Challenge {
return challengeId;
return challengeId;
}
}
/// Before calling this, it is necessary to have loaded all the trie node necessary to
/// write the input hash in the Merkleized initial MIPS state, and to read the output hash
/// and machine state from the Merkleized final MIPS state (i.e. `finalSystemState`). Use
/// `MIPSMemory.AddTrieNode` for this purpose.
/// @notice Calling `initiateChallenge` requires some trie nodes to have been supplied beforehand,
/// @notice Calling `initiateChallenge` requires some trie nodes to have been supplied beforehand,
/// in order to be able to write the input hash in the Merkleized initial MIPS state, and
/// in order to be able to write the input hash in the Merkleized initial MIPS state, and
/// to read the output hash and machine state from the Merkleized final MIPS state.
/// to read the output hash and machine state from the Merkleized final MIPS state.
...
@@ -315,4 +311,13 @@ contract Challenge {
...
@@ -315,4 +311,13 @@ contract Challenge {
// consider the challenger mocked
// consider the challenger mocked
emit ChallengerLoses(challengeId);
emit ChallengerLoses(challengeId);
}
}
/// @notice Allow sending money to the contract (without calldata).
receive() external payable {}
/// @notice Allows the owner to withdraw funds from the contract.
function withdraw() external {
require(msg.sender == owner);
owner.transfer(address(this).balance);
}
}
}
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