-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: call verifier gateway, add deployment instructions, example env…
… for prover network (#13)
- Loading branch information
Showing
14 changed files
with
339 additions
and
484 deletions.
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,5 @@ | ||
# 'mock' for generating mock proofs locally, 'local' for generating proofs locally, 'network' for generating proofs using the proving network. | ||
SP1_PROVER=mock | ||
# If using the proving network, set to your whitelisted private key. For more information, see: | ||
# https://docs.succinct.xyz/prover-network/setup.html#key-setup | ||
SP1_PRIVATE_KEY= |
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,6 +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/sp1-contracts"] | ||
path = contracts/lib/sp1-contracts | ||
url = https://github.com/succinctlabs/sp1-contracts | ||
tag = main |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# SP1 Project Template Contracts | ||
|
||
This is a template for writing a contract that uses verification of [SP1](https://github.com/succinctlabs/sp1) PlonK proofs onchain using the [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/SP1VerifierGateway.sol). | ||
|
||
## Requirements | ||
|
||
- [Foundry](https://book.getfoundry.sh/getting-started/installation) | ||
|
||
## Test | ||
|
||
```sh | ||
forge test -v | ||
``` | ||
|
||
## Deployment | ||
|
||
#### Step 1: Set the `VERIFIER` environment variable | ||
|
||
Find the address of the `verifer` to use from the [deployments](https://github.com/succinctlabs/sp1-contracts/tree/main/contracts/deployments) list for the chain you are deploying to. Set it to the `VERIFIER` environment variable, for example: | ||
|
||
```sh | ||
VERIFIER=0x3B6041173B80E77f038f3F2C0f9744f04837185e | ||
``` | ||
|
||
Note: you can use either the [SP1VerifierGateway](https://github.com/succinctlabs/sp1-contracts/blob/main/contracts/src/SP1VerifierGateway.sol) or a specific version, but it is highly recommended to use the gateway as this will allow you to use different versions of SP1. | ||
|
||
#### Step 2: Set the `PROGRAM_VKEY` environment variable | ||
|
||
Find your program verification key by going into the `../script` directory and running `RUST_LOG=info cargo run --package fibonacci-script --bin vkey --release`, which will print an output like: | ||
|
||
> Program Verification Key: 0x00620892344c310c32a74bf0807a5c043964264e4f37c96a10ad12b5c9214e0e | ||
Then set the `PROGRAM_VKEY` environment variable to the output of that command, for example: | ||
|
||
```sh | ||
PROGRAM_VKEY=0x00620892344c310c32a74bf0807a5c043964264e4f37c96a10ad12b5c9214e0e | ||
``` | ||
|
||
#### Step 3: Deploy the contract | ||
|
||
Fill out the rest of the details needed for deployment: | ||
|
||
```sh | ||
RPC_URL=... | ||
``` | ||
|
||
```sh | ||
PRIVATE_KEY=... | ||
``` | ||
|
||
Then deploy the contract to the chain: | ||
|
||
```sh | ||
forge create src/Fibonacci.sol:Fibonacci --rpc-url $RPC_URL --private-key $PRIVATE_KEY --constructor-args $VERIFIER $PROGRAM_VKEY | ||
``` | ||
|
||
It can also be a good idea to verify the contract when you deploy, in which case you would also need to set `ETHERSCAN_API_KEY`: | ||
|
||
```sh | ||
forge create src/Fibonacci.sol:Fibonacci --rpc-url $RPC_URL --private-key $PRIVATE_KEY --constructor-args $VERIFIER $PROGRAM_VKEY --verify --verifier etherscan --etherscan-api-key $ETHERSCAN_API_KEY | ||
``` |
Submodule forge-std
updated
13 files
+6 −12 | .github/workflows/ci.yml | |
+3 −1 | .github/workflows/sync.yml | |
+2 −2 | foundry.toml | |
+1 −1 | package.json | |
+1 −1 | src/StdAssertions.sol | |
+17 −8 | src/StdChains.sol | |
+18 −3 | src/StdInvariant.sol | |
+1 −1 | src/StdUtils.sol | |
+131 −6 | src/Vm.sol | |
+1 −5 | src/mocks/MockERC721.sol | |
+12 −7 | test/StdChains.t.sol | |
+1 −1 | test/StdCheats.t.sol | |
+2 −2 | test/Vm.t.sol |
Submodule sp1-contracts
updated
31 files
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,32 +1,38 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
pragma solidity ^0.8.20; | ||
|
||
import {SP1Verifier} from "@sp1-contracts/SP1Verifier.sol"; | ||
import {ISP1Verifier} from "@sp1-contracts/ISP1Verifier.sol"; | ||
|
||
/// @title Fibonacci. | ||
/// @author Succinct Labs | ||
/// @notice This contract implements a simple example of verifying the proof of a computing a | ||
/// fibonacci number. | ||
contract Fibonacci is SP1Verifier { | ||
contract Fibonacci { | ||
/// @notice The address of the SP1 verifier contract. | ||
/// @dev This can either be a specific SP1Verifier for a specific version, or the | ||
/// SP1VerifierGateway which can be used to verify proofs for any version of SP1. | ||
/// For the list of supported verifiers on each chain, see: | ||
/// https://github.com/succinctlabs/sp1-contracts/tree/main/contracts/deployments | ||
address public verifier; | ||
|
||
/// @notice The verification key for the fibonacci program. | ||
bytes32 public fibonacciProgramVkey; | ||
|
||
constructor(bytes32 _fibonacciProgramVkey) { | ||
constructor(address _verifier, bytes32 _fibonacciProgramVkey) { | ||
verifier = _verifier; | ||
fibonacciProgramVkey = _fibonacciProgramVkey; | ||
} | ||
|
||
/// @notice The entrypoint for verifying the proof of a fibonacci number. | ||
/// @param proof The encoded proof. | ||
/// @param publicValues The encoded public values. | ||
function verifyFibonacciProof( | ||
bytes memory proof, | ||
bytes memory publicValues | ||
) public view returns (uint32, uint32, uint32) { | ||
this.verifyProof(fibonacciProgramVkey, publicValues, proof); | ||
(uint32 n, uint32 a, uint32 b) = abi.decode( | ||
publicValues, | ||
(uint32, uint32, uint32) | ||
); | ||
function verifyFibonacciProof(bytes calldata proof, bytes calldata publicValues) | ||
public | ||
view | ||
returns (uint32, uint32, uint32) | ||
{ | ||
ISP1Verifier(verifier).verifyProof(fibonacciProgramVkey, publicValues, proof); | ||
(uint32 n, uint32 a, uint32 b) = abi.decode(publicValues, (uint32, uint32, uint32)); | ||
return (n, a, b); | ||
} | ||
} |
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
Oops, something went wrong.