Skip to content

Commit

Permalink
Update rvsol deployment sol scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Sep 24, 2024
1 parent ba7287e commit 012d01e
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 79 deletions.
1 change: 1 addition & 0 deletions rvsol/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ remappings = [
# We need these remappings to use the Optimism monorepo contracts as a library.
'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',

# required for etherscan contract verification
'src/L1=lib/optimism/packages/contracts-bedrock/src/L1',
Expand Down
131 changes: 106 additions & 25 deletions rvsol/scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,29 @@ import { RISCV } from "../src/RISCV.sol";

import { IBigStepper } from "@optimism/src/dispute/interfaces/IBigStepper.sol";
import { IPreimageOracle } from "@optimism/src/cannon/interfaces/IPreimageOracle.sol";
import { DisputeGameFactory } from "@optimism/src/dispute/DisputeGameFactory.sol";
import { DelayedWETH } from "@optimism/src/dispute/weth/DelayedWETH.sol";
import { AnchorStateRegistry } from "@optimism/src/dispute/AnchorStateRegistry.sol";
import { FaultDisputeGame } from "@optimism/src/dispute/FaultDisputeGame.sol";
import { IDisputeGameFactory } from "@optimism/src/dispute/interfaces/IDisputeGameFactory.sol";
import { IDisputeGame } from "@optimism/src/dispute/interfaces/IDisputeGame.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";
import { Enum as SafeOps } from "safe-contracts/common/Enum.sol";
import "@optimism/src/dispute/lib/Types.sol";

contract Deploy is Deployer {
/// @notice FaultDisputeGameParams is a struct that contains the parameters necessary to call
/// the function _setFaultGameImplementation. This struct exists because the EVM needs
/// to finally adopt PUSHN and get rid of stack too deep once and for all.
/// Someday we will look back and laugh about stack too deep, today is not that day.
struct FaultDisputeGameParams {
IAnchorStateRegistry anchorStateRegistry;
IDelayedWETH weth;
GameType gameType;
Claim absolutePrestate;
IBigStepper faultVm;
uint256 maxGameDepth;
Duration maxClockDuration;
}

/// @notice Modifier that wraps a function in broadcasting.
modifier broadcast() {
vm.startBroadcast(msg.sender);
Expand Down Expand Up @@ -111,36 +125,103 @@ contract Deploy is Deployer {
/// @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");
DisputeGameFactory factory = DisputeGameFactory(mustGetChainAddress("DisputeGameFactoryProxy"));
DelayedWETH weth = DelayedWETH(mustGetChainAddress("DelayedWETHProxy"));
AnchorStateRegistry anchorStateRegistry = AnchorStateRegistry(mustGetChainAddress("AnchorStateRegistryProxy"));
IDisputeGameFactory factory = IDisputeGameFactory(mustGetAddress("DisputeGameFactoryProxy"));
IDelayedWETH weth = IDelayedWETH(mustGetAddress("DelayedWETHProxy"));

// Set the Asterisc FaultDisputeGame implementation in the factory.
_setFaultGameImplementation({
_factory: factory,
_allowUpgrade: _allowUpgrade,
_params: FaultDisputeGameParams({
anchorStateRegistry: IAnchorStateRegistry(mustGetAddress("AnchorStateRegistryProxy")),
weth: weth,
gameType: GameTypes.ASTERISC,
absolutePrestate: loadRiscvAbsolutePrestate(),
faultVm: IBigStepper(mustGetAddress("RISCV")),
maxGameDepth: cfg.faultGameMaxDepth(),
maxClockDuration: Duration.wrap(uint64(cfg.faultGameMaxClockDuration()))
})
});
}

if (address(factory.gameImpls(GameTypes.ASTERISC)) != address(0) && !_allowUpgrade) {
/// @notice Sets the implementation for the given fault game type in the `DisputeGameFactory`.
function _setFaultGameImplementation(
IDisputeGameFactory _factory,
bool _allowUpgrade,
FaultDisputeGameParams memory _params
)
internal
{
if (address(_factory.gameImpls(_params.gameType)) != address(0) && !_allowUpgrade) {
console.log(
"[WARN] DisputeGameFactoryProxy: `FaultDisputeGame` implementation already set for game type: ASTERISC"
"[WARN] DisputeGameFactoryProxy: `FaultDisputeGame` implementation already set for game type: %s",
vm.toString(GameType.unwrap(_params.gameType))
);
return;
}

FaultDisputeGame fdg = new FaultDisputeGame{ salt: _implSalt() }({
_gameType: GameTypes.ASTERISC,
_absolutePrestate: loadRiscvAbsolutePrestate(),
_maxGameDepth: cfg.faultGameMaxDepth(),
_splitDepth: cfg.faultGameSplitDepth(),
_clockExtension: Duration.wrap(uint64(cfg.faultGameClockExtension())),
_maxClockDuration: Duration.wrap(uint64(cfg.faultGameMaxClockDuration())),
_vm: IBigStepper(mustGetAddress("RISCV")),
_weth: weth,
_anchorStateRegistry: anchorStateRegistry,
_l2ChainId: cfg.l2ChainID()
});
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()
)
)
)
);

bytes memory data = abi.encodeCall(DisputeGameFactory.setImplementation, (GameTypes.ASTERISC, fdg));
_callViaSafe(address(factory), data);
string memory gameTypeString = "Asterisc";

console.log(
"DisputeGameFactoryProxy: set `FaultDisputeGame` implementation (Backend: ASTERISC | GameType: %s)",
vm.toString(GameType.unwrap(GameTypes.ASTERISC))
"DisputeGameFactoryProxy: set `FaultDisputeGame` implementation (Backend: %s | GameType: %s)",
gameTypeString,
vm.toString(rawGameType)
);
}

/// @notice Deploys a contract via CREATE2.
/// @param _name The name of the contract.
/// @param _constructorParams The constructor parameters.
function _deploy(string memory _name, bytes memory _constructorParams) internal returns (address addr_) {
return _deploy(_name, _name, _constructorParams);
}

/// @notice Deploys a contract via CREATE2.
/// @param _name The name of the contract.
/// @param _nickname The nickname of the contract.
/// @param _constructorParams The constructor parameters.
function _deploy(
string memory _name,
string memory _nickname,
bytes memory _constructorParams
)
internal
returns (address addr_)
{
console.log("Deploying %s", _nickname);
bytes32 salt = _implSalt();
bytes memory initCode = abi.encodePacked(vm.getCode(_name), _constructorParams);
address preComputedAddress = vm.computeCreate2Address(salt, keccak256(initCode));
require(preComputedAddress.code.length == 0, "Deploy: contract already deployed");
assembly {
addr_ := create2(0, add(initCode, 0x20), mload(initCode), salt)
}
require(addr_ != address(0), "deployment failed");
save(_nickname, addr_);
console.log("%s deployed at %s", _nickname, addr_);
}
}
Loading

0 comments on commit 012d01e

Please sign in to comment.