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
ed8c2527
Commit
ed8c2527
authored
Dec 08, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
:broom:
parent
9ee84e27
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
144 additions
and
112 deletions
+144
-112
OutputBisectionActors.sol
...s/contracts-bedrock/test/actors/OutputBisectionActors.sol
+76
-77
OutputBisectionGame.t.sol
.../contracts-bedrock/test/dispute/OutputBisectionGame.t.sol
+68
-35
No files found.
packages/contracts-bedrock/test/actors/OutputBisectionActors.sol
View file @
ed8c2527
This diff is collapsed.
Click to expand it.
packages/contracts-bedrock/test/dispute/OutputBisectionGame.t.sol
View file @
ed8c2527
...
@@ -657,32 +657,37 @@ contract OutputBisection_1v1_Actors_Test is OutputBisectionGame_Init {
...
@@ -657,32 +657,37 @@ contract OutputBisection_1v1_Actors_Test is OutputBisectionGame_Init {
/// @notice Static unit test for a 1v1 output bisection dispute.
/// @notice Static unit test for a 1v1 output bisection dispute.
function test_static_1v1honestRoot_succeeds() public {
function test_static_1v1honestRoot_succeeds() public {
// Create the dispute game with an honest `ROOT_CLAIM`
// Create the dispute game with an honest `ROOT_CLAIM`
bytes memory absolutePrestateData = abi.encode(0);
bytes memory absolutePrestateData = _setup({ _absolutePrestateData: 0, _rootClaim: 16 });
Claim absolutePrestateExec =
_changeClaimStatus(Claim.wrap(keccak256(absolutePrestateData)), VMStatuses.UNFINISHED);
Claim rootClaim = Claim.wrap(bytes32(uint256(0x10)));
super.init({
rootClaim: rootClaim,
absolutePrestate: absolutePrestateExec,
l2BlockNumber: 0x10,
genesisBlockNumber: 0,
genesisOutputRoot: Hash.wrap(bytes32(0))
});
// The honest l2 outputs are from [1, 16] in this game.
uint256[] memory honestL2Outputs = new uint256[](16);
for (uint256 i; i < honestL2Outputs.length; i++) {
honestL2Outputs[i] = i + 1;
}
// The honest trace covers all block -> block + 1 transitions, and is 256 bytes long, consisting
// The honest trace covers all block -> block + 1 transitions, and is 256 bytes long, consisting
// of bytes [0, 255].
// of bytes [0, 255].
bytes memory honestTrace = new bytes(256);
bytes memory honestTrace = new bytes(256);
for (uint256 i; i < honestTrace.length; i++) {
for (uint256 i; i < honestTrace.length; i++) {
honestTrace[i] = bytes1(uint8(i));
honestTrace[i] = bytes1(uint8(i));
}
}
// The dishonest l2 outputs are from [2, 17] in this game.
uint256[] memory dishonestL2Outputs = new uint256[](16);
for (uint256 i; i < dishonestL2Outputs.length; i++) {
dishonestL2Outputs[i] = i + 2;
}
// The dishonest trace covers all block -> block + 1 transitions, and is 256 bytes long, consisting
// of all zeros.
bytes memory dishonestTrace = new bytes(256);
// Create actors
// Create actors
_createActors({
_createActors({
_honestTrace: honestTrace,
_honestTrace: honestTrace,
_honestPreStateData: absolutePrestateData,
_honestPreStateData: absolutePrestateData,
_honest
StartingBlock: 0
,
_honest
L2Outputs: honestL2Outputs
,
_dishonestTrace:
new bytes(256)
,
_dishonestTrace:
dishonestTrace
,
_dishonestPreStateData: absolutePrestateData,
_dishonestPreStateData: absolutePrestateData,
_dishonest
StartingBlock: 1
_dishonest
L2Outputs: dishonestL2Outputs
});
});
// Exhaust all moves from both actors
// Exhaust all moves from both actors
...
@@ -696,24 +701,25 @@ contract OutputBisection_1v1_Actors_Test is OutputBisectionGame_Init {
...
@@ -696,24 +701,25 @@ contract OutputBisection_1v1_Actors_Test is OutputBisectionGame_Init {
/// @notice Static unit test for a 1v1 output bisection dispute.
/// @notice Static unit test for a 1v1 output bisection dispute.
function test_static_1v1dishonestRoot_succeeds() public {
function test_static_1v1dishonestRoot_succeeds() public {
// Create the dispute game with an honest `ROOT_CLAIM`
// Create the dispute game with an honest `ROOT_CLAIM`
bytes memory absolutePrestateData = abi.encode(0);
bytes memory absolutePrestateData = _setup({ _absolutePrestateData: 0, _rootClaim: 17 });
Claim absolutePrestateExec =
_changeClaimStatus(Claim.wrap(keccak256(absolutePrestateData)), VMStatuses.UNFINISHED);
Claim rootClaim = Claim.wrap(bytes32(uint256(0x11)));
super.init({
rootClaim: rootClaim,
absolutePrestate: absolutePrestateExec,
l2BlockNumber: 0x11,
genesisBlockNumber: 0,
genesisOutputRoot: Hash.wrap(bytes32(0))
});
// The honest l2 outputs are from [1, 16] in this game.
uint256[] memory honestL2Outputs = new uint256[](16);
for (uint256 i; i < honestL2Outputs.length; i++) {
honestL2Outputs[i] = i + 1;
}
// The honest trace covers all block -> block + 1 transitions, and is 256 bytes long, consisting
// The honest trace covers all block -> block + 1 transitions, and is 256 bytes long, consisting
// of bytes [0, 255].
// of bytes [0, 255].
bytes memory honestTrace = new bytes(256);
bytes memory honestTrace = new bytes(256);
for (uint256 i; i < honestTrace.length; i++) {
for (uint256 i; i < honestTrace.length; i++) {
honestTrace[i] = bytes1(uint8(i));
honestTrace[i] = bytes1(uint8(i));
}
}
// The dishonest l2 outputs are from [2, 17] in this game.
uint256[] memory dishonestL2Outputs = new uint256[](16);
for (uint256 i; i < dishonestL2Outputs.length; i++) {
dishonestL2Outputs[i] = i + 2;
}
// The dishonest trace covers all block -> block + 1 transitions, and is 256 bytes long, consisting
// The dishonest trace covers all block -> block + 1 transitions, and is 256 bytes long, consisting
// of all zeros.
// of all zeros.
bytes memory dishonestTrace = new bytes(256);
bytes memory dishonestTrace = new bytes(256);
...
@@ -722,40 +728,67 @@ contract OutputBisection_1v1_Actors_Test is OutputBisectionGame_Init {
...
@@ -722,40 +728,67 @@ contract OutputBisection_1v1_Actors_Test is OutputBisectionGame_Init {
_createActors({
_createActors({
_honestTrace: honestTrace,
_honestTrace: honestTrace,
_honestPreStateData: absolutePrestateData,
_honestPreStateData: absolutePrestateData,
_honest
StartingBlock: 0
,
_honest
L2Outputs: honestL2Outputs
,
_dishonestTrace: dishonestTrace,
_dishonestTrace: dishonestTrace,
_dishonestPreStateData: absolutePrestateData,
_dishonestPreStateData: absolutePrestateData,
_dishonest
StartingBlock: 1
_dishonest
L2Outputs: dishonestL2Outputs
});
});
// Exhaust all moves from both actors
// Exhaust all moves from both actors
_exhaustMoves();
_exhaustMoves();
// Resolve the game and assert that the
defend
er won
// Resolve the game and assert that the
challeng
er won
_warpAndResolve();
_warpAndResolve();
assertEq(uint8(gameProxy.status()), uint8(GameStatus.CHALLENGER_WINS));
assertEq(uint8(gameProxy.status()), uint8(GameStatus.CHALLENGER_WINS));
}
}
////////////////////////////////////////////////////////////////
// HELPERS //
////////////////////////////////////////////////////////////////
/// @dev Helper to setup the 1v1 test
function _setup(
uint256 _absolutePrestateData,
uint256 _rootClaim
)
internal
returns (bytes memory absolutePrestateData_)
{
absolutePrestateData_ = abi.encode(_absolutePrestateData);
Claim absolutePrestateExec =
_changeClaimStatus(Claim.wrap(keccak256(absolutePrestateData_)), VMStatuses.UNFINISHED);
Claim rootClaim = Claim.wrap(bytes32(uint256(_rootClaim)));
super.init({
rootClaim: rootClaim,
absolutePrestate: absolutePrestateExec,
l2BlockNumber: _rootClaim,
genesisBlockNumber: 0,
genesisOutputRoot: Hash.wrap(bytes32(0))
});
}
/// @dev Helper to create actors for the 1v1 dispute.
/// @dev Helper to create actors for the 1v1 dispute.
function _createActors(
function _createActors(
bytes memory _honestTrace,
bytes memory _honestTrace,
bytes memory _honestPreStateData,
bytes memory _honestPreStateData,
uint256
_honestStartingBlock
,
uint256
[] memory _honestL2Outputs
,
bytes memory _dishonestTrace,
bytes memory _dishonestTrace,
bytes memory _dishonestPreStateData,
bytes memory _dishonestPreStateData,
uint256 _dishonestStartingBlock
uint256[] memory _dishonestL2Outputs
) internal {
)
internal
{
honest = new HonestDisputeActor({
honest = new HonestDisputeActor({
_gameProxy: gameProxy,
_gameProxy: gameProxy,
_l2Outputs: _honestL2Outputs,
_trace: _honestTrace,
_trace: _honestTrace,
_preStateData: _honestPreStateData,
_preStateData: _honestPreStateData
_startingL2BlockNumber: _honestStartingBlock
});
});
dishonest = new HonestDisputeActor({
dishonest = new HonestDisputeActor({
_gameProxy: gameProxy,
_gameProxy: gameProxy,
_l2Outputs: _dishonestL2Outputs,
_trace: _dishonestTrace,
_trace: _dishonestTrace,
_preStateData: _dishonestPreStateData,
_preStateData: _dishonestPreStateData
_startingL2BlockNumber: _dishonestStartingBlock
});
});
vm.label(address(honest), "HonestActor");
vm.label(address(honest), "HonestActor");
...
...
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