diff --git a/op-deployer/pkg/deployer/opcm/asterisc.go b/op-deployer/pkg/deployer/opcm/asterisc.go index c034e6bf3ba53..01f3bb7cbdd48 100644 --- a/op-deployer/pkg/deployer/opcm/asterisc.go +++ b/op-deployer/pkg/deployer/opcm/asterisc.go @@ -1,30 +1,21 @@ package opcm import ( - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum-optimism/optimism/op-chain-ops/script" + "github.com/ethereum/go-ethereum/common" ) type DeployAsteriscInput struct { PreimageOracle common.Address } -func (input *DeployAsteriscInput) InputSet() bool { - return true -} - type DeployAsteriscOutput struct { AsteriscSingleton common.Address } -func (output *DeployAsteriscOutput) CheckOutput(input common.Address) error { - return nil -} +type DeployAsteriscScript script.DeployScriptWithOutput[DeployAsteriscInput, DeployAsteriscOutput] -func DeployAsterisc( - host *script.Host, - input DeployAsteriscInput, -) (DeployAsteriscOutput, error) { - return RunScriptSingle[DeployAsteriscInput, DeployAsteriscOutput](host, input, "DeployAsterisc.s.sol", "DeployAsterisc") +// NewDeployAsteriscScript loads and validates the DeployAsterisc script contract +func NewDeployAsteriscScript(host *script.Host) (DeployAsteriscScript, error) { + return script.NewDeployScriptWithOutputFromFile[DeployAsteriscInput, DeployAsteriscOutput](host, "DeployAsterisc.s.sol", "DeployAsterisc") } diff --git a/op-deployer/pkg/deployer/opcm/asterisc2.go b/op-deployer/pkg/deployer/opcm/asterisc2.go deleted file mode 100644 index 5b7831c78d680..0000000000000 --- a/op-deployer/pkg/deployer/opcm/asterisc2.go +++ /dev/null @@ -1,21 +0,0 @@ -package opcm - -import ( - "github.com/ethereum-optimism/optimism/op-chain-ops/script" - "github.com/ethereum/go-ethereum/common" -) - -type DeployAsterisc2Input struct { - PreimageOracle common.Address -} - -type DeployAsterisc2Output struct { - AsteriscSingleton common.Address -} - -type DeployAsteriscScript script.DeployScriptWithOutput[DeployAsterisc2Input, DeployAsterisc2Output] - -// NewDeployAsteriscScript loads and validates the DeployAsterisc2 script contract -func NewDeployAsteriscScript(host *script.Host) (DeployAsteriscScript, error) { - return script.NewDeployScriptWithOutputFromFile[DeployAsterisc2Input, DeployAsterisc2Output](host, "DeployAsterisc2.s.sol", "DeployAsterisc2") -} diff --git a/op-deployer/pkg/deployer/opcm/asterisc2_test.go b/op-deployer/pkg/deployer/opcm/asterisc2_test.go deleted file mode 100644 index d2d6c88f68525..0000000000000 --- a/op-deployer/pkg/deployer/opcm/asterisc2_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package opcm - -import ( - "math/big" - "testing" - - "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" -) - -func TestNewDeployAsteriscScript(t *testing.T) { - t.Run("should not fail with current version of DeployAsterisc2 contract", func(t *testing.T) { - // First we grab a test host - host1 := createTestHost(t) - - // Then we load the script - // - // This would raise an error if the Go types didn't match the ABI - deploySuperchain, err := NewDeployAsteriscScript(host1) - require.NoError(t, err) - - // Then we deploy - output, err := deploySuperchain.Run(DeployAsterisc2Input{ - PreimageOracle: common.BigToAddress(big.NewInt(1)), - }) - - // And do some simple asserts - require.NoError(t, err) - require.NotNil(t, output) - - // Now we run the old deployer - // - // We run it on a fresh host so that the deployer nonces are the same - // which in turn means we should get identical output - host2 := createTestHost(t) - deprecatedOutput, err := DeployAsterisc(host2, DeployAsteriscInput{ - PreimageOracle: common.BigToAddress(big.NewInt(1)), - }) - - // Make sure it succeeded - require.NoError(t, err) - require.NotNil(t, deprecatedOutput) - - // Now make sure the addresses are the same - require.Equal(t, deprecatedOutput.AsteriscSingleton, output.AsteriscSingleton) - - // And just to be super sure we also compare the code deployed to the addresses - require.Equal(t, host2.GetCode(deprecatedOutput.AsteriscSingleton), host1.GetCode(output.AsteriscSingleton)) - }) -} diff --git a/op-deployer/pkg/deployer/opcm/asterisc_test.go b/op-deployer/pkg/deployer/opcm/asterisc_test.go index 91d463825d24f..79ce60e81925a 100644 --- a/op-deployer/pkg/deployer/opcm/asterisc_test.go +++ b/op-deployer/pkg/deployer/opcm/asterisc_test.go @@ -1,36 +1,31 @@ package opcm import ( + "math/big" "testing" - "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/broadcaster" - "github.com/ethereum-optimism/optimism/op-deployer/pkg/deployer/testutil" - "github.com/ethereum-optimism/optimism/op-deployer/pkg/env" - "github.com/ethereum-optimism/optimism/op-service/testlog" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/log" "github.com/stretchr/testify/require" ) -func TestDeployAsterisc(t *testing.T) { - t.Parallel() - - _, artifacts := testutil.LocalArtifacts(t) - - host, err := env.DefaultScriptHost( - broadcaster.NoopBroadcaster(), - testlog.Logger(t, log.LevelInfo), - common.Address{'D'}, - artifacts, - ) - require.NoError(t, err) - - input := DeployAsteriscInput{ - PreimageOracle: common.Address{0xab}, - } - - output, err := DeployAsterisc(host, input) - require.NoError(t, err) - - require.NotEmpty(t, output.AsteriscSingleton) +func TestNewDeployAsteriscScript(t *testing.T) { + t.Run("should not fail with current version of DeployAsterisc contract", func(t *testing.T) { + // First we grab a test host + host1 := createTestHost(t) + + // Then we load the script + // + // This would raise an error if the Go types didn't match the ABI + deploySuperchain, err := NewDeployAsteriscScript(host1) + require.NoError(t, err) + + // Then we deploy + output, err := deploySuperchain.Run(DeployAsteriscInput{ + PreimageOracle: common.BigToAddress(big.NewInt(1)), + }) + + // And do some simple asserts + require.NoError(t, err) + require.NotNil(t, output) + }) } diff --git a/packages/contracts-bedrock/scripts/deploy/DeployAsterisc.s.sol b/packages/contracts-bedrock/scripts/deploy/DeployAsterisc.s.sol index 66f6ba33f362f..ba55b674cffce 100644 --- a/packages/contracts-bedrock/scripts/deploy/DeployAsterisc.s.sol +++ b/packages/contracts-bedrock/scripts/deploy/DeployAsterisc.s.sol @@ -1,89 +1,57 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.15; +pragma solidity 0.8.15; // Forge import { Script } from "forge-std/Script.sol"; // Scripts -import { BaseDeployIO } from "scripts/deploy/BaseDeployIO.sol"; import { DeployUtils } from "scripts/libraries/DeployUtils.sol"; // Interfaces import { IPreimageOracle } from "interfaces/cannon/IPreimageOracle.sol"; import { IRISCV } from "interfaces/vendor/asterisc/IRISCV.sol"; -/// @title DeployAsteriscInput -contract DeployAsteriscInput is BaseDeployIO { - // Specify the PreimageOracle to use - address internal _preimageOracle; - - function set(bytes4 _sel, address _value) public { - if (_sel == this.preimageOracle.selector) { - require(_value != address(0), "DeployAsterisc: preimageOracle cannot be empty"); - _preimageOracle = _value; - } else { - revert("DeployAsterisc: unknown selector"); - } - } - - function preimageOracle() public view returns (address) { - require(_preimageOracle != address(0), "DeployAsterisc: preimageOracle not set"); - return _preimageOracle; - } -} - -/// @title DeployAsteriscOutput -contract DeployAsteriscOutput is BaseDeployIO { - IRISCV internal _asteriscSingleton; - - function set(bytes4 _sel, address _value) public { - if (_sel == this.asteriscSingleton.selector) { - require(_value != address(0), "DeployAsterisc: asteriscSingleton cannot be zero address"); - _asteriscSingleton = IRISCV(_value); - } else { - revert("DeployAsterisc: unknown selector"); - } - } - - function checkOutput(DeployAsteriscInput _mi) public view { - DeployUtils.assertValidContractAddress(address(_asteriscSingleton)); - assertValidDeploy(_mi); - } - - function asteriscSingleton() public view returns (IRISCV) { - DeployUtils.assertValidContractAddress(address(_asteriscSingleton)); - return _asteriscSingleton; +/// @title DeployAsterisc +contract DeployAsterisc is Script { + struct Input { + IPreimageOracle preimageOracle; } - function assertValidDeploy(DeployAsteriscInput _mi) public view { - assertValidAsteriscSingleton(_mi); + struct Output { + IRISCV asteriscSingleton; } - function assertValidAsteriscSingleton(DeployAsteriscInput _mi) internal view { - IRISCV asterisc = asteriscSingleton(); + function run(Input memory _input) public returns (Output memory output_) { + assertValidInput(_input); - require(address(asterisc.oracle()) == address(_mi.preimageOracle()), "ASTERISC-10"); - } -} + deployAsteriscSingleton(_input, output_); -/// @title DeployAsterisc -contract DeployAsterisc is Script { - function run(DeployAsteriscInput _mi, DeployAsteriscOutput _mo) public { - DeployAsteriscSingleton(_mi, _mo); - _mo.checkOutput(_mi); + assertValidOutput(_input, output_); } - function DeployAsteriscSingleton(DeployAsteriscInput _mi, DeployAsteriscOutput _mo) internal { - IPreimageOracle preimageOracle = IPreimageOracle(_mi.preimageOracle()); + function deployAsteriscSingleton(Input memory _input, Output memory _output) internal { vm.broadcast(msg.sender); IRISCV singleton = IRISCV( DeployUtils.create1({ _name: "RISCV", - _args: DeployUtils.encodeConstructor(abi.encodeCall(IRISCV.__constructor__, (preimageOracle))) + _args: DeployUtils.encodeConstructor(abi.encodeCall(IRISCV.__constructor__, (_input.preimageOracle))) }) ); vm.label(address(singleton), "AsteriscSingleton"); - _mo.set(_mo.asteriscSingleton.selector, address(singleton)); + _output.asteriscSingleton = singleton; + } + + function assertValidInput(Input memory _input) internal pure { + require(address(_input.preimageOracle) != address(0), "DeployAsterisc: preimageOracle not set"); + } + + function assertValidOutput(Input memory _input, Output memory _output) internal view { + DeployUtils.assertValidContractAddress(address(_output.asteriscSingleton)); + + require( + _output.asteriscSingleton.oracle() == _input.preimageOracle, + "DeployAsterisc: preimageOracle does not match input" + ); } } diff --git a/packages/contracts-bedrock/scripts/deploy/DeployAsterisc2.s.sol b/packages/contracts-bedrock/scripts/deploy/DeployAsterisc2.s.sol deleted file mode 100644 index a049c9485409e..0000000000000 --- a/packages/contracts-bedrock/scripts/deploy/DeployAsterisc2.s.sol +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.15; - -// Forge -import { Script } from "forge-std/Script.sol"; - -// Scripts -import { DeployUtils } from "scripts/libraries/DeployUtils.sol"; - -// Interfaces -import { IPreimageOracle } from "interfaces/cannon/IPreimageOracle.sol"; -import { IRISCV } from "interfaces/vendor/asterisc/IRISCV.sol"; - -/// @title DeployAsterisc2 -contract DeployAsterisc2 is Script { - struct Input { - IPreimageOracle preimageOracle; - } - - struct Output { - IRISCV asteriscSingleton; - } - - function run(Input memory _input) public returns (Output memory output_) { - assertValidInput(_input); - - deployAsteriscSingleton(_input, output_); - - assertValidOutput(_input, output_); - } - - function deployAsteriscSingleton(Input memory _input, Output memory _output) internal { - vm.broadcast(msg.sender); - IRISCV singleton = IRISCV( - DeployUtils.create1({ - _name: "RISCV", - _args: DeployUtils.encodeConstructor(abi.encodeCall(IRISCV.__constructor__, (_input.preimageOracle))) - }) - ); - - vm.label(address(singleton), "AsteriscSingleton"); - _output.asteriscSingleton = singleton; - } - - function assertValidInput(Input memory _input) internal pure { - require(address(_input.preimageOracle) != address(0), "DeployAsterisc: preimageOracle not set"); - } - - function assertValidOutput(Input memory _input, Output memory _output) internal view { - DeployUtils.assertValidContractAddress(address(_output.asteriscSingleton)); - - require( - _output.asteriscSingleton.oracle() == _input.preimageOracle, - "DeployAsterisc: preimageOracle does not match input" - ); - } -} diff --git a/packages/contracts-bedrock/test/opcm/DeployAsterisc2.t.sol b/packages/contracts-bedrock/test/opcm/DeployAsterisc.t.sol similarity index 67% rename from packages/contracts-bedrock/test/opcm/DeployAsterisc2.t.sol rename to packages/contracts-bedrock/test/opcm/DeployAsterisc.t.sol index 2cd6fef10193a..f2bd971e646cb 100644 --- a/packages/contracts-bedrock/test/opcm/DeployAsterisc2.t.sol +++ b/packages/contracts-bedrock/test/opcm/DeployAsterisc.t.sol @@ -8,29 +8,29 @@ import { DeployUtils } from "scripts/libraries/DeployUtils.sol"; // Interfaces import { IPreimageOracle } from "interfaces/cannon/IPreimageOracle.sol"; -import { DeployAsterisc2 } from "scripts/deploy/DeployAsterisc2.s.sol"; +import { DeployAsterisc } from "scripts/deploy/DeployAsterisc.s.sol"; -contract DeployAsterisc2_Test is Test { - DeployAsterisc2 deployAsterisc; +contract DeployAsterisc_Test is Test { + DeployAsterisc deployAsterisc; // Define default input variables for testing. IPreimageOracle defaultPreimageOracle = IPreimageOracle(makeAddr("preimageOracle")); function setUp() public { - deployAsterisc = new DeployAsterisc2(); + deployAsterisc = new DeployAsterisc(); } - function test_run_succeeds(DeployAsterisc2.Input memory _input) public { + function test_run_succeeds(DeployAsterisc.Input memory _input) public { vm.assume(address(_input.preimageOracle) != address(0)); - DeployAsterisc2.Output memory output = deployAsterisc.run(_input); + DeployAsterisc.Output memory output = deployAsterisc.run(_input); DeployUtils.assertValidContractAddress(address(output.asteriscSingleton)); assertEq(address(output.asteriscSingleton.oracle()), address(_input.preimageOracle), "100"); } function test_run_nullInput_reverts() public { - DeployAsterisc2.Input memory input; + DeployAsterisc.Input memory input; input = defaultInput(); input.preimageOracle = IPreimageOracle(address(0)); @@ -38,7 +38,7 @@ contract DeployAsterisc2_Test is Test { deployAsterisc.run(input); } - function defaultInput() internal view returns (DeployAsterisc2.Input memory input_) { - input_ = DeployAsterisc2.Input(defaultPreimageOracle); + function defaultInput() internal view returns (DeployAsterisc.Input memory input_) { + input_ = DeployAsterisc.Input(defaultPreimageOracle); } }