Commit 4c188bae authored by clabby's avatar clabby

Allow `FaultDisputeGame` to be deployed with different game types

patch
parent 55012af6
This diff is collapsed.
......@@ -36,6 +36,7 @@ func setupFaultDisputeGame() (common.Address, *bind.TransactOpts, *backends.Simu
_, _, contract, err := bindings.DeployFaultDisputeGame(
opts,
backend,
uint8(0), // Game Type ID
[32]byte{0x01}, // Absolute Prestate Claim
big.NewInt(15), // Max Game Depth
uint64(604800), // 7 days
......
......@@ -69,6 +69,7 @@ func deployDisputeGameContracts(require *require.Assertions, ctx context.Context
_, tx, _, err = bindings.DeployFaultDisputeGame(
opts,
client,
uint8(0),
alphabetVMAbsolutePrestateClaim,
big.NewInt(alphabetGameDepth),
gameDuration,
......
......@@ -100,7 +100,7 @@ FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeed
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 32354)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 32806)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10388)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8266)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8272)
FaultDisputeGame_Test:test_initialize_correctData_succeeds() (gas: 57716)
FaultDisputeGame_Test:test_initialize_firstOutput_reverts() (gas: 210532)
FaultDisputeGame_Test:test_initialize_l1HeadTooOld_reverts() (gas: 228402)
......
......@@ -262,21 +262,17 @@ contract Deploy is Deployer {
/// @notice Deploy the DisputeGameFactoryProxy
function deployDisputeGameFactoryProxy() onlyDevnet broadcast() public returns (address) {
address proxyAdmin = mustGetAddress("ProxyAdmin");
Proxy proxy = new Proxy({
_admin: proxyAdmin
});
string[2] memory contractNames = ["DisputeGameFactoryProxy", "MIPSDisputeGameFactoryProxy"];
for (uint256 i; i < contractNames.length; i++) {
Proxy proxy = new Proxy({
_admin: proxyAdmin
});
address admin = address(uint160(uint256(vm.load(address(proxy), OWNER_KEY))));
require(admin == proxyAdmin);
address admin = address(uint160(uint256(vm.load(address(proxy), OWNER_KEY))));
require(admin == proxyAdmin);
save(contractNames[i], address(proxy));
console.log("%s deployed at %s", contractNames[i], address(proxy));
}
save("DisputeGameFactoryProxy", address(proxy));
console.log("DisputeGameFactoryProxy deployed at %s", address(proxy));
return mustGetAddress(contractNames[0]);
return address(proxy);
}
/// @notice Deploy the L1CrossDomainMessenger
......@@ -367,10 +363,6 @@ contract Deploy is Deployer {
save("DisputeGameFactory", address(factory));
console.log("DisputeGameFactory deployed at %s", address(factory));
DisputeGameFactory mipsFactory = new DisputeGameFactory();
save("MIPSDisputeGameFactory", address(mipsFactory));
console.log("MIPSDisputeGameFactory deployed at %s", address(mipsFactory));
return address(factory);
}
......@@ -487,26 +479,20 @@ contract Deploy is Deployer {
/// @notice Initialize the DisputeGameFactory
function initializeDisputeGameFactory() onlyDevnet broadcast() public {
ProxyAdmin proxyAdmin = ProxyAdmin(mustGetAddress("ProxyAdmin"));
string[2][2] memory contractNames = [
["DisputeGameFactoryProxy", "DisputeGameFactory"],
["MIPSDisputeGameFactoryProxy", "MIPSDisputeGameFactory"]
];
for (uint256 i; i < contractNames.length; i++) {
address disputeGameFactoryProxy = mustGetAddress(contractNames[i][0]);
address disputeGameFactory = mustGetAddress(contractNames[i][1]);
proxyAdmin.upgradeAndCall({
_proxy: payable(disputeGameFactoryProxy),
_implementation: disputeGameFactory,
_data: abi.encodeCall(
DisputeGameFactory.initialize,
(msg.sender)
)
});
address disputeGameFactoryProxy = mustGetAddress("DisputeGameFactoryProxy");
address disputeGameFactory = mustGetAddress("DisputeGameFactory");
string memory version = DisputeGameFactory(disputeGameFactoryProxy).version();
console.log("%s version: %s", contractNames[i][1], version);
}
proxyAdmin.upgradeAndCall({
_proxy: payable(disputeGameFactoryProxy),
_implementation: disputeGameFactory,
_data: abi.encodeCall(
DisputeGameFactory.initialize,
(msg.sender)
)
});
string memory version = DisputeGameFactory(disputeGameFactoryProxy).version();
console.log("DisputeGameFactory version: %s", version);
}
/// @notice Initialize the SystemConfig
......@@ -724,15 +710,12 @@ contract Deploy is Deployer {
/// @notice Transfer ownership of the DisputeGameFactory contract to the final system owner
function transferDisputeGameFactoryOwnership() onlyDevnet broadcast() public {
string[2] memory contractNames = ["DisputeGameFactoryProxy", "MIPSDisputeGameFactoryProxy"];
for (uint256 i; i < contractNames.length; i++) {
DisputeGameFactory disputeGameFactory = DisputeGameFactory(mustGetAddress(contractNames[i]));
address owner = disputeGameFactory.owner();
address finalSystemOwner = cfg.finalSystemOwner();
if (owner != finalSystemOwner) {
disputeGameFactory.transferOwnership(finalSystemOwner);
console.log("%s ownership transferred to: %s", contractNames[i], finalSystemOwner);
}
DisputeGameFactory disputeGameFactory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy"));
address owner = disputeGameFactory.owner();
address finalSystemOwner = cfg.finalSystemOwner();
if (owner != finalSystemOwner) {
disputeGameFactory.transferOwnership(finalSystemOwner);
console.log("DisputeGameFactory ownership transferred to: %s", finalSystemOwner);
}
}
......@@ -752,14 +735,14 @@ contract Deploy is Deployer {
mipsAbsolutePrestate = abi.decode(vm.ffi(commands), (bytes32));
console.log("Absolute prestate: %s", vm.toString(mipsAbsolutePrestate));
string[2] memory contractNames = ["DisputeGameFactoryProxy", "MIPSDisputeGameFactoryProxy"];
for (uint256 i; i < contractNames.length; i++) {
DisputeGameFactory factory = DisputeGameFactory(mustGetAddress(contractNames[i]));
DisputeGameFactory factory = DisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy"));
for (uint8 i; i < 2; i++) {
Claim absolutePrestate = Claim.wrap(i == 0 ? bytes32(cfg.faultGameAbsolutePrestate()) : mipsAbsolutePrestate);
IBigStepper faultVm = IBigStepper(i == 0 ? address(new AlphabetVM(absolutePrestate)) : mustGetAddress("Mips"));
if (address(factory.gameImpls(GameTypes.FAULT)) == address(0)) {
factory.setImplementation(GameTypes.FAULT, new FaultDisputeGame({
GameType gameType = GameType.wrap(i);
if (address(factory.gameImpls(gameType)) == address(0)) {
factory.setImplementation(gameType, new FaultDisputeGame({
_gameType: gameType,
_absolutePrestate: absolutePrestate,
_maxGameDepth: i == 0 ? 4 : cfg.faultGameMaxDepth(), // The max depth of the alphabet game is always 4
_gameDuration: Duration.wrap(uint64(cfg.faultGameMaxDuration())),
......@@ -767,7 +750,7 @@ contract Deploy is Deployer {
_l2oo: L2OutputOracle(mustGetAddress("L2OutputOracleProxy")),
_blockOracle: BlockOracle(mustGetAddress("BlockOracle"))
}));
console.log("%s: set `FaultDisputeGame` implementation", contractNames[i]);
console.log("DisputeGameFactoryProxy: set `FaultDisputeGame` implementation (Backend: %s | GameType: %s)", i == 0 ? "AlphabetVM" : "MIPS", vm.toString(i));
}
}
}
......
......@@ -14,7 +14,7 @@
"src/L2/L2StandardBridge.sol": "0x73a4fea3dca8ac7d7ba32e38aadeb69bd344042666a40a75e8c28849f01999e5",
"src/L2/L2ToL1MessagePasser.sol": "0xed800b600cb3f67e18a1ab10750e3934a8b3e42178f422bcacfde770a6e8e8bd",
"src/L2/SequencerFeeVault.sol": "0xd57c143b1f042400430b991b806bf971628e6980406c751e82d19ae80eeb4e8d",
"src/dispute/FaultDisputeGame.sol": "0x53ef150202f3e22dd0bd92a520c4eaa95752f5fd9d6b22f56d27958b71bb23ec",
"src/dispute/FaultDisputeGame.sol": "0x01b3770e4d056550e71b4b9e9ada5401de98668d0a1e0ff336ed8f73a0127e99",
"src/legacy/DeployerWhitelist.sol": "0x5e80f7b13ef73f06c63bd9b118a49da1ff06a5c0fcf8067b5a3365d731c23765",
"src/legacy/L1BlockNumber.sol": "0x84cc587148de5920dfcd19da44d28e769f0e4d08ca2bcc93f18aa78c6cc2ebe6",
"src/legacy/LegacyMessagePasser.sol": "0x2692b50b227e5f75a53439c0cf303498edfd4fc087555b3fc9bc4bceb518229b",
......
......@@ -46,6 +46,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// than the `BLOCKHASH` opcode allows as well as their estimated timestamps.
BlockOracle public immutable BLOCK_ORACLE;
/// @notice The game type ID
GameType internal immutable GAME_TYPE;
/// @notice The root claim's position is always at gindex 1.
Position internal constant ROOT_POSITION = Position.wrap(1);
......@@ -72,6 +75,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// @notice An internal mapping to allow for constant-time lookups of existing claims.
mapping(ClaimHash => bool) internal claims;
/// @param _gameType The type ID of the game.
/// @param _absolutePrestate The absolute prestate of the instruction trace.
/// @param _maxGameDepth The maximum depth of bisection.
/// @param _gameDuration The duration of the game.
......@@ -83,6 +87,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// timestamps.
/// @custom:semver 0.0.6
constructor(
GameType _gameType,
Claim _absolutePrestate,
uint256 _maxGameDepth,
Duration _gameDuration,
......@@ -90,6 +95,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
L2OutputOracle _l2oo,
BlockOracle _blockOracle
) Semver(0, 0, 6) {
GAME_TYPE = _gameType;
ABSOLUTE_PRESTATE = _absolutePrestate;
MAX_GAME_DEPTH = _maxGameDepth;
GAME_DURATION = _gameDuration;
......@@ -332,8 +338,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
////////////////////////////////////////////////////////////////
/// @inheritdoc IDisputeGame
function gameType() public pure override returns (GameType gameType_) {
gameType_ = GameTypes.FAULT;
function gameType() public view override returns (GameType gameType_) {
gameType_ = GAME_TYPE;
}
/// @inheritdoc IDisputeGame
......@@ -425,7 +431,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
/// @inheritdoc IDisputeGame
function gameData()
external
pure
view
returns (
GameType gameType_,
Claim rootClaim_,
......
......@@ -25,7 +25,7 @@ interface IDisputeGame is IInitializable {
/// @dev The reference impl should be entirely different depending on the type (fault, validity)
/// i.e. The game type should indicate the security model.
/// @return gameType_ The type of proof system being used.
function gameType() external pure returns (GameType gameType_);
function gameType() external view returns (GameType gameType_);
/// @notice Getter for the root claim.
/// @dev `clones-with-immutable-args` argument #1
......@@ -58,7 +58,7 @@ interface IDisputeGame is IInitializable {
/// @return extraData_ Any extra data supplied to the dispute game contract by the creator.
function gameData()
external
pure
view
returns (
GameType gameType_,
Claim rootClaim_,
......
......@@ -60,6 +60,7 @@ contract FaultDisputeGame_Init is DisputeGameFactory_Init {
// Deploy an implementation of the fault game
gameImpl = new FaultDisputeGame(
GAME_TYPE,
absolutePrestate,
4,
Duration.wrap(7 days),
......
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