Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Optimistic ZK Game Contract #11

Closed
wants to merge 14 commits into from
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
[submodule "packages/contracts-bedrock/lib/automate"]
path = packages/contracts-bedrock/lib/automate
url = https://github.com/gelatodigital/automate
[submodule "packages/contracts-bedrock/lib/sp1-contracts"]
path = packages/contracts-bedrock/lib/sp1-contracts
url = https://github.com/succinctlabs/sp1-contracts
1 change: 1 addition & 0 deletions packages/contracts-bedrock/lib/sp1-contracts
Submodule sp1-contracts added at 610395
22 changes: 22 additions & 0 deletions packages/contracts-bedrock/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
@rari-capital/solmate/=lib/solmate/
@lib-keccak/=lib/lib-keccak/contracts/lib/
@solady/=lib/solady/src/
forge-std/=lib/forge-std/src/
ds-test/=lib/forge-std/lib/ds-test/src/
safe-contracts/=lib/safe-contracts/contracts/
kontrol-cheatcodes/=lib/kontrol-cheatcodes/src/
gelato/=lib/automate/contracts/
@solady-test/=lib/lib-keccak/lib/solady/test/
automate/=lib/automate/contracts/
erc4626-tests/=lib/automate/lib/openzeppelin-contracts/lib/erc4626-tests/
hardhat/=lib/automate/node_modules/hardhat/
lib-keccak/=lib/lib-keccak/contracts/
openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/
openzeppelin-contracts/=lib/openzeppelin-contracts/
prb-test/=lib/automate/lib/prb-test/src/
prb/-est/=lib/automate/lib/prb-test/src/
solady/=lib/solady/
solmate/=lib/solmate/src/
@sp1-contracts/=lib/sp1-contracts/contracts/src/
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
pragma solidity ^0.8.15;

import { LibClone } from "@solady/utils/LibClone.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
Expand Down
527 changes: 527 additions & 0 deletions packages/contracts-bedrock/src/dispute/OptimisticZKGame.sol

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { IDisputeGame } from "./IDisputeGame.sol";
import "src/dispute/lib/Types.sol";

/// @title IBlockDisputeGame
/// @notice The interface for a game meant to resolve an L2 Block.
interface IBlockDisputeGame is IDisputeGame {
/// @notice The l2BlockNumber of the disputed output root in the `L2OutputOracle`.
/// @return l2BlockNumber_ The block number that the game claiming is proving.
function l2BlockNumber() external view returns (uint256 l2BlockNumber_);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import { IBlockDisputeGame } from "./IBlockDisputeGame.sol";
import "src/dispute/lib/Types.sol";

interface IOptimisticZKGame is IBlockDisputeGame {
enum IntermediateClaimStatus {
NONE,
ACCEPTED,
CHALLENGED
}

struct IntermediateRootClaim {
OutputRoot outputRoot;
IntermediateClaimStatus status;
}

struct Challenge {
address challenger;
Clock proposerClock;
IntermediateRootClaim left;
IntermediateRootClaim right;
OutputRoot current;
uint totalBonds;
bool resolved;
bytes32 l1Head;
}

struct PublicValuesStruct {
bytes32 l1Head;
bytes32 l2PreRoot;
bytes32 l2PostRoot;
uint256 l2BlockNumber;
uint256 chainId;
}

error Unauthorized();
error ProposerIsChallenger();
error InvalidDurations();
error PreviousGameNotResolved();
error InvalidBlockNumber();
error WrongTurn();
error ReadyToProve();
error NotReadyToProve();
error InvalidChallengeId();
error GameAlreadyResolved();
error ChallengeAlreadyResolved();
error ChallengeCantBeResolved();
error WrongBondAmount();
error TransferFailed();
error ClockNotExpired();
error InvalidPublicInput();
}
3 changes: 3 additions & 0 deletions packages/contracts-bedrock/src/dispute/lib/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ library GameTypes {
/// @notice A dispute game type the uses the asterisc VM
GameType internal constant ASTERISC = GameType.wrap(2);

/// @notice A dispute game type that uses SP1 for Optimistic ZK proofs.
GameType internal constant OPTIMISTIC_ZK = GameType.wrap(3);

/// @notice A dispute game type with short game duration for testing withdrawals.
/// Not intended for production use.
GameType internal constant FAST = GameType.wrap(254);
Expand Down
Loading