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
5e344ac5
Commit
5e344ac5
authored
Jun 10, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clock / lint
parent
507ddd2c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
39 deletions
+58
-39
FaultDisputeGame.sol
.../contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
+27
-15
FaultDisputeGame.t.sol
...s/contracts-bedrock/contracts/test/FaultDisputeGame.t.sol
+18
-15
LibClock.t.sol
packages/contracts-bedrock/contracts/test/LibClock.t.sol
+2
-2
LibPosition.t.sol
packages/contracts-bedrock/contracts/test/LibPosition.t.sol
+11
-7
No files found.
packages/contracts-bedrock/contracts/dispute/FaultDisputeGame.sol
View file @
5e344ac5
...
@@ -55,12 +55,12 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
...
@@ -55,12 +55,12 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
Timestamp public gameStart;
Timestamp public gameStart;
/**
/**
* @
notice The current status of the game.
* @
inheritdoc IDisputeGame
*/
*/
GameStatus public status;
GameStatus public status;
/**
/**
* @
notice The DisputeGame's bond manager.
* @
inheritdoc IDisputeGame
*/
*/
IBondManager public bondManager;
IBondManager public bondManager;
...
@@ -96,11 +96,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
...
@@ -96,11 +96,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
}
}
/**
/**
* @notice Performs a VM step via an on-chain fault proof processor
* @inheritdoc IFaultDisputeGame
* @dev This function should point to a fault proof processor in order to execute
* a step in the fault proof program on-chain. The interface of the fault proof processor
* contract should be generic enough such that we can use different fault proof VMs (MIPS, RiscV5, etc.)
* @param disagreement The GindexClaim of the disagreement
*/
*/
function step(ClaimHash disagreement) public {
function step(ClaimHash disagreement) public {
// TODO - Call the VM to perform the execution step.
// TODO - Call the VM to perform the execution step.
...
@@ -153,21 +149,36 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
...
@@ -153,21 +149,36 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
? LibPosition.attack(parent.position)
? LibPosition.attack(parent.position)
: LibPosition.defend(parent.position);
: LibPosition.defend(parent.position);
// Compute the clock for the next claim. The clock's duration is computed by taking the
// Fetch the grandparent clock, if it exists.
// difference between the current block timestamp and the parent's clock timestamp.
// The grandparent clock should always exist unless the parent is the root claim.
Clock nextClock = LibClock.wrap(
Clock grandparentClock;
Duration.wrap(
if (parent.parentIndex != type(uint32).max) {
uint64(block.timestamp - Timestamp.unwrap(LibClock.timestamp(parent.clock)))
grandparentClock = claimData[parent.parentIndex].clock;
),
}
Timestamp.wrap(uint64(block.timestamp))
// Compute the duration of the next clock. This is done by adding the duration of the
// grandparent claim to the difference between the current block timestamp and the
// parent's clock timestamp.
Duration nextDuration = Duration.wrap(
uint64(
// First, fetch the duration of the grandparent claim.
Duration.unwrap(LibClock.duration(grandparentClock)) +
// Second, add the difference between the current block timestamp and the
// parent's clock timestamp.
block.timestamp -
Timestamp.unwrap(LibClock.timestamp(parent.clock))
)
);
);
// Enforce the clock time. If the new clock duration is greater than half of the game
// Enforce the clock time. If the new clock duration is greater than half of the game
// duration, then the move is invalid and cannot be made.
// duration, then the move is invalid and cannot be made.
if (Duration.unwrap(
LibClock.duration(nextClock)
) > Duration.unwrap(GAME_DURATION) >> 1) {
if (Duration.unwrap(
nextDuration
) > Duration.unwrap(GAME_DURATION) >> 1) {
revert ClockTimeExceeded();
revert ClockTimeExceeded();
}
}
// Construct the next clock with the new duration and the current 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.
// TODO.
// TODO.
// Maybe map the claimHash? There's no efficient way to check for this with the flat DAG.
// Maybe map the claimHash? There's no efficient way to check for this with the flat DAG.
...
@@ -184,6 +195,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
...
@@ -184,6 +195,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
})
})
);
);
// Emit the appropriate event for the attack or defense.
if (isAttack) {
if (isAttack) {
emit Attack(challengeIndex, pivot, msg.sender);
emit Attack(challengeIndex, pivot, msg.sender);
} else {
} else {
...
...
packages/contracts-bedrock/contracts/test/FaultDisputeGame.t.sol
View file @
5e344ac5
...
@@ -97,8 +97,7 @@ contract FaultDisputeGame_Test is Test {
...
@@ -97,8 +97,7 @@ contract FaultDisputeGame_Test is Test {
* @dev Tests that the game's data is set correctly.
* @dev Tests that the game's data is set correctly.
*/
*/
function test_gameData_succeeds() public {
function test_gameData_succeeds() public {
(GameType gameType, Claim rootClaim, bytes memory extraData) =
(GameType gameType, Claim rootClaim, bytes memory extraData) = gameProxy.gameData();
gameProxy.gameData();
assertEq(uint256(gameType), uint256(GAME_TYPE));
assertEq(uint256(gameType), uint256(GAME_TYPE));
assertEq(Claim.unwrap(rootClaim), Claim.unwrap(ROOT_CLAIM));
assertEq(Claim.unwrap(rootClaim), Claim.unwrap(ROOT_CLAIM));
...
@@ -127,7 +126,10 @@ contract FaultDisputeGame_Test is Test {
...
@@ -127,7 +126,10 @@ contract FaultDisputeGame_Test is Test {
assertEq(countered, false);
assertEq(countered, false);
assertEq(Claim.unwrap(claim), Claim.unwrap(ROOT_CLAIM));
assertEq(Claim.unwrap(claim), Claim.unwrap(ROOT_CLAIM));
assertEq(Position.unwrap(position), 0);
assertEq(Position.unwrap(position), 0);
assertEq(Clock.unwrap(clock), Clock.unwrap(LibClock.wrap(Duration.wrap(0), Timestamp.wrap(uint64(block.timestamp)))));
assertEq(
Clock.unwrap(clock),
Clock.unwrap(LibClock.wrap(Duration.wrap(0), Timestamp.wrap(uint64(block.timestamp))))
);
}
}
/**
/**
...
@@ -138,7 +140,7 @@ contract FaultDisputeGame_Test is Test {
...
@@ -138,7 +140,7 @@ contract FaultDisputeGame_Test is Test {
vm.warp(block.timestamp + 5);
vm.warp(block.timestamp + 5);
// Perform the attack.
// Perform the attack.
gameProxy.attack(0, Claim.wrap(bytes32(uint(5))));
gameProxy.attack(0, Claim.wrap(bytes32(uint
256
(5))));
// Grab the claim data of the attack.
// Grab the claim data of the attack.
(
(
...
@@ -154,19 +156,15 @@ contract FaultDisputeGame_Test is Test {
...
@@ -154,19 +156,15 @@ contract FaultDisputeGame_Test is Test {
assertEq(parentIndex, 0);
assertEq(parentIndex, 0);
assertEq(rc, 0);
assertEq(rc, 0);
assertEq(countered, false);
assertEq(countered, false);
assertEq(Claim.unwrap(claim), Claim.unwrap(Claim.wrap(bytes32(uint(5)))));
assertEq(Claim.unwrap(claim), Claim.unwrap(Claim.wrap(bytes32(uint
256
(5)))));
assertEq(Position.unwrap(position), Position.unwrap(LibPosition.attack(Position.wrap(0))));
assertEq(Position.unwrap(position), Position.unwrap(LibPosition.attack(Position.wrap(0))));
assertEq(Clock.unwrap(clock), Clock.unwrap(LibClock.wrap(Duration.wrap(5), Timestamp.wrap(uint64(block.timestamp)))));
assertEq(
Clock.unwrap(clock),
Clock.unwrap(LibClock.wrap(Duration.wrap(5), Timestamp.wrap(uint64(block.timestamp))))
);
// Grab the claim data of the parent.
// Grab the claim data of the parent.
(
(parentIndex, rc, countered, claim, position, clock) = gameProxy.claimData(0);
parentIndex,
rc,
countered,
claim,
position,
clock
) = gameProxy.claimData(0);
// Assert correctness of the parent claim's data.
// Assert correctness of the parent claim's data.
assertEq(parentIndex, type(uint32).max);
assertEq(parentIndex, type(uint32).max);
...
@@ -174,7 +172,12 @@ contract FaultDisputeGame_Test is Test {
...
@@ -174,7 +172,12 @@ contract FaultDisputeGame_Test is Test {
assertEq(countered, true);
assertEq(countered, true);
assertEq(Claim.unwrap(claim), Claim.unwrap(ROOT_CLAIM));
assertEq(Claim.unwrap(claim), Claim.unwrap(ROOT_CLAIM));
assertEq(Position.unwrap(position), 0);
assertEq(Position.unwrap(position), 0);
assertEq(Clock.unwrap(clock), Clock.unwrap(LibClock.wrap(Duration.wrap(0), Timestamp.wrap(uint64(block.timestamp - 5)))));
assertEq(
Clock.unwrap(clock),
Clock.unwrap(
LibClock.wrap(Duration.wrap(0), Timestamp.wrap(uint64(block.timestamp - 5)))
)
);
// Resolve the game.
// Resolve the game.
assertEq(uint256(gameProxy.resolve()), uint256(GameStatus.CHALLENGER_WINS));
assertEq(uint256(gameProxy.resolve()), uint256(GameStatus.CHALLENGER_WINS));
...
...
packages/contracts-bedrock/contracts/test/LibClock.t.sol
View file @
5e344ac5
...
@@ -12,7 +12,7 @@ contract LibClock_Test is Test {
...
@@ -12,7 +12,7 @@ contract LibClock_Test is Test {
/**
/**
* @notice Tests that the `duration` function correctly shifts out the `Duration` from a packed `Clock` type.
* @notice Tests that the `duration` function correctly shifts out the `Duration` from a packed `Clock` type.
*/
*/
function testFuzz_duration_
correctnes
s(uint64 _duration, uint64 _timestamp) public {
function testFuzz_duration_
succeed
s(uint64 _duration, uint64 _timestamp) public {
Clock clock = LibClock.wrap(Duration.wrap(_duration), Timestamp.wrap(_timestamp));
Clock clock = LibClock.wrap(Duration.wrap(_duration), Timestamp.wrap(_timestamp));
assertEq(Duration.unwrap(LibClock.duration(clock)), _duration);
assertEq(Duration.unwrap(LibClock.duration(clock)), _duration);
}
}
...
@@ -20,7 +20,7 @@ contract LibClock_Test is Test {
...
@@ -20,7 +20,7 @@ contract LibClock_Test is Test {
/**
/**
* @notice Tests that the `timestamp` function correctly shifts out the `Timestamp` from a packed `Clock` type.
* @notice Tests that the `timestamp` function correctly shifts out the `Timestamp` from a packed `Clock` type.
*/
*/
function testFuzz_timestamp_
correctnes
s(uint64 _duration, uint64 _timestamp) public {
function testFuzz_timestamp_
succeed
s(uint64 _duration, uint64 _timestamp) public {
Clock clock = LibClock.wrap(Duration.wrap(_duration), Timestamp.wrap(_timestamp));
Clock clock = LibClock.wrap(Duration.wrap(_duration), Timestamp.wrap(_timestamp));
assertEq(Timestamp.unwrap(LibClock.timestamp(clock)), _timestamp);
assertEq(Timestamp.unwrap(LibClock.timestamp(clock)), _timestamp);
}
}
...
...
packages/contracts-bedrock/contracts/test/LibPosition.t.sol
View file @
5e344ac5
...
@@ -39,7 +39,7 @@ contract LibPosition_Test is Test {
...
@@ -39,7 +39,7 @@ contract LibPosition_Test is Test {
// Depth bound: [0, 127]
// Depth bound: [0, 127]
_depth = uint8(bound(_depth, 0, MAX_DEPTH));
_depth = uint8(bound(_depth, 0, MAX_DEPTH));
// Index at depth bound: [0, 2 ** _depth]
// Index at depth bound: [0, 2 ** _depth]
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position left = LibPosition.left(position);
Position left = LibPosition.left(position);
...
@@ -55,7 +55,7 @@ contract LibPosition_Test is Test {
...
@@ -55,7 +55,7 @@ contract LibPosition_Test is Test {
// Depth bound: [0, 127]
// Depth bound: [0, 127]
_depth = uint8(bound(_depth, 0, MAX_DEPTH));
_depth = uint8(bound(_depth, 0, MAX_DEPTH));
// Index at depth bound: [0, 2 ** _depth]
// Index at depth bound: [0, 2 ** _depth]
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position right = LibPosition.right(position);
Position right = LibPosition.right(position);
...
@@ -71,7 +71,7 @@ contract LibPosition_Test is Test {
...
@@ -71,7 +71,7 @@ contract LibPosition_Test is Test {
// Depth bound: [1, 127]
// Depth bound: [1, 127]
_depth = uint8(bound(_depth, 1, MAX_DEPTH));
_depth = uint8(bound(_depth, 1, MAX_DEPTH));
// Index at depth bound: [0, 2 ** _depth]
// Index at depth bound: [0, 2 ** _depth]
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position parent = LibPosition.parent(position);
Position parent = LibPosition.parent(position);
...
@@ -84,14 +84,18 @@ contract LibPosition_Test is Test {
...
@@ -84,14 +84,18 @@ contract LibPosition_Test is Test {
* @notice Tests that the `rightIndex` function correctly computes the deepest, right most index relative
* @notice Tests that the `rightIndex` function correctly computes the deepest, right most index relative
* to a given position.
* to a given position.
*/
*/
function testFuzz_rightIndex_correctness(uint8 _maxDepth, uint8 _depth, uint128 _indexAtDepth) public {
function testFuzz_rightIndex_correctness(
uint8 _maxDepth,
uint8 _depth,
uint128 _indexAtDepth
) public {
// Max depth bound: [1, 127]
// Max depth bound: [1, 127]
// The max game depth MUST be at least 1.
// The max game depth MUST be at least 1.
_maxDepth = uint8(bound(_maxDepth, 1, MAX_DEPTH));
_maxDepth = uint8(bound(_maxDepth, 1, MAX_DEPTH));
// Depth bound: [0, _maxDepth]
// Depth bound: [0, _maxDepth]
_depth = uint8(bound(_depth, 0, _maxDepth));
_depth = uint8(bound(_depth, 0, _maxDepth));
// Index at depth bound: [0, 2 ** _depth]
// Index at depth bound: [0, 2 ** _depth]
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
uint128 rightIndex = LibPosition.rightIndex(position, _maxDepth);
uint128 rightIndex = LibPosition.rightIndex(position, _maxDepth);
...
@@ -114,7 +118,7 @@ contract LibPosition_Test is Test {
...
@@ -114,7 +118,7 @@ contract LibPosition_Test is Test {
// Depth bound: [0, 127]
// Depth bound: [0, 127]
_depth = uint8(bound(_depth, 0, MAX_DEPTH));
_depth = uint8(bound(_depth, 0, MAX_DEPTH));
// Index at depth bound: [0, 2 ** _depth]
// Index at depth bound: [0, 2 ** _depth]
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position attack = LibPosition.attack(position);
Position attack = LibPosition.attack(position);
...
@@ -133,7 +137,7 @@ contract LibPosition_Test is Test {
...
@@ -133,7 +137,7 @@ contract LibPosition_Test is Test {
// Depth bound: [1, 127]
// Depth bound: [1, 127]
_depth = uint8(bound(_depth, 1, MAX_DEPTH));
_depth = uint8(bound(_depth, 1, MAX_DEPTH));
// Index at depth bound: [0, 2 ** _depth]
// Index at depth bound: [0, 2 ** _depth]
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
_indexAtDepth = uint128(bound(_indexAtDepth, 0, 2
**
_depth));
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position position = LibPosition.wrap(_depth, _indexAtDepth);
Position defend = LibPosition.defend(position);
Position defend = LibPosition.defend(position);
...
...
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