Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
e8cdf4e4
Unverified
Commit
e8cdf4e4
authored
Jun 19, 2023
by
OptimismBot
Committed by
GitHub
Jun 19, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6038 from ethereum-optimism/clabby/ctb/broom-type-libs
feat(ctb): Global usage of type-specific libraries
parents
3319b5b3
c2a4e558
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
36 deletions
+42
-36
.gas-snapshot
packages/contracts-bedrock/.gas-snapshot
+4
-4
FaultDisputeGame.sol
.../contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
+5
-7
DisputeTypes.sol
...es/contracts-bedrock/contracts/libraries/DisputeTypes.sol
+8
-0
FaultDisputeGame.t.sol
...s/contracts-bedrock/contracts/test/FaultDisputeGame.t.sol
+1
-1
LibClock.t.sol
packages/contracts-bedrock/contracts/test/LibClock.t.sol
+2
-2
LibPosition.t.sol
packages/contracts-bedrock/contracts/test/LibPosition.t.sol
+20
-20
package.json
packages/contracts-bedrock/package.json
+2
-2
No files found.
packages/contracts-bedrock/.gas-snapshot
View file @
e8cdf4e4
...
...
@@ -32,19 +32,19 @@ DisputeGameFactory_SetImplementation_Test:test_setImplementation_notOwner_revert
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: 264
68
)
FaultDisputeGame_Test:test_clockTimeExceeded_reverts() (gas: 264
74
)
FaultDisputeGame_Test:test_defendRoot_reverts() (gas: 13258)
FaultDisputeGame_Test:test_duplicateClaim_reverts() (gas: 1033
69
)
FaultDisputeGame_Test:test_duplicateClaim_reverts() (gas: 1033
81
)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 17478)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17859)
FaultDisputeGame_Test:test_gameDepthExceeded_reverts() (gas: 590
6891
)
FaultDisputeGame_Test:test_gameDepthExceeded_reverts() (gas: 590
7275
)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10337)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8194)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 17580)
FaultDisputeGame_Test:test_moveAgainstNonexistentParent_reverts() (gas: 24587)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 10945)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8191)
FaultDisputeGame_Test:test_simpleAttack_succeeds() (gas: 10736
1
)
FaultDisputeGame_Test:test_simpleAttack_succeeds() (gas: 10736
7
)
FaultDisputeGame_Test:test_version_succeeds() (gas: 9780)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352135)
...
...
packages/contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
View file @
e8cdf4e4
...
...
@@ -136,14 +136,12 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// 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
// or not the move is an attack or defense.
Position nextPosition = _isAttack
? LibPosition.attack(parent.position)
: LibPosition.defend(parent.position);
Position nextPosition = _isAttack ? parent.position.attack() : parent.position.defend();
// 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
// instruction step.
if (
LibPosition.depth(nextPosition
) >= MAX_GAME_DEPTH) {
if (
nextPosition.depth(
) >= MAX_GAME_DEPTH) {
revert GameDepthExceeded();
}
...
...
@@ -160,11 +158,11 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
Duration nextDuration = Duration.wrap(
uint64(
// 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
// parent's clock timestamp.
block.timestamp -
Timestamp.unwrap(
LibClock.timestamp(parent.clock
))
Timestamp.unwrap(
parent.clock.timestamp(
))
)
);
...
...
@@ -178,7 +176,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
Clock nextClock = LibClock.wrap(nextDuration, Timestamp.wrap(uint64(block.timestamp)));
// Do not allow for a duplicate claim to be made.
ClaimHash claimHash =
LibHashing.hashClaimPos(_pivot,
nextPosition);
ClaimHash claimHash =
_pivot.hashClaimPos(
nextPosition);
if (claims[claimHash]) {
revert ClaimAlreadyExists();
}
...
...
packages/contracts-bedrock/contracts/libraries/DisputeTypes.sol
View file @
e8cdf4e4
// SPDX-License-Identifier: MIT
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.
*/
...
...
packages/contracts-bedrock/contracts/test/FaultDisputeGame.t.sol
View file @
e8cdf4e4
...
...
@@ -247,7 +247,7 @@ contract FaultDisputeGame_Test is DisputeGameFactory_Init {
assertEq(parentIndex, 0);
assertEq(countered, false);
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(
Clock.unwrap(clock),
Clock.unwrap(LibClock.wrap(Duration.wrap(5), Timestamp.wrap(uint64(block.timestamp))))
...
...
packages/contracts-bedrock/contracts/test/LibClock.t.sol
View file @
e8cdf4e4
...
...
@@ -14,7 +14,7 @@ contract LibClock_Test is Test {
*/
function testFuzz_duration_succeeds(Duration _duration, Timestamp _timestamp) public {
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 {
*/
function testFuzz_timestamp_succeeds(Duration _duration, Timestamp _timestamp) public {
Clock clock = LibClock.wrap(_duration, _timestamp);
assertEq(Timestamp.unwrap(
LibClock.timestamp(clock
)), Timestamp.unwrap(_timestamp));
assertEq(Timestamp.unwrap(
clock.timestamp(
)), Timestamp.unwrap(_timestamp));
}
}
packages/contracts-bedrock/contracts/test/LibPosition.t.sol
View file @
e8cdf4e4
...
...
@@ -32,7 +32,7 @@ contract LibPosition_Test is Test {
_depth = uint8(bound(_depth, 0, MAX_DEPTH));
_indexAtDepth = boundIndexAtDepth(_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 {
_depth = uint8(bound(_depth, 0, MAX_DEPTH));
_indexAtDepth = boundIndexAtDepth(_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 {
_indexAtDepth = boundIndexAtDepth(_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(
LibPosition.indexAtDepth(left
), _indexAtDepth * 2);
assertEq(
left.depth(
), uint64(_depth) + 1);
assertEq(
left.indexAtDepth(
), _indexAtDepth * 2);
}
/**
...
...
@@ -68,10 +68,10 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position right =
LibPosition.right(position
);
Position right =
position.right(
);
assertEq(
LibPosition.depth(right
), _depth + 1);
assertEq(
LibPosition.indexAtDepth(right
), _indexAtDepth * 2 + 1);
assertEq(
right.depth(
), _depth + 1);
assertEq(
right.indexAtDepth(
), _indexAtDepth * 2 + 1);
}
/**
...
...
@@ -82,10 +82,10 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position parent =
LibPosition.parent(position
);
Position parent =
position.parent(
);
assertEq(
LibPosition.depth(parent
), _depth - 1);
assertEq(
LibPosition.indexAtDepth(parent
), _indexAtDepth / 2);
assertEq(
parent.depth(
), _depth - 1);
assertEq(
parent.indexAtDepth(
), _indexAtDepth / 2);
}
/**
...
...
@@ -105,13 +105,13 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_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
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);
}
...
...
@@ -127,10 +127,10 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position attack =
LibPosition.attack(position
);
Position attack =
position.attack(
);
assertEq(
LibPosition.depth(attack
), _depth + 1);
assertEq(
LibPosition.indexAtDepth(attack
), _indexAtDepth * 2);
assertEq(
attack.depth(
), _depth + 1);
assertEq(
attack.indexAtDepth(
), _indexAtDepth * 2);
}
/**
...
...
@@ -145,9 +145,9 @@ contract LibPosition_Test is Test {
_indexAtDepth = boundIndexAtDepth(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position defend =
LibPosition.defend(position
);
Position defend =
position.defend(
);
assertEq(
LibPosition.depth(defend
), _depth + 1);
assertEq(
LibPosition.indexAtDepth(defend
), ((_indexAtDepth / 2) * 2 + 1) * 2);
assertEq(
defend.depth(
), _depth + 1);
assertEq(
defend.indexAtDepth(
), ((_indexAtDepth / 2) * 2 + 1) * 2);
}
}
packages/contracts-bedrock/package.json
View file @
e8cdf4e4
...
...
@@ -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"
,
"lint:ts:check"
:
"eslint . --max-warnings=0"
,
"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: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"
:
"yarn lint:fix && yarn lint:check"
,
"typechain"
:
"typechain --target ethers-v5 --out-dir dist/types --glob 'artifacts/!(build-info)/**/+([a-zA-Z0-9_]).json'"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment