diff --git a/contracts/interfaces/IYellowAdjudicator.sol b/contracts/interfaces/IYellowAdjudicator.sol index 6d6febf65..33fbac5d7 100644 --- a/contracts/interfaces/IYellowAdjudicator.sol +++ b/contracts/interfaces/IYellowAdjudicator.sol @@ -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 {} diff --git a/contracts/nitro/ForceMove.sol b/contracts/nitro/ForceMove.sol index 0489c8ba2..01d4b97bb 100644 --- a/contracts/nitro/ForceMove.sol +++ b/contracts/nitro/ForceMove.sol @@ -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. @@ -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.'); } @@ -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.'); } diff --git a/contracts/nitro/MultiAssetHolder.sol b/contracts/nitro/MultiAssetHolder.sol index c90418272..e7b9ccb11 100644 --- a/contracts/nitro/MultiAssetHolder.sol +++ b/contracts/nitro/MultiAssetHolder.sol @@ -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' @@ -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) diff --git a/contracts/nitro/StatusManager.sol b/contracts/nitro/StatusManager.sol index 65fed5c06..bf785b565 100644 --- a/contracts/nitro/StatusManager.sol +++ b/contracts/nitro/StatusManager.sol @@ -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. @@ -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 @@ -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)); - } } diff --git a/contracts/nitro/interfaces/IStatusManager.sol b/contracts/nitro/interfaces/IStatusManager.sol index f925a544e..d810a20ec 100644 --- a/contracts/nitro/interfaces/IStatusManager.sol +++ b/contracts/nitro/interfaces/IStatusManager.sol @@ -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); }