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

fix: readme typo #6

Merged
merged 47 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5c68b4f
cleanup
yuwen01 Oct 3, 2024
8c2e7f0
Working E2E example
yuwen01 Oct 4, 2024
1dfb248
merge main
yuwen01 Oct 7, 2024
80ff894
change tests to use fixture
yuwen01 Oct 7, 2024
5649bea
refactor serialization logic to library crate
yuwen01 Oct 7, 2024
6e9d7c7
readme and cleanup
yuwen01 Oct 7, 2024
cc80e84
add load and save helpers
yuwen01 Oct 7, 2024
4093f9c
add another test
yuwen01 Oct 7, 2024
90e3b1c
more fixes and comments
yuwen01 Oct 7, 2024
b8e6b8f
revert verifier cargo toml
yuwen01 Oct 8, 2024
cf85743
update readme with install instructions
yuwen01 Oct 8, 2024
2826af5
add comments, rename test file
yuwen01 Oct 8, 2024
c1cdaf3
remove redundant readme
yuwen01 Oct 8, 2024
18c907a
simplify script and program, use pnpm wherever possible
yuwen01 Oct 8, 2024
83dd138
clean script more
yuwen01 Oct 8, 2024
84c23d4
add docs, reorganize workspace
yuwen01 Oct 9, 2024
d8df4fe
add some helper methods
yuwen01 Oct 9, 2024
aaadf24
refactor tests to library + new convenience methods
yuwen01 Oct 9, 2024
3648030
fewer dependencies
yuwen01 Oct 9, 2024
e97276b
add groth16 vkey checking
yuwen01 Oct 9, 2024
b8fa325
make verify_proof_raw public
yuwen01 Oct 9, 2024
8aef677
remove unused dependencies
yuwen01 Oct 9, 2024
62f7fbc
WIP: issue importing solana-client or solana-test-validator or any of…
yuwen01 Oct 10, 2024
8ef66cd
add checking vkey example
yuwen01 Oct 10, 2024
0bf08ba
merge master
yuwen01 Oct 11, 2024
dc7b4de
finished migration
yuwen01 Oct 11, 2024
092c876
add tests
yuwen01 Oct 11, 2024
0119dd9
merge unify rust
yuwen01 Oct 11, 2024
a7739c7
added hashing the public values
yuwen01 Oct 11, 2024
8136a7f
deserialized the public values
yuwen01 Oct 11, 2024
8cca0a9
Merge branch 'master' into yuwen/example-improvement
yuwen01 Oct 11, 2024
027f4f6
first round fixes
yuwen01 Oct 11, 2024
0a20301
readme fixes
yuwen01 Oct 11, 2024
68b2a4a
nits
yuwen01 Oct 11, 2024
f7ef66d
add snippets to readme
yuwen01 Oct 11, 2024
f5604fa
refactor
yuwen01 Oct 15, 2024
ebf0958
add deployment instructions
yuwen01 Oct 15, 2024
46a175d
nits 1
yuwen01 Oct 15, 2024
67c6ea1
refactor
yuwen01 Oct 15, 2024
f2cec4d
another refactor
yuwen01 Oct 15, 2024
2c6d62d
nits
yuwen01 Oct 15, 2024
1b85bd4
started versioning system for groth16 vkeys
yuwen01 Oct 16, 2024
c3a2f7d
readme typo
yuwen01 Oct 16, 2024
ce75210
readme fix
yuwen01 Oct 16, 2024
25124b3
patch solana-bn254
yuwen01 Oct 16, 2024
97f029c
version groth16 vk
yuwen01 Oct 16, 2024
ff217d5
Readme fix
yuwen01 Oct 16, 2024
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
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.