-
Notifications
You must be signed in to change notification settings - Fork 1
feat: NitroRPC app implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
philanton
wants to merge
8
commits into
main
Choose a base branch
from
feat/nitro-rpc-app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
970f2f7
forge install: exit-format
philanton 7c64dde
feat: verify rpc payload
philanton 60a4331
forge install: nitro
philanton 5020a31
fix imports
philanton baae394
fix contract build
philanton 21b5560
feat: nitro-rpc proto and golang draft implementation (#2)
philanton 9450e1e
Delete .vscode/settings.json
mod 4dcb246
Adding Nitro Channel Protocol
mod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| [submodule "nitro_rpc/lib/forge-std"] | ||
| path = nitro_rpc/lib/forge-std | ||
| url = https://github.com/foundry-rs/forge-std | ||
| [submodule "nitro_rpc/lib/exit-format"] | ||
| path = nitro_rpc/lib/exit-format | ||
| url = https://github.com/statechannels/exit-format | ||
| [submodule "nitro_rpc/lib/nitro"] | ||
| path = nitro_rpc/lib/nitro | ||
| url = https://github.com/erc7824/nitro |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "solidity.packageDefaultDependenciesContractsDirectory": "src", | ||
| "solidity.packageDefaultDependenciesDirectory": "lib" | ||
| } | ||
|
|
Submodule exit-format
added at
08169b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,82 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.17; | ||
|
|
||
|
|
||
| import {INitroTypes} from "nitro/interfaces/INitroTypes.sol"; | ||
| import {NitroUtils} from "nitro/libraries/NitroUtils.sol"; | ||
| import {IForceMoveApp} from "nitro/interfaces/IForceMoveApp.sol"; | ||
|
|
||
| /** | ||
| * @title NitroRPC | ||
| * @dev Solidity implementation of Nitro RPC protocol structures | ||
| */ | ||
| interface NitroRPC { | ||
|
|
||
| contract NitroRPC is IForceMoveApp { | ||
| struct Payload { | ||
| uint256 requestId; | ||
| uint256 timestamp; | ||
| string method; | ||
| bytes params; | ||
| bytes result; | ||
| uint256 timestamp; | ||
| } | ||
|
|
||
| struct PayloadSigned { | ||
| Payload rpcMessage; | ||
| INitroTypes.Signature clientSig | ||
| INitroTypes.Signature serverSig | ||
| INitroTypes.Signature clientSig; | ||
| INitroTypes.Signature serverSig; | ||
| } | ||
|
|
||
| enum AllocationIndices { | ||
| Client, | ||
| Server | ||
| } | ||
|
|
||
| /** | ||
| * @notice Encodes application-specific rules for a particular ForceMove-compliant state channel. | ||
| * @dev Encodes application-specific rules for a particular ForceMove-compliant state channel. | ||
| * @param fixedPart Fixed part of the state channel. | ||
| * @param proof Array of recovered variable parts which constitutes a support proof for the candidate. | ||
| * @param candidate Recovered variable part the proof was supplied for. | ||
| */ | ||
| function stateIsSupported( | ||
| INitroTypes.FixedPart calldata fixedPart, | ||
| INitroTypes.RecoveredVariablePart[] calldata proof, | ||
| INitroTypes.RecoveredVariablePart calldata candidate | ||
| ) external pure override returns (bool, string memory) { | ||
| require(fixedPart.participants.length == uint256(AllocationIndices.Server) + 1, "bad number of participants"); | ||
|
|
||
| PayloadSigned memory payloadSigned = abi.decode(candidate.variablePart.appData, (PayloadSigned)); | ||
| requireValidPayload(fixedPart, payloadSigned); | ||
|
|
||
| return (true, ""); | ||
|
Comment on lines
+48
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have any other checks pertaining to |
||
| } | ||
|
|
||
| function requireValidPayload(INitroTypes.FixedPart calldata fixedPart, PayloadSigned memory payloadSigned) internal pure { | ||
| require(recoverPayloadSigner(payloadSigned.rpcMessage, payloadSigned.clientSig) == fixedPart.participants[uint256(AllocationIndices.Client)], "bad client signature"); | ||
| require(recoverPayloadSigner(payloadSigned.rpcMessage, payloadSigned.serverSig) == fixedPart.participants[uint256(AllocationIndices.Server)], "bad server signature"); | ||
|
|
||
| // TODO: verify timestamp and requestId | ||
| } | ||
|
|
||
| // This pure internal function recovers the signer address from the payload and its signature. | ||
| function recoverPayloadSigner(Payload memory payload, INitroTypes.Signature memory signature) internal pure returns (address) { | ||
philanton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Encode and hash the payload data. | ||
| // Using abi.encode ensures proper padding and decoding, avoiding potential ambiguities with dynamic types. | ||
| bytes32 messageHash = keccak256( | ||
| abi.encode( | ||
| payload.requestId, | ||
| payload.timestamp, | ||
| payload.method, | ||
| payload.params, | ||
| payload.result | ||
| ) | ||
| ); | ||
|
|
||
| // Apply the Ethereum Signed Message prefix. | ||
| bytes32 ethSignedMessageHash = keccak256( | ||
| abi.encodePacked("\x19Ethereum Signed Message:\n32", messageHash) | ||
| ); | ||
|
|
||
| // Recover the signer address using ecrecover. | ||
| return ecrecover(ethSignedMessageHash, signature.v, signature.r, signature.s); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.