Skip to content

Commit 7fc3f10

Browse files
authored
chore: cargo openvm build also outputs committed exe (#1560)
1 parent a5550a9 commit 7fc3f10

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ hex = "0.4.3"
3636
target-lexicon = "0.12.15"
3737
tempfile = "3.10.1"
3838
toml = { workspace = true }
39+
bitcode.workspace = true
3940

4041
[features]
4142
default = []

crates/cli/src/commands/build.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
fs::{create_dir_all, read, write},
33
path::PathBuf,
4+
sync::Arc,
45
};
56

67
use clap::Parser;
@@ -18,7 +19,7 @@ use openvm_transpiler::{elf::Elf, openvm_platform::memory::MEM_SIZE};
1819
use crate::{
1920
default::{
2021
DEFAULT_APP_CONFIG_PATH, DEFAULT_APP_EXE_PATH, DEFAULT_COMMITTED_APP_EXE_PATH,
21-
DEFAULT_MANIFEST_DIR,
22+
DEFAULT_EXE_COMMIT_PATH, DEFAULT_MANIFEST_DIR,
2223
},
2324
util::read_config_toml_or_default,
2425
};
@@ -83,6 +84,13 @@ pub struct BuildArgs {
8384
)]
8485
pub committed_exe_output: PathBuf,
8586

87+
#[arg(
88+
long,
89+
default_value = DEFAULT_EXE_COMMIT_PATH,
90+
help = "Output path for the exe commit (bn254 commit of committed program)"
91+
)]
92+
pub exe_commit_output: PathBuf,
93+
8694
#[arg(long, default_value = "release", help = "Build profile")]
8795
pub profile: String,
8896
}
@@ -146,12 +154,24 @@ pub(crate) fn build(build_args: &BuildArgs) -> Result<Option<PathBuf>> {
146154
let exe = Sdk::new().transpile(elf, transpiler)?;
147155
let committed_exe = commit_app_exe(app_config.app_fri_params.fri_params, exe.clone());
148156
write_exe_to_file(exe, output_path)?;
157+
158+
if let Some(parent) = build_args.exe_commit_output.parent() {
159+
create_dir_all(parent)?;
160+
}
161+
write(
162+
&build_args.exe_commit_output,
163+
committed_exe_as_bn254(&committed_exe).value.to_bytes(),
164+
)?;
149165
if let Some(parent) = build_args.committed_exe_output.parent() {
150166
create_dir_all(parent)?;
151167
}
168+
let committed_exe = match Arc::try_unwrap(committed_exe) {
169+
Ok(exe) => exe,
170+
Err(_) => return Err(eyre::eyre!("Failed to unwrap committed_exe Arc")),
171+
};
152172
write(
153173
&build_args.committed_exe_output,
154-
committed_exe_as_bn254(&committed_exe).value.to_bytes(),
174+
bitcode::serialize(&committed_exe)?,
155175
)?;
156176

157177
println!(
@@ -192,6 +212,7 @@ mod tests {
192212
config: PathBuf::from(DEFAULT_APP_CONFIG_PATH),
193213
exe_output: PathBuf::from(DEFAULT_APP_EXE_PATH),
194214
committed_exe_output: PathBuf::from(DEFAULT_COMMITTED_APP_EXE_PATH),
215+
exe_commit_output: PathBuf::from(DEFAULT_EXE_COMMIT_PATH),
195216
profile: "dev".to_string(),
196217
target_dir: Some(target_dir.to_path_buf()),
197218
};

crates/cli/src/default.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub const DEFAULT_EVM_HALO2_VERIFIER_PATH: &str = concat!(env!("HOME"), "/.openv
1010

1111
pub const DEFAULT_APP_CONFIG_PATH: &str = "./openvm.toml";
1212
pub const DEFAULT_APP_EXE_PATH: &str = "./openvm/app.vmexe";
13-
pub const DEFAULT_COMMITTED_APP_EXE_PATH: &str = "./openvm/committed_app_exe.bytes";
13+
pub const DEFAULT_EXE_COMMIT_PATH: &str = "./openvm/exe_commit.bytes";
14+
pub const DEFAULT_COMMITTED_APP_EXE_PATH: &str = "./openvm/committed_app_exe.bc";
1415
pub const DEFAULT_APP_PK_PATH: &str = "./openvm/app.pk";
1516
pub const DEFAULT_APP_VK_PATH: &str = "./openvm/app.vk";
1617
pub const DEFAULT_APP_PROOF_PATH: &str = "./openvm/app.proof";

0 commit comments

Comments
 (0)