Skip to content

Commit

Permalink
Merge branch 'master' into fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
f01dab1e committed Oct 2, 2023
2 parents b23b763 + f7869e6 commit c5c045b
Show file tree
Hide file tree
Showing 32 changed files with 354 additions and 136 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test-noir-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ jobs:
- name: Build noirc_abi
run: yarn workspace @noir-lang/noirc_abi build

- name: Build noir_js_types
run: yarn workspace @noir-lang/types build

- name: Build barretenberg wrapper
run: yarn workspace @noir-lang/backend_barretenberg build

- name: Run noir_js tests
run: |
yarn workspace @noir-lang/noir_js build
Expand Down
32 changes: 10 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions acvm-repo/acvm/src/pwg/brillig.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use acir::{
brillig::{RegisterIndex, Value},
brillig::{ForeignCallParam, RegisterIndex, Value},
circuit::{
brillig::{Brillig, BrilligInputs, BrilligOutputs},
OpcodeLocation,
Expand Down Expand Up @@ -159,5 +159,5 @@ pub struct ForeignCallWaitInfo {
/// An identifier interpreted by the caller process
pub function: String,
/// Resolved inputs to a foreign call computed in the previous steps of a Brillig VM process
pub inputs: Vec<Vec<Value>>,
pub inputs: Vec<ForeignCallParam>,
}
15 changes: 10 additions & 5 deletions acvm-repo/acvm/tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ fn inversion_brillig_oracle_equivalence() {
assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input");

// As caller of VM, need to resolve foreign calls
let foreign_call_result = Value::from(foreign_call_wait_info.inputs[0][0].to_field().inverse());
let foreign_call_result =
Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse());
// Alter Brillig oracle opcode with foreign call resolution
acvm.resolve_pending_foreign_call(foreign_call_result.into());

Expand Down Expand Up @@ -274,7 +275,8 @@ fn double_inversion_brillig_oracle() {
acvm.get_pending_foreign_call().expect("should have a brillig foreign call request");
assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input");

let x_plus_y_inverse = Value::from(foreign_call_wait_info.inputs[0][0].to_field().inverse());
let x_plus_y_inverse =
Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse());

// Resolve Brillig foreign call
acvm.resolve_pending_foreign_call(x_plus_y_inverse.into());
Expand All @@ -291,7 +293,8 @@ fn double_inversion_brillig_oracle() {
acvm.get_pending_foreign_call().expect("should have a brillig foreign call request");
assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input");

let i_plus_j_inverse = Value::from(foreign_call_wait_info.inputs[0][0].to_field().inverse());
let i_plus_j_inverse =
Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse());
assert_ne!(x_plus_y_inverse, i_plus_j_inverse);

// Alter Brillig oracle opcode
Expand Down Expand Up @@ -396,7 +399,8 @@ fn oracle_dependent_execution() {
assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input");

// Resolve Brillig foreign call
let x_inverse = Value::from(foreign_call_wait_info.inputs[0][0].to_field().inverse());
let x_inverse =
Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse());
acvm.resolve_pending_foreign_call(x_inverse.into());

// After filling data request, continue solving
Expand All @@ -412,7 +416,8 @@ fn oracle_dependent_execution() {
assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input");

// Resolve Brillig foreign call
let y_inverse = Value::from(foreign_call_wait_info.inputs[0][0].to_field().inverse());
let y_inverse =
Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse());
acvm.resolve_pending_foreign_call(y_inverse.into());

// We've resolved all the brillig foreign calls so we should be able to complete execution now.
Expand Down
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
2 changes: 1 addition & 1 deletion acvm-repo/barretenberg_blackbox_solver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ wasmer = "3.3"
pkg-config = "0.3"
tar = "~0.4.15"
flate2 = "~1.0.1"
reqwest = { version = "0.11.16", default-features = false, features = [
reqwest = { version = "0.11.20", default-features = false, features = [
"rustls-tls",
"blocking",
] }
Expand Down
40 changes: 34 additions & 6 deletions acvm-repo/brillig/src/foreign_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,60 @@ use serde::{Deserialize, Serialize};

/// Single output of a [foreign call][crate::Opcode::ForeignCall].
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
pub enum ForeignCallOutput {
pub enum ForeignCallParam {
Single(Value),
Array(Vec<Value>),
}

impl From<Value> for ForeignCallParam {
fn from(value: Value) -> Self {
ForeignCallParam::Single(value)
}
}

impl From<Vec<Value>> for ForeignCallParam {
fn from(values: Vec<Value>) -> Self {
ForeignCallParam::Array(values)
}
}

impl ForeignCallParam {
pub fn values(&self) -> Vec<Value> {
match self {
ForeignCallParam::Single(value) => vec![*value],
ForeignCallParam::Array(values) => values.clone(),
}
}

pub fn unwrap_value(&self) -> Value {
match self {
ForeignCallParam::Single(value) => *value,
ForeignCallParam::Array(_) => panic!("Expected single value, found array"),
}
}
}

/// Represents the full output of a [foreign call][crate::Opcode::ForeignCall].
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
pub struct ForeignCallResult {
/// Resolved output values of the foreign call.
pub values: Vec<ForeignCallOutput>,
pub values: Vec<ForeignCallParam>,
}

impl From<Value> for ForeignCallResult {
fn from(value: Value) -> Self {
ForeignCallResult { values: vec![ForeignCallOutput::Single(value)] }
ForeignCallResult { values: vec![value.into()] }
}
}

impl From<Vec<Value>> for ForeignCallResult {
fn from(values: Vec<Value>) -> Self {
ForeignCallResult { values: vec![ForeignCallOutput::Array(values)] }
ForeignCallResult { values: vec![values.into()] }
}
}

impl From<Vec<ForeignCallOutput>> for ForeignCallResult {
fn from(values: Vec<ForeignCallOutput>) -> Self {
impl From<Vec<ForeignCallParam>> for ForeignCallResult {
fn from(values: Vec<ForeignCallParam>) -> Self {
ForeignCallResult { values }
}
}
2 changes: 1 addition & 1 deletion acvm-repo/brillig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod opcodes;
mod value;

pub use black_box::BlackBoxOp;
pub use foreign_call::{ForeignCallOutput, ForeignCallResult};
pub use foreign_call::{ForeignCallParam, ForeignCallResult};
pub use opcodes::{
BinaryFieldOp, BinaryIntOp, HeapArray, HeapVector, RegisterIndex, RegisterOrMemory,
};
Expand Down
Loading

0 comments on commit c5c045b

Please sign in to comment.