From 67201bfc21a9c8858aa86be9cd47d463fb78d925 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:57:40 +0000 Subject: [PATCH] fix: return error rather instead of panicking on invalid circuit (#3976) # Description ## Problem\* Resolves ## 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. --- acvm-repo/acvm_js/src/execute.rs | 4 ++-- cspell.json | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/acvm-repo/acvm_js/src/execute.rs b/acvm-repo/acvm_js/src/execute.rs index 439a929cc9..3f691e1abf 100644 --- a/acvm-repo/acvm_js/src/execute.rs +++ b/acvm-repo/acvm_js/src/execute.rs @@ -61,8 +61,8 @@ pub async fn execute_circuit_with_black_box_solver( foreign_call_handler: ForeignCallHandler, ) -> Result { 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()); diff --git a/cspell.json b/cspell.json index c4a530b8d3..8e3f248acf 100644 --- a/cspell.json +++ b/cspell.json @@ -11,6 +11,7 @@ "arity", "arkworks", "arraysort", + "barebones", "barretenberg", "bincode", "bindgen", @@ -82,6 +83,7 @@ "jmpif", "jmpifs", "jmps", + "jsdoc", "Jubjub", "keccak", "krate", @@ -154,8 +156,7 @@ "vecmap", "wasi", "Weierstraß", - "zshell", - "barebones" + "zshell" ], "ignorePaths": [ "./**/node_modules/**"