Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 0 additions & 82 deletions packages/contracts-bedrock/scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Deployer } from "scripts/deploy/Deployer.sol";
import { Chains } from "scripts/libraries/Chains.sol";
import { Config } from "scripts/libraries/Config.sol";
import { StateDiff } from "scripts/libraries/StateDiff.sol";
import { Process } from "scripts/libraries/Process.sol";
import { ChainAssertions } from "scripts/deploy/ChainAssertions.sol";
import { DeployUtils } from "scripts/libraries/DeployUtils.sol";
import { DeploySuperchain2 } from "scripts/deploy/DeploySuperchain2.s.sol";
Expand All @@ -30,8 +29,6 @@ import { IOPContractsManager } from "interfaces/L1/IOPContractsManager.sol";
import { IProxy } from "interfaces/universal/IProxy.sol";
import { IProxyAdmin } from "interfaces/universal/IProxyAdmin.sol";
import { ISuperchainConfig } from "interfaces/L1/ISuperchainConfig.sol";
import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol";
import { IBigStepper } from "interfaces/dispute/IBigStepper.sol";
import { IDisputeGameFactory } from "interfaces/dispute/IDisputeGameFactory.sol";
import { IDelayedWETH } from "interfaces/dispute/IDelayedWETH.sol";
import { IAnchorStateRegistry } from "interfaces/dispute/IAnchorStateRegistry.sol";
Expand Down Expand Up @@ -373,8 +370,6 @@ contract Deploy is Deployer {
_implementation: delayedWETHImpl,
_data: abi.encodeCall(IDelayedWETH.initialize, (deployOutput.systemConfigProxy))
});

setCannonFaultGameImplementation();
}

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -406,83 +401,6 @@ contract Deploy is Deployer {
addr_ = address(proxy);
}

///////////////////////////////////////////////////////////
// Proofs setup helper functions //
///////////////////////////////////////////////////////////

/// @notice Load the appropriate mips absolute prestate for devenets depending on config environment.
function loadMipsAbsolutePrestate() internal returns (Claim mipsAbsolutePrestate_) {
if (block.chainid == Chains.LocalDevnet || block.chainid == Chains.GethDevnet) {
return _loadDevnetMtMipsAbsolutePrestate();
} else {
console.log(
"[Cannon Dispute Game] Using absolute prestate from config: %x", cfg.faultGameAbsolutePrestate()
);
mipsAbsolutePrestate_ = Claim.wrap(bytes32(cfg.faultGameAbsolutePrestate()));
}
}

function loadInteropDevnetAbsolutePrestate() internal returns (Claim interopDevnetAbsolutePrestate_) {
string memory filePath = string.concat(vm.projectRoot(), "/../../op-program/bin/prestate-proof-interop.json");
if (bytes(Process.bash(string.concat("[[ -f ", filePath, " ]] && echo \"present\""))).length == 0) {
revert(
"Deploy: cannon prestate dump not found, generate it with `make cannon-prestate` in the monorepo root"
);
}
interopDevnetAbsolutePrestate_ =
Claim.wrap(abi.decode(bytes(Process.bash(string.concat("cat ", filePath, " | jq -r .pre"))), (bytes32)));
console.log(
"[Cannon Dispute Game] Using devnet Interop Devnet Absolute Prestate: %s",
vm.toString(Claim.unwrap(interopDevnetAbsolutePrestate_))
);
}

/// @notice Loads the multithreaded mips absolute prestate from the prestate-proof-mt64 for devnets otherwise
/// from the config.
function _loadDevnetMtMipsAbsolutePrestate() internal returns (Claim mipsAbsolutePrestate_) {
// Fetch the absolute prestate dump
string memory filePath = string.concat(vm.projectRoot(), "/../../op-program/bin/prestate-proof-mt64.json");
if (bytes(Process.bash(string.concat("[[ -f ", filePath, " ]] && echo \"present\""))).length == 0) {
revert(
"Deploy: MT-Cannon prestate dump not found, generate it with `make cannon-prestate-mt64` in the monorepo root"
);
}
mipsAbsolutePrestate_ =
Claim.wrap(abi.decode(bytes(Process.bash(string.concat("cat ", filePath, " | jq -r .pre"))), (bytes32)));
console.log(
"[MT-Cannon Dispute Game] Using devnet MIPS64 Absolute prestate: %s",
vm.toString(Claim.unwrap(mipsAbsolutePrestate_))
);
}

/// @notice Sets the implementation for the `CANNON` game type in the `DisputeGameFactory`
function setCannonFaultGameImplementation() public {
console.log("Setting Cannon FaultDisputeGame implementation");
address opcm = artifacts.mustGetAddress("OPContractsManager");
IProxyAdmin proxyAdmin = IProxyAdmin(artifacts.mustGetAddress("ProxyAdmin"));

IOPContractsManager.AddGameInput[] memory addGameInput = new IOPContractsManager.AddGameInput[](1);
addGameInput[0] = IOPContractsManager.AddGameInput({
saltMixer: "CannonFaultGame",
systemConfig: ISystemConfig(artifacts.mustGetAddress("SystemConfigProxy")),
proxyAdmin: proxyAdmin,
delayedWETH: IDelayedWETH(artifacts.mustGetAddress("DelayedWETHProxy")),
disputeGameType: GameTypes.CANNON,
disputeAbsolutePrestate: loadMipsAbsolutePrestate(),
disputeMaxGameDepth: cfg.faultGameMaxDepth(),
disputeSplitDepth: cfg.faultGameSplitDepth(),
disputeClockExtension: Duration.wrap(uint64(cfg.faultGameClockExtension())),
disputeMaxClockDuration: Duration.wrap(uint64(cfg.faultGameMaxClockDuration())),
initialBond: 0.08 ether,
vm: IBigStepper(artifacts.mustGetAddress("MipsSingleton")),
permissioned: false
});

vm.prank(cfg.finalSystemOwner(), true);
(bool success,) = opcm.delegatecall(abi.encodeCall(IOPContractsManager.addGameType, (addGameInput)));
require(success, "Deploy: Cannon FaultDisputeGame implementation not set");
}

/// @notice Get the DeployInput struct to use for testing
function getDeployInput() public view returns (IOPContractsManager.DeployInput memory) {
string memory saltMixer = "salt mixer";
Expand Down
5 changes: 4 additions & 1 deletion packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { console2 as console } from "forge-std/console2.sol";
import { CommonTest } from "test/setup/CommonTest.sol";
import { NextImpl } from "test/mocks/NextImpl.sol";
import { EIP1967Helper } from "test/mocks/EIP1967Helper.sol";
import { DisputeGameFactory_Init } from "test/dispute/DisputeGameFactory.t.sol";

// Scripts
import { ForgeArtifacts, StorageSlot } from "scripts/libraries/ForgeArtifacts.sol";
Expand Down Expand Up @@ -463,7 +464,7 @@ contract OptimismPortal2_Test is CommonTest {
}
}

contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
contract OptimismPortal2_FinalizeWithdrawal_Test is DisputeGameFactory_Init {
// Reusable default values for a test withdrawal
Types.WithdrawalTransaction _defaultTx;
IFaultDisputeGame game;
Expand Down Expand Up @@ -521,6 +522,8 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
_proposedBlockNumber = 0xFF;
}

setupFaultDisputeGame(Claim.wrap(_outputRoot));

// Warp forward in time to ensure that the game is created after the retirement timestamp.
vm.warp(anchorStateRegistry.retirementTimestamp() + 1);

Expand Down
156 changes: 156 additions & 0 deletions packages/contracts-bedrock/test/dispute/DisputeGameFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CommonTest } from "test/setup/CommonTest.sol";

// Scripts
import { ForgeArtifacts, StorageSlot } from "scripts/libraries/ForgeArtifacts.sol";
import { DeployUtils } from "scripts/libraries/DeployUtils.sol";

// Libraries
import "src/dispute/lib/Types.sol";
Expand All @@ -15,6 +16,13 @@ import "src/dispute/lib/Errors.sol";
import { IDisputeGameFactory } from "interfaces/dispute/IDisputeGameFactory.sol";
import { IDisputeGame } from "interfaces/dispute/IDisputeGame.sol";
import { IProxyAdminOwnedBase } from "interfaces/L1/IProxyAdminOwnedBase.sol";
import { IPreimageOracle } from "interfaces/cannon/IPreimageOracle.sol";
import { IFaultDisputeGame } from "interfaces/dispute/IFaultDisputeGame.sol";
import { ISuperFaultDisputeGame } from "interfaces/dispute/ISuperFaultDisputeGame.sol";
import { IPermissionedDisputeGame } from "interfaces/dispute/IPermissionedDisputeGame.sol";
import { ISuperPermissionedDisputeGame } from "interfaces/dispute/ISuperPermissionedDisputeGame.sol";
// Mocks
import { AlphabetVM } from "test/mocks/AlphabetVM.sol";

contract DisputeGameFactory_Init is CommonTest {
FakeClone fakeClone;
Expand All @@ -31,6 +39,154 @@ contract DisputeGameFactory_Init is CommonTest {
vm.prank(disputeGameFactory.owner());
disputeGameFactory.transferOwnership(address(this));
}

/// @notice Creates a new VM instance with the given absolute prestate
function _createVM(Claim _absolutePrestate) internal returns (AlphabetVM vm_, IPreimageOracle preimageOracle_) {
// Set preimage oracle challenge period to something arbitrary (4 seconds) just so we can
// actually test the clock extensions later on. This is not a realistic value.
preimageOracle_ = IPreimageOracle(
DeployUtils.create1({
_name: "PreimageOracle",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IPreimageOracle.__constructor__, (0, 4)))
})
);
vm_ = new AlphabetVM(_absolutePrestate, preimageOracle_);
}

function _getGameConstructorParams(
Claim _absolutePrestate,
AlphabetVM _vm,
GameType _gameType
)
internal
view
returns (IFaultDisputeGame.GameConstructorParams memory params_)
{
return IFaultDisputeGame.GameConstructorParams({
gameType: _gameType,
absolutePrestate: _absolutePrestate,
maxGameDepth: 2 ** 3,
splitDepth: 2 ** 2,
clockExtension: Duration.wrap(3 hours),
maxClockDuration: Duration.wrap(3.5 days),
vm: _vm,
weth: delayedWeth,
anchorStateRegistry: anchorStateRegistry,
l2ChainId: 0
});
}

function _getSuperGameConstructorParams(
Claim _absolutePrestate,
AlphabetVM _vm,
GameType _gameType
)
private
view
returns (ISuperFaultDisputeGame.GameConstructorParams memory params_)
{
bytes memory args = abi.encode(_getGameConstructorParams(_absolutePrestate, _vm, _gameType));
params_ = abi.decode(args, (ISuperFaultDisputeGame.GameConstructorParams));
}

function _setGame(address _gameImpl, GameType _gameType) internal {
vm.startPrank(disputeGameFactory.owner());
disputeGameFactory.setImplementation(_gameType, IDisputeGame(_gameImpl));
disputeGameFactory.setInitBond(_gameType, 0.08 ether);
vm.stopPrank();
}

/// @notice Sets up a super cannon game implementation
function setupSuperFaultDisputeGame(Claim _absolutePrestate)
internal
returns (address gameImpl_, AlphabetVM vm_, IPreimageOracle preimageOracle_)
{
(vm_, preimageOracle_) = _createVM(_absolutePrestate);

gameImpl_ = DeployUtils.create1({
_name: "SuperFaultDisputeGame",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(
ISuperFaultDisputeGame.__constructor__,
(_getSuperGameConstructorParams(_absolutePrestate, vm_, GameTypes.SUPER_CANNON))
)
)
});

_setGame(gameImpl_, GameTypes.SUPER_CANNON);
}

/// @notice Sets up a super permissioned game implementation
function setupSuperPermissionedDisputeGame(
Claim _absolutePrestate,
address _proposer,
address _challenger
)
internal
returns (address gameImpl_, AlphabetVM vm_, IPreimageOracle preimageOracle_)
{
(vm_, preimageOracle_) = _createVM(_absolutePrestate);

gameImpl_ = DeployUtils.create1({
_name: "SuperPermissionedDisputeGame",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(
ISuperPermissionedDisputeGame.__constructor__,
(
_getSuperGameConstructorParams(_absolutePrestate, vm_, GameTypes.SUPER_PERMISSIONED_CANNON),
_proposer,
_challenger
)
)
)
});

_setGame(gameImpl_, GameTypes.SUPER_PERMISSIONED_CANNON);
}

/// @notice Sets up a fault game implementation
function setupFaultDisputeGame(Claim _absolutePrestate)
internal
returns (address gameImpl_, AlphabetVM vm_, IPreimageOracle preimageOracle_)
{
(vm_, preimageOracle_) = _createVM(_absolutePrestate);
gameImpl_ = DeployUtils.create1({
_name: "FaultDisputeGame",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(
IFaultDisputeGame.__constructor__, (_getGameConstructorParams(_absolutePrestate, vm_, GameTypes.CANNON))
)
)
});

_setGame(gameImpl_, GameTypes.CANNON);
}

function setupPermissionedDisputeGame(
Claim _absolutePrestate,
address _proposer,
address _challenger
)
internal
returns (address gameImpl_, AlphabetVM vm_, IPreimageOracle preimageOracle_)
{
(vm_, preimageOracle_) = _createVM(_absolutePrestate);
gameImpl_ = DeployUtils.create1({
_name: "PermissionedDisputeGame",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(
IPermissionedDisputeGame.__constructor__,
(
_getGameConstructorParams(_absolutePrestate, vm_, GameTypes.PERMISSIONED_CANNON),
_proposer,
_challenger
)
)
)
});

_setGame(gameImpl_, GameTypes.PERMISSIONED_CANNON);
}
}

contract DisputeGameFactory_initialize_Test is DisputeGameFactory_Init {
Expand Down
42 changes: 2 additions & 40 deletions packages/contracts-bedrock/test/dispute/FaultDisputeGame.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,8 @@ contract FaultDisputeGame_Init is DisputeGameFactory_Init {
// Set the extra data for the game creation
extraData = abi.encode(l2BlockNumber);

// Set preimage oracle challenge period to something arbitrary (4 seconds) just so we can
// actually test the clock extensions later on. This is not a realistic value.
AlphabetVM _vm = new AlphabetVM(
absolutePrestate,
IPreimageOracle(
DeployUtils.create1({
_name: "PreimageOracle",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IPreimageOracle.__constructor__, (0, 4)))
})
)
);

// Deploy an implementation of the fault game
gameImpl = IFaultDisputeGame(
DeployUtils.create1({
_name: "FaultDisputeGame",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(
IFaultDisputeGame.__constructor__,
(
IFaultDisputeGame.GameConstructorParams({
gameType: GAME_TYPE,
absolutePrestate: absolutePrestate,
maxGameDepth: 2 ** 3,
splitDepth: 2 ** 2,
clockExtension: Duration.wrap(3 hours),
maxClockDuration: Duration.wrap(3.5 days),
vm: _vm,
weth: delayedWeth,
anchorStateRegistry: anchorStateRegistry,
l2ChainId: 10
})
)
)
)
})
);

// Register the game implementation with the factory.
disputeGameFactory.setImplementation(GAME_TYPE, gameImpl);
(address _impl, AlphabetVM _vm,) = setupFaultDisputeGame(absolutePrestate);
gameImpl = IFaultDisputeGame(_impl);

// Set the init bond for the given game type.
initBond = disputeGameFactory.initBonds(GAME_TYPE);
Expand Down
Loading