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
19 changes: 5 additions & 14 deletions op-deployer/pkg/deployer/opcm/asterisc.go
Original file line number Diff line number Diff line change
@@ -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")
}
21 changes: 0 additions & 21 deletions op-deployer/pkg/deployer/opcm/asterisc2.go

This file was deleted.

50 changes: 0 additions & 50 deletions op-deployer/pkg/deployer/opcm/asterisc2_test.go

This file was deleted.

47 changes: 21 additions & 26 deletions op-deployer/pkg/deployer/opcm/asterisc_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
86 changes: 27 additions & 59 deletions packages/contracts-bedrock/scripts/deploy/DeployAsterisc.s.sol
Original file line number Diff line number Diff line change
@@ -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"
);
}
}
57 changes: 0 additions & 57 deletions packages/contracts-bedrock/scripts/deploy/DeployAsterisc2.s.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ 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));
vm.expectRevert("DeployAsterisc: preimageOracle not set");
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);
}
}