Skip to content

Commit

Permalink
first round fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwen01 committed Oct 11, 2024
1 parent 8cca0a9 commit 027f4f6
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 119 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ jobs:
- name: "Update lock files"
run: |
cargo tree
(cd ./example/program && cargo tree)
(cd ./example/script && cargo tree)
(cd ./example/sp1-program && cargo tree)
- name: "Assert no changes"
run: |
Expand Down
45 changes: 23 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resolver = "2"

# workspace
sp1-solana = { path = "verifier" }
example-solana-contract = { path = "example/program" }
fibonacci-verifier-contract = { path = "example/program" }

# solana
solana-program = { git = "https://github.com/anza-xyz/agave", rev = "6e62af0f0de6a40e4e22628cbbcf63b1a6da560e" }
Expand Down
5 changes: 2 additions & 3 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ RUST_LOG=info cargo run --release -- --prove
## Overview: Solana Program

The code in [`program`](./program) is a simple Solana contract that verifies a
`SP1ProofFixture` using the `sp1-solana` crate. It costs roughly 280,000 compute units.

**TODO**
`SP1ProofFixture` using the `sp1-solana` crate. It costs roughly 280,000 compute units. It also
demonstrates how to verify the sp1 program vkey and the public inputs.

### Running the Solana program

Expand Down
2 changes: 1 addition & 1 deletion example/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "example-solana-contract"
name = "fibonacci-verifier-contract"
version = "0.1.0"
edition = "2021"
publish = false
Expand Down
23 changes: 7 additions & 16 deletions example/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use borsh::BorshDeserialize;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg, pubkey::Pubkey};
use sp1_solana::{hash_public_inputs, verify_proof_fixture, SP1ProofFixture};
use sp1_solana::{verify_proof_fixture, SP1ProofFixture};

#[cfg(not(feature = "no-entrypoint"))]
use solana_program::entrypoint;
Expand All @@ -9,7 +9,6 @@ use solana_program::entrypoint;
entrypoint!(process_instruction);

// Derived by running `cargo prove vkey --elf ../../sp1-program/elf/riscv32im-succinct-zkvm-elf`
// TODO:
const FIBONACCI_VKEY_HASH: &str =
"0083e8e370d7f0d1c463337f76c9a60b62ad7cc54c89329107c92c1e62097872";

Expand All @@ -29,22 +28,14 @@ pub fn process_instruction(
assert!(result.is_ok());

// Make sure that we're verifying a fibonacci program.
assert_eq!(&fixture.vkey_hash(), FIBONACCI_VKEY_HASH);

// Verify that the provided public inputs match the proof fixture's committed values digest.
if let Some(sp1_public_inputs) = &fixture.sp1_public_inputs {
let digest = hash_public_inputs(sp1_public_inputs);
assert_eq!(digest, fixture.commited_values_digest());
}
assert_eq!(FIBONACCI_VKEY_HASH, hex::encode(fixture.sp1_vkey_hash));

// Print out the public values.
if let Some(sp1_public_inputs) = &fixture.sp1_public_inputs {
let mut reader = sp1_public_inputs.as_slice();
let n = u32::deserialize(&mut reader).unwrap();
let a = u32::deserialize(&mut reader).unwrap();
let b = u32::deserialize(&mut reader).unwrap();
msg!("Public values: (n: {}, a: {}, b: {})", n, a, b);
}
let mut reader = fixture.sp1_public_inputs.as_slice();
let n = u32::deserialize(&mut reader).unwrap();
let a = u32::deserialize(&mut reader).unwrap();
let b = u32::deserialize(&mut reader).unwrap();
msg!("Public values: (n: {}, a: {}, b: {})", n, a, b);

Ok(())
}
2 changes: 1 addition & 1 deletion example/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
[dependencies]
borsh.workspace = true
sp1-solana = { workspace = true, features = ["sp1-serialize"] }
example-solana-contract = { workspace = true }
fibonacci-verifier-contract = { workspace = true }
solana-program-test = { workspace = true }
solana-sdk = { workspace = true }
tokio = { workspace = true }
Expand Down
12 changes: 1 addition & 11 deletions example/script/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
use sp1_build::build_program;

fn main() {
// build_program_with_args(
// "../sp1-program",
// BuildArgs {
// output_directory: "../../elf".to_string(),
// elf_name: "fibonacci_elf".to_string(),
// ..Default::default()
// },
// );
build_program("../sp1-program");
sp1_build::build_program("../sp1-program");
}
6 changes: 3 additions & 3 deletions example/script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ async fn run_example_instruction(fixture: SP1ProofFixture) {

// Create program test environment
let (banks_client, payer, recent_blockhash) = ProgramTest::new(
"example-solana-contract",
"fibonacci-verifier-contract",
program_id,
processor!(example_solana_contract::process_instruction),
processor!(fibonacci_verifier_contract::process_instruction),
)
.start()
.await;
Expand Down Expand Up @@ -83,7 +83,7 @@ async fn main() {

// Load the proof from the file, and convert it to a fixture.
let sp1_proof_with_public_values = SP1ProofWithPublicValues::load(&proof_file).unwrap();
let fixture = SP1ProofFixture::from_sp1(sp1_proof_with_public_values, true);
let fixture = SP1ProofFixture::from(sp1_proof_with_public_values);
let fixture_file = "../../proof-fixtures/fibonacci_fixture.bin";
fixture.save(&fixture_file).unwrap();

Expand Down
Binary file modified proof-fixtures/fibonacci_fixture.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "sp1-solana"
version = "0.1.0"
edition = "2021"
authors = ["Bhargav Annem, Yuwen Zhang"]
description = "A Groth16 verifier implementation"
description = "Verifier for SP1 Groth16proofs on Solana"
license = "MIT OR Apache-2.0"
repository = "https://github.com/succinctlabs/groth16-solana"
readme = "README.md"
Expand All @@ -19,7 +19,7 @@ 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 = { path = "../../groth16-solana-patch" }
groth16-solana = { git = "https://github.com/yuwen01/groth16-solana-patch", rev = "42ea919b62f90868a4003a9a55a471aae7929a81" }
thiserror = "1.0.63"
hex = { version = "0.4.3" }

Expand Down
Loading

0 comments on commit 027f4f6

Please sign in to comment.