Skip to content

Commit

Permalink
Merge pull request ethereum-optimism#31 from JustXxx/develop_1.20_nary4
Browse files Browse the repository at this point in the history
Support Nary=4, draft version
  • Loading branch information
JustXxx authored Jun 23, 2024
2 parents 6a2d8fe + dee83c0 commit b37e73d
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 3,476 deletions.
945 changes: 0 additions & 945 deletions packages/contracts-bedrock/src/dispute/FaultDisputeGame2.sol

This file was deleted.

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/contracts-bedrock/src/dispute/lib/LibPosition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ library LibPosition {
}
}

function moveN(Position _position, uint256 _bits, uint64 _branch) internal pure returns (Position move_) {
assembly {
move_ := shl(_bits, or(_branch, _position))
}
}

/// @notice Get the value of a `Position` type in the form of the underlying uint128.
/// @param _position The position to get the value of.
/// @return raw_ The value of the `position` as a uint128 type.
Expand Down
418 changes: 0 additions & 418 deletions packages/contracts-bedrock/test/actors/FaultDisputeActors2.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.15;

import { CommonBase } from "forge-std/Base.sol";

import { FaultDisputeGame } from "src/dispute/FaultDisputeGame3.sol";
import { FaultDisputeGame } from "src/dispute/FaultDisputeGameN.sol";
import { IFaultDisputeGame } from "src/dispute/interfaces/IFaultDisputeGame.sol";

import "src/dispute/lib/Types.sol";
Expand Down
2,045 changes: 0 additions & 2,045 deletions packages/contracts-bedrock/test/dispute/FaultDisputeGame2.t.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Test } from "forge-std/Test.sol";
import { Vm } from "forge-std/Vm.sol";
import { DisputeGameFactory_Init } from "test/dispute/DisputeGameFactory.t.sol";
import { DisputeGameFactory } from "src/dispute/DisputeGameFactory.sol";
import { FaultDisputeGame, IDisputeGame } from "src/dispute/FaultDisputeGame3.sol";
import { FaultDisputeGame, IDisputeGame } from "src/dispute/FaultDisputeGameN.sol";
import { DelayedWETH } from "src/dispute/weth/DelayedWETH.sol";
import { PreimageOracle } from "src/cannon/PreimageOracle.sol";

Expand All @@ -20,7 +20,7 @@ import { IPreimageOracle } from "src/dispute/interfaces/IBigStepper.sol";
import { IAnchorStateRegistry } from "src/dispute/interfaces/IAnchorStateRegistry.sol";
import { AlphabetVM } from "test/mocks/AlphabetVM.sol";

import { DisputeActor, HonestDisputeActor } from "test/actors/FaultDisputeActors3.sol";
import { DisputeActor, HonestDisputeActor } from "test/actors/FaultDisputeActorsN.sol";

contract FaultDisputeGame_Init is DisputeGameFactory_Init {
/// @dev The type of the game being tested.
Expand Down Expand Up @@ -86,7 +86,7 @@ contract FaultDisputeGame_Init is DisputeGameFactory_Init {
receive() external payable { }
}

contract FaultDisputeGame3_Test is FaultDisputeGame_Init {
contract FaultDisputeGameN_Test is FaultDisputeGame_Init {
/// @dev The root claim of the game.
Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32((uint256(1) << 248) | uint256(10)));

Expand Down Expand Up @@ -795,26 +795,22 @@ contract FaultDisputeGame3_Test is FaultDisputeGame_Init {

// Make claims all the way down the tree.
(,,,, Claim disputed,,) = gameProxy.claimData(0);
gameProxy.attack{ value: _getRequiredBond(0) }(disputed, 0, _dummyClaim());
gameProxy.attackV2{ value: _getRequiredBondV2(0, 0) }(disputed, 0, _dummyClaim(), 0);

(,,,, disputed,,) = gameProxy.claimData(1);
gameProxy.attack{ value: _getRequiredBond(1) }(disputed, 1, _dummyClaim());
gameProxy.attackV2{ value: _getRequiredBondV2(1, 0) }(disputed, 1, _dummyClaim(), 0);

(,,,, disputed,,) = gameProxy.claimData(2);
gameProxy.attack{ value: _getRequiredBond(2) }(disputed, 2, _dummyClaim());
gameProxy.attackV2{ value: _getRequiredBondV2(2, 0) }(disputed, 2, _changeClaimStatus(_dummyClaim(), VMStatuses.PANIC), 0);

(,,,, disputed,,) = gameProxy.claimData(3);
gameProxy.attack{ value: _getRequiredBond(3) }(disputed, 3, _dummyClaim());
(,,,, disputed,,) = gameProxy.claimData(4);
gameProxy.attack{ value: _getRequiredBond(4) }(disputed, 4, _changeClaimStatus(_dummyClaim(), VMStatuses.PANIC));
(,,,, disputed,,) = gameProxy.claimData(5);
gameProxy.attack{ value: _getRequiredBond(5) }(disputed, 5, _dummyClaim());
(,,,, disputed,,) = gameProxy.claimData(6);
gameProxy.attack{ value: _getRequiredBond(6) }(disputed, 6, _dummyClaim());
(,,,, disputed,,) = gameProxy.claimData(7);
gameProxy.attack{ value: _getRequiredBond(7) }(disputed, 7, _dummyClaim());
gameProxy.addLocalData(LocalPreimageKey.DISPUTED_L2_BLOCK_NUMBER, 8, 0);
gameProxy.step(8, true, absolutePrestateData, hex"");
gameProxy.attackV2{ value: _getRequiredBondV2(3, 0) }(disputed, 3, _dummyClaim(), 0);

gameProxy.addLocalData(LocalPreimageKey.DISPUTED_L2_BLOCK_NUMBER, 4, 0);
gameProxy.stepV2(4, 0, absolutePrestateData, hex"");

vm.expectRevert(DuplicateStep.selector);
gameProxy.step(8, true, absolutePrestateData, hex"");
gameProxy.stepV2(4, 0, absolutePrestateData, hex"");
}

/// @dev Tests that successfully step with true attacking claim when there is a true defend claim(claim5) in the
Expand Down Expand Up @@ -1783,6 +1779,13 @@ contract FaultDisputeGame3_Test is FaultDisputeGame_Init {
bond_ = gameProxy.getRequiredBond(pos);
}

/// @dev Helper to get the required bond for the given claim index.
function _getRequiredBondV2(uint256 _claimIndex, uint64 _attackBranch) internal view returns (uint256 bond_) {
(,,,,, Position parent,) = gameProxy.claimData(_claimIndex);
Position pos = parent.moveN(2, _attackBranch);
bond_ = gameProxy.getRequiredBond(pos);
}

/// @dev Helper to return a pseudo-random claim
function _dummyClaim() internal view returns (Claim) {
return Claim.wrap(keccak256(abi.encode(gasleft())));
Expand All @@ -1795,7 +1798,7 @@ contract FaultDisputeGame3_Test is FaultDisputeGame_Init {
}
}

contract FaultDispute3_1v1_Actors_Test is FaultDisputeGame_Init {
contract FaultDisputeN_1v1_Actors_Test is FaultDisputeGame_Init {
/// @dev The honest actor
DisputeActor internal honest;
/// @dev The dishonest actor
Expand Down

0 comments on commit b37e73d

Please sign in to comment.