1
1
use std:: {
2
2
fs:: { create_dir_all, read, write} ,
3
3
path:: PathBuf ,
4
+ sync:: Arc ,
4
5
} ;
5
6
6
7
use clap:: Parser ;
@@ -18,7 +19,7 @@ use openvm_transpiler::{elf::Elf, openvm_platform::memory::MEM_SIZE};
18
19
use crate :: {
19
20
default:: {
20
21
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 ,
22
23
} ,
23
24
util:: read_config_toml_or_default,
24
25
} ;
@@ -83,6 +84,13 @@ pub struct BuildArgs {
83
84
) ]
84
85
pub committed_exe_output : PathBuf ,
85
86
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
+
86
94
#[ arg( long, default_value = "release" , help = "Build profile" ) ]
87
95
pub profile : String ,
88
96
}
@@ -146,12 +154,24 @@ pub(crate) fn build(build_args: &BuildArgs) -> Result<Option<PathBuf>> {
146
154
let exe = Sdk :: new ( ) . transpile ( elf, transpiler) ?;
147
155
let committed_exe = commit_app_exe ( app_config. app_fri_params . fri_params , exe. clone ( ) ) ;
148
156
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
+ ) ?;
149
165
if let Some ( parent) = build_args. committed_exe_output . parent ( ) {
150
166
create_dir_all ( parent) ?;
151
167
}
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
+ } ;
152
172
write (
153
173
& build_args. committed_exe_output ,
154
- committed_exe_as_bn254 ( & committed_exe) . value . to_bytes ( ) ,
174
+ bitcode :: serialize ( & committed_exe) ? ,
155
175
) ?;
156
176
157
177
println ! (
@@ -192,6 +212,7 @@ mod tests {
192
212
config : PathBuf :: from ( DEFAULT_APP_CONFIG_PATH ) ,
193
213
exe_output : PathBuf :: from ( DEFAULT_APP_EXE_PATH ) ,
194
214
committed_exe_output : PathBuf :: from ( DEFAULT_COMMITTED_APP_EXE_PATH ) ,
215
+ exe_commit_output : PathBuf :: from ( DEFAULT_EXE_COMMIT_PATH ) ,
195
216
profile : "dev" . to_string ( ) ,
196
217
target_dir : Some ( target_dir. to_path_buf ( ) ) ,
197
218
} ;
0 commit comments