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

chore: readme lint #11

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This crate verifies Groth16 proofs generated with SP1, leveraging Solana's BN254

> [!CAUTION]
>
> This repository is under active development and is not yet ready for production use.
> This repository is not audited for production use.

## Repository Overview

Expand All @@ -21,25 +21,26 @@ The `sp1-solana` library itself is in the [`verifier`](verifier) directory. [`ex

- Rust
- Edge Solana CLI
- Install with the following command:
- Install with the following command:

```shell
sh -c "$(curl -sSfL https://release.anza.xyz/edge/install)"
```

## Example usage

The [example](./example) demonstrates how to use the `sp1-solana` crate to verify a proof generated by SP1 on Solana.
The [example](./example) demonstrates how to use the `sp1-solana` crate to verify a proof generated by SP1 on Solana.
Running the script will perform the following steps:

1. Load an SP1 [`SP1ProofWithPublicValues`](https://docs.rs/sp1-sdk/2.0.0/sp1_sdk/proof/struct.SP1ProofWithPublicValues.html)
from the pre-generated proof [`fibonacci_proof.bin`](../proofs/fibonacci_proof.bin). This is a SP1 Groth16 proof that
proves that the 20th fibonacci number is 6765. Optionally, this proof can be freshly generated from
the [`sp1-program`](../sp1-program).

2. Extract the proof and public inputs from the `SP1ProofWithPublicValues`.
2. Extract the proof and public inputs from the `SP1ProofWithPublicValues`.

* The `proof` is the Groth16 proof, serialized in [SP1's standard format](https://docs.rs/sp1-sdk/2.0.0/sp1_sdk/proof/struct.SP1ProofWithPublicValues.html#method.bytes)
* The `sp1_public_inputs` are the public inputs to the underlying sp1 program.
- The `proof` is the Groth16 proof, serialized in [SP1's standard format](https://docs.rs/sp1-sdk/2.0.0/sp1_sdk/proof/struct.SP1ProofWithPublicValues.html#method.bytes)
- The `sp1_public_inputs` are the public inputs to the underlying sp1 program.

Here is a snippet from the [example script](./example/script/src/main.rs) that demonstrates this.

Expand All @@ -66,18 +67,18 @@ let groth16_proof = SP1Groth16Proof {
run_verify_instruction(groth16_proof).await;
```

3. Using the [`solana-program-test`](https://docs.rs/solana-program-test/latest/solana_program_test/) framework, send the `SP1Groth16Proof` to the
3. Using the [`solana-program-test`](https://docs.rs/solana-program-test/latest/solana_program_test/) framework, send the `SP1Groth16Proof` to the
[`fibonacci-verifier-contract`](./example/program). This smart contract will verify the proof using the `sp1-solana`
crate against the fibonacci SP1 program vkey and print out the public inputs.
crate against the fibonacci SP1 program vkey and print out the public inputs.

> [!NOTE]
> In this example, a Groth16 proof and public values are directly passed into the contract as transaction data.
> In this example, a Groth16 proof and public values are directly passed into the contract as transaction data.
> In real use cases, this may not be reasonable, since the upper limit for transaction data is 1232 bytes.
> Groth16 proofs themselves are already 260 bytes, and public inputs can potentially be very large.
> Groth16 proofs themselves are already 260 bytes, and public inputs can potentially be very large.
> See [this article](https://solana.com/developers/courses/program-optimization/lookup-tables) for a discussion
> on how to handle this.

Here is a snippet that demonstrates how to perform the verification and read the public inputs on chain.
Here is a snippet that demonstrates how to perform the verification and read the public inputs on chain.

```rust
// Derived by running `vk.bytes32()` on the program's vkey.
Expand Down Expand Up @@ -118,14 +119,14 @@ pub fn process_instruction(

### Running the script

To load the pregenerated proof and verify it on `solana-program-test`, run the following commands.
To load the pregenerated proof and verify it on `solana-program-test`, run the following commands.

```shell
cd script
RUST_LOG=info cargo run --release
```

To generate a fresh proof from the program in `sp1-program`, run the following commands.
To generate a fresh proof from the program in `sp1-program`, run the following commands.

```shell
cd script
Expand All @@ -136,7 +137,7 @@ RUST_LOG=info cargo run --release -- --prove

Run the following commands to build and deploy the example solana program to devnet. These commands
assume you've already created a Solana keypair locally, and you have the edge solana CLI tools.
Request [devnet sol](https://faucet.solana.com/) as necessary.
Request [devnet sol](https://faucet.solana.com/) as necessary.

```shell
cd example/program
Expand All @@ -151,8 +152,9 @@ Add `sp1-solana` to your `Cargo.toml`:

```toml
[dependencies]
sp1-solana = { git = "https://github.com/succinctlabs/groth16-solana" }
sp1-solana = { git = "https://github.com/succinctlabs/sp1-solana" }
```

## Acknowledgements

This crate uses the [`groth16-solana`](https://github.com/Lightprotocol/groth16-solana/) crate from Light Protocol Labs for the Groth16 proof verification, and the [`ark-bn254`](https://github.com/arkworks-rs/algebra) crate for the elliptic curve operations.