Skip to content

Commit

Permalink
version groth16 vk
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwen01 committed Oct 16, 2024
2 parents 25124b3 + c3a2f7d commit 97f029c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ 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.

<<<<<<< HEAD
=======
## Requirements

- Rust
- Edge Solana CLI
- Install with
```shell
sh -c "$(curl -sSfL https://release.anza.xyz/edge/install)"
```

>>>>>>> yuwen/example-improvement
## 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,21 +85,34 @@ pub fn process_instruction(
_accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
<<<<<<< HEAD
// Deserialize the SP1Groth16Proof from the instruction data.
let groth16_proof = SP1Groth16Proof::try_from_slice(instruction_data)
.map_err(|_| ProgramError::InvalidInstructionData)?;
=======
// Deserialize the `SP1Groth16Proof` from the instruction data.
let groth16_proof = SP1Groth16Proof::try_from_slice(instruction_data).unwrap();
>>>>>>> yuwen/example-improvement
// Get the SP1 Groth16 verification key from the `sp1-solana` crate.
let vk = sp1_solana::GROTH16_VK_2_0_0_BYTES;
// Verify the proof.
<<<<<<< HEAD
verify_proof(
&groth16_proof.proof,
&groth16_proof.sp1_public_inputs,
&FIBONACCI_VKEY_HASH,
vk,
)
.map_err(|_| ProgramError::InvalidInstructionData)?;
=======
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));
>>>>>>> yuwen/example-improvement
// Print out the public values.
let mut reader = groth16_proof.sp1_public_inputs.as_slice();
Expand Down Expand Up @@ -119,7 +144,11 @@ 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
<<<<<<< HEAD
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.
>>>>>>> yuwen/example-improvement
Request [devnet sol](https://faucet.solana.com/) as necessary.
```shell
Expand All @@ -140,8 +169,11 @@ 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.
<<<<<<< HEAD
[^1]: Run this command to install the edge solana CLI.
```shell
sh -c "$(curl -sSfL https://release.anza.xyz/edge/install)"
```
```
=======
>>>>>>> yuwen/example-improvement
1 change: 0 additions & 1 deletion verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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" }
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 97f029c

Please sign in to comment.