Skip to content

Commit

Permalink
maint(ct): add leftover interfaces
Browse files Browse the repository at this point in the history
Adds a few remaining interfaces required before we can migrate
OPCM to use interfaces over source contracts.
  • Loading branch information
smartcontracts committed Sep 27, 2024
1 parent a9c7f34 commit 0d8b5b3
Show file tree
Hide file tree
Showing 31 changed files with 356 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ contract DeployImplementations is Script {
if (existingImplementation != address(0)) {
singleton = MIPS(payable(existingImplementation));
} else if (isDevelopRelease(release)) {
IPreimageOracle preimageOracle = IPreimageOracle(_dio.preimageOracleSingleton());
IPreimageOracle preimageOracle = IPreimageOracle(address(_dio.preimageOracleSingleton()));
vm.broadcast(msg.sender);
singleton = new MIPS(preimageOracle);
} else {
Expand Down
3 changes: 0 additions & 3 deletions packages/contracts-bedrock/scripts/deploy/ChainAssertions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { DeployConfig } from "scripts/deploy/DeployConfig.s.sol";
import { Deployer } from "scripts/deploy/Deployer.sol";
import { ISystemConfigV0 } from "scripts/interfaces/ISystemConfigV0.sol";

// Contracts
import { ProxyAdmin } from "src/universal/ProxyAdmin.sol";

// Libraries
import { Constants } from "src/libraries/Constants.sol";
import { Predeploys } from "src/libraries/Predeploys.sol";
Expand Down
195 changes: 108 additions & 87 deletions packages/contracts-bedrock/scripts/deploy/Deploy.s.sol

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions packages/contracts-bedrock/scripts/fpac/FPACOPS.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ pragma solidity 0.8.15;
import { StdAssertions } from "forge-std/StdAssertions.sol";
import "scripts/deploy/Deploy.s.sol";

// Contracts
import { Proxy } from "src/universal/Proxy.sol";

// Libraries
import "src/dispute/lib/Types.sol";

// Interfaces
import { IProxy } from "src/universal/interfaces/IProxy.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { IAnchorStateRegistry } from "src/dispute/interfaces/IAnchorStateRegistry.sol";
import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
Expand Down Expand Up @@ -78,7 +76,7 @@ contract FPACOPS is Deploy, StdAssertions {
console.log("Initializing DisputeGameFactoryProxy with DisputeGameFactory.");

address dgfProxy = mustGetAddress("DisputeGameFactoryProxy");
Proxy(payable(dgfProxy)).upgradeToAndCall(
IProxy(payable(dgfProxy)).upgradeToAndCall(
mustGetAddress("DisputeGameFactory"), abi.encodeCall(IDisputeGameFactory.initialize, msg.sender)
);

Expand All @@ -93,7 +91,7 @@ contract FPACOPS is Deploy, StdAssertions {

address wethProxy = mustGetAddress("DelayedWETHProxy");
address superchainConfigProxy = mustGetAddress("SuperchainConfigProxy");
Proxy(payable(wethProxy)).upgradeToAndCall(
IProxy(payable(wethProxy)).upgradeToAndCall(
mustGetAddress("DelayedWETH"),
abi.encodeCall(IDelayedWETH.initialize, (msg.sender, ISuperchainConfig(superchainConfigProxy)))
);
Expand Down Expand Up @@ -121,7 +119,7 @@ contract FPACOPS is Deploy, StdAssertions {
});

address asrProxy = mustGetAddress("AnchorStateRegistryProxy");
Proxy(payable(asrProxy)).upgradeToAndCall(
IProxy(payable(asrProxy)).upgradeToAndCall(
mustGetAddress("AnchorStateRegistry"),
abi.encodeCall(IAnchorStateRegistry.initialize, (roots, superchainConfig))
);
Expand All @@ -136,7 +134,7 @@ contract FPACOPS is Deploy, StdAssertions {
dgf.transferOwnership(_systemOwnerSafe);

// Transfer the admin rights of the DisputeGameFactoryProxy to the ProxyAdmin.
Proxy prox = Proxy(payable(address(dgf)));
IProxy prox = IProxy(payable(address(dgf)));
prox.changeAdmin(_proxyAdmin);
}

Expand All @@ -149,7 +147,7 @@ contract FPACOPS is Deploy, StdAssertions {
weth.transferOwnership(_systemOwnerSafe);

// Transfer the admin rights of the DelayedWETHProxy to the ProxyAdmin.
Proxy prox = Proxy(payable(address(weth)));
IProxy prox = IProxy(payable(address(weth)));
prox.changeAdmin(_proxyAdmin);
}

Expand All @@ -158,7 +156,7 @@ contract FPACOPS is Deploy, StdAssertions {
IAnchorStateRegistry asr = IAnchorStateRegistry(mustGetAddress("AnchorStateRegistryProxy"));

// Transfer the admin rights of the AnchorStateRegistryProxy to the ProxyAdmin.
Proxy prox = Proxy(payable(address(asr)));
IProxy prox = IProxy(payable(address(asr)));
prox.changeAdmin(_proxyAdmin);
}

Expand All @@ -182,11 +180,11 @@ contract FPACOPS is Deploy, StdAssertions {
// Check the config elements in the deployed contracts.
ChainAssertions.checkOptimismPortal2(contracts, cfg, false);

PreimageOracle oracle = PreimageOracle(mustGetAddress("PreimageOracle"));
IPreimageOracle oracle = IPreimageOracle(mustGetAddress("PreimageOracle"));
assertEq(oracle.minProposalSize(), cfg.preimageOracleMinProposalSize());
assertEq(oracle.challengePeriod(), cfg.preimageOracleChallengePeriod());

MIPS mips = MIPS(mustGetAddress("Mips"));
IMIPS mips = IMIPS(mustGetAddress("Mips"));
assertEq(address(mips.oracle()), address(oracle));

// Check the AnchorStateRegistry configuration.
Expand Down
16 changes: 7 additions & 9 deletions packages/contracts-bedrock/scripts/fpac/FPACOPS2.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ pragma solidity 0.8.15;
import { StdAssertions } from "forge-std/StdAssertions.sol";
import "scripts/deploy/Deploy.s.sol";

// Contracts
import { Proxy } from "src/universal/Proxy.sol";

// Libraries
import "src/dispute/lib/Types.sol";

// Interfaces
import { IProxy } from "src/universal/interfaces/IProxy.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { IAnchorStateRegistry } from "src/dispute/interfaces/IAnchorStateRegistry.sol";
import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
Expand Down Expand Up @@ -152,7 +150,7 @@ contract FPACOPS2 is Deploy, StdAssertions {

address wethProxy = mustGetAddress("DelayedWETHProxy");
address superchainConfigProxy = mustGetAddress("SuperchainConfigProxy");
Proxy(payable(wethProxy)).upgradeToAndCall(
IProxy(payable(wethProxy)).upgradeToAndCall(
mustGetAddress("DelayedWETH"),
abi.encodeCall(IDelayedWETH.initialize, (msg.sender, ISuperchainConfig(superchainConfigProxy)))
);
Expand All @@ -164,7 +162,7 @@ contract FPACOPS2 is Deploy, StdAssertions {

address wethProxy = mustGetAddress("PermissionedDelayedWETHProxy");
address superchainConfigProxy = mustGetAddress("SuperchainConfigProxy");
Proxy(payable(wethProxy)).upgradeToAndCall(
IProxy(payable(wethProxy)).upgradeToAndCall(
mustGetAddress("DelayedWETH"),
abi.encodeCall(IDelayedWETH.initialize, (msg.sender, ISuperchainConfig(superchainConfigProxy)))
);
Expand All @@ -181,7 +179,7 @@ contract FPACOPS2 is Deploy, StdAssertions {
weth.transferOwnership(_systemOwnerSafe);

// Transfer the admin rights of the DelayedWETHProxy to the ProxyAdmin.
Proxy prox = Proxy(payable(address(weth)));
IProxy prox = IProxy(payable(address(weth)));
prox.changeAdmin(_proxyAdmin);
}

Expand All @@ -196,7 +194,7 @@ contract FPACOPS2 is Deploy, StdAssertions {
weth.transferOwnership(_systemOwnerSafe);

// Transfer the admin rights of the DelayedWETHProxy to the ProxyAdmin.
Proxy prox = Proxy(payable(address(weth)));
IProxy prox = IProxy(payable(address(weth)));
prox.changeAdmin(_proxyAdmin);
}

Expand Down Expand Up @@ -225,12 +223,12 @@ contract FPACOPS2 is Deploy, StdAssertions {
ChainAssertions.checkPermissionedDelayedWETH(contracts, cfg, true, _systemOwnerSafe);

// Verify PreimageOracle configuration.
PreimageOracle oracle = PreimageOracle(mustGetAddress("PreimageOracle"));
IPreimageOracle oracle = IPreimageOracle(mustGetAddress("PreimageOracle"));
assertEq(oracle.minProposalSize(), cfg.preimageOracleMinProposalSize());
assertEq(oracle.challengePeriod(), cfg.preimageOracleChallengePeriod());

// Verify MIPS configuration.
MIPS mips = MIPS(mustGetAddress("Mips"));
IMIPS mips = IMIPS(mustGetAddress("Mips"));
assertEq(address(mips.oracle()), address(oracle));

// Grab ASR
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts-bedrock/scripts/libraries/DeployUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Artifacts } from "scripts/Artifacts.s.sol";
import { LibString } from "@solady/utils/LibString.sol";
import { Bytes } from "src/libraries/Bytes.sol";

// Contracts
import { Proxy } from "src/universal/Proxy.sol";
// Interfaces
import { IProxy } from "src/universal/interfaces/IProxy.sol";

library DeployUtils {
Vm internal constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
Expand Down Expand Up @@ -221,7 +221,7 @@ library DeployUtils {
// We prank as the zero address due to the Proxy's `proxyCallIfNotAdmin` modifier.
// Pranking inside this function also means it can no longer be considered `view`.
vm.prank(address(0));
address implementation = Proxy(payable(_proxy)).implementation();
address implementation = IProxy(payable(_proxy)).implementation();
assertValidContractAddress(implementation);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// TODO: Migrate this script to use DeployUtils

import { console2 as console } from "forge-std/console2.sol";
import { Script } from "forge-std/Script.sol";
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"sourceCodeHash": "0xde4df0f9633dc0cdb1c9f634003ea5b0f7c5c1aebc407bc1b2f44c0ecf938649"
},
"src/L1/OPContractsManager.sol": {
"initCodeHash": "0x620481066bd0979c409ed9c089d32a1b7a05c610509222901ee3e73b0dc5565d",
"sourceCodeHash": "0x1bd201aef876cd32a34f8b100362df87ffaa0c1ddfbf5a19a5c43ced4c26d791"
"initCodeHash": "0x944deadee322fdbae8a8fffd16deceb3766509cfb54da06adb8aa84473f79f53",
"sourceCodeHash": "0x1a48119cbc0b778a4dd3454179060b71361ba44b61af1ac6398cc9274bb5e89f"
},
"src/L1/OptimismPortal.sol": {
"initCodeHash": "0xbe2c0c81b3459014f287d8c89cdc0d27dde5d1f44e5d024fa1e4773ddc47c190",
Expand Down Expand Up @@ -148,8 +148,8 @@
"sourceCodeHash": "0x50ed780b621521047ed36ffb260032f2e5ec287f3e1ab3d742c7de45febb280d"
},
"src/cannon/PreimageOracle.sol": {
"initCodeHash": "0x801e52f9c8439fcf7089575fa93272dfb874641dbfc7d82f36d979c987271c0b",
"sourceCodeHash": "0xdb9421a552e6d7581b3db9e4c2a02d8210ad6ca66ba0f8703d77f7cd4b8e132b"
"initCodeHash": "0x3690e6dafe588c29de74790123bf6de5b0f741869bf5dbd8a122fdef96cab733",
"sourceCodeHash": "0x19b48b7d5fcb296cacf0cb15326b2e12a9556d6d811a16cbe2344792afa30427"
},
"src/dispute/AnchorStateRegistry.sol": {
"initCodeHash": "0x13d00eef8c3f769863fc766180acc8586f5da309ca0a098e67d4d90bd3243341",
Expand Down
7 changes: 4 additions & 3 deletions packages/contracts-bedrock/src/L1/OPContractsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
import { IAnchorStateRegistry } from "src/dispute/interfaces/IAnchorStateRegistry.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { ISystemConfigV160 } from "src/L1/interfaces/ISystemConfigV160.sol";
import { IAddressManager } from "src/legacy/interfaces/IAddressManager.sol";

import { Proxy } from "src/universal/Proxy.sol";
import { ProxyAdmin } from "src/universal/ProxyAdmin.sol";
Expand Down Expand Up @@ -127,8 +128,8 @@ contract OPContractsManager is ISemver, Initializable {

// -------- Constants and Variables --------

/// @custom:semver 1.0.0-beta.13
string public constant version = "1.0.0-beta.13";
/// @custom:semver 1.0.0-beta.14
string public constant version = "1.0.0-beta.14";

/// @notice Represents the interface version so consumers know how to decode the DeployOutput struct
/// that's emitted in the `Deployed` event. Whenever that struct changes, a new version should be used.
Expand Down Expand Up @@ -240,7 +241,7 @@ contract OPContractsManager is ISemver, Initializable {
output.addressManager = AddressManager(Blueprint.deployFrom(blueprint.addressManager, salt));
output.opChainProxyAdmin =
ProxyAdmin(Blueprint.deployFrom(blueprint.proxyAdmin, salt, abi.encode(address(this))));
output.opChainProxyAdmin.setAddressManager(output.addressManager);
output.opChainProxyAdmin.setAddressManager(IAddressManager(address(output.addressManager)));

// -------- Deploy Proxy Contracts --------

Expand Down
68 changes: 56 additions & 12 deletions packages/contracts-bedrock/src/cannon/PreimageOracle.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import { IPreimageOracle } from "./interfaces/IPreimageOracle.sol";
import { ISemver } from "src/universal/interfaces/ISemver.sol";
import { PreimageKeyLib } from "./PreimageKeyLib.sol";
// Libraries
import { LibKeccak } from "@lib-keccak/LibKeccak.sol";
import { PreimageKeyLib } from "src/cannon/PreimageKeyLib.sol";
import "src/cannon/libraries/CannonErrors.sol";
import "src/cannon/libraries/CannonTypes.sol";

// Interfaces
import { ISemver } from "src/universal/interfaces/ISemver.sol";

/// @title PreimageOracle
/// @notice A contract for storing permissioned pre-images.
/// @custom:attribution Solady <https://github.com/Vectorized/solady/blob/main/src/utils/MerkleProofLib.sol#L13-L43>
/// @custom:attribution Beacon Deposit Contract <0x00000000219ab540356cbb839cbe05303d7705fa>
contract PreimageOracle is IPreimageOracle, ISemver {
contract PreimageOracle is ISemver {
////////////////////////////////////////////////////////////////
// Constants & Immutables //
////////////////////////////////////////////////////////////////
Expand All @@ -31,8 +33,8 @@ contract PreimageOracle is IPreimageOracle, ISemver {
uint256 public constant PRECOMPILE_CALL_RESERVED_GAS = 100_000;

/// @notice The semantic version of the Preimage Oracle contract.
/// @custom:semver 1.1.3-beta.2
string public constant version = "1.1.3-beta.2";
/// @custom:semver 1.1.3-beta.3
string public constant version = "1.1.3-beta.3";

////////////////////////////////////////////////////////////////
// Authorized Preimage Parts //
Expand Down Expand Up @@ -107,7 +109,11 @@ contract PreimageOracle is IPreimageOracle, ISemver {
// Standard Preimage Route (External) //
////////////////////////////////////////////////////////////////

/// @inheritdoc IPreimageOracle
/// @notice Reads a preimage from the oracle.
/// @param _key The key of the preimage to read.
/// @param _offset The offset of the preimage to read.
/// @return dat_ The preimage data.
/// @return datLen_ The length of the preimage data.
function readPreimage(bytes32 _key, uint256 _offset) external view returns (bytes32 dat_, uint256 datLen_) {
require(preimagePartOk[_key][_offset], "pre-image must exist");

Expand All @@ -123,7 +129,27 @@ contract PreimageOracle is IPreimageOracle, ISemver {
dat_ = preimageParts[_key][_offset];
}

/// @inheritdoc IPreimageOracle
/// @notice Loads of local data part into the preimage oracle.
/// @param _ident The identifier of the local data.
/// @param _localContext The local key context for the preimage oracle. Optionally, can be set as a constant
/// if the caller only requires one set of local keys.
/// @param _word The local data word.
/// @param _size The number of bytes in `_word` to load.
/// @param _partOffset The offset of the local data part to write to the oracle.
/// @dev The local data parts are loaded into the preimage oracle under the context
/// of the caller - no other account can write to the caller's context
/// specific data.
///
/// There are 5 local data identifiers:
/// ┌────────────┬────────────────────────┐
/// │ Identifier │ Data │
/// ├────────────┼────────────────────────┤
/// │ 1 │ L1 Head Hash (bytes32) │
/// │ 2 │ Output Root (bytes32) │
/// │ 3 │ Root Claim (bytes32) │
/// │ 4 │ L2 Block Number (u64) │
/// │ 5 │ Chain ID (u64) │
/// └────────────┴────────────────────────┘
function loadLocalData(
uint256 _ident,
bytes32 _localContext,
Expand Down Expand Up @@ -163,7 +189,10 @@ contract PreimageOracle is IPreimageOracle, ISemver {
preimageLengths[key_] = _size;
}

/// @inheritdoc IPreimageOracle
/// @notice Prepares a preimage to be read by keccak256 key, starting at the given offset and up to 32 bytes
/// (clipped at preimage length, if out of data).
/// @param _partOffset The offset of the preimage to read.
/// @param _preimage The preimage data.
function loadKeccak256PreimagePart(uint256 _partOffset, bytes calldata _preimage) external {
uint256 size;
bytes32 key;
Expand Down Expand Up @@ -198,7 +227,10 @@ contract PreimageOracle is IPreimageOracle, ISemver {
preimageLengths[key] = size;
}

/// @inheritdoc IPreimageOracle
/// @notice Prepares a preimage to be read by sha256 key, starting at the given offset and up to 32 bytes
/// (clipped at preimage length, if out of data).
/// @param _partOffset The offset of the preimage to read.
/// @param _preimage The preimage data.
function loadSha256PreimagePart(uint256 _partOffset, bytes calldata _preimage) external {
uint256 size;
bytes32 key;
Expand Down Expand Up @@ -247,7 +279,13 @@ contract PreimageOracle is IPreimageOracle, ISemver {
preimageLengths[key] = size;
}

/// @inheritdoc IPreimageOracle
/// @notice Verifies that `p(_z) = _y` given `_commitment` that corresponds to the polynomial `p(x)` and a KZG
// proof. The value `y` is the pre-image, and the preimage key is `5 ++ keccak256(_commitment ++ z)[1:]`.
/// @param _z Big endian point value. Part of the preimage key.
/// @param _y Big endian point value. The preimage for the key.
/// @param _commitment The commitment to the polynomial. 48 bytes, part of the preimage key.
/// @param _proof The KZG proof, part of the preimage key.
/// @param _partOffset The offset of the preimage to store.
function loadBlobPreimagePart(
uint256 _z,
uint256 _y,
Expand Down Expand Up @@ -338,7 +376,13 @@ contract PreimageOracle is IPreimageOracle, ISemver {
preimageLengths[key] = 32;
}

/// @inheritdoc IPreimageOracle
/// @notice Prepares a precompile result to be read by a precompile key for the specified offset.
/// The precompile result data is a concatenation of the precompile call status byte and its return data.
/// The preimage key is `6 ++ keccak256(precompile ++ input)[1:]`.
/// @param _partOffset The offset of the precompile result being loaded.
/// @param _precompile The precompile address
/// @param _requiredGas The gas required to fully execute an L1 precompile.
/// @param _input The input to the precompile call.
function loadPrecompilePreimagePart(
uint256 _partOffset,
address _precompile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ interface IPreimageOracle {
bytes calldata _input
)
external;

/// @notice Returns the minimum size (in bytes) of a large preimage proposal.
function minProposalSize() external view returns (uint256);

function __constructor__(uint256 _minProposalSize, uint256 _challengePeriod) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ interface IFaultDisputeGame is IDisputeGame {
function claimCredit(address _recipient) external;
function claimData(uint256)
external
view // nosemgrep
returns (
view
returns ( // nosemgrep
uint32 parentIndex,
address counteredBy,
address claimant,
Expand Down
Loading

0 comments on commit 0d8b5b3

Please sign in to comment.