Commit 02dd16aa authored by smartcontracts's avatar smartcontracts Committed by GitHub

maint(ct): use mips and oracle interfaces (#12493)

Updates all contracts and tests to use the MIPS and PreimageOracle
interfaces.
parent dea04890
...@@ -26,7 +26,7 @@ var excludeContracts = []string{ ...@@ -26,7 +26,7 @@ var excludeContracts = []string{
"IEAS", "ISchemaResolver", "ISchemaRegistry", "IEAS", "ISchemaResolver", "ISchemaRegistry",
// TODO: Interfaces that need to be fixed // TODO: Interfaces that need to be fixed
"IInitializable", "IPreimageOracle", "ILegacyMintableERC20", "IOptimismMintableERC20", "IInitializable", "ILegacyMintableERC20", "IOptimismMintableERC20",
"IOptimismMintableERC721", "KontrolCheatsBase", "IWETH", "IDelayedWETH", "ISuperchainWETH", "IOptimismMintableERC721", "KontrolCheatsBase", "IWETH", "IDelayedWETH", "ISuperchainWETH",
"IL2ToL2CrossDomainMessenger", "ICrossL2Inbox", "ISystemConfigInterop", "IResolvedDelegateProxy", "IL2ToL2CrossDomainMessenger", "ICrossL2Inbox", "ISystemConfigInterop", "IResolvedDelegateProxy",
} }
......
...@@ -103,6 +103,11 @@ library DeployUtils { ...@@ -103,6 +103,11 @@ library DeployUtils {
require(preComputedAddress.code.length == 0, "DeployUtils: contract already deployed"); require(preComputedAddress.code.length == 0, "DeployUtils: contract already deployed");
assembly { assembly {
addr_ := create2(0, add(initCode, 0x20), mload(initCode), _salt) addr_ := create2(0, add(initCode, 0x20), mload(initCode), _salt)
if iszero(addr_) {
let size := returndatasize()
returndatacopy(0, 0, size)
revert(0, size)
}
} }
assertValidContractAddress(addr_); assertValidContractAddress(addr_);
} }
...@@ -215,6 +220,10 @@ library DeployUtils { ...@@ -215,6 +220,10 @@ library DeployUtils {
/// @notice Asserts that the given address is a valid contract address. /// @notice Asserts that the given address is a valid contract address.
/// @param _who Address to check. /// @param _who Address to check.
function assertValidContractAddress(address _who) internal view { function assertValidContractAddress(address _who) internal view {
// Foundry will set returned address to address(1) whenever a contract creation fails
// inside of a test. If this is the case then let Foundry handle the error itself and don't
// trigger a revert (which would probably break a test).
if (_who == address(1)) return;
require(_who != address(0), "DeployUtils: zero address"); require(_who != address(0), "DeployUtils: zero address");
require(_who.code.length > 0, string.concat("DeployUtils: no code at ", LibString.toHexStringChecksummed(_who))); require(_who.code.length > 0, string.concat("DeployUtils: no code at ", LibString.toHexStringChecksummed(_who)));
} }
......
...@@ -7,6 +7,21 @@ import { IPreimageOracle } from "src/cannon/interfaces/IPreimageOracle.sol"; ...@@ -7,6 +7,21 @@ import { IPreimageOracle } from "src/cannon/interfaces/IPreimageOracle.sol";
/// @title IMIPS /// @title IMIPS
/// @notice Interface for the MIPS contract. /// @notice Interface for the MIPS contract.
interface IMIPS is ISemver { interface IMIPS is ISemver {
struct State {
bytes32 memRoot;
bytes32 preimageKey;
uint32 preimageOffset;
uint32 pc;
uint32 nextPC;
uint32 lo;
uint32 hi;
uint32 heap;
uint8 exitCode;
bool exited;
uint64 step;
uint32[32] registers;
}
error InvalidMemoryProof(); error InvalidMemoryProof();
error InvalidRMWInstruction(); error InvalidRMWInstruction();
......
...@@ -7,6 +7,39 @@ import { IPreimageOracle } from "src/cannon/interfaces/IPreimageOracle.sol"; ...@@ -7,6 +7,39 @@ import { IPreimageOracle } from "src/cannon/interfaces/IPreimageOracle.sol";
/// @title IMIPS2 /// @title IMIPS2
/// @notice Interface for the MIPS2 contract. /// @notice Interface for the MIPS2 contract.
interface IMIPS2 is ISemver { interface IMIPS2 is ISemver {
struct ThreadState {
uint32 threadID;
uint8 exitCode;
bool exited;
uint32 futexAddr;
uint32 futexVal;
uint64 futexTimeoutStep;
uint32 pc;
uint32 nextPC;
uint32 lo;
uint32 hi;
uint32[32] registers;
}
struct State {
bytes32 memRoot;
bytes32 preimageKey;
uint32 preimageOffset;
uint32 heap;
uint8 llReservationStatus;
uint32 llAddress;
uint32 llOwnerThread;
uint8 exitCode;
bool exited;
uint64 step;
uint64 stepsSinceLastContextSwitch;
uint32 wakeup;
bool traverseRight;
bytes32 leftThreadStack;
bytes32 rightThreadStack;
uint32 nextThreadID;
}
error InvalidExitedValue(); error InvalidExitedValue();
error InvalidMemoryProof(); error InvalidMemoryProof();
error InvalidSecondMemoryProof(); error InvalidSecondMemoryProof();
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
/// @title IPreimageOracle import { LibKeccak } from "@lib-keccak/LibKeccak.sol";
/// @notice Interface for a preimage oracle. import { LPPMetaData } from "src/cannon/libraries/CannonTypes.sol";
interface IPreimageOracle { interface IPreimageOracle {
/// @notice Returns the length of the large preimage proposal challenge period. struct Leaf {
/// @return challengePeriod_ The length of the challenge period in seconds. bytes input;
function challengePeriod() external view returns (uint256 challengePeriod_); uint256 index;
bytes32 stateCommitment;
}
/// @notice Reads a preimage from the oracle. error ActiveProposal();
/// @param _key The key of the preimage to read. error AlreadyFinalized();
/// @param _offset The offset of the preimage to read. error AlreadyInitialized();
/// @return dat_ The preimage data. error BadProposal();
/// @return datLen_ The length of the preimage data. error BondTransferFailed();
function readPreimage(bytes32 _key, uint256 _offset) external view returns (bytes32 dat_, uint256 datLen_); error InsufficientBond();
error InvalidInputSize();
error InvalidPreimage();
error InvalidProof();
error NotEOA();
error NotInitialized();
error PartOffsetOOB();
error PostStateMatches();
error StatesNotContiguous();
error TreeSizeOverflow();
error WrongStartingBlock();
/// @notice Loads of local data part into the preimage oracle. function KECCAK_TREE_DEPTH() external view returns (uint256);
/// @param _ident The identifier of the local data. function MAX_LEAF_COUNT() external view returns (uint256);
/// @param _localContext The local key context for the preimage oracle. Optionally, can be set as a constant function MIN_BOND_SIZE() external view returns (uint256);
/// if the caller only requires one set of local keys. function PRECOMPILE_CALL_RESERVED_GAS() external view returns (uint256);
/// @param _word The local data word. function addLeavesLPP(
/// @param _size The number of bytes in `_word` to load. uint256 _uuid,
/// @param _partOffset The offset of the local data part to write to the oracle. uint256 _inputStartBlock,
/// @dev The local data parts are loaded into the preimage oracle under the context bytes memory _input,
/// of the caller - no other account can write to the caller's context bytes32[] memory _stateCommitments,
/// specific data. bool _finalize
/// )
/// There are 5 local data identifiers: external;
/// ┌────────────┬────────────────────────┐ function challengeFirstLPP(
/// │ Identifier │ Data │ address _claimant,
/// ├────────────┼────────────────────────┤ uint256 _uuid,
/// │ 1 │ L1 Head Hash (bytes32) │ Leaf memory _postState,
/// │ 2 │ Output Root (bytes32) │ bytes32[] memory _postStateProof
/// │ 3 │ Root Claim (bytes32) │ )
/// │ 4 │ L2 Block Number (u64) │ external;
/// │ 5 │ Chain ID (u64) │ function challengeLPP(
/// └────────────┴────────────────────────┘ address _claimant,
uint256 _uuid,
LibKeccak.StateMatrix memory _stateMatrix,
Leaf memory _preState,
bytes32[] memory _preStateProof,
Leaf memory _postState,
bytes32[] memory _postStateProof
)
external;
function challengePeriod() external view returns (uint256 challengePeriod_);
function getTreeRootLPP(address _owner, uint256 _uuid) external view returns (bytes32 treeRoot_);
function initLPP(uint256 _uuid, uint32 _partOffset, uint32 _claimedSize) external payable;
function loadBlobPreimagePart(
uint256 _z,
uint256 _y,
bytes memory _commitment,
bytes memory _proof,
uint256 _partOffset
)
external;
function loadKeccak256PreimagePart(uint256 _partOffset, bytes memory _preimage) external;
function loadLocalData( function loadLocalData(
uint256 _ident, uint256 _ident,
bytes32 _localContext, bytes32 _localContext,
...@@ -45,52 +78,40 @@ interface IPreimageOracle { ...@@ -45,52 +78,40 @@ interface IPreimageOracle {
) )
external external
returns (bytes32 key_); returns (bytes32 key_);
/// @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;
/// @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;
/// @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,
bytes calldata _commitment,
bytes calldata _proof,
uint256 _partOffset
)
external;
/// @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( function loadPrecompilePreimagePart(
uint256 _partOffset, uint256 _partOffset,
address _precompile, address _precompile,
uint64 _requiredGas, uint64 _requiredGas,
bytes calldata _input bytes memory _input
) )
external; external;
function loadSha256PreimagePart(uint256 _partOffset, bytes memory _preimage) external;
/// @notice Returns the minimum size (in bytes) of a large preimage proposal. function minProposalSize() external view returns (uint256 minProposalSize_);
function minProposalSize() external view returns (uint256); function preimageLengths(bytes32) external view returns (uint256);
function preimagePartOk(bytes32, uint256) external view returns (bool);
function preimageParts(bytes32, uint256) external view returns (bytes32);
function proposalBlocks(address, uint256, uint256) external view returns (uint64);
function proposalBlocksLen(address _claimant, uint256 _uuid) external view returns (uint256 len_);
function proposalBonds(address, uint256) external view returns (uint256);
function proposalBranches(address, uint256, uint256) external view returns (bytes32);
function proposalCount() external view returns (uint256 count_);
function proposalMetadata(address, uint256) external view returns (LPPMetaData);
function proposalParts(address, uint256) external view returns (bytes32);
function proposals(uint256) external view returns (address claimant, uint256 uuid); // nosemgrep:
// sol-style-return-arg-fmt
function readPreimage(bytes32 _key, uint256 _offset) external view returns (bytes32 dat_, uint256 datLen_);
function squeezeLPP(
address _claimant,
uint256 _uuid,
LibKeccak.StateMatrix memory _stateMatrix,
Leaf memory _preState,
bytes32[] memory _preStateProof,
Leaf memory _postState,
bytes32[] memory _postStateProof
)
external;
function version() external view returns (string memory);
function zeroHashes(uint256) external view returns (bytes32);
function __constructor__(uint256 _minProposalSize, uint256 _challengePeriod) external; function __constructor__(uint256 _minProposalSize, uint256 _challengePeriod) external;
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -6,10 +6,8 @@ import { Test } from "forge-std/Test.sol"; ...@@ -6,10 +6,8 @@ import { Test } from "forge-std/Test.sol";
import { DisputeGameFactory_Init } from "test/dispute/DisputeGameFactory.t.sol"; import { DisputeGameFactory_Init } from "test/dispute/DisputeGameFactory.t.sol";
import { AlphabetVM } from "test/mocks/AlphabetVM.sol"; import { AlphabetVM } from "test/mocks/AlphabetVM.sol";
// Contracts // Scripts
import { PermissionedDisputeGame } from "src/dispute/PermissionedDisputeGame.sol"; import { DeployUtils } from "scripts/libraries/DeployUtils.sol";
import { PreimageOracle } from "src/cannon/PreimageOracle.sol";
import { DelayedWETH } from "src/dispute/DelayedWETH.sol";
// Libraries // Libraries
import "src/dispute/lib/Types.sol"; import "src/dispute/lib/Types.sol";
...@@ -45,29 +43,46 @@ contract PermissionedDisputeGame_Init is DisputeGameFactory_Init { ...@@ -45,29 +43,46 @@ contract PermissionedDisputeGame_Init is DisputeGameFactory_Init {
// Set the extra data for the game creation // Set the extra data for the game creation
extraData = abi.encode(l2BlockNumber); extraData = abi.encode(l2BlockNumber);
AlphabetVM _vm = new AlphabetVM(absolutePrestate, IPreimageOracle(address(new PreimageOracle(0, 0)))); IPreimageOracle oracle = IPreimageOracle(
DeployUtils.create1({
_name: "PreimageOracle",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IPreimageOracle.__constructor__, (0, 0)))
})
);
AlphabetVM _vm = new AlphabetVM(absolutePrestate, oracle);
// Use a 7 day delayed WETH to simulate withdrawals. // Use a 7 day delayed WETH to simulate withdrawals.
IDelayedWETH _weth = IDelayedWETH(payable(new DelayedWETH(7 days))); IDelayedWETH _weth = IDelayedWETH(
DeployUtils.create1({
_name: "DelayedWETH",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IDelayedWETH.__constructor__, (7 days)))
})
);
// Deploy an implementation of the fault game // Deploy an implementation of the fault game
gameImpl = IPermissionedDisputeGame( gameImpl = IPermissionedDisputeGame(
address( DeployUtils.create1({
new PermissionedDisputeGame({ _name: "PermissionedDisputeGame",
_gameType: GAME_TYPE, _args: DeployUtils.encodeConstructor(
_absolutePrestate: absolutePrestate, abi.encodeCall(
_maxGameDepth: 2 ** 3, IPermissionedDisputeGame.__constructor__,
_splitDepth: 2 ** 2, (
_clockExtension: Duration.wrap(3 hours), GAME_TYPE,
_maxClockDuration: Duration.wrap(3.5 days), absolutePrestate,
_vm: _vm, 2 ** 3,
_weth: _weth, 2 ** 2,
_anchorStateRegistry: anchorStateRegistry, Duration.wrap(3 hours),
_l2ChainId: 10, Duration.wrap(3.5 days),
_proposer: PROPOSER, _vm,
_challenger: CHALLENGER _weth,
}) anchorStateRegistry,
) 10,
PROPOSER,
CHALLENGER
)
)
)
})
); );
// Register the game implementation with the factory. // Register the game implementation with the factory.
disputeGameFactory.setImplementation(GAME_TYPE, gameImpl); disputeGameFactory.setImplementation(GAME_TYPE, gameImpl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment