Skip to content

Commit

Permalink
fix: readme typo (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwen01 authored Oct 16, 2024
1 parent a0a3f54 commit 67c827b
Show file tree
Hide file tree
Showing 9 changed files with 519 additions and 152 deletions.
616 changes: 487 additions & 129 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sha2 = "0.10.8"
# See https://github.com/anza-xyz/agave/blob/master/Cargo.toml#L551-L586
solana-curve25519 = { git = "https://github.com/anza-xyz/agave", rev = "6e62af0f0de6a40e4e22628cbbcf63b1a6da560e"}
solana-program = { git = "https://github.com/anza-xyz/agave", rev = "6e62af0f0de6a40e4e22628cbbcf63b1a6da560e"}
solana-bn254 = { git = "https://github.com/anza-xyz/agave", rev = "6e62af0f0de6a40e4e22628cbbcf63b1a6da560e" }
solana-zk-sdk = { git = "https://github.com/anza-xyz/agave", rev = "6e62af0f0de6a40e4e22628cbbcf63b1a6da560e" }
solana-zk-token-sdk = { git = "https://github.com/anza-xyz/agave", rev = "6e62af0f0de6a40e4e22628cbbcf63b1a6da560e"}

35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ The `sp1-solana` library itself is in the [`verifier`](verifier) directory. `exa
- **Easy Integration**: Seamlessly integrates with existing Solana programs and infrastructure.
- **Extensible**: Built with modularity in mind, allowing for future enhancements and integrations.

## Requirements

- Rust
- Edge Solana CLI
- Install with
```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.
Expand Down Expand Up @@ -73,18 +82,21 @@ pub fn process_instruction(
_accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
// Deserialize the `SP1Groth16Proof` from the instruction data.
let groth16_proof = SP1Groth16Proof::try_from_slice(instruction_data).unwrap();
// Deserialize the SP1Groth16Proof from the instruction data.
let groth16_proof = SP1Groth16Proof::try_from_slice(instruction_data)
.map_err(|_| ProgramError::InvalidInstructionData)?;
// Get the SP1 Groth16 verification key from the `sp1-solana` crate.
let vk = sp1_solana::GROTH16_VK_BYTES;
let vk = sp1_solana::GROTH16_VK_2_0_0_BYTES;
// Verify the proof.
let result = verify_sp1_groth16_proof(&groth16_proof, &vk);
assert!(result.is_ok());

// Make sure that we're verifying a fibonacci program.
assert_eq!(FIBONACCI_VKEY_HASH, hex::encode(groth16_proof.sp1_vkey_hash));
verify_proof(
&groth16_proof.proof,
&groth16_proof.sp1_public_inputs,
&FIBONACCI_VKEY_HASH,
vk,
)
.map_err(|_| ProgramError::InvalidInstructionData)?;
// Print out the public values.
let mut reader = groth16_proof.sp1_public_inputs.as_slice();
Expand Down Expand Up @@ -116,7 +128,7 @@ RUST_LOG=info cargo run --release -- --prove
### Deploying the Example Solana Program to Devnet
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 [^1].
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.
```shell
Expand All @@ -137,8 +149,3 @@ sp1-solana = { git = "https://github.com/succinctlabs/groth16-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.

[^1]: Run this command to install the edge solana CLI.
```shell
sh -c "$(curl -sSfL https://release.anza.xyz/edge/install)"
```
8 changes: 4 additions & 4 deletions example/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ pub fn process_instruction(
_accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
// Deserialize the groth16_proof from the instruction data.
// Deserialize the SP1Groth16Proof from the instruction data.
let groth16_proof = SP1Groth16Proof::try_from_slice(instruction_data)
.map_err(|_| ProgramError::InvalidInstructionData)?;

// Get the SP1 Groth16 verification key from the `groth16-solana` crate.
let vk = sp1_solana::GROTH16_VK_BYTES;
// Get the SP1 Groth16 verification key from the `sp1-solana` crate.
let vk = sp1_solana::GROTH16_VK_2_0_0_BYTES;

// Verify the proof.
verify_proof(
&groth16_proof.proof,
&groth16_proof.sp1_public_inputs,
&FIBONACCI_VKEY_HASH,
&vk,
vk,
)
.map_err(|_| ProgramError::InvalidInstructionData)?;

Expand Down
3 changes: 1 addition & 2 deletions verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ sha2.workspace = true
ark-bn254 = "0.4.0"
ark-serialize = "0.4.2"
ark-ff = "0.4.2"
# groth16-solana = { git = "https://github.com/sp1-patches/groth16-solana", branch = "patch-v0.0.3" }
groth16-solana = { git = "https://github.com/yuwen01/groth16-solana-patch", rev = "42ea919b62f90868a4003a9a55a471aae7929a81" }
groth16-solana = { git = "https://github.com/sp1-patches/groth16-solana", branch = "patch-v0.0.3" }
thiserror = "1.0.63"

[dev-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use groth16_solana::groth16::Groth16Verifyingkey;
use sha2::{Digest, Sha256};
use thiserror::Error;

pub const GROTH16_VK_BYTES: &[u8] = include_bytes!("../vk/groth16_vk.bin");
/// Groth16 verification keys for different SP1 versions.
pub const GROTH16_VK_1_2_0_BYTES: &[u8] = include_bytes!("../vk/v1.2.0/groth16_vk.bin");
pub const GROTH16_VK_2_0_0_BYTES: &[u8] = include_bytes!("../vk/v2.0.0/groth16_vk.bin");

#[cfg(test)]
mod test;
Expand Down
4 changes: 2 additions & 2 deletions verifier/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sp1_sdk::SP1ProofWithPublicValues;

#[test]
fn test_verify_from_sp1() {
use crate::{verify_proof, GROTH16_VK_BYTES};
use crate::{verify_proof, GROTH16_VK_2_0_0_BYTES};

// Read the serialized SP1ProofWithPublicValues from the file.
let sp1_proof_with_public_values_file = "../proofs/fibonacci_proof.bin";
Expand Down Expand Up @@ -33,7 +33,7 @@ fn test_verify_from_sp1() {
&proof_bytes,
&sp1_public_inputs,
&vkey_hash[..32].try_into().unwrap(),
&GROTH16_VK_BYTES
&GROTH16_VK_2_0_0_BYTES
)
.is_ok());
}
Expand Down
Binary file added verifier/vk/v1.2.0/groth16_vk.bin
Binary file not shown.
File renamed without changes.

0 comments on commit 67c827b

Please sign in to comment.