16
16
17
17
pub use super :: * ;
18
18
19
- use crate :: { log, types:: native:: {
19
+ use crate :: { log, native :: ProgramIDNative , types:: native:: {
20
20
CurrentNetwork , ExecutionNative , IdentifierNative , ProcessNative , ProgramID , ProgramNative , VerifyingKeyNative
21
21
} , Transition } ;
22
22
use snarkvm_algorithms:: snark:: varuna:: VarunaVersion ;
@@ -110,7 +110,7 @@ pub fn verify_function_execution(
110
110
program : & Program ,
111
111
function_id : & str ,
112
112
imports : Option < Object > ,
113
- import_verifying_keys : Option < Object > ,
113
+ imported_verifying_keys : Option < Object > ,
114
114
) -> Result < bool , String > {
115
115
// Get the function
116
116
let function = IdentifierNative :: from_str ( function_id) . map_err ( |e| e. to_string ( ) ) ?;
@@ -121,12 +121,22 @@ pub fn verify_function_execution(
121
121
ProgramManager :: resolve_imports ( & mut process, program, imports) ?;
122
122
123
123
// Secondly, get the verifying keys and insert them into the process object.
124
- if let Some ( import_verifying_keys) = import_verifying_keys {
124
+ if let Some ( imported_verifying_keys) = imported_verifying_keys {
125
+ // Go through the imports and get the program IDs.
126
+ let program_ids = Object :: entries ( & imported_verifying_keys)
127
+ . iter ( )
128
+ . filter_map ( |entries| Array :: try_from ( entries) . unwrap ( ) . get ( 0 ) . as_string ( ) ) // Safe unwraps because `entries` returns arrays with string keys.
129
+ . map ( |entry| {
130
+ ProgramIDNative :: from_str ( & entry)
131
+ . map_err ( |_| format ! ( "Program ID not found in imports provided: {entry}" ) )
132
+ } )
133
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
134
+
125
135
// Go through the imports and insert the verifying keys for each function.
126
- for imported_program_id in program . imports ( ) . keys ( ) {
136
+ for imported_program_id in & program_ids {
127
137
// Get the list of functions.
128
138
let vk_list = Array :: try_from (
129
- Reflect :: get ( & import_verifying_keys , & imported_program_id. to_string ( ) . into ( ) )
139
+ Reflect :: get ( & imported_verifying_keys , & imported_program_id. to_string ( ) . into ( ) )
130
140
. map_err ( |_| format ! ( "Verifying key not found for imported program {}" , imported_program_id) ) ?,
131
141
)
132
142
. map_err ( |_| format ! ( "Verifying key not found for imported program {}" , imported_program_id) ) ?;
0 commit comments