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
565cd748
Commit
565cd748
authored
Jun 10, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Broken mock `step` func
parent
4feb8a58
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
8 deletions
+61
-8
FaultDisputeGame.sol
.../contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
+45
-6
IFaultDisputeGame.sol
...edrock/contracts/dispute/interfaces/IFaultDisputeGame.sol
+11
-2
DisputeErrors.sol
...s/contracts-bedrock/contracts/libraries/DisputeErrors.sol
+5
-0
No files found.
packages/contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
View file @
565cd748
...
...
@@ -98,8 +98,38 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
/**
* @inheritdoc IFaultDisputeGame
*/
function step(ClaimHash disagreement) public {
function step(
uint256 parentIndex,
bytes32 stateHash,
bytes calldata stateData,
bytes calldata
) public {
// TODO - Call the VM to perform the execution step.
// Mock a state transition
// NOTE: This mock lacks several necessary checks. For testing only.
uint256 inp = abi.decode(stateData, (uint256));
bytes32 nextStateHash = bytes32(uint256(stateHash) + inp);
ClaimData memory parent = claimData[parentIndex];
if (nextStateHash != Claim.unwrap(parent.claim)) {
revert("Invalid state transition");
}
// If the state transition was successful, append a new claim to the game at the
// `MAX_GAME_DEPTH`
Position nextPosition = LibPosition.attack(parent.position);
claimData.push(
ClaimData({
parentIndex: uint32(parentIndex),
claim: Claim.wrap(nextStateHash),
position: nextPosition,
clock: Clock.wrap(0),
rc: 0,
countered: false
})
);
}
////////////////////////////////////////////////////////////////
...
...
@@ -149,6 +179,13 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
? LibPosition.attack(parent.position)
: LibPosition.defend(parent.position);
// At the leaf nodes of the game, the only option is to run a step to prove or disprove
// the above claim. At this depth, the parent claim commits to the state after a single
// instruction step.
if (LibPosition.depth(nextPosition) >= MAX_GAME_DEPTH) {
revert GameDepthExceeded();
}
// Fetch the grandparent clock, if it exists.
// The grandparent clock should always exist unless the parent is the root claim.
Clock grandparentClock;
...
...
@@ -170,7 +207,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
)
);
// Enforce the clock time. If the new clock duration is greater than half of the game
// Enforce the clock time
rules
. If the new clock duration is greater than half of the game
// duration, then the move is invalid and cannot be made.
if (Duration.unwrap(nextDuration) > Duration.unwrap(GAME_DURATION) >> 1) {
revert ClockTimeExceeded();
...
...
@@ -241,7 +278,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// Run an exhaustive search (`O(n)`) over the DAG to find the left most, deepest
// uncontested claim.
for (; i > 0;
i--
) {
for (; i > 0;
--i
) {
ClaimData memory claim = claimData[i];
// If the claim has no refereces, we can virtually prune it.
...
...
@@ -255,12 +292,14 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// we're concerned about.
// All claims that pass this check qualify for pruning.
if (depth != MAX_GAME_DEPTH && !claim.countered) {
uint128 leftMostDepth = LibPosition.depth(leftMost);
// If the claim here is deeper than the current left most, deepest claim,
// update `leftMost`.
// If the claim here is at the same depth, but further left, update `leftMost`.
if (
depth >
LibPosition.depth(leftMost)
||
(depth ==
LibPosition.depth(leftMost)
&&
depth >
leftMostDepth
||
(depth ==
leftMostDepth
&&
LibPosition.indexAtDepth(position) <=
LibPosition.indexAtDepth(leftMost))
) {
...
...
@@ -272,7 +311,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// effectively "prunes" the claim from the DAG without spending extra gas on
// deleting it from storage.
if (claim.parentIndex != type(uint32).max) {
claimData[claim.parentIndex].rc -= 1
;
--claimData[claim.parentIndex].rc
;
}
}
}
...
...
packages/contracts-bedrock/contracts/dispute/interfaces/IFaultDisputeGame.sol
View file @
565cd748
...
...
@@ -62,7 +62,16 @@ interface IFaultDisputeGame is IDisputeGame {
* a step in the fault proof program on-chain. The interface of the fault proof
* processor contract should be generic enough such that we can use different
* fault proof VMs (MIPS, RiscV5, etc.)
* @param disagreement The ClaimHash of the disagreement
* @param parentIndex The index of the parent claim in `claimData`. Contains the state hash
* of the post-state.
* @param stateHash The initial merklized prestate.
* @param stateData The input for the state transition.
* @param proof The proof that the state transition is valid.
*/
function step(ClaimHash disagreement) external;
function step(
uint256 parentIndex,
bytes32 stateHash,
bytes calldata stateData,
bytes calldata proof
) external;
}
packages/contracts-bedrock/contracts/libraries/DisputeErrors.sol
View file @
565cd748
...
...
@@ -55,6 +55,11 @@ error ParentDoesNotExist();
*/
error ClockTimeExceeded();
/**
* @notice Thrown when a move is attempted to be made at the max depth of the game.
*/
error GameDepthExceeded();
////////////////////////////////////////////////////////////////
// `AttestationDisputeGame` Errors //
////////////////////////////////////////////////////////////////
...
...
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