mirror of
https://github.com/eth-act/ere.git
synced 2026-04-03 03:00:17 -04:00
Add InputItem::SerializedObject (#80)
This commit is contained in:
@@ -8,9 +8,9 @@ license.workspace = true
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
bincode.workspace = true
|
||||
clap.workspace = true
|
||||
clap = { workspace = true, optional = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
tracing-subscriber = { workspace = true, features = ["env-filter"] }
|
||||
tracing-subscriber = { workspace = true, features = ["env-filter"], optional = true }
|
||||
|
||||
# Local dependencies
|
||||
ere-jolt = { workspace = true, optional = true }
|
||||
@@ -29,6 +29,7 @@ workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
cli = ["dep:clap", "dep:tracing-subscriber"]
|
||||
jolt = ["dep:ere-jolt"]
|
||||
nexus = ["dep:ere-nexus"]
|
||||
openvm = ["dep:ere-openvm"]
|
||||
|
||||
3
crates/ere-cli/src/lib.rs
Normal file
3
crates/ere-cli/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
|
||||
pub mod serde;
|
||||
@@ -1,26 +1,25 @@
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
|
||||
use anyhow::{Context, Error};
|
||||
use clap::{Parser, Subcommand};
|
||||
use ere_cli::serde;
|
||||
use std::{fs, path::PathBuf};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use zkvm_interface::{Compiler, ProverResourceType, zkVM};
|
||||
|
||||
mod serde;
|
||||
|
||||
// Compile-time check to ensure exactly one backend feature is enabled
|
||||
const _: () = {
|
||||
assert!(
|
||||
(cfg!(feature = "jolt") as u8
|
||||
+ cfg!(feature = "nexus") as u8
|
||||
+ cfg!(feature = "openvm") as u8
|
||||
+ cfg!(feature = "pico") as u8
|
||||
+ cfg!(feature = "risc0") as u8
|
||||
+ cfg!(feature = "sp1") as u8
|
||||
+ cfg!(feature = "zisk") as u8)
|
||||
== 1,
|
||||
"Exactly one zkVM backend feature must be enabled"
|
||||
);
|
||||
if cfg!(feature = "cli") {
|
||||
assert!(
|
||||
(cfg!(feature = "jolt") as u8
|
||||
+ cfg!(feature = "nexus") as u8
|
||||
+ cfg!(feature = "openvm") as u8
|
||||
+ cfg!(feature = "pico") as u8
|
||||
+ cfg!(feature = "risc0") as u8
|
||||
+ cfg!(feature = "sp1") as u8
|
||||
+ cfg!(feature = "zisk") as u8)
|
||||
== 1,
|
||||
"Exactly one zkVM backend feature must be enabled"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
#[derive(Parser)]
|
||||
|
||||
@@ -1,15 +1,30 @@
|
||||
use anyhow::{Context, Error};
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use std::{fs, path::Path};
|
||||
use zkvm_interface::{Input, InputItem};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum SerializableInputItem {
|
||||
SerializedObject(Vec<u8>),
|
||||
Bytes(Vec<u8>),
|
||||
}
|
||||
|
||||
impl From<SerializableInputItem> for InputItem {
|
||||
fn from(value: SerializableInputItem) -> Self {
|
||||
match value {
|
||||
SerializableInputItem::SerializedObject(bytes) => Self::SerializedObject(bytes),
|
||||
SerializableInputItem::Bytes(bytes) => Self::Bytes(bytes),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Read `Input` from `input_path`.
|
||||
///
|
||||
/// `Input` is assumed to be serialized into sequence of bytes, and each bytes
|
||||
/// in the sequence is serialized in the specific way the zkvm does.
|
||||
pub fn read_input(input_path: &Path) -> Result<Input, Error> {
|
||||
read::<Vec<Vec<u8>>>(input_path, "input")
|
||||
.map(|seq| Input::from(Vec::from_iter(seq.into_iter().map(InputItem::Bytes))))
|
||||
read::<Vec<SerializableInputItem>>(input_path, "input")
|
||||
.map(|seq| Input::from(Vec::from_iter(seq.into_iter().map(Into::into))))
|
||||
}
|
||||
|
||||
/// Serialize `value` with [`bincode`] and write to `path`.
|
||||
|
||||
Reference in New Issue
Block a user