Commit a8941d5a authored by clabby's avatar clabby

`LibPosition::rightIndex` update

parent b4d628a1
...@@ -154,7 +154,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone { ...@@ -154,7 +154,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
} }
// Assert that the given prestate commits to the instruction at `gindex - 1`. // Assert that the given prestate commits to the instruction at `gindex - 1`.
if (preStatePos.rightIndex(MAX_GAME_DEPTH) != Position.unwrap(stepPos) - 1) { if (Position.unwrap(preStatePos.rightIndex(MAX_GAME_DEPTH)) != Position.unwrap(stepPos) - 1) {
revert InvalidPrestate(); revert InvalidPrestate();
} }
} }
...@@ -304,7 +304,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone { ...@@ -304,7 +304,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// Search for the left-most dangling non-bottom node // Search for the left-most dangling non-bottom node
// The most recent claim is always a dangling, non-bottom node so we start with that // The most recent claim is always a dangling, non-bottom node so we start with that
uint256 leftMostIndex = claimData.length - 1; uint256 leftMostIndex = claimData.length - 1;
uint256 leftMostTraceIndex = claimData[leftMostIndex].position.rightIndex(MAX_GAME_DEPTH); Position leftMostTraceIndex = claimData[leftMostIndex].position.rightIndex(MAX_GAME_DEPTH);
for (uint256 i = leftMostIndex; i < type(uint64).max; ) { for (uint256 i = leftMostIndex; i < type(uint64).max; ) {
// Fetch the claim at the current index. // Fetch the claim at the current index.
ClaimData storage claim = claimData[i]; ClaimData storage claim = claimData[i];
...@@ -325,8 +325,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone { ...@@ -325,8 +325,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// If the claim is a dangling node, we can check if it is the left-most // If the claim is a dangling node, we can check if it is the left-most
// dangling node we've come across so far. If it is, we can update the // dangling node we've come across so far. If it is, we can update the
// left-most trace index. // left-most trace index.
uint256 traceIndex = claimPos.rightIndex(MAX_GAME_DEPTH); Position traceIndex = claimPos.rightIndex(MAX_GAME_DEPTH);
if (traceIndex < leftMostTraceIndex) { if (Position.unwrap(traceIndex) < Position.unwrap(leftMostTraceIndex)) {
leftMostTraceIndex = traceIndex; leftMostTraceIndex = traceIndex;
leftMostIndex = i + 1; leftMostIndex = i + 1;
} }
......
...@@ -99,7 +99,7 @@ library LibPosition { ...@@ -99,7 +99,7 @@ library LibPosition {
function rightIndex( function rightIndex(
Position _position, Position _position,
uint256 _maxDepth uint256 _maxDepth
) internal pure returns (uint64 rightIndex_) { ) internal pure returns (Position rightIndex_) {
uint256 msb = depth(_position); uint256 msb = depth(_position);
assembly { assembly {
switch eq(msb, _maxDepth) switch eq(msb, _maxDepth)
......
...@@ -105,15 +105,14 @@ contract LibPosition_Test is Test { ...@@ -105,15 +105,14 @@ 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);
uint64 rightIndex = position.rightIndex(_maxDepth); Position rightIndex = position.rightIndex(_maxDepth);
// Find the deepest, rightmost index in Solidity rather than Yul // Find the deepest, rightmost index in Solidity rather than Yul
for (uint256 i = _depth; i < _maxDepth; ++i) { for (uint256 i = _depth; i < _maxDepth; ++i) {
position = position.right(); position = position.right();
} }
uint64 _rightIndex = position.indexAtDepth();
assertEq(rightIndex, _rightIndex); assertEq(Position.unwrap(rightIndex), Position.unwrap(position));
} }
/** /**
......
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