Skip to content

Commit

Permalink
chore: default exe and app_config path in CLI (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh-axiom-xyz authored Dec 16, 2024
1 parent 6c0c0e2 commit 689e171
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ecc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ jobs:
- name: Build openvm-ecc-guest crate for openvm
working-directory: extensions/ecc/guest
run: |
cargo openvm build
cargo openvm build --no-transpile
3 changes: 2 additions & 1 deletion benchmarks/src/bin/base64_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ fn main() -> Result<()> {
.with_extension(Keccak256TranspilerExtension),
)?;
let app_config = AppConfig {
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup),
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup)
.into(),
app_vm_config: Keccak256Rv32Config::default(),
leaf_fri_params: FriParameters::standard_with_100_bits_conjectured_security(agg_log_blowup)
.into(),
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/bin/bincode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() -> Result<()> {
};

let app_config = AppConfig {
app_fri_params,
app_fri_params: app_fri_params.into(),
app_vm_config: Rv32ImConfig::default(),
leaf_fri_params: leaf_fri_params.into(),
compiler_options,
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/src/bin/ecrecover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ fn main() -> Result<()> {
)?;
// TODO: update sw_setup macros and read it from elf.
let vm_config = AppConfig {
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup),
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup)
.into(),
app_vm_config: Rv32ImEcRecoverConfig::for_curves(vec![SECP256K1_CONFIG.clone()]),
leaf_fri_params: FriParameters::standard_with_100_bits_conjectured_security(agg_log_blowup)
.into(),
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/bin/fib_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async fn main() -> Result<()> {
let max_segment_length = cli_args.max_segment_length.unwrap_or(1_000_000);

let app_config = AppConfig {
app_fri_params,
app_fri_params: app_fri_params.into(),
app_vm_config: Rv32ImConfig::with_public_values_and_segment_len(
NUM_PUBLIC_VALUES,
max_segment_length,
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/bin/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> Result<()> {
};

let app_config = AppConfig {
app_fri_params,
app_fri_params: app_fri_params.into(),
app_vm_config: Rv32ImConfig::default(),
leaf_fri_params: leaf_fri_params.into(),
compiler_options,
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/src/bin/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ fn main() -> Result<()> {
.with_extension(Keccak256TranspilerExtension),
)?;
let app_config = AppConfig {
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup),
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup)
.into(),
app_vm_config: Keccak256Rv32Config::default(),
leaf_fri_params: FriParameters::standard_with_100_bits_conjectured_security(agg_log_blowup)
.into(),
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/src/bin/revm_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ fn main() -> Result<()> {
.with_extension(Rv32IoTranspilerExtension),
)?;
let app_config = AppConfig {
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup),
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup)
.into(),
app_vm_config: Keccak256Rv32Config::default(),
leaf_fri_params: FriParameters::standard_with_100_bits_conjectured_security(1).into(),
compiler_options: CompilerOptions::default().with_cycle_tracker(),
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/bin/rkyv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() -> Result<()> {
};

let app_config = AppConfig {
app_fri_params,
app_fri_params: app_fri_params.into(),
app_vm_config: Rv32ImConfig::default(),
leaf_fri_params: leaf_fri_params.into(),
compiler_options,
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/src/bin/verify_fibair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() -> Result<()> {
..Default::default()
};
let app_config = AppConfig {
app_fri_params: leaf_fri_params,
app_fri_params: leaf_fri_params.into(),
app_vm_config,
leaf_fri_params: leaf_fri_params.into(),
compiler_options,
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ where
VC::Executor: Chip<SC>,
VC::Periphery: Chip<SC>,
{
counter!("fri.log_blowup").absolute(app_config.app_fri_params.log_blowup as u64);
let engine = BabyBearPoseidon2Engine::new(app_config.app_fri_params);
counter!("fri.log_blowup").absolute(app_config.app_fri_params.fri_params.log_blowup as u64);
let engine = BabyBearPoseidon2Engine::new(app_config.app_fri_params.fri_params);
let vm = VirtualMachine::new(engine, app_config.app_vm_config.clone());
// 1. Generate proving key from config.
let app_pk = time(gauge!("keygen_time_ms"), || {
AppProvingKey::keygen(app_config.clone())
});
// 2. Commit to the exe by generating cached trace for program.
let committed_exe = time(gauge!("commit_exe_time_ms"), || {
commit_app_exe(app_config.app_fri_params, exe)
commit_app_exe(app_config.app_fri_params.fri_params, exe)
});
// 3. Executes runtime once with full metric collection for flamegraphs (slow).
// 4. Executes runtime again without metric collection and generate trace.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
[app_fri_params]
log_blowup = 2
num_queries = 42
proof_of_work_bits = 16

[app_vm_config.rv32i]
[app_vm_config.rv32m]
range_tuple_checker_sizes = [256, 2048]
6 changes: 2 additions & 4 deletions crates/cli/src/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use openvm_stark_sdk::{
};

use super::build::{build, BuildArgs};
use crate::util::{write_status, Input};
use crate::util::{classical_exe_path, write_status, Input};

#[derive(Clone, Parser)]
#[command(name = "bench", about = "(default) Build and prove a program")]
Expand All @@ -43,10 +43,8 @@ impl BenchCmd {
if self.profile {
setup_tracing();
}
let mut build_args = self.build_args.clone();
build_args.transpile = true;
let elf_path = build(&self.build_args)?.unwrap();
let exe_path = build_args.exe_path(&elf_path);
let exe_path = classical_exe_path(&elf_path);
let exe = read_exe_from_file(&exe_path)?;

// TODO: read from openvm.toml
Expand Down
55 changes: 19 additions & 36 deletions crates/cli/src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
use std::{
fs::read,
path::{Path, PathBuf},
};
use std::{fs::read, path::PathBuf};

use clap::Parser;
use eyre::Result;
use openvm_build::{
build_guest_package, find_unique_executable, get_package, GuestOptions, TargetFilter,
};
use openvm_rv32im_transpiler::{Rv32ITranspilerExtension, Rv32MTranspilerExtension};
use openvm_sdk::{
config::{AppConfig, SdkVmConfig},
fs::write_exe_to_file,
Sdk,
};
use openvm_transpiler::{elf::Elf, openvm_platform::memory::MEM_SIZE, transpiler::Transpiler};
use openvm_sdk::{fs::write_exe_to_file, Sdk};
use openvm_transpiler::{elf::Elf, openvm_platform::memory::MEM_SIZE};

use crate::{default::DEFAULT_MANIFEST_DIR, util::read_to_struct_toml};
use crate::{
default::{DEFAULT_APP_CONFIG_PATH, DEFAULT_APP_EXE_PATH, DEFAULT_MANIFEST_DIR},
util::read_config_toml_or_default,
};

#[derive(Parser)]
#[command(name = "build", about = "Compile an OpenVM program")]
Expand Down Expand Up @@ -53,34 +48,28 @@ pub struct BuildArgs {
#[arg(
long,
default_value = "false",
help = "Transpiles the program after building when set"
help = "Skips transpilation into exe when set"
)]
pub transpile: bool,
pub no_transpile: bool,

#[arg(
long,
default_value = DEFAULT_APP_CONFIG_PATH,
help = "Path to the SDK config .toml file that specifies the transpiler extensions"
)]
pub transpiler_config: Option<PathBuf>,
pub config: PathBuf,

#[arg(
long,
help = "Output path for the transpiled program (default: <ELF base path>.vmexe)"
default_value = DEFAULT_APP_EXE_PATH,
help = "Output path for the transpiled program"
)]
pub transpile_to: Option<PathBuf>,
pub exe_output: PathBuf,

#[arg(long, default_value = "release", help = "Build profile")]
pub profile: String,
}

impl BuildArgs {
pub fn exe_path(&self, elf_path: &Path) -> PathBuf {
self.transpile_to
.clone()
.unwrap_or_else(|| elf_path.with_extension("vmexe"))
}
}

#[derive(Clone, clap::Args)]
#[group(required = false, multiple = false)]
pub struct BinTypeFilter {
Expand Down Expand Up @@ -129,23 +118,17 @@ pub(crate) fn build(build_args: &BuildArgs) -> Result<Option<PathBuf>> {
}
};

if build_args.transpile {
if !build_args.no_transpile {
let elf_path = elf_path?;
println!("[openvm] Transpiling the package...");
let output_path = build_args.exe_path(&elf_path);
let transpiler = if let Some(transpiler_config) = build_args.transpiler_config.clone() {
let app_config: AppConfig<SdkVmConfig> = read_to_struct_toml(&transpiler_config)?;
app_config.app_vm_config.transpiler()
} else {
Transpiler::default()
.with_extension(Rv32ITranspilerExtension)
.with_extension(Rv32MTranspilerExtension)
};
let output_path = &build_args.exe_output;
let app_config = read_config_toml_or_default(&build_args.config)?;
let transpiler = app_config.app_vm_config.transpiler();

let data = read(elf_path.clone())?;
let elf = Elf::decode(&data, MEM_SIZE as u32)?;
let exe = Sdk.transpile(elf, transpiler)?;
write_exe_to_file(exe, &output_path)?;
write_exe_to_file(exe, output_path)?;

println!(
"[openvm] Successfully transpiled to {}",
Expand Down
9 changes: 4 additions & 5 deletions crates/cli/src/commands/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ use std::path::PathBuf;
use clap::Parser;
use eyre::Result;
use openvm_sdk::{
config::{AppConfig, SdkVmConfig},
fs::{write_app_pk_to_file, write_app_vk_to_file},
Sdk,
};

use crate::{
default::{DEFAULT_APP_PK_PATH, DEFAULT_APP_VK_PATH},
util::read_to_struct_toml,
default::{DEFAULT_APP_CONFIG_PATH, DEFAULT_APP_PK_PATH, DEFAULT_APP_VK_PATH},
util::read_config_toml_or_default,
};

#[derive(Parser)]
#[command(name = "keygen", about = "Generate an application proving key")]
pub struct KeygenCmd {
#[clap(long, action, help = "Path to app config TOML file")]
#[clap(long, action, help = "Path to app config TOML file", default_value = DEFAULT_APP_CONFIG_PATH)]
config: PathBuf,

#[clap(
Expand All @@ -38,7 +37,7 @@ pub struct KeygenCmd {

impl KeygenCmd {
pub fn run(&self) -> Result<()> {
let app_config: AppConfig<SdkVmConfig> = read_to_struct_toml(&self.config)?;
let app_config = read_config_toml_or_default(&self.config)?;
let app_pk = Sdk.app_keygen(app_config)?;
write_app_vk_to_file(app_pk.get_vk(), &self.vk_output)?;
write_app_pk_to_file(app_pk, &self.output)?;
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/commands/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use openvm_sdk::{

use crate::{
default::{
DEFAULT_AGG_PK_PATH, DEFAULT_APP_PK_PATH, DEFAULT_APP_PROOF_PATH, DEFAULT_EVM_PROOF_PATH,
DEFAULT_PARAMS_DIR,
DEFAULT_AGG_PK_PATH, DEFAULT_APP_EXE_PATH, DEFAULT_APP_PK_PATH, DEFAULT_APP_PROOF_PATH,
DEFAULT_EVM_PROOF_PATH, DEFAULT_PARAMS_DIR,
},
util::{read_to_stdin, Input},
};
Expand All @@ -35,7 +35,7 @@ enum ProveSubCommand {
#[clap(long, action, help = "Path to app proving key", default_value = DEFAULT_APP_PK_PATH)]
app_pk: PathBuf,

#[clap(long, action, help = "Path to OpenVM executable")]
#[clap(long, action, help = "Path to OpenVM executable", default_value = DEFAULT_APP_EXE_PATH)]
exe: PathBuf,

#[clap(long, value_parser, help = "Input to OpenVM program")]
Expand All @@ -48,7 +48,7 @@ enum ProveSubCommand {
#[clap(long, action, help = "Path to app proving key", default_value = DEFAULT_APP_PK_PATH)]
app_pk: PathBuf,

#[clap(long, action, help = "Path to OpenVM executable")]
#[clap(long, action, help = "Path to OpenVM executable", default_value = DEFAULT_APP_EXE_PATH)]
exe: PathBuf,

#[clap(long, value_parser, help = "Input to OpenVM program")]
Expand Down
17 changes: 8 additions & 9 deletions crates/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ use std::path::PathBuf;

use clap::Parser;
use eyre::Result;
use openvm_sdk::{
config::{AppConfig, SdkVmConfig},
fs::read_exe_from_file,
Sdk,
};
use openvm_sdk::{fs::read_exe_from_file, Sdk};

use crate::util::{read_to_stdin, read_to_struct_toml, Input};
use crate::{
default::{DEFAULT_APP_CONFIG_PATH, DEFAULT_APP_EXE_PATH},
util::{read_config_toml_or_default, read_to_stdin, Input},
};

#[derive(Parser)]
#[command(name = "run", about = "Run an OpenVM program")]
pub struct RunCmd {
#[clap(long, action, help = "Path to OpenVM executable")]
#[clap(long, action, help = "Path to OpenVM executable", default_value = DEFAULT_APP_EXE_PATH)]
exe: PathBuf,

#[clap(long, action, help = "Path to app config TOML file")]
#[clap(long, action, help = "Path to app config TOML file", default_value = DEFAULT_APP_CONFIG_PATH)]
config: PathBuf,

#[clap(long, value_parser, help = "Input to OpenVM program")]
Expand All @@ -26,7 +25,7 @@ pub struct RunCmd {
impl RunCmd {
pub fn run(&self) -> Result<()> {
let exe = read_exe_from_file(&self.exe)?;
let app_config: AppConfig<SdkVmConfig> = read_to_struct_toml(&self.config)?;
let app_config = read_config_toml_or_default(&self.config)?;
let output = Sdk.execute(exe, app_config.app_vm_config, read_to_stdin(&self.input)?)?;
println!("Execution output: {:?}", output);
Ok(())
Expand Down
19 changes: 19 additions & 0 deletions crates/cli/src/default.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
use openvm_sdk::config::{AppConfig, SdkVmConfig};
use openvm_stark_sdk::config::FriParameters;

pub const DEFAULT_MANIFEST_DIR: &str = ".";

pub const DEFAULT_AGG_PK_PATH: &str = concat!(env!("HOME"), "/.openvm/agg.pk");
pub const DEFAULT_VERIFIER_PATH: &str = concat!(env!("HOME"), "/.openvm/verifier.sol");
pub const DEFAULT_PARAMS_DIR: &str = concat!(env!("HOME"), "/.openvm/params/");

pub const DEFAULT_APP_CONFIG_PATH: &str = "./openvm.toml";
pub const DEFAULT_APP_EXE_PATH: &str = "./openvm/app.vmexe";
pub const DEFAULT_APP_PK_PATH: &str = "./openvm/app.pk";
pub const DEFAULT_APP_VK_PATH: &str = "./openvm/app.vk";
pub const DEFAULT_APP_PROOF_PATH: &str = "./openvm/app.proof";
pub const DEFAULT_EVM_PROOF_PATH: &str = "./openvm/evm.proof";

pub fn default_app_config() -> AppConfig<SdkVmConfig> {
AppConfig {
app_fri_params: FriParameters::standard_with_100_bits_conjectured_security(2).into(),
app_vm_config: SdkVmConfig::builder()
.system(Default::default())
.rv32i(Default::default())
.rv32m(Default::default())
.io(Default::default())
.build(),
leaf_fri_params: FriParameters::standard_with_100_bits_conjectured_security(2).into(),
compiler_options: Default::default(),
}
}
Loading

0 comments on commit 689e171

Please sign in to comment.