Commit 44a42cc2 authored by clabby's avatar clabby

rm: `attack` / `defend`; add: `move`

gas snapshot
parent 27db7ed1
...@@ -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
......
...@@ -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))
} }
} }
} }
...@@ -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))))
......
...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment