Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions contracts/interfaces/IYellowAdjudicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ pragma solidity ^0.8.22;

import '../nitro/interfaces/INitroAdjudicator.sol';

interface IYellowAdjudicator is INitroAdjudicator {
function unpackStatus(
bytes32 channelId
) external view returns (uint48 turnNumRecord, uint48 finalizesAt, uint160 fingerprint);
}
interface IYellowAdjudicator is INitroAdjudicator {}
18 changes: 2 additions & 16 deletions contracts/nitro/ForceMove.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ contract ForceMove is IForceMove, StatusManager {
// External methods:
// *****************

/**
* @notice Unpacks turnNumRecord, finalizesAt and fingerprint from the status of a particular channel.
* @dev Unpacks turnNumRecord, finalizesAt and fingerprint from the status of a particular channel.
* @param channelId Unique identifier for a state channel.
* @return turnNumRecord A turnNum that (the adjudicator knows) is supported by a signature from each participant.
* @return finalizesAt The unix timestamp when `channelId` will finalize.
* @return fingerprint The last 160 bits of keccak256(stateHash, outcomeHash)
*/
function unpackStatus(
bytes32 channelId
) external view returns (uint48 turnNumRecord, uint48 finalizesAt, uint160 fingerprint) {
(turnNumRecord, finalizesAt, fingerprint) = _unpackStatus(channelId);
}

/**
* @notice Registers a challenge against a state channel. A challenge will either prompt another participant into clearing the challenge (via one of the other methods), or cause the channel to finalize at a specific time.
* @dev Registers a challenge against a state channel. A challenge will either prompt another participant into clearing the challenge (via one of the other methods), or cause the channel to finalize at a specific time.
Expand Down Expand Up @@ -290,7 +276,7 @@ contract ForceMove is IForceMove, StatusManager {
* @param newTurnNumRecord New turnNumRecord intended to overwrite existing value
*/
function _requireIncreasedTurnNumber(bytes32 channelId, uint48 newTurnNumRecord) internal view {
(uint48 turnNumRecord, , ) = _unpackStatus(channelId);
(uint48 turnNumRecord, , ) = unpackStatus(channelId);
require(newTurnNumRecord > turnNumRecord, 'turnNumRecord not increased.');
}

Expand All @@ -304,7 +290,7 @@ contract ForceMove is IForceMove, StatusManager {
bytes32 channelId,
uint48 newTurnNumRecord
) internal view {
(uint48 turnNumRecord, , ) = _unpackStatus(channelId);
(uint48 turnNumRecord, , ) = unpackStatus(channelId);
require(newTurnNumRecord >= turnNumRecord, 'turnNumRecord decreased.');
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/nitro/MultiAssetHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ contract MultiAssetHolder is IMultiAssetHolder, StatusManager {
bytes32 outcomeHash,
bytes32 channelId
) internal view {
(, , uint160 fingerprint) = _unpackStatus(channelId);
(, , uint160 fingerprint) = unpackStatus(channelId);
require(
fingerprint == _generateFingerprint(stateHash, outcomeHash),
'incorrect fingerprint'
Expand All @@ -491,7 +491,7 @@ contract MultiAssetHolder is IMultiAssetHolder, StatusManager {
bytes32 stateHash,
bytes32 outcomeHash
) internal {
(uint48 turnNumRecord, uint48 finalizesAt, ) = _unpackStatus(channelId);
(uint48 turnNumRecord, uint48 finalizesAt, ) = unpackStatus(channelId);

bytes32 newStatus = _generateStatus(
ChannelData(turnNumRecord, finalizesAt, stateHash, outcomeHash)
Expand Down
38 changes: 19 additions & 19 deletions contracts/nitro/StatusManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ import {IStatusManager} from './interfaces/IStatusManager.sol';
contract StatusManager is IStatusManager {
mapping(bytes32 => bytes32) public statusOf;

/**
* @notice Unpacks turnNumRecord, finalizesAt and fingerprint from the status of a particular channel.
* @dev Unpacks turnNumRecord, finalizesAt and fingerprint from the status of a particular channel.
* @param channelId Unique identifier for a state channel.
* @return turnNumRecord A turnNum that (the adjudicator knows) is supported by a signature from each participant.
* @return finalizesAt The unix timestamp when `channelId` will finalize.
* @return fingerprint The last 160 bits of keccak256(stateHash, outcomeHash)
*/
function unpackStatus(
bytes32 channelId
) public view returns (uint48 turnNumRecord, uint48 finalizesAt, uint160 fingerprint) {
bytes32 status = statusOf[channelId];
uint16 cursor = 256;
turnNumRecord = uint48(uint256(status) >> (cursor -= 48));
finalizesAt = uint48(uint256(status) >> (cursor -= 48));
fingerprint = uint160(uint256(status));
}

/**
* @notice Computes the ChannelMode for a given channelId.
* @dev Computes the ChannelMode for a given channelId.
Expand All @@ -18,7 +36,7 @@ contract StatusManager is IStatusManager {
// Note that _unpackStatus(someRandomChannelId) returns (0,0,0), which is
// correct when nobody has written to storage yet.

(, uint48 finalizesAt, ) = _unpackStatus(channelId);
(, uint48 finalizesAt, ) = unpackStatus(channelId);
if (finalizesAt == 0) {
return ChannelMode.Open;
// solhint-disable-next-line not-rely-on-time
Expand Down Expand Up @@ -60,22 +78,4 @@ contract StatusManager is IStatusManager {
) internal pure returns (uint160) {
return uint160(uint256(keccak256(abi.encode(stateHash, outcomeHash))));
}

/**
* @notice Unpacks turnNumRecord, finalizesAt and fingerprint from the status of a particular channel.
* @dev Unpacks turnNumRecord, finalizesAt and fingerprint from the status of a particular channel.
* @param channelId Unique identifier for a state channel.
* @return turnNumRecord A turnNum that (the adjudicator knows) is supported by a signature from each participant.
* @return finalizesAt The unix timestamp when `channelId` will finalize.
* @return fingerprint The last 160 bits of kecca256(stateHash, outcomeHash)
*/
function _unpackStatus(
bytes32 channelId
) internal view returns (uint48 turnNumRecord, uint48 finalizesAt, uint160 fingerprint) {
bytes32 status = statusOf[channelId];
uint16 cursor = 256;
turnNumRecord = uint48(uint256(status) >> (cursor -= 48));
finalizesAt = uint48(uint256(status) >> (cursor -= 48));
fingerprint = uint160(uint256(status));
}
}
4 changes: 4 additions & 0 deletions contracts/nitro/interfaces/IStatusManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ interface IStatusManager {
bytes32 stateHash; // keccak256(abi.encode(State))
bytes32 outcomeHash;
}

function unpackStatus(
bytes32 channelId
) external view returns (uint48 turnNumRecord, uint48 finalizesAt, uint160 fingerprint);
}