Skip to content

Commit

Permalink
fix: return error rather instead of panicking on invalid circuit (#3976)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

This PR replaces a panic on an invalid circuit in ACVM JS with an error.
If this occurs it's likely due to serialisation differences rather than
a user passing in garbage bytes so I've added that to the error message.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jan 8, 2024
1 parent 3801956 commit 67201bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions acvm-repo/acvm_js/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub async fn execute_circuit_with_black_box_solver(
foreign_call_handler: ForeignCallHandler,
) -> Result<JsWitnessMap, Error> {
console_error_panic_hook::set_once();
let circuit: Circuit =
Circuit::deserialize_circuit(&circuit).expect("Failed to deserialize circuit");
let circuit: Circuit = Circuit::deserialize_circuit(&circuit)
.map_err(|_| JsExecutionError::new("Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(), None))?;

let mut acvm = ACVM::new(&solver.0, &circuit.opcodes, initial_witness.into());

Expand Down
5 changes: 3 additions & 2 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"arity",
"arkworks",
"arraysort",
"barebones",
"barretenberg",
"bincode",
"bindgen",
Expand Down Expand Up @@ -82,6 +83,7 @@
"jmpif",
"jmpifs",
"jmps",
"jsdoc",
"Jubjub",
"keccak",
"krate",
Expand Down Expand Up @@ -154,8 +156,7 @@
"vecmap",
"wasi",
"Weierstraß",
"zshell",
"barebones"
"zshell"
],
"ignorePaths": [
"./**/node_modules/**"
Expand Down

0 comments on commit 67201bf

Please sign in to comment.