diff --git a/core/src/lib.rs b/core/src/lib.rs index 1a8773d15..403cfaf4c 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -203,6 +203,14 @@ mod tests { fn test_proof_params() -> HashMap { let mut prover_args = HashMap::new(); + prover_args.insert( + "native".to_string(), + json! { + { + "write_guest_input_path": null + } + }, + ); prover_args.insert( "risc0".to_string(), json! { diff --git a/core/src/prover.rs b/core/src/prover.rs index 14dbd7289..84a1e26b4 100644 --- a/core/src/prover.rs +++ b/core/src/prover.rs @@ -1,14 +1,23 @@ +use std::path::Path; + use raiko_lib::{ consts::VerifierType, input::{GuestInput, GuestOutput}, protocol_instance::ProtocolInstance, - prover::{to_proof, Proof, Prover, ProverError, ProverResult}, + prover::{to_proof, Proof, Prover, ProverConfig, ProverError, ProverResult}, }; -use serde::{Deserialize, Serialize}; +use serde::{de::Error, Deserialize, Serialize}; +use serde_with::serde_as; use tracing::trace; pub struct NativeProver; +#[serde_as] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct NativeParam { + pub write_guest_input_path: Option, +} + #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NativeResponse { pub output: GuestOutput, @@ -18,8 +27,24 @@ impl Prover for NativeProver { async fn run( input: GuestInput, output: &GuestOutput, - _request: &serde_json::Value, + config: &ProverConfig, ) -> ProverResult { + let param = config + .get("native") + .map(|v| NativeParam::deserialize(v)) + .ok_or(ProverError::Param(serde_json::Error::custom( + "native param not provided", + )))??; + + if let Some(path) = param.write_guest_input_path { + let path = Path::new(&path); + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent)?; + } + let json = serde_json::to_string(&input)?; + std::fs::write(path, json)?; + } + trace!("Running the native prover for input {input:?}"); let pi = ProtocolInstance::new(&input, &output.header, VerifierType::None) diff --git a/host/config/config.json b/host/config/config.json index b691035b1..8abe5daab 100644 --- a/host/config/config.json +++ b/host/config/config.json @@ -16,5 +16,8 @@ "snark": true, "profile": false, "execution_po2": 20 - } + }, + "native" : { + "write_guest_input_path": null + } } diff --git a/lib/src/prover.rs b/lib/src/prover.rs index a331fe93f..e5d93343d 100644 --- a/lib/src/prover.rs +++ b/lib/src/prover.rs @@ -1,5 +1,3 @@ -use std::fmt; - use serde::Serialize; use thiserror::Error as ThisError; @@ -7,15 +5,12 @@ use crate::input::{GuestInput, GuestOutput}; #[derive(ThisError, Debug)] pub enum ProverError { + #[error("ProverError::GuestError `{0}`")] GuestError(String), -} - -impl fmt::Display for ProverError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - ProverError::GuestError(e) => e.fmt(f), - } - } + #[error("ProverError::FileIo `{0}`")] + FileIo(#[from] std::io::Error), + #[error("ProverError::Param `{0}`")] + Param(#[from] serde_json::Error), } impl From for ProverError { diff --git a/provers/risc0/driver/src/methods/risc0_guest.rs b/provers/risc0/driver/src/methods/risc0_guest.rs index fed1ddac0..639c7760f 100644 --- a/provers/risc0/driver/src/methods/risc0_guest.rs +++ b/provers/risc0/driver/src/methods/risc0_guest.rs @@ -1,7 +1,7 @@ pub const RISC0_GUEST_ELF: &[u8] = include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest"); pub const RISC0_GUEST_ID: [u32; 8] = [ - 405814261, 645472475, 3368860906, 1069727513, 2312368391, 2313520942, 2156489466, 779875178, + 1444642754, 3434511061, 2910616417, 2829025913, 3284452016, 1678600137, 1001540409, 1336920303, ]; pub const RISC0_GUEST_PATH: &str = r#"/home/ubuntu/raiko/provers/risc0/guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest"#; diff --git a/provers/sgx/setup/Cargo.toml b/provers/sgx/setup/Cargo.toml index 2ad179990..7c040da6d 100644 --- a/provers/sgx/setup/Cargo.toml +++ b/provers/sgx/setup/Cargo.toml @@ -5,9 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -# sp1-driver = { path = "../provers/sp1/driver", optional = true } -# risc0-driver = { path = "../provers/risc0/driver", optional = true } -sgx-prover = { path = "../prover", optional = true } +sgx-prover = { path = "../prover", features = ["enable"] } # raiko raiko-lib = { workspace = true, features = ["c-kzg"] } @@ -61,18 +59,3 @@ dirs = { workspace = true } assert_cmd = { workspace = true } rstest = { workspace = true } ethers-core = { workspace = true } - -# [build-dependencies] -# sp1-helper = { workspace = true } - -[features] -default = ["sgx"] -# sp1 = [ -# "dep:sp1-driver", -# "sp1-driver/enable", -# ] -# risc0 = [ -# "dep:risc0-driver", -# "risc0-driver/enable", -# ] -sgx = ["dep:sgx-prover", "sgx-prover/enable"] diff --git a/provers/sp1/driver/Cargo.toml b/provers/sp1/driver/Cargo.toml index 758c2d898..971cfe025 100644 --- a/provers/sp1/driver/Cargo.toml +++ b/provers/sp1/driver/Cargo.toml @@ -28,7 +28,6 @@ regex = "1.5.4" [features] -default = ["enable"] enable = [ "serde", "serde_json", diff --git a/provers/sp1/guest/elf/sp1-guest b/provers/sp1/guest/elf/sp1-guest index 611a80bd6..a786405d5 100755 Binary files a/provers/sp1/guest/elf/sp1-guest and b/provers/sp1/guest/elf/sp1-guest differ diff --git a/script/prove-block.sh b/script/prove-block.sh index 90a5b734d..6a2cc2923 100755 --- a/script/prove-block.sh +++ b/script/prove-block.sh @@ -39,7 +39,10 @@ fi if [ "$proof" == "native" ]; then proofParam=' - "proof_type": "native" + "proof_type": "native", + "native" : { + "write_guest_input_path": null + } ' elif [ "$proof" == "sp1" ]; then proofParam='