Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(acvm_js): Improve program handling and error messages in wit… #7232

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions acvm-repo/acvm_js/src/public_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,32 @@ pub(crate) fn extract_indices(

/// Extracts a `WitnessMap` containing the witness indices corresponding to the circuit's return values.
///
/// @param {Uint8Array} circuit - A serialized representation of an ACIR circuit
/// @param {Uint8Array} program - A serialized representation of an ACIR program
/// @param {WitnessMap} witness_map - The completed witness map after executing the circuit.
/// @returns {WitnessMap} A witness map containing the circuit's return values.
#[wasm_bindgen(js_name = getReturnWitness)]
pub fn get_return_witness(
// TODO(https://github.com/noir-lang/noir/issues/4428): These need to be updated to match the same interfaces
// as the native ACVM executor. Right now native execution still only handles one circuit so I do not feel the need
// to break the JS interface just yet.
program: Vec<u8>,
witness_map: JsWitnessMap,
) -> Result<JsWitnessMap, JsString> {
console_error_panic_hook::set_once();
let program: Program<FieldElement> =
Program::deserialize_program(&program).expect("Failed to deserialize circuit");
let circuit = match program.functions.len() {
0 => return Ok(JsWitnessMap::from(WitnessMap::new())),
1 => &program.functions[0],
_ => return Err(JsString::from("Program contains multiple circuits however ACVM currently only supports programs containing a single circuit"))
};
Program::deserialize_program(&program).expect("Failed to deserialize program");

// Handle empty program case first
if program.functions.is_empty() {
return Ok(JsWitnessMap::from(WitnessMap::new()));
}

// For now we only support single-circuit programs
// This maintains compatibility while allowing for future multi-circuit support
if program.functions.len() > 1 {
return Err(JsString::from(
"Multi-circuit programs are not yet supported in ACVM JS bindings",
));
}

let circuit = &program.functions[0];
let witness_map = WitnessMap::from(witness_map);

let return_witness =
Expand Down
Loading