Skip to content

Commit 3b7caec

Browse files
Search for verifying keys by the programs specified
1 parent c2f5a47 commit 3b7caec

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

sdk/tests/program-manager.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ describe('Program Manager', () => {
4747

4848
describe('Verify execution with multiple imports', () => {
4949
it('Program manager should verify an execution with multiple imports', async () => {
50-
console.log(`Network: ${network}`);
51-
console.log(`Host: ${programManager.networkClient.host}`);
5250
if (network === "mainnet") {
5351
// Get the execution, program, and verifying key from the transaction.
5452
const transaction = <Transaction>await programManager.networkClient.getTransactionObject("at1ve39dz2nlm636ewq6g3wl978kmsfqafcvhaj9px4mk28hk855srq06veqh");

wasm/src/programs/execution.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
pub use super::*;
1818

19-
use crate::{log, types::native::{
19+
use crate::{log, native::ProgramIDNative, types::native::{
2020
CurrentNetwork, ExecutionNative, IdentifierNative, ProcessNative, ProgramID, ProgramNative, VerifyingKeyNative
2121
}, Transition};
2222
use snarkvm_algorithms::snark::varuna::VarunaVersion;
@@ -110,7 +110,7 @@ pub fn verify_function_execution(
110110
program: &Program,
111111
function_id: &str,
112112
imports: Option<Object>,
113-
import_verifying_keys: Option<Object>,
113+
imported_verifying_keys: Option<Object>,
114114
) -> Result<bool, String> {
115115
// Get the function
116116
let function = IdentifierNative::from_str(function_id).map_err(|e| e.to_string())?;
@@ -121,12 +121,22 @@ pub fn verify_function_execution(
121121
ProgramManager::resolve_imports(&mut process, program, imports)?;
122122

123123
// 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+
125135
// 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 {
127137
// Get the list of functions.
128138
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())
130140
.map_err(|_| format!("Verifying key not found for imported program {}", imported_program_id))?,
131141
)
132142
.map_err(|_| format!("Verifying key not found for imported program {}", imported_program_id))?;

0 commit comments

Comments
 (0)