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
b1cf7a64
Commit
b1cf7a64
authored
Mar 09, 2022
by
Nicolas "Norswap" Laurent
Committed by
norswap
Mar 17, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
document callWithTrieNodes
parent
a87200d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
18 deletions
+32
-18
Challenge.sol
contracts/Challenge.sol
+32
-18
No files found.
contracts/Challenge.sol
View file @
b1cf7a64
...
...
@@ -72,28 +72,12 @@ contract Challenge {
require(sent, "Failed to send Ether");
}
// 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;
// Emitted when a new challenge is created.
//
/ @notice
Emitted when a new challenge is created.
event ChallengeCreated(uint256 challengeId);
// helper function to determine what nodes we need
function callWithTrieNodes(address target, bytes calldata dat, bytes[] calldata nodes) public {
for (uint i = 0; i < nodes.length; i++) {
mem.AddTrieNode(nodes[i]);
}
(bool success, bytes memory revertData) = target.call(dat);
// TODO: better way to revert?
if (!success) {
uint256 revertDataLength = revertData.length;
assembly {
let revertDataStart := add(revertData, 32)
revert(revertDataStart, revertDataLength)
}
}
}
/// @notice Challenges the transition from block `blockNumberN` to the next block (N+1), which is
/// the block being challenged.
/// Before calling this, it is necessary to have loaded all the trie node necessary to
...
...
@@ -177,6 +161,36 @@ contract Challenge {
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,
/// 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.
/// This function can be used to figure out which nodes are needed, as memory-reading
/// functions in MIPSMemory.sol will revert with the missing node ID when a node is
/// missing. Therefore, you can call this function repeatedly via `eth_call`, and
/// iteratively build the list of required node until the call succeeds.
/// @param target The contract to call to (usually this contract)
/// @param dat The data to include in the call (usually the calldata for a call to
/// `initiateChallenge`
/// @param nodes The nodes to add the MIPS state trie before making the call
function callWithTrieNodes(address target, bytes calldata dat, bytes[] calldata nodes) public {
for (uint i = 0; i < nodes.length; i++) {
mem.AddTrieNode(nodes[i]);
}
(bool success, bytes memory revertData) = target.call(dat);
if (!success) {
uint256 revertDataLength = revertData.length;
assembly {
let revertDataStart := add(revertData, 32)
revert(revertDataStart, revertDataLength)
}
}
}
/// @notice Indicates whether the given challenge is still searching (true), or if the single step
/// of disagreement has been found (false).
function isSearching(uint256 challengeId) view public returns (bool) {
...
...
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