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
44a42cc2
Commit
44a42cc2
authored
Jun 20, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rm: `attack` / `defend`; add: `move`
gas snapshot
parent
27db7ed1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
26 deletions
+13
-26
FaultDisputeGame.sol
.../contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
+2
-2
LibPosition.sol
...s/contracts-bedrock/contracts/dispute/lib/LibPosition.sol
+8
-21
FaultDisputeGame.t.sol
...s/contracts-bedrock/contracts/test/FaultDisputeGame.t.sol
+1
-1
LibPosition.t.sol
packages/contracts-bedrock/contracts/test/LibPosition.t.sol
+2
-2
No files found.
packages/contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
View file @
44a42cc2
...
@@ -123,7 +123,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
...
@@ -123,7 +123,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// Pull the parent position out of storage.
// Pull the parent position out of storage.
Position parentPos = parent.position;
Position parentPos = parent.position;
// Determine the position of the step.
// Determine the position of the step.
Position stepPos =
_isAttack ? parentPos.attack() : parentPos.defend(
);
Position stepPos =
parentPos.move(_isAttack
);
// Ensure that the step position is 1 deeper than the maximum game depth.
// Ensure that the step position is 1 deeper than the maximum game depth.
if (stepPos.depth() != MAX_GAME_DEPTH + 1) {
if (stepPos.depth() != MAX_GAME_DEPTH + 1) {
...
@@ -214,7 +214,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
...
@@ -214,7 +214,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// Compute the position that the claim commits to. Because the parent's position is already
// Compute the position that the claim commits to. Because the parent's position is already
// known, we can compute the next position by moving left or right depending on whether
// known, we can compute the next position by moving left or right depending on whether
// or not the move is an attack or defense.
// or not the move is an attack or defense.
Position nextPosition =
_isAttack ? parent.position.attack() : parent.position.defend(
);
Position nextPosition =
parent.position.move(_isAttack
);
// At the leaf nodes of the game, the only option is to run a step to prove or disprove
// 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
// the above claim. At this depth, the parent claim commits to the state after a single
...
...
packages/contracts-bedrock/contracts/dispute/lib/LibPosition.sol
View file @
44a42cc2
...
@@ -126,29 +126,16 @@ library LibPosition {
...
@@ -126,29 +126,16 @@ library LibPosition {
}
}
/**
/**
* @notice Get the attack position relative to `position`. The attack position is the next
* @notice Get the move position of `_position`, which is the left child of:
* logical point of bisection if the parent claim is disagreed with, which is the
* 1. `_position + 1` if `_isAttack` is true.
* midway point of the trace that the attacked node commits to.
* 1. `_position` if `_isAttack` is false.
* @param _position The position to get the relative attack position of.
* @param _position The position to get the relative attack/defense position of.
* @return attack_ The attack position relative to `position`.
* @param _isAttack Whether or not the move is a defense move.
* @return move_ The move position relative to `position`.
*/
*/
function attack(Position _position) internal pure returns (Position attack_) {
function move(Position _position, bool _isAttack) internal pure returns (Position move_) {
// Move: Left
return left(_position);
}
/**
* @notice Get the defense position relative to `position`. The defense position is the next
* logical point of bisection if the parent claim and the grandparent claim are agreed
* with, which is at the midway point of the trace that the defended node's right
* sibling commits to.
* @param _position The position to get the relative defense position of.
* @return defense_ The defense position relative to `position`.
*/
function defend(Position _position) internal pure returns (Position defense_) {
assembly {
assembly {
// Move: Parent -> Right -> Left
move_ := shl(1, or(iszero(_isAttack), _position))
defense_ := shl(1, or(1, _position))
}
}
}
}
}
}
packages/contracts-bedrock/contracts/test/FaultDisputeGame.t.sol
View file @
44a42cc2
...
@@ -250,7 +250,7 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
...
@@ -250,7 +250,7 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
assertEq(parentIndex, 0);
assertEq(parentIndex, 0);
assertEq(countered, false);
assertEq(countered, false);
assertEq(Claim.unwrap(claim), Claim.unwrap(counter));
assertEq(Claim.unwrap(claim), Claim.unwrap(counter));
assertEq(Position.unwrap(position), Position.unwrap(Position.wrap(1).
attack(
)));
assertEq(Position.unwrap(position), Position.unwrap(Position.wrap(1).
move(true
)));
assertEq(
assertEq(
Clock.unwrap(clock),
Clock.unwrap(clock),
Clock.unwrap(LibClock.wrap(Duration.wrap(5), Timestamp.wrap(uint64(block.timestamp))))
Clock.unwrap(LibClock.wrap(Duration.wrap(5), Timestamp.wrap(uint64(block.timestamp))))
...
...
packages/contracts-bedrock/contracts/test/LibPosition.t.sol
View file @
44a42cc2
...
@@ -126,7 +126,7 @@ contract LibPosition_Test is Test {
...
@@ -126,7 +126,7 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position attack = position.
attack(
);
Position attack = position.
move(true
);
assertEq(attack.depth(), _depth + 1);
assertEq(attack.depth(), _depth + 1);
assertEq(attack.indexAtDepth(), _indexAtDepth * 2);
assertEq(attack.indexAtDepth(), _indexAtDepth * 2);
...
@@ -144,7 +144,7 @@ contract LibPosition_Test is Test {
...
@@ -144,7 +144,7 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position defend = position.
defend(
);
Position defend = position.
move(false
);
assertEq(defend.depth(), _depth + 1);
assertEq(defend.depth(), _depth + 1);
assertEq(defend.indexAtDepth(), ((_indexAtDepth / 2) * 2 + 1) * 2);
assertEq(defend.indexAtDepth(), ((_indexAtDepth / 2) * 2 + 1) * 2);
...
...
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