Skip to content
Merged
3 changes: 1 addition & 2 deletions cannon/mipsevm/tests/evm_multithreaded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func TestEVM_MT_StoreOpsClearMemReservation32(t *testing.T) {
}

func TestEVM_SysClone_FlagHandling(t *testing.T) {
contracts := testutil.TestContractsSetup(t, testutil.MipsMultithreaded)

cases := []struct {
name string
Expand Down Expand Up @@ -283,7 +282,7 @@ func TestEVM_SysClone_FlagHandling(t *testing.T) {
require.Equal(t, 2, state.ThreadCount())
}

testutil.ValidateEVM(t, stepWitness, curStep, goVm, multithreaded.GetStateHashFn(), contracts)
testutil.ValidateEVM(t, stepWitness, curStep, goVm, multithreaded.GetStateHashFn(), version.Contracts)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions cannon/mipsevm/tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type VersionedVMTestCase struct {
func GetSingleThreadedTestCase(t require.TestingT) VersionedVMTestCase {
return VersionedVMTestCase{
Name: "single-threaded",
Contracts: testutil.TestContractsSetup(t, testutil.MipsSingleThreaded),
Contracts: testutil.TestContractsSetup(t, testutil.MipsSingleThreaded, 0),
StateHashFn: singlethreaded.GetStateHashFn(),
VMFactory: singleThreadedVmFactory,
ElfVMFactory: singleThreadElfVmFactory,
Expand All @@ -112,7 +112,7 @@ func GetMultiThreadedTestCase(t require.TestingT, version versions.StateVersion)
features := versions.FeaturesForVersion(version)
return VersionedVMTestCase{
Name: version.String(),
Contracts: testutil.TestContractsSetup(t, testutil.MipsMultithreaded),
Contracts: testutil.TestContractsSetup(t, testutil.MipsMultithreaded, uint8(version)),
StateHashFn: multithreaded.GetStateHashFn(),
VMFactory: func(po mipsevm.PreimageOracle, stdOut, stdErr io.Writer, log log.Logger, opts ...testutil.StateOption) mipsevm.FPVM {
return multiThreadedVmFactory(po, stdOut, stdErr, log, features, opts...)
Expand Down
22 changes: 17 additions & 5 deletions cannon/mipsevm/testutil/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/triedb"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"

"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
Expand Down Expand Up @@ -42,9 +43,10 @@ type Addresses struct {
type ContractMetadata struct {
Artifacts *Artifacts
Addresses *Addresses
Version uint8 // versions.StateVersion can't be used as it causes dependency cycles
}

func TestContractsSetup(t require.TestingT, version MipsVersion) *ContractMetadata {
func TestContractsSetup(t require.TestingT, version MipsVersion, stateVersion uint8) *ContractMetadata {
artifacts, err := loadArtifacts(version)
require.NoError(t, err)

Expand All @@ -55,7 +57,7 @@ func TestContractsSetup(t require.TestingT, version MipsVersion) *ContractMetada
FeeRecipient: common.Address{0xaa},
}

return &ContractMetadata{Artifacts: artifacts, Addresses: addrs}
return &ContractMetadata{Artifacts: artifacts, Addresses: addrs, Version: stateVersion}
}

// loadArtifacts loads the Cannon contracts, from the contracts package.
Expand Down Expand Up @@ -116,9 +118,19 @@ func NewEVMEnv(contracts *ContractMetadata) (*vm.EVM, *state.StateDB) {
// pre-deploy the contracts
env.StateDB.SetCode(contracts.Addresses.Oracle, contracts.Artifacts.Oracle.DeployedBytecode.Object)

var mipsCtorArgs [32]byte
copy(mipsCtorArgs[12:], contracts.Addresses.Oracle[:])
mipsDeploy := append(bytes.Clone(contracts.Artifacts.MIPS.Bytecode.Object), mipsCtorArgs[:]...)
var ctorArgs []byte
if contracts.Version == 0 { // Old MIPS.sol doesn't specify the state version in the constructor
var mipsCtorArgs [32]byte
copy(mipsCtorArgs[12:], contracts.Addresses.Oracle[:])
ctorArgs = mipsCtorArgs[:]
} else {
var mipsCtorArgs [64]byte
copy(mipsCtorArgs[12:], contracts.Addresses.Oracle[:])
vers := uint256.NewInt(uint64(contracts.Version)).Bytes32()
copy(mipsCtorArgs[32:], vers[:])
ctorArgs = mipsCtorArgs[:]
}
mipsDeploy := append(bytes.Clone(contracts.Artifacts.MIPS.Bytecode.Object), ctorArgs...)
startingGas := uint64(30_000_000)
_, deployedMipsAddr, leftOverGas, err := env.Create(contracts.Addresses.Sender, mipsDeploy, startingGas, common.U2560)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion op-chain-ops/interopgen/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (recipe *InteropDevRecipe) Build(addrs devkeys.Addresses) (*WorldConfig, er
ChallengePeriodSeconds: big.NewInt(120),
ProofMaturityDelaySeconds: big.NewInt(12),
DisputeGameFinalityDelaySeconds: big.NewInt(6),
MipsVersion: big.NewInt(2),
MipsVersion: big.NewInt(6),
},
UseInterop: true,
},
Expand Down
4 changes: 2 additions & 2 deletions op-deployer/pkg/deployer/bootstrap/implementations.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (c *ImplementationsConfig) Check() error {
} else {
c.L1ContractsRelease = "dev"
}
if c.MIPSVersion != 1 && c.MIPSVersion != 2 {
return errors.New("MIPS version must be specified as either 1 or 2")
if c.MIPSVersion != 1 && c.MIPSVersion != 6 {
return errors.New("MIPS version must be specified as either 1 or 6")
}
if c.WithdrawalDelaySeconds == 0 {
return errors.New("withdrawal delay in seconds must be specified")
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/integration_test/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func TestProofParamOverrides(t *testing.T) {
"preimageOracleChallengePeriod": standard.ChallengePeriodSeconds + 1,
"proofMaturityDelaySeconds": standard.ProofMaturityDelaySeconds + 1,
"disputeGameFinalityDelaySeconds": standard.DisputeGameFinalityDelaySeconds + 1,
"mipsVersion": standard.MIPSVersion + 1,
"mipsVersion": 6, // Contract enforces a valid value be used
"respectedGameType": standard.DisputeGameType, // This must be set to the permissioned game
"faultGameAbsolutePrestate": common.Hash{'A', 'B', 'S', 'O', 'L', 'U', 'T', 'E'},
"faultGameMaxDepth": standard.DisputeMaxGameDepth + 1,
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/pipeline/dispute_games.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func deployDisputeGame(
case state.VMTypeCannon1, state.VMTypeCannon2:
mipsVersion := 1
if game.VMType == state.VMTypeCannon2 {
mipsVersion = 2
mipsVersion = 6
}

out, err := opcm.DeployMIPS(env.L1ScriptHost, opcm.DeployMIPSInput{
Expand Down
2 changes: 1 addition & 1 deletion op-deployer/pkg/deployer/standard/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
ChallengePeriodSeconds uint64 = 86400
ProofMaturityDelaySeconds uint64 = 604800
DisputeGameFinalityDelaySeconds uint64 = 302400
MIPSVersion uint64 = 2
MIPSVersion uint64 = 6
DisputeGameType uint32 = 1 // PERMISSIONED game type
DisputeMaxGameDepth uint64 = 73
DisputeSplitDepth uint64 = 30
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/interfaces/cannon/IMIPS2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ interface IMIPS2 is ISemver {
external
returns (bytes32 postState_);

function __constructor__(IPreimageOracle _oracle) external;
function __constructor__(IPreimageOracle _oracle, uint256 /*_stateVersion*/) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ ALLOWED_FILES=(
"src/L2/SuperchainTokenBridge.sol:SuperchainTokenBridge"
"src/L2/SuperchainETHBridge.sol:SuperchainETHBridge"
"src/L2/WETH.sol:WETH"
# "src/cannon/MIPS.sol:MIPS"
# "src/cannon/MIPS2.sol:MIPS2"
# "src/cannon/MIPS64.sol:MIPS64"
"src/cannon/MIPS.sol:MIPS"
"src/cannon/MIPS2.sol:MIPS2"
"src/cannon/MIPS64.sol:MIPS64"
"src/cannon/PreimageOracle.sol:PreimageOracle"
# "src/dispute/AnchorStateRegistry.sol:AnchorStateRegistry"
"src/dispute/DelayedWETH.sol:DelayedWETH"
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ contract Deploy is Deployer {
dii.set(dii.challengePeriodSeconds.selector, cfg.preimageOracleChallengePeriod());
dii.set(dii.proofMaturityDelaySeconds.selector, cfg.proofMaturityDelaySeconds());
dii.set(dii.disputeGameFinalityDelaySeconds.selector, cfg.disputeGameFinalityDelaySeconds());
dii.set(dii.mipsVersion.selector, Config.useMultithreadedCannon() ? 2 : 1);
dii.set(dii.mipsVersion.selector, Config.useMultithreadedCannon() ? 6 : 1);
string memory release = "dev";
dii.set(dii.l1ContractsRelease.selector, release);
dii.set(dii.protocolVersionsProxy.selector, artifacts.mustGetAddress("ProtocolVersionsProxy"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IProtocolVersions } from "interfaces/L1/IProtocolVersions.sol";
import { IDelayedWETH } from "interfaces/dispute/IDelayedWETH.sol";
import { IPreimageOracle } from "interfaces/cannon/IPreimageOracle.sol";
import { IMIPS } from "interfaces/cannon/IMIPS.sol";
import { IMIPS2 } from "interfaces/cannon/IMIPS2.sol";
import { IDisputeGameFactory } from "interfaces/dispute/IDisputeGameFactory.sol";
import { IAnchorStateRegistry } from "interfaces/dispute/IAnchorStateRegistry.sol";
import {
Expand Down Expand Up @@ -838,23 +839,36 @@ contract DeployImplementations is Script {
}

function deployMipsSingleton(DeployImplementationsInput _dii, DeployImplementationsOutput _dio) public virtual {
IMIPS singleton;
uint256 mipsVersion = _dii.mipsVersion();
IPreimageOracle preimageOracle = IPreimageOracle(address(_dio.preimageOracleSingleton()));

// We want to ensure that the OPCM for upgrade 13 is deployed with Mips32 on production networks.
if (mipsVersion != 2) {
if (mipsVersion < 2) {
if (block.chainid == Chains.Mainnet || block.chainid == Chains.Sepolia) {
revert("DeployImplementations: Only Mips64 should be deployed on Mainnet or Sepolia");
}
}

IMIPS singleton = IMIPS(
DeployUtils.createDeterministic({
_name: mipsVersion == 1 ? "MIPS" : "MIPS64",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle))),
_salt: _salt
})
);
if (mipsVersion == 1) {
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: "MIPS",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle))),
_salt: DeployUtils.DEFAULT_SALT
})
);
} else {
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: "MIPS64",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(IMIPS2.__constructor__, (preimageOracle, mipsVersion))
),
_salt: DeployUtils.DEFAULT_SALT
})
);
}
vm.label(address(singleton), "MIPSSingleton");
_dio.set(_dio.mipsSingleton.selector, address(singleton));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { IProtocolVersions } from "interfaces/L1/IProtocolVersions.sol";
import { IDelayedWETH } from "interfaces/dispute/IDelayedWETH.sol";
import { IPreimageOracle } from "interfaces/cannon/IPreimageOracle.sol";
import { IMIPS } from "interfaces/cannon/IMIPS.sol";
import { IMIPS2 } from "interfaces/cannon/IMIPS2.sol";
import { IDisputeGameFactory } from "interfaces/dispute/IDisputeGameFactory.sol";
import { IAnchorStateRegistry } from "interfaces/dispute/IAnchorStateRegistry.sol";
import {
Expand Down Expand Up @@ -400,23 +401,36 @@ contract DeployImplementations2 is Script {
}

function deployMipsSingleton(Input memory _input, Output memory _output) private {
IMIPS singleton;
uint256 mipsVersion = _input.mipsVersion;
IPreimageOracle preimageOracle = IPreimageOracle(address(_output.preimageOracleSingleton));

// We want to ensure that the OPCM for upgrade 13 is deployed with Mips32 on production networks.
if (mipsVersion != 2) {
if (mipsVersion < 2) {
if (block.chainid == Chains.Mainnet || block.chainid == Chains.Sepolia) {
revert("DeployImplementations: Only Mips64 should be deployed on Mainnet or Sepolia");
}
}

IMIPS singleton = IMIPS(
DeployUtils.createDeterministic({
_name: mipsVersion == 1 ? "MIPS" : "MIPS64",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle))),
_salt: _salt
})
);
if (mipsVersion == 1) {
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: "MIPS",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle))),
_salt: DeployUtils.DEFAULT_SALT
})
);
} else {
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: "MIPS64",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(IMIPS2.__constructor__, (preimageOracle, mipsVersion))
),
_salt: DeployUtils.DEFAULT_SALT
})
);
}
vm.label(address(singleton), "MIPSSingleton");
_output.mipsSingleton = singleton;
}
Expand Down
31 changes: 22 additions & 9 deletions packages/contracts-bedrock/scripts/deploy/DeployMIPS.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DeployUtils } from "scripts/libraries/DeployUtils.sol";
// Interfaces
import { IPreimageOracle } from "interfaces/cannon/IPreimageOracle.sol";
import { IMIPS } from "interfaces/cannon/IMIPS.sol";
import { IMIPS2 } from "interfaces/cannon/IMIPS2.sol";

/// @title DeployMIPSInput
contract DeployMIPSInput is BaseDeployIO {
Expand All @@ -22,7 +23,7 @@ contract DeployMIPSInput is BaseDeployIO {

function set(bytes4 _sel, uint256 _value) public {
if (_sel == this.mipsVersion.selector) {
require(_value == 1 || _value == 2, "DeployMIPS: unknown mips version");
require(_value == 1 || _value == 6, "DeployMIPS: unknown mips version");
_mipsVersion = _value;
} else {
revert("DeployMIPS: unknown selector");
Expand All @@ -40,7 +41,7 @@ contract DeployMIPSInput is BaseDeployIO {

function mipsVersion() public view returns (uint256) {
require(_mipsVersion != 0, "DeployMIPS: mipsVersion not set");
require(_mipsVersion == 1 || _mipsVersion == 2, "DeployMIPS: unknown mips version");
require(_mipsVersion == 1 || _mipsVersion == 6, "DeployMIPS: unknown mips version");
return _mipsVersion;
}

Expand Down Expand Up @@ -80,13 +81,25 @@ contract DeployMIPS is Script {
IMIPS singleton;
uint256 mipsVersion = _mi.mipsVersion();
IPreimageOracle preimageOracle = IPreimageOracle(_mi.preimageOracle());
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: mipsVersion == 1 ? "MIPS" : "MIPS64",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle))),
_salt: DeployUtils.DEFAULT_SALT
})
);
if (mipsVersion == 1) {
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: "MIPS",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle))),
_salt: DeployUtils.DEFAULT_SALT
})
);
} else {
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: "MIPS64",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(IMIPS2.__constructor__, (preimageOracle, mipsVersion))
),
_salt: DeployUtils.DEFAULT_SALT
})
);
}

vm.label(address(singleton), "MIPSSingleton");
_mo.set(_mo.mipsSingleton.selector, address(singleton));
Expand Down
31 changes: 22 additions & 9 deletions packages/contracts-bedrock/scripts/deploy/DeployMIPS2.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DeployUtils } from "scripts/libraries/DeployUtils.sol";
// Interfaces
import { IPreimageOracle } from "interfaces/cannon/IPreimageOracle.sol";
import { IMIPS } from "interfaces/cannon/IMIPS.sol";
import { IMIPS2 } from "interfaces/cannon/IMIPS2.sol";

/// @title DeployMIPS
contract DeployMIPS2 is Script {
Expand All @@ -33,16 +34,28 @@ contract DeployMIPS2 is Script {
}

function deployMipsSingleton(Input memory _input, Output memory _output) internal {
IMIPS singleton;
uint256 mipsVersion = _input.mipsVersion;
string memory contractName = mipsVersion == 1 ? "MIPS" : "MIPS64";

IMIPS singleton = IMIPS(
DeployUtils.createDeterministic({
_name: contractName,
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (_input.preimageOracle))),
_salt: DeployUtils.DEFAULT_SALT
})
);
if (mipsVersion == 1) {
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: "MIPS",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (_input.preimageOracle))),
_salt: DeployUtils.DEFAULT_SALT
})
);
} else {
singleton = IMIPS(
DeployUtils.createDeterministic({
_name: "MIPS64",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(IMIPS2.__constructor__, (_input.preimageOracle, mipsVersion))
),
_salt: DeployUtils.DEFAULT_SALT
})
);
}

vm.label(address(singleton), "MIPSSingleton");
_output.mipsSingleton = singleton;
Expand All @@ -51,7 +64,7 @@ contract DeployMIPS2 is Script {
function assertValidInput(Input memory _input) public pure {
require(address(_input.preimageOracle) != address(0), "DeployMIPS: preimageOracle not set");
require(_input.mipsVersion != 0, "DeployMIPS: mipsVersion not set");
require(_input.mipsVersion == 1 || _input.mipsVersion == 2, "DeployMIPS: unknown mips version");
require(_input.mipsVersion == 1 || _input.mipsVersion == 6, "DeployMIPS: unknown mips version");
}

function assertValidOutput(Input memory _input, Output memory _output) public view {
Expand Down
5 changes: 5 additions & 0 deletions packages/contracts-bedrock/snapshots/abi/MIPS2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"internalType": "contract IPreimageOracle",
"name": "_oracle",
"type": "address"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
Expand Down
Loading