MCPcopy Create free account
hub / github.com/ProvableHQ/sdk / verify_function_execution

Function verify_function_execution

wasm/src/programs/execution.rs:121–220  ·  view source on GitHub ↗
(
    execution: &Execution,
    verifying_key: &VerifyingKey,
    program: &Program,
    function_id: &str,
    imports: Option<Object>,
    imported_verifying_keys: Option<Object>,
    block_height:

Source from the content-addressed store, hash-verified

119/// @returns {boolean} True if the execution is valid, false otherwise
120#[wasm_bindgen(js_name = "verifyFunctionExecution")]
121pub fn verify_function_execution(
122 execution: &Execution,
123 verifying_key: &VerifyingKey,
124 program: &Program,
125 function_id: &str,
126 imports: Option<Object>,
127 imported_verifying_keys: Option<Object>,
128 block_height: u32,
129 program_imports: Option<ProgramImports>,
130) -> Result<bool, String> {
131 // Get the function
132 let function = IdentifierNative::from_str(function_id).map_err(|e| e.to_string())?;
133 let program_native = ProgramNative::from(program);
134 let program_id = program_native.id().to_string();
135
136 // Use ProgramImports' internal process when available, otherwise load fresh.
137 let mut owned_process;
138 let mut inner_guard;
139 let process: &mut ProcessNative = match program_imports.as_ref() {
140 Some(pi) => {
141 inner_guard = pi.borrow_inner_mut();
142 &mut inner_guard.process
143 }
144 None => {
145 owned_process = ProcessNative::load_web().map_err(|e| e.to_string())?;
146 ProgramManager::resolve_imports(&mut owned_process, imports, Some(program_id.as_str()))?;
147 &mut owned_process
148 }
149 };
150
151 // Get the verifying keys and insert them into the process object.
152 if let Some(imported_verifying_keys) = imported_verifying_keys {
153 // Go through the imports and get the program IDs.
154 let program_ids = Object::keys(&imported_verifying_keys)
155 .iter()
156 .map(|entry| {
157 let entry = entry.as_string().unwrap(); // Safe unwraps because `keys` returns array of string keys.
158 ProgramIDNative::from_str(&entry)
159 .map_err(|_| format!("Program ID not found in imports provided: {entry}"))
160 })
161 .collect::<Result<Vec<_>, _>>()?;
162
163 // Go through the imports and insert the verifying keys for each function.
164 for imported_program_id in &program_ids {
165 // Get the list of functions.
166 let vk_list = Array::try_from(
167 Reflect::get(&imported_verifying_keys, &imported_program_id.to_string().into())
168 .map_err(|_| format!("Verifying key not found for imported program {imported_program_id}"))?,
169 )
170 .map_err(|_| format!("Verifying key not found for imported program {imported_program_id}"))?;
171 // Get the verifying key for each function.
172 for vk in vk_list.iter() {
173 let vk = Array::try_from(vk).map_err(|_| format!("Verifying key and function not found for {imported_program_id}, for each function provide an array of the form ['function_name', 'vk']"))?;
174 {
175 // Insert the verifying key into the temporary process.
176 let imported_function = IdentifierNative::from_str(
177 &vk.get(0).as_string().ok_or("Function not found in imports provided")?,
178 )

Callers

nothing calls this directly

Calls 7

borrow_inner_mutMethod · 0.80
add_programMethod · 0.80
getFunction · 0.50
logFunction · 0.50
to_stringMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected