From 8658f70ebec1c186115500f34a87ffaefd170982 Mon Sep 17 00:00:00 2001 From: Kamen Mladenov Date: Wed, 15 Jan 2025 13:10:17 +0200 Subject: feat(zkvms): Add zkwasm host --- zkvms/zkwasm/host/src/main.rs | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 zkvms/zkwasm/host/src/main.rs (limited to 'zkvms/zkwasm/host/src/main.rs') diff --git a/zkvms/zkwasm/host/src/main.rs b/zkvms/zkwasm/host/src/main.rs new file mode 100644 index 0000000..dc37b34 --- /dev/null +++ b/zkvms/zkwasm/host/src/main.rs @@ -0,0 +1,74 @@ +use zkvms_host_io::{read_args, RunType::{Execute, Prove, Verify}}; +use std::io::{self, Write}; +use std::process::{Command, Stdio}; + +static K: &str = "19"; +static SCHEME: &str = "shplonk"; + +type Input = (Vec>, u32, Vec>); + +fn build_input((graph, colors, coloring): &Input) -> String { + let mut ret = String::new(); + for vec in graph { + for b in vec { + ret.push_str(&(*b as i32).to_string()); + ret.push_str(":i64,"); + } + } + ret.push_str(&colors.to_string()); + ret.push_str(":i64,"); + for vec in coloring { + for c in vec { + ret.push_str(&c.to_string()); + ret.push_str(":i64,"); + } + } + ret.pop(); // removes trailing comma + ret +} + +fn zkwasm_command(subcmd: &str) -> Command { + let mut command = Command::new("zkwasm-cli"); + command + .arg("--params").arg("./params") + .arg("prog").arg(subcmd) + .arg("--wasm").arg(env!("GUEST_PATH")); + command +} + +fn run(cmd: &mut Command) { + assert!(cmd.status().expect("couldn't execute command!").success()); +} + +fn main() { + let run_info = read_args(); + + run(zkwasm_command("setup") + .arg("-k").arg(K) + .arg("--scheme").arg(SCHEME)); + + let input = build_input(&run_info.input); + + match run_info.run_type { + Execute => { + run(zkwasm_command("dry-run") + .arg("--private").arg(input) + .arg("--output").arg("./output")); + }, + Prove => { + run(zkwasm_command("prove") + .arg("--private").arg(input) + .arg("--output").arg("./output")); + }, + Verify => { + run(zkwasm_command("prove") + .arg("--private").arg(input) + .arg("--output").arg("./output")); + + run(Command::new("zkwasm-cli") + .arg("--params").arg("./params") + .arg("prog").arg("verify") + .arg("--output").arg("./output")); + }, + } +} -- cgit v1.2.3