Commit 84e8b55b authored by clabby's avatar clabby

`_in` & `out_` naming convention

fix
parent d8cd3b8a
......@@ -77,25 +77,25 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
/**
* @inheritdoc IFaultDisputeGame
*/
function attack(uint256 parentIndex, Claim pivot) external payable {
_move(parentIndex, pivot, true);
function attack(uint256 _parentIndex, Claim _pivot) external payable {
_move(_parentIndex, _pivot, true);
}
/**
* @inheritdoc IFaultDisputeGame
*/
function defend(uint256 parentIndex, Claim pivot) external payable {
_move(parentIndex, pivot, false);
function defend(uint256 _parentIndex, Claim _pivot) external payable {
_move(_parentIndex, _pivot, false);
}
/**
* @inheritdoc IFaultDisputeGame
*/
function step(
uint256 prestateIndex,
uint256 parentIndex,
bytes calldata stateData,
bytes calldata
uint256 _prestateIndex,
uint256 _parentIndex,
bytes calldata _stateData,
bytes calldata _proof
) external {
// TODO - Call the VM to perform the execution step.
}
......@@ -106,14 +106,14 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
/**
* @notice Internal move function, used by both `attack` and `defend`.
* @param challengeIndex The index of the claim being moved against.
* @param pivot The claim at the next logical position in the game.
* @param isAttack Whether or not the move is an attack or defense.
* @param _challengeIndex The index of the claim being moved against.
* @param _pivot The claim at the next logical position in the game.
* @param _isAttack Whether or not the move is an attack or defense.
*/
function _move(
uint256 challengeIndex,
Claim pivot,
bool isAttack
uint256 _challengeIndex,
Claim _pivot,
bool _isAttack
) internal {
// Moves cannot be made unless the game is currently in progress.
if (status != GameStatus.IN_PROGRESS) {
......@@ -121,19 +121,19 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
}
// The zero hash is not a valid claim.
if (Claim.unwrap(pivot) == bytes32(0)) {
if (Claim.unwrap(_pivot) == bytes32(0)) {
revert InvalidClaim();
}
// The only move that can be made against a root claim is an attack. This is because the
// root claim commits to the entire state; Therefore, the only valid defense is to do
// nothing if it is agreed with.
if (challengeIndex == 0 && !isAttack) {
if (_challengeIndex == 0 && !_isAttack) {
revert CannotDefendRootClaim();
}
// Get the parent
ClaimData memory parent = claimData[challengeIndex];
ClaimData memory parent = claimData[_challengeIndex];
// The parent must exist.
if (Claim.unwrap(parent.claim) == bytes32(0)) {
......@@ -141,12 +141,12 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
}
// Set the parent claim as countered.
claimData[challengeIndex].countered = true;
claimData[_challengeIndex].countered = true;
// 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
Position nextPosition = _isAttack
? LibPosition.attack(parent.position)
: LibPosition.defend(parent.position);
......@@ -188,7 +188,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 = LibHashing.hashClaimPos(_pivot, nextPosition);
if (claims[claimHash]) {
revert ClaimAlreadyExists();
}
......@@ -197,8 +197,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
// Create the new claim.
claimData.push(
ClaimData({
parentIndex: uint32(challengeIndex),
claim: pivot,
parentIndex: uint32(_challengeIndex),
claim: _pivot,
position: nextPosition,
clock: nextClock,
countered: false
......@@ -206,7 +206,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
);
// Emit the appropriate event for the attack or defense.
emit Move(challengeIndex, pivot, msg.sender);
emit Move(_challengeIndex, _pivot, msg.sender);
}
////////////////////////////////////////////////////////////////
......@@ -216,39 +216,41 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
/**
* @inheritdoc IDisputeGame
*/
function gameType() public pure override returns (GameType _gameType) {
_gameType = GameTypes.FAULT;
function gameType() public pure override returns (GameType gameType_) {
gameType_ = GameTypes.FAULT;
}
/**
* @inheritdoc IDisputeGame
*/
function createdAt() external view returns (Timestamp _createdAt) {
_createdAt = gameStart;
function createdAt() external view returns (Timestamp createdAt_) {
createdAt_ = gameStart;
}
/**
* @inheritdoc IDisputeGame
*/
function resolve() external returns (GameStatus _status) {
function resolve() external returns (GameStatus status_) {
// TODO - Resolve the game
status = GameStatus.IN_PROGRESS;
status_ = status;
}
/**
* @inheritdoc IDisputeGame
*/
function rootClaim() public pure returns (Claim _rootClaim) {
_rootClaim = Claim.wrap(_getArgFixedBytes(0x00));
function rootClaim() public pure returns (Claim rootClaim_) {
rootClaim_ = Claim.wrap(_getArgFixedBytes(0x00));
}
/**
* @inheritdoc IDisputeGame
*/
function extraData() public pure returns (bytes memory _extraData) {
function extraData() public pure returns (bytes memory extraData_) {
// The extra data starts at the second word within the cwia calldata.
// TODO: What data do we need to pass along to this contract from the factory?
// Block hash, preimage data, etc.?
_extraData = _getArgDynBytes(0x20, 0x20);
extraData_ = _getArgDynBytes(0x20, 0x20);
}
/**
......@@ -258,14 +260,14 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
external
pure
returns (
GameType _gameType,
Claim _rootClaim,
bytes memory _extraData
GameType gameType_,
Claim rootClaim_,
bytes memory extraData_
)
{
_gameType = gameType();
_rootClaim = rootClaim();
_extraData = extraData();
gameType_ = gameType();
rootClaim_ = rootClaim();
extraData_ = extraData();
}
/**
......@@ -292,7 +294,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone {
/**
* @inheritdoc IVersioned
*/
function version() external pure override returns (string memory _version) {
_version = VERSION;
function version() external pure override returns (string memory version_) {
version_ = VERSION;
}
}
......@@ -20,44 +20,44 @@ interface IDisputeGame is IInitializable, IVersioned {
/**
* @notice Returns the timestamp that the DisputeGame contract was created at.
* @return _createdAt The timestamp that the DisputeGame contract was created at.
* @return createdAt_ The timestamp that the DisputeGame contract was created at.
*/
function createdAt() external view returns (Timestamp _createdAt);
function createdAt() external view returns (Timestamp createdAt_);
/**
* @notice Returns the current status of the game.
* @return _status The current status of the game.
* @return status_ The current status of the game.
*/
function status() external view returns (GameStatus _status);
function status() external view returns (GameStatus status_);
/**
* @notice Getter for the game type.
* @dev `clones-with-immutable-args` argument #1
* @dev The reference impl should be entirely different depending on the type (fault, validity)
* i.e. The game type should indicate the security model.
* @return _gameType The type of proof system being used.
* @return gameType_ The type of proof system being used.
*/
function gameType() external pure returns (GameType _gameType);
function gameType() external pure returns (GameType gameType_);
/**
* @notice Getter for the root claim.
* @dev `clones-with-immutable-args` argument #2
* @return _rootClaim The root claim of the DisputeGame.
* @return rootClaim_ The root claim of the DisputeGame.
*/
function rootClaim() external pure returns (Claim _rootClaim);
function rootClaim() external pure returns (Claim rootClaim_);
/**
* @notice Getter for the extra data.
* @dev `clones-with-immutable-args` argument #3
* @return _extraData Any extra data supplied to the dispute game contract by the creator.
* @return extraData_ Any extra data supplied to the dispute game contract by the creator.
*/
function extraData() external pure returns (bytes memory _extraData);
function extraData() external pure returns (bytes memory extraData_);
/**
* @notice Returns the address of the `BondManager` used.
* @return _bondManager The address of the `BondManager` used.
* @return bondManager_ The address of the `BondManager` used.
*/
function bondManager() external view returns (IBondManager _bondManager);
function bondManager() external view returns (IBondManager bondManager_);
/**
* @notice If all necessary information has been gathered, this function should mark the game
......@@ -65,22 +65,25 @@ interface IDisputeGame is IInitializable, IVersioned {
* the resolved game. It is at this stage that the bonds should be awarded to the
* necessary parties.
* @dev May only be called if the `status` is `IN_PROGRESS`.
* @return _status The status of the game after resolution.
* @return status_ The status of the game after resolution.
*/
function resolve() external returns (GameStatus _status);
function resolve() external returns (GameStatus status_);
/**
* @notice A compliant implementation of this interface should return the components of the
* game UUID's preimage provided in the cwia payload. The preimage of the UUID is
* constructed as `keccak256(gameType . rootClaim . extraData)` where `.` denotes
* concatenation.
* @return gameType_ The type of proof system being used.
* @return rootClaim_ The root claim of the DisputeGame.
* @return extraData_ Any extra data supplied to the dispute game contract by the creator.
*/
function gameData()
external
pure
returns (
GameType _gameType,
Claim _rootClaim,
bytes memory _extraData
GameType gameType_,
Claim rootClaim_,
bytes memory extraData_
);
}
......@@ -32,18 +32,18 @@ interface IFaultDisputeGame is IDisputeGame {
event Move(uint256 indexed parentIndex, Claim indexed pivot, address indexed claimant);
/**
* Attack a disagreed upon `Claim`.
* @param parentIndex Index of the `Claim` to attack in `claimData`.
* @param pivot The `Claim` at the relative attack position.
* @notice Attack a disagreed upon `Claim`.
* @param _parentIndex Index of the `Claim` to attack in `claimData`.
* @param _pivot The `Claim` at the relative attack position.
*/
function attack(uint256 parentIndex, Claim pivot) external payable;
function attack(uint256 _parentIndex, Claim _pivot) external payable;
/**
* Defend an agreed upon `Claim`.
* @param parentIndex Index of the claim to defend in `claimData`.
* @param pivot The `Claim` at the relative defense position.
* @notice Defend an agreed upon `Claim`.
* @param _parentIndex Index of the claim to defend in `claimData`.
* @param _pivot The `Claim` at the relative defense position.
*/
function defend(uint256 parentIndex, Claim pivot) external payable;
function defend(uint256 _parentIndex, Claim _pivot) external payable;
/**
* @notice Perform the final step via an on-chain fault proof processor
......@@ -51,15 +51,15 @@ interface IFaultDisputeGame is IDisputeGame {
* 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 prestateIndex The index of the prestate of the step within `claimData`.
* @param parentIndex The index of the parent claim within `claimData`.
* @param stateData The stateData of the step is the preimage of the claim @ `prestateIndex`
* @param proof Proof to access memory leaf nodes in the VM.
* @param _prestateIndex The index of the prestate of the step within `claimData`.
* @param _parentIndex The index of the parent claim within `claimData`.
* @param _stateData The stateData of the step is the preimage of the claim @ `prestateIndex`
* @param _proof Proof to access memory leaf nodes in the VM.
*/
function step(
uint256 prestateIndex,
uint256 parentIndex,
bytes calldata stateData,
bytes calldata proof
uint256 _prestateIndex,
uint256 _parentIndex,
bytes calldata _stateData,
bytes calldata _proof
) external;
}
......@@ -12,36 +12,36 @@ library LibClock {
* @notice Packs a `Duration` and `Timestamp` into a `Clock` type.
* @param _duration The `Duration` to pack into the `Clock` type.
* @param _timestamp The `Timestamp` to pack into the `Clock` type.
* @return _clock The `Clock` containing the `_duration` and `_timestamp`.
* @return clock_ The `Clock` containing the `_duration` and `_timestamp`.
*/
function wrap(Duration _duration, Timestamp _timestamp) internal pure returns (Clock _clock) {
function wrap(Duration _duration, Timestamp _timestamp) internal pure returns (Clock clock_) {
assembly {
_clock := or(shl(0x40, _duration), _timestamp)
clock_ := or(shl(0x40, _duration), _timestamp)
}
}
/**
* @notice Pull the `Duration` out of a `Clock` type.
* @param _clock The `Clock` type to pull the `Duration` out of.
* @return _duration The `Duration` pulled out of `_clock`.
* @return duration_ The `Duration` pulled out of `_clock`.
*/
function duration(Clock _clock) internal pure returns (Duration _duration) {
function duration(Clock _clock) internal pure returns (Duration duration_) {
// Shift the high-order 64 bits into the low-order 64 bits, leaving only the `duration`.
assembly {
_duration := shr(0x40, _clock)
duration_ := shr(0x40, _clock)
}
}
/**
* @notice Pull the `Timestamp` out of a `Clock` type.
* @param _clock The `Clock` type to pull the `Timestamp` out of.
* @return _timestamp The `Timestamp` pulled out of `_clock`.
* @return timestamp_ The `Timestamp` pulled out of `_clock`.
*/
function timestamp(Clock _clock) internal pure returns (Timestamp _timestamp) {
function timestamp(Clock _clock) internal pure returns (Timestamp timestamp_) {
// Clean the high-order 192 bits by shifting the clock left and then right again, leaving
// only the `timestamp`.
assembly {
_timestamp := shr(0xC0, shl(0xC0, _clock))
timestamp_ := shr(0xC0, shl(0xC0, _clock))
}
}
}
......@@ -10,15 +10,15 @@ import "../../libraries/DisputeTypes.sol";
library LibHashing {
/**
* @notice Hashes a claim and a position together.
* @param claim A Claim type.
* @param position The position of `claim`.
* @return claimHash A hash of abi.encodePacked(claim, position);
* @param _claim A Claim type.
* @param _position The position of `claim`.
* @return claimHash_ A hash of abi.encodePacked(claim, position);
*/
function hashClaimPos(Claim claim, Position position) internal pure returns (ClaimHash claimHash) {
function hashClaimPos(Claim _claim, Position _position) internal pure returns (ClaimHash claimHash_) {
assembly {
mstore(0x00, claim)
mstore(0x20, position)
claimHash := keccak256(0x00, 0x40)
mstore(0x00, _claim)
mstore(0x20, _position)
claimHash_ := keccak256(0x00, 0x40)
}
}
}
......@@ -8,113 +8,120 @@ import "../../libraries/DisputeTypes.sol";
* @notice This library contains helper functions for working with the `Position` type.
*/
library LibPosition {
function wrap(uint64 _depth, uint64 _indexAtDepth) internal pure returns (Position _position) {
function wrap(uint64 _depth, uint64 _indexAtDepth) internal pure returns (Position position_) {
assembly {
_position := or(shl(0x40, _depth), _indexAtDepth)
position_ := or(shl(0x40, _depth), _indexAtDepth)
}
}
/**
* @notice Pulls the `depth` out of a packed `Position` type.
* @param _position The position to get the `depth` of.
* @return depth_ The `depth` of the `position`.
*/
function depth(Position position) internal pure returns (uint64 _depth) {
function depth(Position _position) internal pure returns (uint64 depth_) {
// Shift the high-order 64 bits into the low-order 64 bits, leaving only the `depth`.
assembly {
_depth := shr(0x40, position)
depth_ := shr(0x40, _position)
}
}
/**
* @notice Pulls the `indexAtDepth` out of a packed `Position` type.
* @param _position The position to get the `indexAtDepth` of.
* @return indexAtDepth_ The `indexAtDepth` of the `position`.
*/
function indexAtDepth(Position position) internal pure returns (uint64 _indexAtDepth) {
function indexAtDepth(Position _position) internal pure returns (uint64 indexAtDepth_) {
// Clean the high-order 192 bits by shifting the position left and then right again, leaving
// only the `indexAtDepth`.
assembly {
_indexAtDepth := shr(0xC0, shl(0xC0, position))
indexAtDepth_ := shr(0xC0, shl(0xC0, _position))
}
}
/**
* @notice Get the position to the left of `position`.
* @param position The position to get the left position of.
* @return _left The position to the left of `position`.
* @param _position The position to get the left position of.
* @return left_ The position to the left of `position`.
*/
function left(Position position) internal pure returns (Position _left) {
uint64 _depth = depth(position);
uint64 _indexAtDepth = indexAtDepth(position);
function left(Position _position) internal pure returns (Position left_) {
uint64 _depth = depth(_position);
uint64 _indexAtDepth = indexAtDepth(_position);
// Left = { depth: position.depth + 1, indexAtDepth: position.indexAtDepth * 2 }
assembly {
_left := or(shl(0x40, add(_depth, 0x01)), shl(0x01, _indexAtDepth))
left_ := or(shl(0x40, add(_depth, 0x01)), shl(0x01, _indexAtDepth))
}
}
/**
* @notice Get the position to the right of `position`.
* @param position The position to get the right position of.
* @return _right The position to the right of `position`.
* @param _position The position to get the right position of.
* @return right_ The position to the right of `position`.
*/
function right(Position position) internal pure returns (Position _right) {
uint64 _depth = depth(position);
uint64 _indexAtDepth = indexAtDepth(position);
function right(Position _position) internal pure returns (Position right_) {
uint64 _depth = depth(_position);
uint64 _indexAtDepth = indexAtDepth(_position);
// Right = { depth: position.depth + 1, indexAtDepth: position.indexAtDepth * 2 + 1 }
assembly {
_right := or(shl(0x40, add(_depth, 0x01)), add(shl(0x01, _indexAtDepth), 0x01))
right_ := or(shl(0x40, add(_depth, 0x01)), add(shl(0x01, _indexAtDepth), 0x01))
}
}
/**
* @notice Get the parent position of `position`.
* @param position The position to get the parent position of.
* @return _parent The parent position of `position`.
* @param _position The position to get the parent position of.
* @return parent_ The parent position of `position`.
*/
function parent(Position position) internal pure returns (Position _parent) {
uint64 _depth = depth(position);
uint64 _indexAtDepth = indexAtDepth(position);
function parent(Position _position) internal pure returns (Position parent_) {
uint64 _depth = depth(_position);
uint64 _indexAtDepth = indexAtDepth(_position);
// Parent = { depth: position.depth - 1, indexAtDepth: position.indexAtDepth / 2 }
assembly {
_parent := or(shl(0x40, sub(_depth, 0x01)), shr(0x01, _indexAtDepth))
parent_ := or(shl(0x40, sub(_depth, 0x01)), shr(0x01, _indexAtDepth))
}
}
/**
* @notice Get the deepest, right most index relative to the `position`.
* @param position The position to get the relative deepest, right most index of.
* @param maxDepth The maximum depth of the game.
* @return _rightIndex The deepest, right most index relative to the `position`.
* TODO: Optimize; No need to update the full position in the sub loop.
* @param _position The position to get the relative deepest, right most index of.
* @param _maxDepth The maximum depth of the game.
* @return rightIndex_ The deepest, right most index relative to the `position`.
*/
function rightIndex(Position position, uint256 maxDepth) internal pure returns (uint64 _rightIndex) {
function rightIndex(Position _position, uint256 _maxDepth) internal pure returns (uint64 rightIndex_) {
assembly {
_rightIndex := shr(0xC0, shl(0xC0, position))
rightIndex_ := shr(0xC0, shl(0xC0, _position))
// Walk down to the max depth by moving right
for { let i := shr(0x40, position) } lt(i, sub(maxDepth, 0x01)) { i := add(i, 0x01) } {
_rightIndex := add(0x01, shl(0x01, _rightIndex))
for { let i := shr(0x40, _position) } lt(i, sub(_maxDepth, 0x01)) { i := add(i, 0x01) } {
rightIndex_ := add(0x01, shl(0x01, rightIndex_))
}
}
}
/**
* @notice Get the attack position relative to `position`.
* @param _position The position to get the relative attack position of.
* @return attack_ The attack position relative to `position`.
*/
function attack(Position position) internal pure returns (Position _attack) {
return left(position);
function attack(Position _position) internal pure returns (Position attack_) {
return left(_position);
}
/**
* @notice Get the defend position of `position`.
* @notice Get the defense position relative to `position`.
* @param _position The position to get the relative defense position of.
* @return defense_ The defense position relative to `position`.
*/
function defend(Position position) internal pure returns (Position _defend) {
uint64 _depth = depth(position);
uint64 _indexAtDepth = indexAtDepth(position);
function defend(Position _position) internal pure returns (Position defense_) {
uint64 _depth = depth(_position);
uint64 _indexAtDepth = indexAtDepth(_position);
// Defend = { depth: position.depth + 1, indexAtDepth: ((position.indexAtDepth / 2) * 2 + 1) * 2 }
assembly {
_defend := or(shl(0x40, add(_depth, 0x01)), shl(0x01, add(0x01, shl(0x01, shr(0x01, _indexAtDepth)))))
defense_ := or(shl(0x40, add(_depth, 0x01)), shl(0x01, add(0x01, shl(0x01, shr(0x01, _indexAtDepth)))))
}
}
}
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