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
b9936d07
Commit
b9936d07
authored
Jun 16, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Global usage of type-specific libraries
parent
3319b5b3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
31 deletions
+38
-31
.gas-snapshot
packages/contracts-bedrock/.gas-snapshot
+0
-1
FaultDisputeGame.sol
.../contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
+6
-6
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
+21
-21
No files found.
packages/contracts-bedrock/.gas-snapshot
View file @
b9936d07
...
...
@@ -449,4 +449,3 @@ SystemConfig_Setters_TestFail:test_setResourceConfig_notOwner_reverts() (gas: 11
SystemConfig_Setters_TestFail:test_setResourceConfig_zeroDenominator_reverts() (gas: 13039)
SystemConfig_Setters_TestFail:test_setUnsafeBlockSigner_notOwner_reverts() (gas: 10616)
TransferOnionTest:test_constructor_succeeds() (gas: 564855)
TransferOnionTest:test_unwrap_succeeds() (gas: 724955)
\ No newline at end of file
packages/contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
View file @
b9936d07
...
...
@@ -137,13 +137,13 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// 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
);
?
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 +160,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 +178,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 @
b9936d07
// 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 @
b9936d07
...
...
@@ -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(0).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 @
b9936d07
...
...
@@ -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 @
b9936d07
...
...
@@ -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
);
for (uint256 i = _depth; i < _maxDepth
- 1
; ++i) {
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);
}
}
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