Skip to content

Commit

Permalink
Merge branch 'develop' into cannon
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Jun 16, 2023
2 parents d35fa87 + 0c1a113 commit 69e6747
Show file tree
Hide file tree
Showing 15 changed files with 2,718 additions and 233 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-shoes-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/fault-detector': patch
---

Fix false error to warning
1 change: 1 addition & 0 deletions .github/workflows/tag-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ on:
- proxyd
- indexer
- fault-detector
- ci-builder
prerelease:
description: Increment major/minor/patch as prerelease?
required: false
Expand Down
9 changes: 9 additions & 0 deletions op-bindings/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ bindings: l1block-bindings \
basefee-vault-bindings \
legacy-erc20-eth-bindings \
dispute-game-factory-bindings \
standard-bridge-bindings \
cross-domain-messenger-bindings \
cannon-mips \
cannon-oracle

Expand Down Expand Up @@ -128,12 +130,19 @@ l1-blocknumber-bindings: compile
dispute-game-factory-bindings: compile
./gen_bindings.sh contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory $(pkg)

standard-bridge-bindings: compile
./gen_bindings.sh contracts/universal/StandardBridge.sol:StandardBridge $(pkg)

cross-domain-messenger-bindings: compile
./gen_bindings.sh contracts/universal/CrossDomainMessenger.sol:CrossDomainMessenger $(pkg)

cannon-mips: compile
./gen_bindings.sh contracts/cannon/MIPS.sol:MIPS $(pkg)

cannon-oracle: compile
./gen_bindings.sh contracts/cannon/Oracle.sol:Oracle $(pkg)


more:
go run ./gen/main.go \
-artifacts ../packages/contracts-bedrock/artifacts \
Expand Down
1,371 changes: 1,371 additions & 0 deletions op-bindings/bindings/crossdomainmessenger.go

Large diffs are not rendered by default.

92 changes: 60 additions & 32 deletions op-bindings/bindings/disputegamefactory.go

Large diffs are not rendered by default.

1,091 changes: 1,091 additions & 0 deletions op-bindings/bindings/standardbridge.go

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions packages/contracts-bedrock/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ CrossDomainOwnable_Test:test_onlyOwner_notOwner_reverts() (gas: 10597)
CrossDomainOwnable_Test:test_onlyOwner_succeeds() (gas: 34883)
DeployerWhitelist_Test:test_owner_succeeds() (gas: 7582)
DeployerWhitelist_Test:test_storageSlots_succeeds() (gas: 33395)
DisputeGameFactory_Test:test_owner_succeeds() (gas: 12610)
DisputeGameFactory_Test:test_setImplementation_notOwner_reverts() (gas: 16099)
DisputeGameFactory_Test:test_setImplementation_succeeds() (gas: 44302)
DisputeGameFactory_Test:test_transferOwnership_notOwner_reverts() (gas: 15974)
DisputeGameFactory_Test:test_transferOwnership_succeeds() (gas: 18694)
DisputeGameFactory_Owner_Test:test_owner_succeeds() (gas: 12559)
DisputeGameFactory_SetImplementation_Test:test_setImplementation_notOwner_reverts() (gas: 16042)
DisputeGameFactory_SetImplementation_Test:test_setImplementation_succeeds() (gas: 44243)
DisputeGameFactory_TransferOwnership_Test:test_transferOwnership_notOwner_reverts() (gas: 15950)
DisputeGameFactory_TransferOwnership_Test:test_transferOwnership_succeeds() (gas: 18642)
FaultDisputeGame_Test:test_clockTimeExceeded_reverts() (gas: 26413)
FaultDisputeGame_Test:test_defendRoot_reverts() (gas: 13258)
FaultDisputeGame_Test:test_duplicateClaim_reverts() (gas: 103259)
Expand Down
20 changes: 10 additions & 10 deletions packages/contracts-bedrock/.storage-layout
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@
➡ contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory
=======================

| Name | Type | Slot | Offset | Bytes | Contract |
|-----------------|--------------------------------------------|------|--------|-------|-------------------------------------------------------------|
| _initialized | uint8 | 0 | 0 | 1 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| _initializing | bool | 0 | 1 | 1 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| __gap | uint256[50] | 1 | 0 | 1600 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| _owner | address | 51 | 0 | 20 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| __gap | uint256[49] | 52 | 0 | 1568 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| gameImpls | mapping(GameType => contract IDisputeGame) | 101 | 0 | 32 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| disputeGames | mapping(Hash => contract IDisputeGame) | 102 | 0 | 32 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| disputeGameList | contract IDisputeGame[] | 103 | 0 | 32 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| Name | Type | Slot | Offset | Bytes | Contract |
|------------------|--------------------------------------------|------|--------|-------|-------------------------------------------------------------|
| _initialized | uint8 | 0 | 0 | 1 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| _initializing | bool | 0 | 1 | 1 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| __gap | uint256[50] | 1 | 0 | 1600 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| _owner | address | 51 | 0 | 20 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| __gap | uint256[49] | 52 | 0 | 1568 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| gameImpls | mapping(GameType => contract IDisputeGame) | 101 | 0 | 32 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| _disputeGames | mapping(Hash => GameId) | 102 | 0 | 32 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
| _disputeGameList | GameId[] | 103 | 0 | 32 | contracts/dispute/DisputeGameFactory.sol:DisputeGameFactory |
77 changes: 61 additions & 16 deletions packages/contracts-bedrock/contracts/dispute/DisputeGameFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { IVersioned } from "./interfaces/IVersioned.sol";

/**
* @title DisputeGameFactory
* @notice A factory contract for creating `IDisputeGame` contracts.
* @notice A factory contract for creating `IDisputeGame` contracts. All created dispute games
* are stored in both a mapping and an append only array. The timestamp of the creation
* time of the dispute game is packed tightly into the storage slot with the address of
* the dispute game. This is to make offchain discoverability of playable dispute games
* easier.
*/
contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, IVersioned {
/**
Expand All @@ -29,18 +33,18 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, IVersion
mapping(GameType => IDisputeGame) public gameImpls;

/**
* @notice Mapping of a hash of `gameType . rootClaim . extraData` to
* @notice Mapping of a hash of `gameType || rootClaim || extraData` to
* the deployed `IDisputeGame` clone.
* @dev Note: `.` denotes concatenation.
* @dev Note: `||` denotes concatenation.
*/
mapping(Hash => IDisputeGame) internal disputeGames;
mapping(Hash => GameId) internal _disputeGames;

/**
* @notice An append-only array of disputeGames that have been created.
* @dev This accessor is used by offchain game solvers to efficiently
* track dispute games
*/
IDisputeGame[] public disputeGameList;
GameId[] internal _disputeGameList;

/**
* @notice Constructs a new DisputeGameFactory contract.
Expand All @@ -60,27 +64,46 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, IVersion

/**
* @inheritdoc IVersioned
* @custom:semver 0.0.2
*/
function version() external pure returns (string memory) {
return "0.0.1";
return "0.0.2";
}

/**
* @inheritdoc IDisputeGameFactory
*/
function gameCount() external view returns (uint256 _gameCount) {
_gameCount = disputeGameList.length;
function gameCount() external view returns (uint256 gameCount_) {
gameCount_ = _disputeGameList.length;
}

/**
* @inheritdoc IDisputeGameFactory
*/
function games(
GameType gameType,
Claim rootClaim,
bytes calldata extraData
) external view returns (IDisputeGame _proxy) {
return disputeGames[getGameUUID(gameType, rootClaim, extraData)];
GameType _gameType,
Claim _rootClaim,
bytes calldata _extraData
) external view returns (IDisputeGame proxy_, uint256 timestamp_) {
Hash uuid = getGameUUID(_gameType, _rootClaim, _extraData);
GameId slot = _disputeGames[uuid];
(address addr, uint256 timestamp) = _unpackSlot(slot);
proxy_ = IDisputeGame(addr);
timestamp_ = timestamp;
}

/**
* @inheritdoc IDisputeGameFactory
*/
function gameAtIndex(uint256 _index)
external
view
returns (IDisputeGame proxy_, uint256 timestamp_)
{
GameId slot = _disputeGameList[_index];
(address addr, uint256 timestamp) = _unpackSlot(slot);
proxy_ = IDisputeGame(addr);
timestamp_ = timestamp;
}

/**
Expand All @@ -107,13 +130,15 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, IVersion
Hash uuid = getGameUUID(gameType, rootClaim, extraData);

// If a dispute game with the same UUID already exists, revert.
if (address(disputeGames[uuid]) != address(0)) {
if (GameId.unwrap(_disputeGames[uuid]) != bytes32(0)) {
revert GameAlreadyExists(uuid);
}

GameId slot = _packSlot(address(proxy), block.timestamp);

// Store the dispute game in the mapping & emit the `DisputeGameCreated` event.
disputeGames[uuid] = proxy;
disputeGameList.push(proxy);
_disputeGames[uuid] = slot;
_disputeGameList.push(slot);
emit DisputeGameCreated(address(proxy), gameType, rootClaim);
}

Expand Down Expand Up @@ -163,4 +188,24 @@ contract DisputeGameFactory is OwnableUpgradeable, IDisputeGameFactory, IVersion
gameImpls[gameType] = impl;
emit ImplementationSet(address(impl), gameType);
}

/**
* @dev Packs an address and a uint256 into a single bytes32 slot. This
* is only safe for up to uint96 values.
*/
function _packSlot(address _addr, uint256 _num) internal pure returns (GameId slot_) {
assembly {
slot_ := or(shl(0xa0, _num), _addr)
}
}

/**
* @dev Unpacks an address and a uint256 from a single bytes32 slot.
*/
function _unpackSlot(GameId _slot) internal pure returns (address addr_, uint256 num_) {
assembly {
addr_ := and(_slot, 0xffffffffffffffffffffffffffffffffffffffff)
num_ := shr(0xa0, _slot)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,26 @@ interface IDisputeGameFactory {
* @param extraData Any extra data that should be provided to the created dispute game.
* @return _proxy The clone of the `DisputeGame` created with the given parameters.
* Returns `address(0)` if nonexistent.
* @return _timestamp The timestamp of the creation of the dispute game.
*/
function games(
GameType gameType,
Claim rootClaim,
bytes calldata extraData
) external view returns (IDisputeGame _proxy);
) external view returns (IDisputeGame _proxy, uint256 _timestamp);

/**
* @notice `gameAtIndex` returns the dispute game contract address and its creation timestamp
* at the given index. Each created dispute game increments the underlying index.
* @param _index The index of the dispute game.
* @return _proxy The clone of the `DisputeGame` created with the given parameters.
* Returns `address(0)` if nonexistent.
* @return _timestamp The timestamp of the creation of the dispute game.
*/
function gameAtIndex(uint256 _index)
external
view
returns (IDisputeGame _proxy, uint256 _timestamp);

/**
* @notice `gameImpls` is a mapping that maps `GameType`s to their respective
Expand Down
12 changes: 12 additions & 0 deletions packages/contracts-bedrock/contracts/libraries/DisputeTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ type Timestamp is uint64;
*/
type Duration is uint64;

/**
* @notice A `GameId` represents a packed 12 byte timestamp and a 20 byte address.
* @dev The packed layout of this type is as follows:
* ┌────────────┬────────────────┐
* │ Bits │ Value │
* ├────────────┼────────────────┤
* │ [0, 96) │ Timestamp │
* │ [96, 256) │ Address │
* └────────────┴────────────────┘
*/
type GameId is bytes32;

/**
* @notice A `Clock` represents a packed `Duration` and `Timestamp`
* @dev The packed layout of this type is as follows:
Expand Down
Loading

0 comments on commit 69e6747

Please sign in to comment.