Commit e8cdf4e4 authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #6038 from ethereum-optimism/clabby/ctb/broom-type-libs

feat(ctb): Global usage of type-specific libraries
parents 3319b5b3 c2a4e558
...@@ -32,19 +32,19 @@ DisputeGameFactory_SetImplementation_Test:test_setImplementation_notOwner_revert ...@@ -32,19 +32,19 @@ DisputeGameFactory_SetImplementation_Test:test_setImplementation_notOwner_revert
DisputeGameFactory_SetImplementation_Test:test_setImplementation_succeeds() (gas: 44243) DisputeGameFactory_SetImplementation_Test:test_setImplementation_succeeds() (gas: 44243)
DisputeGameFactory_TransferOwnership_Test:test_transferOwnership_notOwner_reverts() (gas: 15950) DisputeGameFactory_TransferOwnership_Test:test_transferOwnership_notOwner_reverts() (gas: 15950)
DisputeGameFactory_TransferOwnership_Test:test_transferOwnership_succeeds() (gas: 18642) DisputeGameFactory_TransferOwnership_Test:test_transferOwnership_succeeds() (gas: 18642)
FaultDisputeGame_Test:test_clockTimeExceeded_reverts() (gas: 26468) FaultDisputeGame_Test:test_clockTimeExceeded_reverts() (gas: 26474)
FaultDisputeGame_Test:test_defendRoot_reverts() (gas: 13258) FaultDisputeGame_Test:test_defendRoot_reverts() (gas: 13258)
FaultDisputeGame_Test:test_duplicateClaim_reverts() (gas: 103369) FaultDisputeGame_Test:test_duplicateClaim_reverts() (gas: 103381)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 17478) FaultDisputeGame_Test:test_extraData_succeeds() (gas: 17478)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17859) FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17859)
FaultDisputeGame_Test:test_gameDepthExceeded_reverts() (gas: 5906891) FaultDisputeGame_Test:test_gameDepthExceeded_reverts() (gas: 5907275)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10337) FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10337)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8194) FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8194)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 17580) FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 17580)
FaultDisputeGame_Test:test_moveAgainstNonexistentParent_reverts() (gas: 24587) FaultDisputeGame_Test:test_moveAgainstNonexistentParent_reverts() (gas: 24587)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 10945) FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 10945)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8191) FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8191)
FaultDisputeGame_Test:test_simpleAttack_succeeds() (gas: 107361) FaultDisputeGame_Test:test_simpleAttack_succeeds() (gas: 107367)
FaultDisputeGame_Test:test_version_succeeds() (gas: 9780) FaultDisputeGame_Test:test_version_succeeds() (gas: 9780)
FeeVault_Test:test_constructor_succeeds() (gas: 18185) FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352135) GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352135)
......
...@@ -136,14 +136,12 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone { ...@@ -136,14 +136,12 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// Compute the position that the claim commits to. Because the parent's position is already // Compute the position that the claim commits to. Because the parent's position is already
// known, we can compute the next position by moving left or right depending on whether // known, we can compute the next position by moving left or right depending on whether
// or not the move is an attack or defense. // or not the move is an attack or defense.
Position nextPosition = _isAttack Position nextPosition = _isAttack ? parent.position.attack() : parent.position.defend();
? LibPosition.attack(parent.position)
: LibPosition.defend(parent.position);
// At the leaf nodes of the game, the only option is to run a step to prove or disprove // At the leaf nodes of the game, the only option is to run a step to prove or disprove
// the above claim. At this depth, the parent claim commits to the state after a single // the above claim. At this depth, the parent claim commits to the state after a single
// instruction step. // instruction step.
if (LibPosition.depth(nextPosition) >= MAX_GAME_DEPTH) { if (nextPosition.depth() >= MAX_GAME_DEPTH) {
revert GameDepthExceeded(); revert GameDepthExceeded();
} }
...@@ -160,11 +158,11 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone { ...@@ -160,11 +158,11 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
Duration nextDuration = Duration.wrap( Duration nextDuration = Duration.wrap(
uint64( uint64(
// First, fetch the duration of the grandparent claim. // First, fetch the duration of the grandparent claim.
Duration.unwrap(LibClock.duration(grandparentClock)) + Duration.unwrap(grandparentClock.duration()) +
// Second, add the difference between the current block timestamp and the // Second, add the difference between the current block timestamp and the
// parent's clock timestamp. // parent's clock timestamp.
block.timestamp - block.timestamp -
Timestamp.unwrap(LibClock.timestamp(parent.clock)) Timestamp.unwrap(parent.clock.timestamp())
) )
); );
...@@ -178,7 +176,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone { ...@@ -178,7 +176,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
Clock nextClock = LibClock.wrap(nextDuration, Timestamp.wrap(uint64(block.timestamp))); Clock nextClock = LibClock.wrap(nextDuration, Timestamp.wrap(uint64(block.timestamp)));
// Do not allow for a duplicate claim to be made. // Do not allow for a duplicate claim to be made.
ClaimHash claimHash = LibHashing.hashClaimPos(_pivot, nextPosition); ClaimHash claimHash = _pivot.hashClaimPos(nextPosition);
if (claims[claimHash]) { if (claims[claimHash]) {
revert ClaimAlreadyExists(); revert ClaimAlreadyExists();
} }
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.15; pragma solidity ^0.8.15;
import { LibHashing } from "../dispute/lib/LibHashing.sol";
import { LibPosition } from "../dispute/lib/LibPosition.sol";
import { LibClock } from "../dispute/lib/LibClock.sol";
using LibHashing for Claim global;
using LibPosition for Position global;
using LibClock for Clock global;
/** /**
* @notice A custom type for a generic hash. * @notice A custom type for a generic hash.
*/ */
......
...@@ -247,7 +247,7 @@ contract FaultDisputeGame_Test is DisputeGameFactory_Init { ...@@ -247,7 +247,7 @@ contract FaultDisputeGame_Test is DisputeGameFactory_Init {
assertEq(parentIndex, 0); assertEq(parentIndex, 0);
assertEq(countered, false); assertEq(countered, false);
assertEq(Claim.unwrap(claim), Claim.unwrap(counter)); assertEq(Claim.unwrap(claim), Claim.unwrap(counter));
assertEq(Position.unwrap(position), Position.unwrap(LibPosition.attack(Position.wrap(1)))); assertEq(Position.unwrap(position), Position.unwrap(Position.wrap(1).attack()));
assertEq( assertEq(
Clock.unwrap(clock), Clock.unwrap(clock),
Clock.unwrap(LibClock.wrap(Duration.wrap(5), Timestamp.wrap(uint64(block.timestamp)))) Clock.unwrap(LibClock.wrap(Duration.wrap(5), Timestamp.wrap(uint64(block.timestamp))))
......
...@@ -14,7 +14,7 @@ contract LibClock_Test is Test { ...@@ -14,7 +14,7 @@ contract LibClock_Test is Test {
*/ */
function testFuzz_duration_succeeds(Duration _duration, Timestamp _timestamp) public { function testFuzz_duration_succeeds(Duration _duration, Timestamp _timestamp) public {
Clock clock = LibClock.wrap(_duration, _timestamp); Clock clock = LibClock.wrap(_duration, _timestamp);
assertEq(Duration.unwrap(LibClock.duration(clock)), Duration.unwrap(_duration)); assertEq(Duration.unwrap(clock.duration()), Duration.unwrap(_duration));
} }
/** /**
...@@ -22,6 +22,6 @@ contract LibClock_Test is Test { ...@@ -22,6 +22,6 @@ contract LibClock_Test is Test {
*/ */
function testFuzz_timestamp_succeeds(Duration _duration, Timestamp _timestamp) public { function testFuzz_timestamp_succeeds(Duration _duration, Timestamp _timestamp) public {
Clock clock = LibClock.wrap(_duration, _timestamp); Clock clock = LibClock.wrap(_duration, _timestamp);
assertEq(Timestamp.unwrap(LibClock.timestamp(clock)), Timestamp.unwrap(_timestamp)); assertEq(Timestamp.unwrap(clock.timestamp()), Timestamp.unwrap(_timestamp));
} }
} }
...@@ -32,7 +32,7 @@ contract LibPosition_Test is Test { ...@@ -32,7 +32,7 @@ contract LibPosition_Test is Test {
_depth = uint8(bound(_depth, 0, MAX_DEPTH)); _depth = uint8(bound(_depth, 0, MAX_DEPTH));
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth); _indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth); Position position = LibPosition.wrap(_depth, _indexAtDepth);
assertEq(LibPosition.depth(position), _depth); assertEq(position.depth(), _depth);
} }
/** /**
...@@ -42,7 +42,7 @@ contract LibPosition_Test is Test { ...@@ -42,7 +42,7 @@ contract LibPosition_Test is Test {
_depth = uint8(bound(_depth, 0, MAX_DEPTH)); _depth = uint8(bound(_depth, 0, MAX_DEPTH));
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth); _indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth); Position position = LibPosition.wrap(_depth, _indexAtDepth);
assertEq(LibPosition.indexAtDepth(position), _indexAtDepth); assertEq(position.indexAtDepth(), _indexAtDepth);
} }
/** /**
...@@ -53,10 +53,10 @@ contract LibPosition_Test is Test { ...@@ -53,10 +53,10 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth); _indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth); Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position left = LibPosition.left(position); Position left = position.left();
assertEq(LibPosition.depth(left), uint64(_depth) + 1); assertEq(left.depth(), uint64(_depth) + 1);
assertEq(LibPosition.indexAtDepth(left), _indexAtDepth * 2); assertEq(left.indexAtDepth(), _indexAtDepth * 2);
} }
/** /**
...@@ -68,10 +68,10 @@ contract LibPosition_Test is Test { ...@@ -68,10 +68,10 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth); _indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth); Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position right = LibPosition.right(position); Position right = position.right();
assertEq(LibPosition.depth(right), _depth + 1); assertEq(right.depth(), _depth + 1);
assertEq(LibPosition.indexAtDepth(right), _indexAtDepth * 2 + 1); assertEq(right.indexAtDepth(), _indexAtDepth * 2 + 1);
} }
/** /**
...@@ -82,10 +82,10 @@ contract LibPosition_Test is Test { ...@@ -82,10 +82,10 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth); _indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth); Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position parent = LibPosition.parent(position); Position parent = position.parent();
assertEq(LibPosition.depth(parent), _depth - 1); assertEq(parent.depth(), _depth - 1);
assertEq(LibPosition.indexAtDepth(parent), _indexAtDepth / 2); assertEq(parent.indexAtDepth(), _indexAtDepth / 2);
} }
/** /**
...@@ -105,13 +105,13 @@ contract LibPosition_Test is Test { ...@@ -105,13 +105,13 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth); _indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth); Position position = LibPosition.wrap(_depth, _indexAtDepth);
uint64 rightIndex = LibPosition.rightIndex(position, _maxDepth); uint64 rightIndex = position.rightIndex(_maxDepth);
// Find the deepest, rightmost index in Solidity rather than Yul // Find the deepest, rightmost index in Solidity rather than Yul
for (uint256 i = _depth; i < _maxDepth; ++i) { for (uint256 i = _depth; i < _maxDepth; ++i) {
position = LibPosition.right(position); position = position.right();
} }
uint64 _rightIndex = LibPosition.indexAtDepth(position); uint64 _rightIndex = position.indexAtDepth();
assertEq(rightIndex, _rightIndex); assertEq(rightIndex, _rightIndex);
} }
...@@ -127,10 +127,10 @@ contract LibPosition_Test is Test { ...@@ -127,10 +127,10 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth); _indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth); Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position attack = LibPosition.attack(position); Position attack = position.attack();
assertEq(LibPosition.depth(attack), _depth + 1); assertEq(attack.depth(), _depth + 1);
assertEq(LibPosition.indexAtDepth(attack), _indexAtDepth * 2); assertEq(attack.indexAtDepth(), _indexAtDepth * 2);
} }
/** /**
...@@ -145,9 +145,9 @@ contract LibPosition_Test is Test { ...@@ -145,9 +145,9 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth); _indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth); Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position defend = LibPosition.defend(position); Position defend = position.defend();
assertEq(LibPosition.depth(defend), _depth + 1); assertEq(defend.depth(), _depth + 1);
assertEq(LibPosition.indexAtDepth(defend), ((_indexAtDepth / 2) * 2 + 1) * 2); assertEq(defend.indexAtDepth(), ((_indexAtDepth / 2) * 2 + 1) * 2);
} }
} }
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
"clean": "rm -rf ./dist ./artifacts ./forge-artifacts ./cache ./tsconfig.tsbuildinfo ./tsconfig.build.tsbuildinfo ./src/contract-artifacts.ts ./test-case-generator/fuzz", "clean": "rm -rf ./dist ./artifacts ./forge-artifacts ./cache ./tsconfig.tsbuildinfo ./tsconfig.build.tsbuildinfo ./src/contract-artifacts.ts ./test-case-generator/fuzz",
"lint:ts:check": "eslint . --max-warnings=0", "lint:ts:check": "eslint . --max-warnings=0",
"lint:forge-tests:check": "ts-node scripts/forge-test-names.ts", "lint:forge-tests:check": "ts-node scripts/forge-test-names.ts",
"lint:contracts:check": "yarn solhint -f table 'contracts/**/*.sol' && yarn prettier --check 'contracts/**/*.sol' && yarn lint:forge-tests:check", "lint:contracts:check": "yarn solhint -f table 'contracts/**/!(DisputeTypes).sol' && yarn prettier --check 'contracts/**/!(DisputeTypes).sol' && yarn lint:forge-tests:check",
"lint:check": "yarn lint:contracts:check && yarn lint:ts:check", "lint:check": "yarn lint:contracts:check && yarn lint:ts:check",
"lint:ts:fix": "eslint --fix .", "lint:ts:fix": "eslint --fix .",
"lint:contracts:fix": "yarn solhint --fix 'contracts/**/*.sol' && yarn prettier --write 'contracts/**/*.sol'", "lint:contracts:fix": "yarn solhint --fix 'contracts/**/!(DisputeTypes).sol' && yarn prettier --write 'contracts/**/!(DisputeTypes).sol'",
"lint:fix": "yarn lint:contracts:fix && yarn lint:ts:fix", "lint:fix": "yarn lint:contracts:fix && yarn lint:ts:fix",
"lint": "yarn lint:fix && yarn lint:check", "lint": "yarn lint:fix && yarn lint:check",
"typechain": "typechain --target ethers-v5 --out-dir dist/types --glob 'artifacts/!(build-info)/**/+([a-zA-Z0-9_]).json'", "typechain": "typechain --target ethers-v5 --out-dir dist/types --glob 'artifacts/!(build-info)/**/+([a-zA-Z0-9_]).json'",
......
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