From 84967ed6643f90027873b470bf7456596e07b246 Mon Sep 17 00:00:00 2001 From: Kamen Mladenov Date: Tue, 28 Jan 2025 16:41:53 +0200 Subject: feat(zkvms_host_io): Implement using a guest's default input --- flake.nix | 2 +- zkvms_host_io/src/lib.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 0c402c2..63ad109 100644 --- a/flake.nix +++ b/flake.nix @@ -78,7 +78,7 @@ ''; buildPhase = '' - export INPUTS="$PWD/Vertices-010.in" + export INPUTS_DIR="$PWD/${zkpPath}" pushd zkvms/${currentPackage.pname} runHook preBuild diff --git a/zkvms_host_io/src/lib.rs b/zkvms_host_io/src/lib.rs index 74c3992..191d2ad 100644 --- a/zkvms_host_io/src/lib.rs +++ b/zkvms_host_io/src/lib.rs @@ -1,16 +1,18 @@ use clap::{Parser, ValueEnum}; use num_traits::NumCast; use serde::{ Serialize, Deserialize }; +use std::fs::read_to_string; pub use input_macros::foreach_input_field; +static DEFAULT_PUBLIC_INPUT: &str = include_str!(concat!(env!("INPUTS_DIR"), "/default_public_input.toml")); + #[derive(Parser, Debug)] #[command(version, about, long_about = None)] struct Cli { /// What the ZKVM is going to do run_type: RunType, - #[arg(default_value = "./public_input.toml")] - public_input: String, + public_input: Option, } #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] @@ -31,7 +33,12 @@ input_macros::generate_input_struct!(); pub fn read_args() -> RunWith { let cli = Cli::parse(); - let val: Input = toml::from_str(&std::fs::read_to_string(cli.public_input).unwrap()).unwrap(); + let contents: String = if cli.public_input.is_some() { + read_to_string(cli.public_input.unwrap()).unwrap() + } else { + DEFAULT_PUBLIC_INPUT.to_string() + }; + let val: Input = toml::from_str(&contents).unwrap(); RunWith { run_type: cli.run_type, -- cgit v1.2.3