Skip to content
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: call verifier gateway, add deployment instructions, example env for prover network #13

Merged
merged 14 commits into from
Jul 2, 2024
2 changes: 2 additions & 0 deletions .gitmodules
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
33 changes: 20 additions & 13 deletions contracts/src/Fibonacci.sol
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
// 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)
{
// this.verifyProof(fibonacciProgramVkey, publicValues, proof);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove?

ISP1Verifier(verifier).verifyProof(fibonacciProgramVkey, publicValues, proof);
(uint32 n, uint32 a, uint32 b) = abi.decode(publicValues, (uint32, uint32, uint32));
return (n, a, b);
}
}
19 changes: 11 additions & 8 deletions contracts/test/Fibonacci.t.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
pragma solidity ^0.8.20;

import {Test, console} from "forge-std/Test.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {Fibonacci} from "../src/Fibonacci.sol";
import {SP1Verifier} from "@sp1-contracts/SP1Verifier.sol";
import {SP1VerifierGateway} from "@sp1-contracts/SP1VerifierGateway.sol";

struct SP1ProofFixtureJson {
uint32 a;
Expand All @@ -18,6 +18,7 @@ struct SP1ProofFixtureJson {
contract FibonacciTest is Test {
using stdJson for string;

address verifier;
Fibonacci public fibonacci;

function loadFixture() public view returns (SP1ProofFixtureJson memory) {
Expand All @@ -30,15 +31,17 @@ contract FibonacciTest is Test {

function setUp() public {
SP1ProofFixtureJson memory fixture = loadFixture();
fibonacci = new Fibonacci(fixture.vkey);

verifier = address(new SP1VerifierGateway(address(1)));
fibonacci = new Fibonacci(verifier, fixture.vkey);
}

function test_ValidFibonacciProof() public view {
function test_ValidFibonacciProof() public {
SP1ProofFixtureJson memory fixture = loadFixture();
(uint32 n, uint32 a, uint32 b) = fibonacci.verifyFibonacciProof(
fixture.proof,
fixture.publicValues
);

vm.mockCall(verifier, abi.encodeWithSelector(SP1VerifierGateway.verifyProof.selector), abi.encode(true));

(uint32 n, uint32 a, uint32 b) = fibonacci.verifyFibonacciProof(fixture.proof, fixture.publicValues);
assert(n == fixture.n);
assert(a == fixture.a);
assert(b == fixture.b);
Expand Down
Loading