Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwen01 committed Oct 15, 2024
1 parent f2cec4d commit 2c6d62d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Run tests
run: |
cd verifier
cargo test --package sp1-solana:0.1.0 --lib --features sp1-serialize --release
cargo test --package sp1-solana --lib -- test --show-output
lock-files:
name: "Check lock files"
Expand Down
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ pub struct SP1Groth16Proof {

...

let (proof, sp1_public_inputs, _program_vkey_hash) =
extract_groth16_components(sp1_proof_with_public_values);
// Load the proof from the file, and extract the proof, public inputs, and program vkey hash.
let sp1_proof_with_public_values = SP1ProofWithPublicValues::load(&proof_file).unwrap();

let groth16_proof = SP1Groth16Proof {
proof,
sp1_public_inputs,
proof: sp1_proof_with_public_values.bytes(),
sp1_public_inputs: sp1_proof_with_public_values.public_values.to_vec(),
};

/// Now we can send the Borsh serialized `SP1Groth16Proof` to the solana contract.
// Send the proof to the contract, and verify it on `solana-program-test`.
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
Expand All @@ -63,7 +64,7 @@ crate against the fibonacci sp1 program vkey and print out the public inputs. He
how to do some common operations on the SP1 Groth16 proof.

```rust
// Derived by `vk.bytes32()` on the program's vkey.
// Derived by running `vk.bytes32()` on the program's vkey.
const FIBONACCI_VKEY_HASH: &str =
"0083e8e370d7f0d1c463337f76c9a60b62ad7cc54c89329107c92c1e62097872";

Expand Down Expand Up @@ -98,8 +99,7 @@ pub fn process_instruction(

### Running the script

To load the pregenerated proof, convert it to a [`SP1Groth16Proof`], and verify it on in
`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
Expand All @@ -116,7 +116,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.
assume you've already created a Solana keypair locally, and you have the edge solana CLI tools [^1].
Request [devnet sol](https://faucet.solana.com/) as necessary.

```shell
Expand All @@ -136,4 +136,9 @@ 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.
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)"
```
2 changes: 1 addition & 1 deletion example/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use solana_program::entrypoint;
#[cfg(not(feature = "no-entrypoint"))]
entrypoint!(process_instruction);

// Derived by `vk.bytes32()` on the program's vkey.
// Derived by running `vk.bytes32()` on the program's vkey.
const FIBONACCI_VKEY_HASH: [u8; 32] =
hex_literal::hex!("0083e8e370d7f0d1c463337f76c9a60b62ad7cc54c89329107c92c1e62097872");

Expand Down
7 changes: 3 additions & 4 deletions example/script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn main() {
// Setup logging for the application.
utils::setup_logger();

// Where to save / load the proof from.
// Where to save / load the sp1 proof from.
let proof_file = "../../proofs/fibonacci_proof.bin";

// Parse command line arguments.
Expand All @@ -79,14 +79,13 @@ async fn main() {
proof.save(&proof_file).unwrap();
}

// Load the proof from the file, and extract the proof, public inputs, and program vkey hash.
// Load the proof from the file, and convert it to a Borsh-serializable `SP1Groth16Proof`.
let sp1_proof_with_public_values = SP1ProofWithPublicValues::load(&proof_file).unwrap();

let groth16_proof = SP1Groth16Proof {
proof: sp1_proof_with_public_values.bytes(),
sp1_public_inputs: sp1_proof_with_public_values.public_values.to_vec(),
};

// Run the example instruction in a test environment
// Send the proof to the contract, and verify it on `solana-program-test`.
run_verify_instruction(groth16_proof).await;
}
1 change: 1 addition & 0 deletions verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use thiserror::Error;

pub const GROTH16_VK_BYTES: &[u8] = include_bytes!("../vk/groth16_vk.bin");

#[cfg(test)]
mod test;

#[derive(Error, Debug)]
Expand Down

0 comments on commit 2c6d62d

Please sign in to comment.