Skip to content

Commit

Permalink
fix: Fix acvm wasm code
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant committed Oct 2, 2023
1 parent d16ee47 commit 066de05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions acvm-repo/acvm_js/src/foreign_call/inputs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use acvm::brillig_vm::brillig::Value;
use acvm::brillig_vm::brillig::ForeignCallParam;

use crate::js_witness_map::field_element_to_js_string;

pub(super) fn encode_foreign_call_inputs(foreign_call_inputs: &[Vec<Value>]) -> js_sys::Array {
pub(super) fn encode_foreign_call_inputs(
foreign_call_inputs: &[ForeignCallParam],
) -> js_sys::Array {
let inputs = js_sys::Array::default();
for input in foreign_call_inputs {
let input_array = js_sys::Array::default();
for value in input {
for value in input.values() {
let hex_js_string = field_element_to_js_string(&value.to_field());
input_array.push(&hex_js_string);
}
Expand Down
12 changes: 6 additions & 6 deletions acvm-repo/acvm_js/src/foreign_call/outputs.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use acvm::brillig_vm::brillig::{ForeignCallOutput, ForeignCallResult, Value};
use acvm::brillig_vm::brillig::{ForeignCallParam, ForeignCallResult, Value};
use wasm_bindgen::JsValue;

use crate::js_witness_map::js_value_to_field_element;

fn decode_foreign_call_output(output: JsValue) -> Result<ForeignCallOutput, String> {
fn decode_foreign_call_output(output: JsValue) -> Result<ForeignCallParam, String> {
if output.is_string() {
let value = Value::from(js_value_to_field_element(output)?);
Ok(ForeignCallOutput::Single(value))
Ok(ForeignCallParam::Single(value))
} else if output.is_array() {
let output = js_sys::Array::from(&output);

let mut values: Vec<Value> = Vec::with_capacity(output.length() as usize);
for elem in output.iter() {
values.push(Value::from(js_value_to_field_element(elem)?))
values.push(Value::from(js_value_to_field_element(elem)?));
}
Ok(ForeignCallOutput::Array(values))
Ok(ForeignCallParam::Array(values))
} else {
return Err("Non-string-or-array element in foreign_call_handler return".into());
}
Expand All @@ -23,7 +23,7 @@ fn decode_foreign_call_output(output: JsValue) -> Result<ForeignCallOutput, Stri
pub(super) fn decode_foreign_call_result(
js_array: js_sys::Array,
) -> Result<ForeignCallResult, String> {
let mut values: Vec<ForeignCallOutput> = Vec::with_capacity(js_array.length() as usize);
let mut values: Vec<ForeignCallParam> = Vec::with_capacity(js_array.length() as usize);
for elem in js_array.iter() {
values.push(decode_foreign_call_output(elem)?);
}
Expand Down

0 comments on commit 066de05

Please sign in to comment.