Skip to content

Commit

Permalink
Merge pull request #1637 from statechannels/move-nitro-protocol
Browse files Browse the repository at this point in the history
Absorb `nitro-protocol` as a yarn workspace
  • Loading branch information
geoknee authored Sep 6, 2023
2 parents c7f774a + cc75ab4 commit c2df09e
Show file tree
Hide file tree
Showing 30 changed files with 17,604 additions and 46,694 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bindings-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install nitro-protocol dependencies
run: |
cd ./nitro-protocol
npm ci --legacy-peer-deps
yarn
- name: make bin folder
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ jobs:
with:
node-version: "18.15.0"
- name: Install dependencies
run: npm ci --legacy-peer-deps
run: yarn
- name: Compile contracts
run: npx hardhat compile
run: yarn hardhat compile
- name: Run eslint (including prettier)
run: npm run lint:check
run: yarn lint:check
- name: Run gas benchmarks
run: npm run benchmark:diff
run: yarn benchmark:diff
- name: Archive logs
if: always()
uses: actions/upload-artifact@v2
with:
name: logs
path: ./**/*.log
- name: Run tests
run: npm test
run: yarn test
- name: Notify slack fail
if: ${{ failure() && github.ref == 'refs/heads/main'}}
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ node_modules/

#
**/storybook-static

**/tmp-build
7 changes: 4 additions & 3 deletions generate-adjudicator-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ echo "Deleted tmp-build directory."

echo "Compiling contracts..."

solc --base-path $NITRO_PROTOCOL_DIR \
@statechannels/exit-format/=node_modules/@statechannels/exit-format/ \
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/ \
solc --include-path $GONITRO_DIR \
--base-path $NITRO_PROTOCOL_DIR \
@statechannels/exit-format/=../node_modules/@statechannels/exit-format/ \
@openzeppelin/contracts/=../node_modules/@openzeppelin/contracts/ \
$NITRO_PROTOCOL_DIR/contracts/NitroAdjudicator.sol \
$NITRO_PROTOCOL_DIR/contracts/ConsensusApp.sol \
$NITRO_PROTOCOL_DIR/contracts/Token.sol \
Expand Down
8 changes: 4 additions & 4 deletions nitro-protocol/contracts/CountingApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ contract CountingApp is IForceMoveApp {
* @param a First RecoveredVariablePart.
* @param b Second RecoveredVariablePart.
*/
function _requireEqualOutcomes(RecoveredVariablePart memory a, RecoveredVariablePart memory b)
internal
pure
{
function _requireEqualOutcomes(
RecoveredVariablePart memory a,
RecoveredVariablePart memory b
) internal pure {
require(
Outcome.exitsEqual(a.variablePart.outcome, b.variablePart.outcome),
'Outcome must not change'
Expand Down
48 changes: 20 additions & 28 deletions nitro-protocol/contracts/ForceMove.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,9 @@ contract ForceMove is IForceMove, StatusManager {
* @return finalizesAt The unix timestamp when `channelId` will finalize.
* @return fingerprint The last 160 bits of kecca256(stateHash, outcomeHash)
*/
function unpackStatus(bytes32 channelId)
external
view
returns (
uint48 turnNumRecord,
uint48 finalizesAt,
uint160 fingerprint
)
{
function unpackStatus(
bytes32 channelId
) external view returns (uint48 turnNumRecord, uint48 finalizesAt, uint160 fingerprint) {
(turnNumRecord, finalizesAt, fingerprint) = _unpackStatus(channelId);
}

Expand Down Expand Up @@ -121,11 +115,10 @@ contract ForceMove is IForceMove, StatusManager {
* @param fixedPart Data describing properties of the state channel that do not change with state updates.
* @param candidate A struct, that can be signed by any number of participants, describing the properties of the state channel to change to.
*/
function conclude(FixedPart memory fixedPart, SignedVariablePart memory candidate)
external
virtual
override
{
function conclude(
FixedPart memory fixedPart,
SignedVariablePart memory candidate
) external virtual override {
_conclude(fixedPart, candidate);
}

Expand All @@ -135,10 +128,10 @@ contract ForceMove is IForceMove, StatusManager {
* @param fixedPart Data describing properties of the state channel that do not change with state updates.
* @param candidate A struct, that can be signed by any number of participants, describing the properties of the state channel to change to.
*/
function _conclude(FixedPart memory fixedPart, SignedVariablePart memory candidate)
internal
returns (bytes32 channelId)
{
function _conclude(
FixedPart memory fixedPart,
SignedVariablePart memory candidate
) internal returns (bytes32 channelId) {
channelId = NitroUtils.getChannelId(fixedPart);

// checks
Expand Down Expand Up @@ -197,11 +190,10 @@ contract ForceMove is IForceMove, StatusManager {
* @param addresses A line-up of possible perpetrators.
* @return true if the address is in the array, false otherwise
*/
function _isAddressInArray(address suspect, address[] memory addresses)
internal
pure
returns (bool)
{
function _isAddressInArray(
address suspect,
address[] memory addresses
) internal pure returns (bool) {
for (uint256 i = 0; i < addresses.length; i++) {
if (suspect == addresses[i]) {
return true;
Expand Down Expand Up @@ -274,7 +266,7 @@ contract ForceMove is IForceMove, StatusManager {
// Check each participant to see if they signed it
for (uint256 i = 0; i < fixedPart.participants.length; i++) {
if (signer == fixedPart.participants[i]) {
rvp.signedBy |= 2**i;
rvp.signedBy |= 2 ** i;
break; // Once we have found a match, assuming distinct participants, no-one else signed it
}
}
Expand Down Expand Up @@ -312,10 +304,10 @@ contract ForceMove is IForceMove, StatusManager {
* @param channelId Unique identifier for a channel.
* @param newTurnNumRecord New turnNumRecord intended to overwrite existing value
*/
function _requireNonDecreasedTurnNumber(bytes32 channelId, uint48 newTurnNumRecord)
internal
view
{
function _requireNonDecreasedTurnNumber(
bytes32 channelId,
uint48 newTurnNumRecord
) internal view {
(uint48 turnNumRecord, , ) = _unpackStatus(channelId);
require(newTurnNumRecord >= turnNumRecord, 'turnNumRecord decreased.');
}
Expand Down
8 changes: 3 additions & 5 deletions nitro-protocol/contracts/InterestBearingApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ contract InterestBearingApp is IForceMoveApp {
// - the latest consensus principal
// - the channel's interest rate
// - the time elapsed since the last principal adjustment
function computeOutstandingInterest(InterestAppData memory appData)
private
view
returns (Funds memory)
{
function computeOutstandingInterest(
InterestAppData memory appData
) private view returns (Funds memory) {
uint256 numBlocks = block.number - appData.blocknumber;

address[] memory assets = new address[](appData.principal.asset.length);
Expand Down
10 changes: 4 additions & 6 deletions nitro-protocol/contracts/MultiAssetHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ contract MultiAssetHolder is IMultiAssetHolder, StatusManager {
/**
* @dev Checks that the source and target channels are finalized; that the supplied outcomes match the stored fingerprints; that the asset is identical in source and target. Computes and returns the decoded outcomes.
*/
function _apply_reclaim_checks(ReclaimArgs memory reclaimArgs)
function _apply_reclaim_checks(
ReclaimArgs memory reclaimArgs
)
internal
view
returns (
Expand Down Expand Up @@ -416,11 +418,7 @@ contract MultiAssetHolder is IMultiAssetHolder, StatusManager {
* @param destination ethereum address to be credited.
* @param amount Quantity of assets to be transferred.
*/
function _transferAsset(
address asset,
address destination,
uint256 amount
) internal {
function _transferAsset(address asset, address destination, uint256 amount) internal {
if (asset == address(0)) {
(bool success, ) = destination.call{value: amount}(''); //solhint-disable-line avoid-low-level-calls
require(success, 'Could not transfer ETH');
Expand Down
29 changes: 10 additions & 19 deletions nitro-protocol/contracts/StatusManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ contract StatusManager is IStatusManager {
* @dev Formats the input data for on chain storage.
* @param channelData ChannelData data.
*/
function _generateStatus(ChannelData memory channelData)
internal
pure
returns (bytes32 status)
{
function _generateStatus(
ChannelData memory channelData
) internal pure returns (bytes32 status) {
// The hash is constructed from left to right.
uint256 result;
uint16 cursor = 256;
Expand All @@ -56,11 +54,10 @@ contract StatusManager is IStatusManager {
status = bytes32(result);
}

function _generateFingerprint(bytes32 stateHash, bytes32 outcomeHash)
internal
pure
returns (uint160)
{
function _generateFingerprint(
bytes32 stateHash,
bytes32 outcomeHash
) internal pure returns (uint160) {
return uint160(uint256(keccak256(abi.encode(stateHash, outcomeHash))));
}

Expand All @@ -72,15 +69,9 @@ contract StatusManager is IStatusManager {
* @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
)
{
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));
Expand Down
9 changes: 4 additions & 5 deletions nitro-protocol/contracts/VirtualPaymentApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ contract VirtualPaymentApp is IForceMoveApp {
);
}

function requireValidVoucher(bytes memory appData, FixedPart memory fixedPart)
internal
pure
returns (uint256)
{
function requireValidVoucher(
bytes memory appData,
FixedPart memory fixedPart
) internal pure returns (uint256) {
VoucherAmountAndSignature memory voucher = abi.decode(appData, (VoucherAmountAndSignature));

address signer = NitroUtils.recoverSigner(
Expand Down
6 changes: 1 addition & 5 deletions nitro-protocol/contracts/deploy/Create2Deployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ pragma solidity ^0.8.17;
import '@openzeppelin/contracts/utils/Create2.sol';

contract Create2Deployer {
function deploy(
uint256 value,
bytes32 salt,
bytes memory code
) public {
function deploy(uint256 value, bytes32 salt, bytes memory code) public {
Create2.deploy(value, salt, code);
}

Expand Down
8 changes: 3 additions & 5 deletions nitro-protocol/contracts/examples/HashLockedSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ contract HashLockedSwap is IForceMoveApp {
return (true, '');
}

function decode2PartyAllocation(Outcome.SingleAssetExit[] memory outcome)
private
pure
returns (Outcome.Allocation[] memory allocations)
{
function decode2PartyAllocation(
Outcome.SingleAssetExit[] memory outcome
) private pure returns (Outcome.Allocation[] memory allocations) {
Outcome.SingleAssetExit memory assetOutcome = outcome[0];

allocations = assetOutcome.allocations; // TODO should we check each allocation is a "simple" one?
Expand Down
8 changes: 4 additions & 4 deletions nitro-protocol/contracts/examples/SingleAssetPayments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ contract SingleAssetPayments is IForceMoveApp {
* @param nParticipants Number of participants in a channel.
* @param outcome Outcome to check.
*/
function _requireValidOutcome(uint256 nParticipants, Outcome.SingleAssetExit[] memory outcome)
internal
pure
{
function _requireValidOutcome(
uint256 nParticipants,
Outcome.SingleAssetExit[] memory outcome
) internal pure {
// Throws if more than one asset
require(outcome.length == 1, 'outcome: Only one asset allowed');

Expand Down
Loading

0 comments on commit c2df09e

Please sign in to comment.