-
Notifications
You must be signed in to change notification settings - Fork 13
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
feat: SP1VerifierGateway #7
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
64d37f2
wip
ctian1 ceca647
forge install: openzeppelin-contracts
ctian1 f4b3330
wip
ctian1 37560d3
update contracts
mattstam 367f8ba
tests1
mattstam 887ba4a
tests2
mattstam 19a1c6c
cleanup
mattstam fb565ad
cleanup
mattstam 652ff33
cleanup
mattstam cb913ad
foundry.toml link
mattstam 750394c
fix ci
mattstam 805044a
add back tests
mattstam 75a1cde
check that selector matches on updateVerifier
mattstam 38e8bfe
new design and interface, todo redo tests
mattstam 9d7aa3f
tests
mattstam e82d722
comments
mattstam 1bc9014
nit
mattstam f4bffe8
nit
mattstam fad1a08
nit
mattstam 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 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,38 @@ | ||
name: Unit Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
||
jobs: | ||
sol: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Foundry | ||
uses: "foundry-rs/foundry-toolchain@v1" | ||
|
||
- name: Build the contracts and print their size | ||
working-directory: ./contracts | ||
run: forge build --sizes | ||
|
||
- name: Ensure files are the same as forge fmt | ||
working-directory: ./contracts | ||
run: forge fmt --check | ||
|
||
- name: Run the tests | ||
working-directory: ./contracts | ||
run: forge test | ||
|
||
- name: Add test summary | ||
run: | | ||
echo "## Tests result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY |
This file contains 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,8 @@ | ||
[submodule "contracts/lib/forge-std"] | ||
path = contracts/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
tag = v1.8.2 | ||
[submodule "contracts/lib/openzeppelin-contracts"] | ||
path = contracts/lib/openzeppelin-contracts | ||
url = https://github.com/openzeppelin/openzeppelin-contracts | ||
tag = v5.0.2 |
This file was deleted.
Oops, something went wrong.
This file contains 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,21 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"rules": { | ||
"code-complexity": [ | ||
"error", | ||
18 | ||
], | ||
"compiler-version": [ | ||
"error", | ||
">=0.8.20" | ||
], | ||
"max-line-length": [ | ||
"off", | ||
100 | ||
], | ||
"no-console": "off", | ||
"var-name-mixedcase": "off", | ||
"func-name-mixedcase": "off", | ||
"avoid-low-level-calls": "off" | ||
} | ||
} |
This file contains 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
Submodule openzeppelin-contracts
added at
dbb610
This file contains 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
This file contains 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,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
pragma solidity ^0.8.20; | ||
|
||
/// @title SP1 Verifier Interface | ||
/// @author Succinct Labs | ||
/// @notice This contract is the interface for the SP1 Verifier. | ||
interface ISP1Verifier { | ||
/// @notice Returns the version of SP1 this verifier corresponds to. | ||
function VERSION() external pure returns (string memory); | ||
|
||
/// @notice Returns the hash of the verification key. | ||
function VKEY_HASH() external pure returns (bytes32); | ||
|
||
/// @notice Verifies a proof with given public values and vkey. | ||
/// @param vkey The verification key for the RISC-V program. | ||
/// @dev It is expected that the first 4 bytes of proofBytes must match the first 4 bytes of | ||
/// target verifier's VERIFIER_HASH. | ||
/// @param programVKey The verification key for the RISC-V program. | ||
/// @param publicValues The public values encoded as bytes. | ||
/// @param proofBytes The proof of the program execution the SP1 zkVM encoded as bytes. | ||
function verifyProof( | ||
bytes32 vkey, | ||
bytes32 programVKey, | ||
bytes calldata publicValues, | ||
bytes calldata proofBytes | ||
) external view; | ||
} | ||
|
||
interface ISP1VerifierWithHash is ISP1Verifier { | ||
/// @notice Returns the hash of the verifier. | ||
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. Should note that this is autogenerated by taking sha256 of the vkey file 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. added |
||
function VERIFIER_HASH() external pure returns (bytes32); | ||
} |
This file contains 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,72 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {ISP1Verifier} from "./ISP1Verifier.sol"; | ||
|
||
/// @dev A struct containing the address of a verifier and whether the verifier is frozen. A | ||
/// frozen verifier cannot be routed to. | ||
struct VerifierRoute { | ||
address verifier; | ||
bool frozen; | ||
} | ||
|
||
interface ISP1VerifierGatewayEvents { | ||
/// @notice Emitted when a verifier route is added. | ||
/// @param selector The verifier selector that was added. | ||
/// @param verifier The address of the verifier contract. | ||
event RouteAdded(bytes4 selector, address verifier); | ||
|
||
/// @notice Emitted when a verifier route is frozen. | ||
/// @param selector The verifier selector that was frozen. | ||
/// @param verifier The address of the verifier contract. | ||
event RouteFrozen(bytes4 selector, address verifier); | ||
} | ||
|
||
interface ISP1VerifierGatewayErrors { | ||
/// @notice Thrown when the verifier route is not found. | ||
/// @param selector The verifier selector that was specified. | ||
error RouteNotFound(bytes4 selector); | ||
|
||
/// @notice Thrown when the verifier route is found, but is frozen. | ||
/// @param selector The verifier selector that was specified. | ||
error RouteIsFrozen(bytes4 selector); | ||
|
||
/// @notice Thrown when adding a verifier route and the selector already contains a route. | ||
/// @param verifier The address of the verifier contract in the existing route. | ||
error RouteAlreadyExists(address verifier); | ||
|
||
/// @notice Thrown when adding a verifier route and the selector returned by the verifier is | ||
/// zero. | ||
error SelectorCannotBeZero(); | ||
} | ||
|
||
/// @title SP1 Verifier Gateway Interface | ||
/// @author Succinct Labs | ||
/// @notice This contract is the interface for the SP1 Verifier Gateway. | ||
interface ISP1VerifierGateway is | ||
ISP1VerifierGatewayEvents, | ||
ISP1VerifierGatewayErrors, | ||
ISP1Verifier | ||
{ | ||
/// @notice Mapping of 4-byte verifier selectors to verifier routes. | ||
/// @dev Only one verifier route can be added for each selector. | ||
/// @param selector The verifier selector, which is both the first 4 bytes of the VERIFIER_HASH | ||
/// and the first 4 bytes of the proofs designed for that verifier. | ||
/// @return verifier The address of the verifier contract. | ||
/// @return frozen Whether the verifier is frozen. | ||
function routes(bytes4 selector) external view returns (address verifier, bool frozen); | ||
|
||
/// @notice Adds a verifier route. This enable proofs to be routed to this verifier. | ||
/// @dev Only callable by the owner. The owner is responsible for ensuring that the specified | ||
/// verifier is correct with a valid VERIFIER_HASH. Once a route to a verifier is added, it | ||
/// cannot be removed. | ||
/// @param verifier The address of the verifier contract. This verifier MUST implement the | ||
/// ISP1VerifierWithHash interface. | ||
function addRoute(address verifier) external; | ||
|
||
/// @notice Freezes a verifier route. This prevents proofs from being routed to this verifier. | ||
/// @dev Only callable by the owner. Once a route to a verifier is frozen, it cannot be | ||
/// unfrozen. | ||
/// @param selector The verifier selector to freeze. | ||
function freezeRoute(bytes4 selector) external; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: using sol 0.8.20 because that's what the OZ lib is on