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
2d17ec5d
Commit
2d17ec5d
authored
Jun 20, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add start of alphabet `step` func
parent
3589cb98
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
6 deletions
+78
-6
FaultDisputeGame.sol
.../contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
+58
-4
IFaultDisputeGame.sol
...edrock/contracts/dispute/interfaces/IFaultDisputeGame.sol
+4
-2
DisputeErrors.sol
...s/contracts-bedrock/contracts/libraries/DisputeErrors.sol
+16
-0
No files found.
packages/contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
View file @
2d17ec5d
...
...
@@ -92,12 +92,66 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
* @inheritdoc IFaultDisputeGame
*/
function step(
uint256 _
pre
stateIndex,
uint256 _stateIndex,
uint256 _parentIndex,
bytes calldata _stateData,
bytes calldata _proof
bool _isAttack,
bytes calldata,
bytes calldata
) external {
// TODO - Call the VM to perform the execution step.
// TODO: Determine where the prestate for the full trace comes from (i.e. instruction 0 -> 1)
// This will likely be in the preimage oracle, but this function currently does not
// support an attack step against the first trace instruction.
// Steps cannot be made unless the game is currently in progress.
if (status != GameStatus.IN_PROGRESS) {
revert GameNotInProgress();
}
// Get the parent. If it does not exist, the call will revert with OOB.
ClaimData storage parent = claimData[_parentIndex];
// Get the pre/post state. If it does not exist, the call will revert with OOB.
ClaimData storage state = claimData[_stateIndex];
// Pull the parent position out of storage.
Position parentPos = parent.position;
// Determine the position of the step.
Position stepPos = _isAttack ? parentPos.attack() : parentPos.defend();
// Ensure that the step position is at the maximum game depth.
if (stepPos.depth() != MAX_GAME_DEPTH) {
revert InvalidParent();
}
// Determine the expected pre & post states of the step.
ClaimData storage preState;
Claim postStateClaim;
if (_isAttack) {
// If the step is an attack, the prestate exists elsewhere in the game state,
// and the parent claim is the expected post-state.
preState = state;
postStateClaim = parent.claim;
} else {
// If the step is a defense, the poststate exists elsewhere in the game state,
// and the parent claim is the expected pre-state.
preState = parent;
postStateClaim = state.claim;
}
// Assert that the prestate commits to the instruction at `gindex - 1`
if (preState.position.rightIndex(MAX_GAME_DEPTH) != Position.unwrap(stepPos) - 1) {
revert InvalidStep();
}
// TODO: Call `MIPS.sol#step` to verify the step.
// For now, we just use a simple state transition function that increments the prestate,
// `s_p`, by 1.
if (uint256(Claim.unwrap(preState.claim)) + 1 != uint256(Claim.unwrap(postStateClaim))) {
revert InvalidStep();
}
// Set the parent claim as countered. We do not need to append a new claim to the game;
// instead, we can just set the existing parent as countered.
parent.countered = true;
}
////////////////////////////////////////////////////////////////
...
...
packages/contracts-bedrock/contracts/dispute/interfaces/IFaultDisputeGame.sol
View file @
2d17ec5d
...
...
@@ -51,14 +51,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 _
prestateIndex The index of the pre
state of the step within `claimData`.
* @param _
stateIndex The index of the pre/post
state of the step within `claimData`.
* @param _parentIndex The index of the parent claim within `claimData`.
* @param _isAttack Whether or not the step is an attack or a defense.
* @param _stateData The stateData of the step is the preimage of the claim @ `prestateIndex`
* @param _proof Proof to access memory leaf nodes in the VM.
*/
function step(
uint256 _
pre
stateIndex,
uint256 _stateIndex,
uint256 _parentIndex,
bool _isAttack,
bytes calldata _stateData,
bytes calldata _proof
) external;
...
...
packages/contracts-bedrock/contracts/libraries/DisputeErrors.sol
View file @
2d17ec5d
...
...
@@ -60,6 +60,22 @@ error ClockTimeExceeded();
*/
error GameDepthExceeded();
/**
* @notice Thrown when a step is attempted above the maximum game depth.
*/
error InvalidParent();
/**
* @notice Thrown when an invalid prestate is supplied to `step`.
*/
error InvalidPrestate();
/**
* @notice Thrown when a step is attempted to be made where the post state does not match
* what was expected.
*/
error InvalidStep();
////////////////////////////////////////////////////////////////
// `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