Skip to content

Commit

Permalink
Fix asterisc deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Sep 25, 2024
1 parent 4878538 commit 31f16fa
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 149 deletions.
1 change: 1 addition & 0 deletions rvsol/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ remappings = [
'src/dispute=lib/optimism/packages/contracts-bedrock/src/dispute',
'src/libraries=lib/optimism/packages/contracts-bedrock/src/libraries',
'scripts/libraries=lib/optimism/packages/contracts-bedrock/scripts/libraries',
'test/mocks=lib/optimism/packages/contracts-bedrock/test/mocks',

# required for etherscan contract verification
'src/L1=lib/optimism/packages/contracts-bedrock/src/L1',
Expand Down
85 changes: 41 additions & 44 deletions rvsol/scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IBigStepper } from "@optimism/src/dispute/interfaces/IBigStepper.sol";
import { IPreimageOracle } from "@optimism/src/cannon/interfaces/IPreimageOracle.sol";
import { IDisputeGameFactory } from "@optimism/src/dispute/interfaces/IDisputeGameFactory.sol";
import { IDisputeGame } from "@optimism/src/dispute/interfaces/IDisputeGame.sol";
import { FaultDisputeGame } from "@optimism/src/dispute/FaultDisputeGame.sol";
import { IDelayedWETH } from "@optimism/src/dispute/interfaces/IDelayedWETH.sol";
import { IAnchorStateRegistry } from "@optimism/src/dispute/interfaces/IAnchorStateRegistry.sol";
import { GnosisSafe as Safe } from "safe-contracts/GnosisSafe.sol";
Expand Down Expand Up @@ -70,7 +71,7 @@ contract Deploy is Deployer {
/// @notice Deploy RISCV
function deployRiscv() public broadcast returns (address addr_) {
console.log("Deploying RISCV implementation");
RISCV riscv = new RISCV{ salt: _implSalt() }(IPreimageOracle(mustGetChainAddress("PreimageOracle")));
RISCV riscv = new RISCV{ salt: _implSalt() }(IPreimageOracle(mustGetAddress("PreimageOracle")));
save("RISCV", address(riscv));
console.log("RISCV deployed at %s", address(riscv));
addr_ = address(riscv);
Expand Down Expand Up @@ -101,27 +102,6 @@ contract Deploy is Deployer {
}
}

/// @notice Make a call from the Safe contract to an arbitrary address with arbitrary data
function _callViaSafe(address _target, bytes memory _data) internal {
Safe safe = Safe(mustGetChainAddress("SystemOwnerSafe"));

// This is the signature format used the caller is also the signer.
bytes memory signature = abi.encodePacked(uint256(uint160(msg.sender)), bytes32(0), uint8(1));

safe.execTransaction({
to: _target,
value: 0,
data: _data,
operation: SafeOps.Operation.Call,
safeTxGas: 0,
baseGas: 0,
gasPrice: 0,
gasToken: address(0),
refundReceiver: payable(address(0)),
signatures: signature
});
}

/// @notice Sets the implementation for the given fault game type in the `DisputeGameFactory`.
function setAsteriscFaultGameImplementation(bool _allowUpgrade) public broadcast {
console.log("Setting Asterisc FaultDisputeGame implementation");
Expand All @@ -144,6 +124,27 @@ contract Deploy is Deployer {
});
}

/// @notice Make a call from the Safe contract to an arbitrary address with arbitrary data
function _callViaSafe(address _target, bytes memory _data) internal {
Safe safe = Safe(mustGetAddress("SystemOwnerSafe"));

// This is the signature format used the caller is also the signer.
bytes memory signature = abi.encodePacked(uint256(uint160(msg.sender)), bytes32(0), uint8(1));

safe.execTransaction({
to: _target,
value: 0,
data: _data,
operation: SafeOps.Operation.Call,
safeTxGas: 0,
baseGas: 0,
gasPrice: 0,
gasToken: address(0),
refundReceiver: payable(address(0)),
signatures: signature
});
}

/// @notice Sets the implementation for the given fault game type in the `DisputeGameFactory`.
function _setFaultGameImplementation(
IDisputeGameFactory _factory,
Expand All @@ -161,34 +162,30 @@ contract Deploy is Deployer {
}

uint32 rawGameType = GameType.unwrap(_params.gameType);
_factory.setImplementation(
_params.gameType,
IDisputeGame(
_deploy(
"RISCV",
abi.encode(
_params.gameType,
_params.absolutePrestate,
_params.maxGameDepth,
cfg.faultGameSplitDepth(),
cfg.faultGameClockExtension(),
_params.maxClockDuration,
_params.faultVm,
_params.weth,
_params.anchorStateRegistry,
cfg.l2ChainID(),
cfg.l2OutputOracleProposer(),
cfg.l2OutputOracleChallenger()
)
IDisputeGame dg = IDisputeGame(
_deploy(
"FaultDisputeGame",
string.concat("FaultDisputeGame_", vm.toString(rawGameType)),
abi.encode(
_params.gameType,
_params.absolutePrestate,
_params.maxGameDepth,
cfg.faultGameSplitDepth(),
cfg.faultGameClockExtension(),
_params.maxClockDuration,
_params.faultVm,
_params.weth,
_params.anchorStateRegistry,
cfg.l2ChainID()
)
)
);

string memory gameTypeString = "Asterisc";
bytes memory data = abi.encodeCall(IDisputeGameFactory.setImplementation, (_params.gameType, dg));
_callViaSafe(address(_factory), data);

console.log(
"DisputeGameFactoryProxy: set `FaultDisputeGame` implementation (Backend: %s | GameType: %s)",
gameTypeString,
"DisputeGameFactoryProxy: set `FaultDisputeGame` implementation (Backend: Asterisc | GameType: %s)",
vm.toString(rawGameType)
);
}
Expand Down
71 changes: 45 additions & 26 deletions rvsol/scripts/Deploy_Stage_1_4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ISuperchainConfig } from "src/L1/interfaces/ISuperchainConfig.sol";
import { IPreimageOracle } from "src/cannon/interfaces/IPreimageOracle.sol";
import { IDisputeGameFactory } from "src/dispute/interfaces/IDisputeGameFactory.sol";
import { IFaultDisputeGame } from "src/dispute/interfaces/IFaultDisputeGame.sol";
import { FaultDisputeGame } from "@optimism/src/dispute/FaultDisputeGame.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
import { IAnchorStateRegistry } from "@optimism/src/dispute/interfaces/IAnchorStateRegistry.sol";
Expand All @@ -23,6 +24,8 @@ import { Chains } from "@optimism/scripts/libraries/Chains.sol";
import { IBigStepper } from "@optimism/src/dispute/interfaces/IBigStepper.sol";
import "@optimism/src/dispute/lib/Types.sol";
import { console2 as console } from "forge-std/console2.sol";
import { GnosisSafe as Safe } from "safe-contracts/GnosisSafe.sol";
import { Enum as SafeOps } from "safe-contracts/common/Enum.sol";
import { StdAssertions } from "forge-std/StdAssertions.sol";

contract Deploy is Deployer, StdAssertions {
Expand Down Expand Up @@ -98,7 +101,7 @@ contract Deploy is Deployer, StdAssertions {
/// @notice Deploy RISCV
function deployRiscv() public broadcast returns (address addr_) {
console.log("Deploying RISCV implementation");
RISCV riscv = new RISCV{ salt: _implSalt() }(IPreimageOracle(mustGetChainAddress("PreimageOracle")));
RISCV riscv = new RISCV{ salt: _implSalt() }(IPreimageOracle(mustGetAddress("PreimageOracle")));
save("RISCV", address(riscv));
console.log("RISCV deployed at %s", address(riscv));
addr_ = address(riscv);
Expand Down Expand Up @@ -278,6 +281,27 @@ contract Deploy is Deployer, StdAssertions {
}
}

/// @notice Make a call from the Safe contract to an arbitrary address with arbitrary data
function _callViaSafe(address _target, bytes memory _data) internal {
Safe safe = Safe(mustGetAddress("SystemOwnerSafe"));

// This is the signature format used the caller is also the signer.
bytes memory signature = abi.encodePacked(uint256(uint160(msg.sender)), bytes32(0), uint8(1));

safe.execTransaction({
to: _target,
value: 0,
data: _data,
operation: SafeOps.Operation.Call,
safeTxGas: 0,
baseGas: 0,
gasPrice: 0,
gasToken: address(0),
refundReceiver: payable(address(0)),
signatures: signature
});
}

/// @notice Sets the implementation for the given fault game type in the `DisputeGameFactory`.
function setAsteriscFaultGameImplementation(bool _allowUpgrade) public broadcast {
console.log("Setting Asterisc FaultDisputeGame implementation");
Expand All @@ -299,14 +323,13 @@ contract Deploy is Deployer, StdAssertions {
})
});
}

/// @notice Sets the implementation for the given fault game type in the `DisputeGameFactory`.
function _setFaultGameImplementation(
IDisputeGameFactory _factory,
bool _allowUpgrade,
FaultDisputeGameParams memory _params
)
internal
internal
{
if (address(_factory.gameImpls(_params.gameType)) != address(0) && !_allowUpgrade) {
console.log(
Expand All @@ -317,34 +340,30 @@ contract Deploy is Deployer, StdAssertions {
}

uint32 rawGameType = GameType.unwrap(_params.gameType);
_factory.setImplementation(
_params.gameType,
IDisputeGame(
_deploy(
"RISCV",
abi.encode(
_params.gameType,
_params.absolutePrestate,
_params.maxGameDepth,
cfg.faultGameSplitDepth(),
cfg.faultGameClockExtension(),
_params.maxClockDuration,
_params.faultVm,
_params.weth,
_params.anchorStateRegistry,
cfg.l2ChainID(),
cfg.l2OutputOracleProposer(),
cfg.l2OutputOracleChallenger()
)
IDisputeGame dg = IDisputeGame(
_deploy(
"FaultDisputeGame",
string.concat("FaultDisputeGame_", vm.toString(rawGameType)),
abi.encode(
_params.gameType,
_params.absolutePrestate,
_params.maxGameDepth,
cfg.faultGameSplitDepth(),
cfg.faultGameClockExtension(),
_params.maxClockDuration,
_params.faultVm,
_params.weth,
_params.anchorStateRegistry,
cfg.l2ChainID()
)
)
);

string memory gameTypeString = "Asterisc";
bytes memory data = abi.encodeCall(IDisputeGameFactory.setImplementation, (_params.gameType, dg));
_callViaSafe(address(_factory), data);

console.log(
"DisputeGameFactoryProxy: set `FaultDisputeGame` implementation (Backend: %s | GameType: %s)",
gameTypeString,
"DisputeGameFactoryProxy: set `FaultDisputeGame` implementation (Backend: Asterisc | GameType: %s)",
vm.toString(rawGameType)
);
}
Expand Down Expand Up @@ -418,7 +437,7 @@ contract Deploy is Deployer, StdAssertions {
} else {
assertEq(gameImpl.absolutePrestate().raw(), bytes32(cfg.faultGameAbsolutePrestate()));
}
address wethProxyAddr = mustGetChainAddress("DelayedWETHProxy");
address wethProxyAddr = mustGetAddress("DelayedWETHProxy");
assertEq(address(gameImpl.weth()), wethProxyAddr);
assertEq(address(gameImpl.anchorStateRegistry()), address(asr));
assertEq(address(gameImpl.vm()), address(riscv));
Expand Down
Loading

0 comments on commit 31f16fa

Please sign in to comment.