From 9c2496ec2ab98cfed8c87426dab4bd0eec5c7d29 Mon Sep 17 00:00:00 2001 From: Kamen Mladenov Date: Tue, 14 Jan 2025 14:04:23 +0200 Subject: feat(zkvms): Add sp1 host --- zkvms/sp1/host/Cargo.toml | 13 +++++++++ zkvms/sp1/host/src/main.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 zkvms/sp1/host/Cargo.toml create mode 100644 zkvms/sp1/host/src/main.rs (limited to 'zkvms/sp1/host') diff --git a/zkvms/sp1/host/Cargo.toml b/zkvms/sp1/host/Cargo.toml new file mode 100644 index 0000000..40722b6 --- /dev/null +++ b/zkvms/sp1/host/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "host-sp1" +version = "0.1.0" +edition = "2021" + +[dependencies] +sp1-sdk = { path = "/nix/store/8g5sf8h6nfypnd736x6ns4c44s8g6qd4-sp1-unstable-2024-12-23/crates/sdk" } +serde_json = { version = "1.0", default-features = false, features = ["alloc"] } +serde = { version = "1.0", default-features = false, features = ["derive"] } +clap = { version = "4.0", features = ["derive", "env"] } +tracing = "0.1.40" +hex = "0.4.3" +alloy-sol-types = "0.7.7" diff --git a/zkvms/sp1/host/src/main.rs b/zkvms/sp1/host/src/main.rs new file mode 100644 index 0000000..bed7c29 --- /dev/null +++ b/zkvms/sp1/host/src/main.rs @@ -0,0 +1,69 @@ +use clap::Parser; +use sp1_sdk::{ProverClient, SP1Stdin}; + +/// The ELF (executable and linkable format) file for the Succinct RISC-V zkVM. +pub const FIBONACCI_ELF: &[u8] = include_bytes!("./guest"); + +/// The arguments for the command. +#[derive(Parser, Debug)] +#[clap(author, version, about, long_about = None)] +struct Args { + #[clap(long)] + execute: bool, + + #[clap(long)] + prove: bool, +} + +fn main() { + // Setup the logger. + sp1_sdk::utils::setup_logger(); + + // Parse the command line arguments. + let args = Args::parse(); + + if args.execute == args.prove { + eprintln!("Error: You must specify either --execute or --prove"); + std::process::exit(1); + } + + // Setup the prover client. + let client = ProverClient::new(); + + // Setup the inputs. + let mut stdin = SP1Stdin::new(); + + let (graph, colors, coloring): (Vec>, u32, Vec>) = include!(env!("INPUTS")); + + stdin.write(&graph); + stdin.write(&colors); + stdin.write(&coloring); + + if args.execute { + // Execute the program + let (output, report) = client.execute(FIBONACCI_ELF, &stdin).run().unwrap(); + println!("Program executed successfully."); + + // Read the output. + let decoded = output; + println!("{:?}", decoded); + + // Record the number of cycles executed. + println!("Number of cycles: {}", report.total_instruction_count()); + } else { + // Setup the program for proving. + let (pk, vk) = client.setup(FIBONACCI_ELF); + + // Generate the proof + let proof = client + .prove(&pk, &stdin) + .run() + .expect("failed to generate proof"); + + println!("Successfully generated proof!"); + + // Verify the proof. + client.verify(&proof, &vk).expect("failed to verify proof"); + println!("Successfully verified proof!"); + } +} -- cgit v1.2.3