aboutsummaryrefslogtreecommitdiff
path: root/zkvms/sp1/host/src/main.rs
diff options
context:
space:
mode:
authorKamen Mladenov <kamen@syndamia.com>2025-01-14 14:04:23 +0200
committerKamen Mladenov <kamen@syndamia.com>2025-01-14 14:04:23 +0200
commit9c2496ec2ab98cfed8c87426dab4bd0eec5c7d29 (patch)
tree0f6f76b95c4500ca46c38dbb4544a1afe2902110 /zkvms/sp1/host/src/main.rs
parent7bdd131420125285b6dc61b1d7f505b0d4b15537 (diff)
downloadzkVMs-benchmarks-9c2496ec2ab98cfed8c87426dab4bd0eec5c7d29.tar
zkVMs-benchmarks-9c2496ec2ab98cfed8c87426dab4bd0eec5c7d29.tar.gz
zkVMs-benchmarks-9c2496ec2ab98cfed8c87426dab4bd0eec5c7d29.zip
feat(zkvms): Add sp1 host
Diffstat (limited to 'zkvms/sp1/host/src/main.rs')
-rw-r--r--zkvms/sp1/host/src/main.rs69
1 files changed, 69 insertions, 0 deletions
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<Vec<bool>>, u32, Vec<Vec<u32>>) = 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!");
+ }
+}