mirror of
https://github.com/eth-act/ere.git
synced 2026-02-19 11:54:42 -05:00
Merge pull request #29 from jsign/jsign-execution-duration
zkvm-interface: add execution duration
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use openvm_build::GuestOptions;
|
||||
use openvm_circuit::arch::ContinuationVmProof;
|
||||
use openvm_sdk::{
|
||||
@@ -12,8 +14,8 @@ use openvm_stark_sdk::config::{
|
||||
};
|
||||
use openvm_transpiler::elf::Elf;
|
||||
use zkvm_interface::{
|
||||
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport,
|
||||
ProverResourceType, zkVM, zkVMError,
|
||||
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport, ProverResourceType,
|
||||
zkVM, zkVMError,
|
||||
};
|
||||
|
||||
mod error;
|
||||
@@ -57,10 +59,7 @@ impl EreOpenVM {
|
||||
}
|
||||
}
|
||||
impl zkVM for EreOpenVM {
|
||||
fn execute(
|
||||
&self,
|
||||
inputs: &Input,
|
||||
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
|
||||
fn execute(&self, inputs: &Input) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
|
||||
let sdk = Sdk::new();
|
||||
let vm_cfg = SdkVmConfig::builder()
|
||||
.system(Default::default())
|
||||
@@ -82,12 +81,16 @@ impl zkVM for EreOpenVM {
|
||||
}
|
||||
}
|
||||
|
||||
let start = Instant::now();
|
||||
let _outputs = sdk
|
||||
.execute(exe.clone(), vm_cfg.clone(), stdin)
|
||||
.map_err(|e| CompileError::Client(e.into()))
|
||||
.map_err(OpenVMError::from)?;
|
||||
|
||||
Ok(ProgramExecutionReport::default())
|
||||
Ok(ProgramExecutionReport {
|
||||
execution_duration: start.elapsed(),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn prove(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use pico_sdk::client::DefaultProverClient;
|
||||
use std::process::Command;
|
||||
use std::{process::Command, time::Instant};
|
||||
use zkvm_interface::{
|
||||
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport, ProverResourceType,
|
||||
zkVM, zkVMError,
|
||||
@@ -75,9 +75,15 @@ impl zkVM for ErePico {
|
||||
InputItem::Bytes(items) => stdin.write_slice(items),
|
||||
}
|
||||
}
|
||||
|
||||
let start = Instant::now();
|
||||
let num_cycles = client.emulate(stdin);
|
||||
|
||||
Ok(ProgramExecutionReport::new(num_cycles))
|
||||
Ok(ProgramExecutionReport {
|
||||
total_num_cycles: num_cycles,
|
||||
execution_duration: start.elapsed(),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn prove(
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use compile::compile_risczero_program;
|
||||
use risc0_zkvm::{ExecutorEnv, Receipt, default_executor, default_prover};
|
||||
use zkvm_interface::{
|
||||
@@ -69,12 +71,14 @@ impl zkVM for EreRisc0 {
|
||||
}
|
||||
let env = env.build().map_err(|err| zkVMError::Other(err.into()))?;
|
||||
|
||||
let start = Instant::now();
|
||||
let session_info = executor
|
||||
.execute(env, &self.program.elf)
|
||||
.map_err(|err| zkVMError::Other(err.into()))?;
|
||||
Ok(ProgramExecutionReport {
|
||||
total_num_cycles: session_info.cycles() as u64,
|
||||
region_cycles: Default::default(),
|
||||
execution_duration: start.elapsed(),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use compile::compile_sp1_program;
|
||||
use sp1_sdk::{
|
||||
CpuProver, CudaProver, Prover, ProverClient, SP1ProofWithPublicValues, SP1ProvingKey, SP1Stdin,
|
||||
@@ -7,8 +9,8 @@ use sp1_sdk::{
|
||||
};
|
||||
use tracing::info;
|
||||
use zkvm_interface::{
|
||||
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport,
|
||||
ProverResourceType, zkVM, zkVMError,
|
||||
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport, ProverResourceType,
|
||||
zkVM, zkVMError,
|
||||
};
|
||||
|
||||
mod compile;
|
||||
@@ -114,10 +116,7 @@ impl EreSP1 {
|
||||
}
|
||||
|
||||
impl zkVM for EreSP1 {
|
||||
fn execute(
|
||||
&self,
|
||||
inputs: &Input,
|
||||
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
|
||||
fn execute(&self, inputs: &Input) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
|
||||
let mut stdin = SP1Stdin::new();
|
||||
for input in inputs.iter() {
|
||||
match input {
|
||||
@@ -126,15 +125,13 @@ impl zkVM for EreSP1 {
|
||||
}
|
||||
}
|
||||
|
||||
let start = Instant::now();
|
||||
let (_, exec_report) = self.client.execute(&self.program, &stdin)?;
|
||||
let total_num_cycles = exec_report.total_instruction_count();
|
||||
let region_cycles: indexmap::IndexMap<_, _> =
|
||||
exec_report.cycle_tracker.into_iter().collect();
|
||||
|
||||
let mut ere_report = ProgramExecutionReport::new(total_num_cycles);
|
||||
ere_report.region_cycles = region_cycles;
|
||||
|
||||
Ok(ere_report)
|
||||
Ok(ProgramExecutionReport {
|
||||
total_num_cycles: exec_report.total_instruction_count(),
|
||||
region_cycles: exec_report.cycle_tracker.into_iter().collect(),
|
||||
execution_duration: start.elapsed(),
|
||||
})
|
||||
}
|
||||
|
||||
fn prove(
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::{
|
||||
io::Write,
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
time,
|
||||
time::{self, Instant},
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
use zkvm_interface::{
|
||||
@@ -88,6 +88,7 @@ impl zkVM for EreZisk {
|
||||
.into());
|
||||
}
|
||||
|
||||
let start = Instant::now();
|
||||
let total_num_cycles = String::from_utf8_lossy(&output.stdout)
|
||||
.split_once("total steps = ")
|
||||
.and_then(|(_, stats)| {
|
||||
@@ -98,7 +99,11 @@ impl zkVM for EreZisk {
|
||||
})
|
||||
.ok_or(ZiskError::Execute(ExecuteError::TotalStepsNotFound))?;
|
||||
|
||||
Ok(ProgramExecutionReport::new(total_num_cycles))
|
||||
Ok(ProgramExecutionReport {
|
||||
total_num_cycles,
|
||||
execution_duration: start.elapsed(),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn prove(&self, input: &Input) -> Result<(Vec<u8>, ProgramProvingReport), zkVMError> {
|
||||
|
||||
@@ -10,13 +10,15 @@ pub struct ProgramExecutionReport {
|
||||
pub total_num_cycles: u64,
|
||||
/// Region-specific cycles, mapping region names (e.g., "setup", "compute") to their cycle counts.
|
||||
pub region_cycles: IndexMap<String, u64>,
|
||||
/// Execution duration.
|
||||
pub execution_duration: Duration,
|
||||
}
|
||||
|
||||
impl ProgramExecutionReport {
|
||||
pub fn new(total_num_cycles: u64) -> Self {
|
||||
ProgramExecutionReport {
|
||||
total_num_cycles,
|
||||
region_cycles: Default::default(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
pub fn insert_region(&mut self, region_name: String, num_cycles: u64) {
|
||||
|
||||
Reference in New Issue
Block a user