@@ -230,19 +230,27 @@ fn handle_synthesize<A: Aleo>(
230230 Ok ( hex)
231231 } ;
232232
233+ // Collect record names for translation key synthesis.
234+ let record_names: Vec < _ > = stack. program ( ) . records ( ) . keys ( ) . cloned ( ) . collect ( ) ;
235+
233236 println ! ( "\n 🌱 Synthesizing the following keys in {program_id}:" ) ;
234237 for id in & function_ids {
235- println ! ( " - {id}" ) ;
238+ println ! ( " - {id} (function)" ) ;
239+ }
240+ for name in & record_names {
241+ println ! ( " - {name} (record translation)" ) ;
236242 }
237243
238244 let mut synthesized_functions = Vec :: new ( ) ;
239245
240- for function_id in function_ids {
241- stack. synthesize_key :: < A , _ > ( function_id, rng) ?;
242- let proving_key = stack. get_proving_key ( function_id) ?;
243- let verifying_key = stack. get_verifying_key ( function_id) ?;
246+ // Helper: process a synthesized key (function or translation), print circuit info,
247+ // record metadata, and optionally save keys to disk.
248+ let mut process_key = |name : & str , label : & str | -> Result < ( ) > {
249+ let name_id = snarkvm:: prelude:: Identifier :: < A :: Network > :: from_str ( name) ?;
250+ let proving_key = stack. get_proving_key ( & name_id) ?;
251+ let verifying_key = stack. get_verifying_key ( & name_id) ?;
244252
245- println ! ( "\n 🔑 Synthesized keys for {program_id}/{function_id } (edition {edition})" ) ;
253+ println ! ( "\n 🔑 Synthesized {label} for {program_id}/{name } (edition {edition})" ) ;
246254 println ! ( "ℹ️ Circuit Information:" ) ;
247255 println ! ( " - Public Inputs: {}" , verifying_key. circuit_info. num_public_inputs) ;
248256 println ! ( " - Variables: {}" , verifying_key. circuit_info. num_public_and_private_variables) ;
@@ -252,13 +260,11 @@ fn handle_synthesize<A: Aleo>(
252260 println ! ( " - Non-Zero Entries in C: {}" , verifying_key. circuit_info. num_non_zero_c) ;
253261 println ! ( " - Circuit ID: {}" , verifying_key. id) ;
254262
255- // Get the checksums of the keys.
256263 let prover_bytes = proving_key. to_bytes_le ( ) ?;
257264 let verifier_bytes = verifying_key. to_bytes_le ( ) ?;
258265 let prover_checksum = hash ( & prover_bytes) ?;
259266 let verifier_checksum = hash ( & verifier_bytes) ?;
260267
261- // Construct the metadata.
262268 let metadata = Metadata {
263269 prover_checksum,
264270 prover_size : prover_bytes. len ( ) ,
@@ -279,44 +285,44 @@ fn handle_synthesize<A: Aleo>(
279285 } ;
280286
281287 synthesized_functions. push ( SynthesizedFunction {
282- name : function_id . to_string ( ) ,
288+ name : name . to_string ( ) ,
283289 circuit_info,
284290 metadata : metadata. clone ( ) ,
285291 } ) ;
286292
287- // A helper to write to a file.
288- let write_to_file = |path : PathBuf , data : & [ u8 ] | -> Result < ( ) > {
289- std:: fs:: write ( path, data) . map_err ( |e| CliError :: custom ( format ! ( "Failed to write to file: {e}" ) ) ) ?;
290- Ok ( ( ) )
291- } ;
292-
293- // If the `save` option is set, save the proving and verifying keys to a file in the specified directory.
294- // The file format is `program_id.function_id.edition_or_local.type.timestamp`.
295- // The directory is created if it doesn't exist.
296293 if let Some ( path) = & command. action . save {
297- // Create the directory if it doesn't exist.
298294 std:: fs:: create_dir_all ( path) . map_err ( |e| CliError :: custom ( format ! ( "Failed to create directory: {e}" ) ) ) ?;
299- // Get the current timestamp.
300295 let timestamp = chrono:: Utc :: now ( ) . timestamp ( ) ;
301- // The edition.
302- let edition = if command. local { "local" . to_string ( ) } else { edition. to_string ( ) } ;
303- // The prefix for the file names.
304- let prefix = format ! ( "{network}.{program_id}.{function_id}.{edition}" ) ;
305- // Get the file paths.
296+ let edition_str = if command. local { "local" . to_string ( ) } else { edition. to_string ( ) } ;
297+ let prefix = format ! ( "{network}.{program_id}.{name}.{edition_str}" ) ;
306298 let prover_file_path = PathBuf :: from ( path) . join ( format ! ( "{prefix}.prover.{timestamp}" ) ) ;
307299 let verifier_file_path = PathBuf :: from ( path) . join ( format ! ( "{prefix}.verifier.{timestamp}" ) ) ;
308- let metadata_file_path = PathBuf :: from ( path)
309- . join ( format ! ( "{network}.{program_id}.{function_id}.{edition}.metadata.{timestamp}" ) ) ;
310- // Print the save location.
300+ let metadata_file_path = PathBuf :: from ( path) . join ( format ! ( "{prefix}.metadata.{timestamp}" ) ) ;
311301 println ! (
312- "💾 Saving proving key, verifying key, and metadata to: {}/{network}.{program_id}.{function_id}.{edition }.prover|verifier|metadata.{timestamp}" ,
302+ "💾 Saving {label} to: {}/{prefix }.prover|verifier|metadata.{timestamp}" ,
313303 metadata_file_path. parent( ) . unwrap( ) . display( )
314304 ) ;
315- // Save the keys.
316- write_to_file ( prover_file_path, & prover_bytes) ?;
317- write_to_file ( verifier_file_path, & verifier_bytes) ?;
318- write_to_file ( metadata_file_path, metadata_pretty. as_bytes ( ) ) ?;
305+ std:: fs:: write ( & prover_file_path, & prover_bytes)
306+ . map_err ( |e| CliError :: custom ( format ! ( "Failed to write to file: {e}" ) ) ) ?;
307+ std:: fs:: write ( & verifier_file_path, & verifier_bytes)
308+ . map_err ( |e| CliError :: custom ( format ! ( "Failed to write to file: {e}" ) ) ) ?;
309+ std:: fs:: write ( & metadata_file_path, metadata_pretty. as_bytes ( ) )
310+ . map_err ( |e| CliError :: custom ( format ! ( "Failed to write to file: {e}" ) ) ) ?;
319311 }
312+
313+ Ok ( ( ) )
314+ } ;
315+
316+ // Synthesize function keys.
317+ for function_id in function_ids {
318+ stack. synthesize_key :: < A , _ > ( function_id, rng) ?;
319+ process_key ( & function_id. to_string ( ) , "keys" ) ?;
320+ }
321+
322+ // Synthesize record translation keys.
323+ for record_name in & record_names {
324+ stack. synthesize_translation_key :: < A , _ > ( record_name, rng) ?;
325+ process_key ( & record_name. to_string ( ) , "translation key" ) ?;
320326 }
321327
322328 Ok ( SynthesizeOutput { program : program_id. to_string ( ) , functions : synthesized_functions } )
0 commit comments