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
98bfbd81
Commit
98bfbd81
authored
Sep 02, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix first `MIPS` tests
parent
e4b9e3b8
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
62 additions
and
31 deletions
+62
-31
faultdisputegame.go
op-bindings/bindings/faultdisputegame.go
+2
-2
faultdisputegame_more.go
op-bindings/bindings/faultdisputegame_more.go
+1
-1
mips.go
op-bindings/bindings/mips.go
+1
-1
mips_more.go
op-bindings/bindings/mips_more.go
+2
-2
MIPS.sol
packages/contracts-bedrock/src/cannon/MIPS.sol
+9
-4
DisputeGameFactory.sol
...ages/contracts-bedrock/src/dispute/DisputeGameFactory.sol
+0
-4
FaultDisputeGame.sol
packages/contracts-bedrock/src/dispute/FaultDisputeGame.sol
+4
-0
DisputeGameFactory.t.sol
packages/contracts-bedrock/test/DisputeGameFactory.t.sol
+6
-17
FaultDisputeGame.t.sol
packages/contracts-bedrock/test/FaultDisputeGame.t.sol
+16
-0
MIPS.t.sol
packages/contracts-bedrock/test/MIPS.t.sol
+21
-0
No files found.
op-bindings/bindings/faultdisputegame.go
View file @
98bfbd81
This diff is collapsed.
Click to expand it.
op-bindings/bindings/faultdisputegame_more.go
View file @
98bfbd81
This diff is collapsed.
Click to expand it.
op-bindings/bindings/mips.go
View file @
98bfbd81
This diff is collapsed.
Click to expand it.
op-bindings/bindings/mips_more.go
View file @
98bfbd81
This diff is collapsed.
Click to expand it.
packages/contracts-bedrock/src/cannon/MIPS.sol
View file @
98bfbd81
...
...
@@ -123,10 +123,15 @@ contract MIPS {
switch _exited
case 1 {
switch _exitCode
case 0 { status_ := 0 } // VMStatusValid
case 1 { status_ := 1 } // VMStatusInvalid
default { status_ := 2 } // VMStatusPanic
} default { status_ := 3 } // VMStatusUnfinished
// VMStatusValid
case 0 { status_ := 0 }
// VMStatusInvalid
case 1 { status_ := 1 }
// VMStatusPanic
default { status_ := 2 }
}
// VMStatusUnfinished
default { status_ := 3 }
}
let status := vmStatus(exited, exitCode)
...
...
packages/contracts-bedrock/src/dispute/DisputeGameFactory.sol
View file @
98bfbd81
...
...
@@ -91,10 +91,6 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, Semver {
// If there is no implementation to clone for the given `GameType`, revert.
if (address(impl) == address(0)) revert NoImplementation(_gameType);
// The VMStatus must indicate (1) 'invalid', to argue that disputed thing is invalid.
// Games that agree with the existing outcome are not allowed.
if (uint8(Claim.unwrap(_rootClaim)[0]) != 1) revert UnexpectedRootClaim(_rootClaim);
// Clone the implementation contract and initialize it with the given parameters.
proxy_ = IDisputeGame(address(impl).clone(abi.encodePacked(_rootClaim, _extraData)));
proxy_.initialize();
...
...
packages/contracts-bedrock/src/dispute/FaultDisputeGame.sol
View file @
98bfbd81
...
...
@@ -437,6 +437,10 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
// Implicit assumptions:
// - The `gameStatus` state variable defaults to 0, which is `GameStatus.IN_PROGRESS`
// The VMStatus must indicate (1) 'invalid', to argue that disputed thing is invalid.
// Games that agree with the existing outcome are not allowed.
if (uint8(Claim.unwrap(rootClaim())[0]) != 1) revert UnexpectedRootClaim(rootClaim());
// Set the game's starting timestamp
createdAt = Timestamp.wrap(uint64(block.timestamp));
...
...
packages/contracts-bedrock/test/DisputeGameFactory.t.sol
View file @
98bfbd81
...
...
@@ -36,12 +36,6 @@ contract DisputeGameFactory_Init is L2OutputOracle_Initializer {
}
contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init {
function changeClaimStatus(Claim claim, uint8 status) public pure returns (Claim _out) {
bytes32 hash = Claim.unwrap(claim);
hash = bytes32((uint256(hash) & (~(uint256(0xff) << 248))) | (uint256(status) << 248));
return Claim.wrap(hash);
}
/// @dev Tests that the `create` function succeeds when creating a new dispute game
/// with a `GameType` that has an implementation set.
function testFuzz_create_succeeds(uint8 gameType, Claim rootClaim, bytes calldata extraData) public {
...
...
@@ -83,17 +77,6 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init {
factory.create(gt, rootClaim, extraData);
}
/// @dev Tests that the `create` function reverts when the rootClaim does not disagree with the outcome.
function testFuzz_create_badRootStatus_reverts(uint8 gameType, Claim rootClaim, bytes calldata extraData) public {
// Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values.
GameType gt = GameType.wrap(uint8(bound(gameType, 0, 2)));
// Ensure the root claim does not have the correct VM status
if (uint8(Claim.unwrap(rootClaim)[0]) == 1) rootClaim = changeClaimStatus(rootClaim, 0);
vm.expectRevert(abi.encodeWithSelector(UnexpectedRootClaim.selector, rootClaim));
factory.create(gt, rootClaim, extraData);
}
/// @dev Tests that the `create` function reverts when there exists a dispute game with the same UUID.
function testFuzz_create_sameUUID_reverts(uint8 gameType, Claim rootClaim, bytes calldata extraData) public {
// Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values.
...
...
@@ -122,6 +105,12 @@ contract DisputeGameFactory_Create_Test is DisputeGameFactory_Init {
);
factory.create(gt, rootClaim, extraData);
}
function changeClaimStatus(Claim claim, uint8 status) public pure returns (Claim _out) {
bytes32 hash = Claim.unwrap(claim);
hash = bytes32((uint256(hash) & (~(uint256(0xff) << 248))) | (uint256(status) << 248));
return Claim.wrap(hash);
}
}
contract DisputeGameFactory_SetImplementation_Test is DisputeGameFactory_Init {
...
...
packages/contracts-bedrock/test/FaultDisputeGame.t.sol
View file @
98bfbd81
...
...
@@ -143,6 +143,16 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
factory.create(GAME_TYPE, ROOT_CLAIM, abi.encode(1800, block.number - 1));
}
/// @dev Tests that the `create` function reverts when the rootClaim does not disagree with the outcome.
function testFuzz_initialize_badRootStatus_reverts(Claim rootClaim, bytes calldata extraData) public {
// Ensure that the `gameType` is within the bounds of the `GameType` enum's possible values.
// Ensure the root claim does not have the correct VM status
if (uint8(Claim.unwrap(rootClaim)[0]) == 1) rootClaim = changeClaimStatus(rootClaim, 0);
vm.expectRevert(abi.encodeWithSelector(UnexpectedRootClaim.selector, rootClaim));
factory.create(GameTypes.FAULT, rootClaim, extraData);
}
/// @dev Tests that the game is initialized with the correct data.
function test_initialize_correctData_succeeds() public {
// Starting
...
...
@@ -449,6 +459,12 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
bytes32 h = keccak256(abi.encode(_ident | (1 << 248), address(gameProxy)));
return bytes32((uint256(h) & ~uint256(0xFF << 248)) | (1 << 248));
}
function changeClaimStatus(Claim claim, uint8 status) public pure returns (Claim _out) {
bytes32 hash = Claim.unwrap(claim);
hash = bytes32((uint256(hash) & (~(uint256(0xff) << 248))) | (uint256(status) << 248));
return Claim.wrap(hash);
}
}
/// @notice A generic game player actor with a configurable trace.
...
...
packages/contracts-bedrock/test/MIPS.t.sol
View file @
98bfbd81
...
...
@@ -1553,10 +1553,31 @@ contract MIPS_Test is CommonTest {
);
}
/// @dev MIPS VM status codes:
/// 0. Exited with success (Valid)
/// 1. Exited with success (Invalid)
/// 2. Exited with failure (Panic)
/// 3. Unfinished
function vmStatus(MIPS.State memory state) internal pure returns (uint8 out_) {
if (state.exited) {
if (state.exitCode == 0) {
return 0;
} else if (state.exitCode == 1) {
return 1;
} else {
return 2;
}
} else {
return 3;
}
}
function outputState(MIPS.State memory state) internal pure returns (bytes32 out_) {
bytes memory enc = encodeState(state);
uint8 status = vmStatus(state);
assembly {
out_ := keccak256(add(enc, 0x20), 226)
out_ := or(and(not(shl(248, 0xFF)), out_), shl(248, status))
}
}
...
...
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