From 3b1296dc5b7ef5a94c9122fa1476650b7c9962e5 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Tue, 13 Jun 2023 15:54:39 +0100 Subject: [PATCH 01/19] Expand memory on ForeignCall outputs that are greater than the max mem pointer --- brillig_vm/src/lib.rs | 73 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index 7712c7331..3542c931a 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -214,14 +214,25 @@ impl VM { self.registers.set(*index, values[0]) } RegisterValueOrArray::HeapArray(index, size) => { - let destination_value = self.registers.get(*index); assert_eq!( values.len(), *size, "Function result size does not match brillig bytecode" ); + // Convert the destination pointer to a usize + let destination = self.registers.get(*index).to_usize(); + // Expand memory if the array to be written + // will overtake the maximum memory pointer + if (destination + size) >= self.memory.len() { + self.memory.append(&mut vec![ + Value::from(0_usize); + (destination + size) + - self.memory.len() + ]); + } + for (i, value) in values.iter().enumerate() { - self.memory[destination_value.to_usize() + i] = *value; + self.memory[destination + i] = *value; } } } @@ -912,6 +923,64 @@ mod tests { assert_eq!(vm.foreign_call_counter, 1); } + #[test] + fn foreign_call_opcode_memory_alloc_result() { + let r_input = RegisterIndex::from(0); + let r_output = RegisterIndex::from(1); + + // Define a simple 2x2 matrix in memory + let initial_matrix = + vec![Value::from(1u128), Value::from(2u128), Value::from(3u128), Value::from(4u128)]; + + // Transpose of the matrix (but arbitrary for this test, the 'correct value') + let expected_result = + vec![Value::from(1u128), Value::from(3u128), Value::from(2u128), Value::from(4u128)]; + + let invert_program = vec![ + // input = 0 + Opcode::Const { destination: r_input, value: Value::from(0u128) }, + // output = 0 + Opcode::Const { destination: r_output, value: Value::from(4u128) }, + // *output = matrix_2x2_transpose(*input) + Opcode::ForeignCall { + function: "matrix_2x2_transpose".into(), + destinations: vec![RegisterValueOrArray::HeapArray(r_output, initial_matrix.len())], + inputs: vec![RegisterValueOrArray::HeapArray(r_input, initial_matrix.len())], + }, + ]; + + let mut vm = brillig_execute_and_get_vm(initial_matrix.clone(), invert_program); + + // Check that VM is waiting + assert_eq!( + vm.status, + VMStatus::ForeignCallWait { + function: "matrix_2x2_transpose".into(), + inputs: vec![initial_matrix.clone()] + } + ); + + // Push result we're waiting for + vm.foreign_call_results.push(ForeignCallResult { values: vec![expected_result.clone()] }); + + // Resume VM + brillig_execute(&mut vm); + + // Check that VM finished once resumed + assert_eq!(vm.status, VMStatus::Finished); + + // Check initial memory still in place + let initial_values = vm.memory[0..4].to_vec(); + assert_eq!(initial_values, initial_matrix); + + // Check result in memory + let result_values = vm.memory[4..8].to_vec(); + assert_eq!(result_values, expected_result); + + // Ensure the foreign call counter has been incremented + assert_eq!(vm.foreign_call_counter, 1); + } + #[test] fn foreign_call_opcode_multiple_array_inputs_result() { let r_input_a = RegisterIndex::from(0); From 37930976c8d4e1002df7e7e73c4211bf6743acb5 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Jun 2023 13:44:55 -0400 Subject: [PATCH 02/19] Merge --- acvm/src/pwg/mod.rs | 18 ++--- brillig_vm/src/lib.rs | 146 ++++++++++++++++++++++++++++++-------- brillig_vm/src/opcodes.rs | 21 +++++- 3 files changed, 143 insertions(+), 42 deletions(-) diff --git a/acvm/src/pwg/mod.rs b/acvm/src/pwg/mod.rs index 0d455bad8..2b79d5d96 100644 --- a/acvm/src/pwg/mod.rs +++ b/acvm/src/pwg/mod.rs @@ -310,7 +310,7 @@ mod tests { use std::collections::BTreeMap; use acir::{ - brillig_vm::{self, BinaryFieldOp, RegisterIndex, RegisterValueOrArray, Value}, + brillig_vm::{self, BinaryFieldOp, RegisterIndex, RegisterOrMemory, Value}, circuit::{ brillig::{Brillig, BrilligInputs, BrilligOutputs}, directives::Directive, @@ -483,8 +483,8 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![RegisterValueOrArray::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![RegisterValueOrArray::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], }, ], predicate: None, @@ -611,13 +611,13 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![RegisterValueOrArray::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![RegisterValueOrArray::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], }, brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![RegisterValueOrArray::RegisterIndex(RegisterIndex::from(3))], - inputs: vec![RegisterValueOrArray::RegisterIndex(RegisterIndex::from(2))], + destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(3))], + inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(2))], }, ], predicate: None, @@ -759,8 +759,8 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![RegisterValueOrArray::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![RegisterValueOrArray::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], }, ], predicate: Some(Expression::default()), diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index 3542c931a..4c0baf9b0 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -11,7 +11,7 @@ mod registers; mod value; pub use opcodes::Opcode; -pub use opcodes::{BinaryFieldOp, BinaryIntOp, RegisterValueOrArray}; +pub use opcodes::{BinaryFieldOp, BinaryIntOp, RegisterOrMemory}; pub use registers::{RegisterIndex, Registers}; use serde::{Deserialize, Serialize}; pub use value::Typ; @@ -205,32 +205,46 @@ impl VM { for (destination, values) in destinations.iter().zip(values) { match destination { - RegisterValueOrArray::RegisterIndex(index) => { + RegisterOrMemory::RegisterIndex(value_index) => { assert_eq!( values.len(), 1, - "Function result size does not match brillig bytecode" + "Function result size does not match brillig (expected 1 result)" ); - self.registers.set(*index, values[0]) + self.registers.set(*value_index, values[0]) } - RegisterValueOrArray::HeapArray(index, size) => { + RegisterOrMemory::HeapArray(pointer_index, size) => { assert_eq!( values.len(), *size, - "Function result size does not match brillig bytecode" + "Function result size does not match brillig size" ); // Convert the destination pointer to a usize - let destination = self.registers.get(*index).to_usize(); - // Expand memory if the array to be written - // will overtake the maximum memory pointer - if (destination + size) >= self.memory.len() { - self.memory.append(&mut vec![ - Value::from(0_usize); - (destination + size) - - self.memory.len() - ]); + let destination = self.registers.get(*pointer_index).to_usize(); + // Calculate new memory size + let new_size = std::cmp::max(self.memory.len(), destination + size); + // Expand memory to new size with default values if needed + self.memory.resize(new_size, Value::from(0_usize)); + // Write to our destination memory + for (i, value) in values.iter().enumerate() { + self.memory[destination + i] = *value; } - + } + RegisterOrMemory::HeapVector(pointer_index, size_index) => { + // Convert the size pointer to a usize + let size = self.registers.get(*size_index).to_usize(); + assert_eq!( + values.len(), + size, + "Function result size does not match brillig size register" + ); + // Convert the destination pointer to a usize + let destination = self.registers.get(*pointer_index).to_usize(); + // Calculate new memory size + let new_size = std::cmp::max(self.memory.len(), destination + size); + // Expand memory to new size with default values if needed + self.memory.resize(new_size, Value::from(0_usize)); + // Write to our destination memory for (i, value) in values.iter().enumerate() { self.memory[destination + i] = *value; } @@ -308,13 +322,20 @@ impl VM { self.status.clone() } - fn get_register_value_or_memory_values(&self, input: RegisterValueOrArray) -> Vec { + fn get_register_value_or_memory_values(&self, input: RegisterOrMemory) -> Vec { match input { - RegisterValueOrArray::RegisterIndex(index) => vec![self.registers.get(index)], - RegisterValueOrArray::HeapArray(index, size) => { - let start = self.registers.get(index); + RegisterOrMemory::RegisterIndex(value_index) => { + vec![self.registers.get(value_index)] + } + RegisterOrMemory::HeapArray(pointer_index, size) => { + let start = self.registers.get(pointer_index); self.memory[start.to_usize()..(start.to_usize() + size)].to_vec() } + RegisterOrMemory::HeapVector(pointer_index, size_index) => { + let start = self.registers.get(pointer_index); + let size = self.registers.get(size_index); + self.memory[start.to_usize()..(start.to_usize() + size.to_usize())].to_vec() + } } } @@ -349,7 +370,6 @@ impl VM { let rhs_value = self.registers.get(rhs); let result_value = op.evaluate_int(lhs_value.to_u128(), rhs_value.to_u128(), bit_size); - self.registers.set(result, result_value.into()); } } @@ -835,8 +855,8 @@ mod tests { // Call foreign function "double" with the input register Opcode::ForeignCall { function: "double".into(), - destinations: vec![RegisterValueOrArray::RegisterIndex(r_result)], - inputs: vec![RegisterValueOrArray::RegisterIndex(r_input)], + destinations: vec![RegisterOrMemory::RegisterIndex(r_result)], + inputs: vec![RegisterOrMemory::RegisterIndex(r_input)], }, ]; @@ -890,8 +910,8 @@ mod tests { // *output = matrix_2x2_transpose(*input) Opcode::ForeignCall { function: "matrix_2x2_transpose".into(), - destinations: vec![RegisterValueOrArray::HeapArray(r_output, initial_matrix.len())], - inputs: vec![RegisterValueOrArray::HeapArray(r_input, initial_matrix.len())], + destinations: vec![RegisterOrMemory::HeapArray(r_output, initial_matrix.len())], + inputs: vec![RegisterOrMemory::HeapArray(r_input, initial_matrix.len())], }, ]; @@ -923,6 +943,72 @@ mod tests { assert_eq!(vm.foreign_call_counter, 1); } + /// Calling a foreign call identity function that takes any string input and concatenates it with itself + #[test] + fn foreign_call_opcode_vector_input_and_output() { + let r_input_pointer = RegisterIndex::from(0); + let r_input_size = RegisterIndex::from(1); + // We need to pass a location of appropriate size + let r_output_pointer = RegisterIndex::from(2); + let r_output_size = RegisterIndex::from(3); + + // Our first string to use the identity function with + let input_string = + vec![Value::from(1u128), Value::from(2u128), Value::from(3u128), Value::from(4u128)]; + // Double the string (concate it with itself) + let output_string: Vec = + input_string.iter().cloned().chain(input_string.clone()).collect(); + + // Expected results are the same as the initial results + // First call: + let string_double_program = vec![ + // input_pointer = 0 + Opcode::Const { destination: r_input_pointer, value: Value::from(0u128) }, + // input_size = input_string.len() (constant here) + Opcode::Const { destination: r_input_size, value: Value::from(input_string.len()) }, + // output_pointer = 0 + input_size = input_size + Opcode::Const { destination: r_output_pointer, value: Value::from(input_string.len()) }, + // output_size = input_size * 2 + Opcode::Const { + destination: r_output_size, + value: Value::from(input_string.len() * 2), + }, + // output_pointer[0..output_size] = string_double(input_pointer[0...input_size]) + Opcode::ForeignCall { + function: "string_double".into(), + destinations: vec![RegisterOrMemory::HeapVector(r_output_pointer, r_output_size)], + inputs: vec![RegisterOrMemory::HeapVector(r_input_pointer, r_input_size)], + }, + ]; + + let mut vm = brillig_execute_and_get_vm(input_string.clone(), string_double_program); + + // Check that VM is waiting + assert_eq!( + vm.status, + VMStatus::ForeignCallWait { + function: "string_double".into(), + inputs: vec![input_string] + } + ); + + // Push result we're waiting for + vm.foreign_call_results.push(ForeignCallResult { values: vec![output_string.clone()] }); + + // Resume VM + brillig_execute(&mut vm); + + // Check that VM finished once resumed + assert_eq!(vm.status, VMStatus::Finished); + + // Check result in memory + let result_values = vm.memory[0..4].to_vec(); + assert_eq!(result_values, output_string); + + // Ensure the foreign call counter has been incremented + assert_eq!(vm.foreign_call_counter, 1); + } + #[test] fn foreign_call_opcode_memory_alloc_result() { let r_input = RegisterIndex::from(0); @@ -944,8 +1030,8 @@ mod tests { // *output = matrix_2x2_transpose(*input) Opcode::ForeignCall { function: "matrix_2x2_transpose".into(), - destinations: vec![RegisterValueOrArray::HeapArray(r_output, initial_matrix.len())], - inputs: vec![RegisterValueOrArray::HeapArray(r_input, initial_matrix.len())], + destinations: vec![RegisterOrMemory::HeapArray(r_output, initial_matrix.len())], + inputs: vec![RegisterOrMemory::HeapArray(r_input, initial_matrix.len())], }, ]; @@ -1016,10 +1102,10 @@ mod tests { // *output = matrix_2x2_transpose(*input) Opcode::ForeignCall { function: "matrix_2x2_transpose".into(), - destinations: vec![RegisterValueOrArray::HeapArray(r_output, matrix_a.len())], + destinations: vec![RegisterOrMemory::HeapArray(r_output, matrix_a.len())], inputs: vec![ - RegisterValueOrArray::HeapArray(r_input_a, matrix_a.len()), - RegisterValueOrArray::HeapArray(r_input_b, matrix_b.len()), + RegisterOrMemory::HeapArray(r_input_a, matrix_a.len()), + RegisterOrMemory::HeapArray(r_input_b, matrix_b.len()), ], }, ]; diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index 565f48beb..2df731e75 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -4,10 +4,25 @@ use serde::{Deserialize, Serialize}; pub type Label = usize; +/// Lays out various ways we might interpret memory when passing to a foreign call external from Brillig. +/// +/// While we are usually are agnostic to how memory is passed within Brillig, +/// this needs to be encoded somehow when dealing with an external system. +/// For simplicity, the extra type information is given right in the ForeignCall instructions. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy)] -pub enum RegisterValueOrArray { +pub enum RegisterOrMemory { + /// An immediate value passed to or from an external call + /// For a foreign call input, this is read directly from the register. + /// For a foreign call output, this is written directly to the register. RegisterIndex(RegisterIndex), + /// A fix-sized array passed starting from a Brillig register memory location. + /// In the case of a foreign call input, this is read from this Brillig memory location + usize more cells. + /// In the case of a foreign call output, this is written to this Brillig memory location with the usize being here just as a sanity check for the size write. HeapArray(RegisterIndex, usize), + /// A register-sized vector passed starting from a Brillig register memory location and with a register-held size + /// In the case of a foreign call input, this is read from this Brillig memory location + as many cells as the 2nd register indicates. + /// In the case of a foreign call output, this is written to this Brillig memory location with the usize being here just as a sanity check for the size write. + HeapVector(RegisterIndex, RegisterIndex), } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -64,9 +79,9 @@ pub enum Opcode { /// who the caller is. function: String, /// Destination registers (may be single values or memory pointers). - destinations: Vec, + destinations: Vec, /// Input registers (may be single values or memory pointers). - inputs: Vec, + inputs: Vec, }, Mov { destination: RegisterIndex, From 0a5fea969631da4c1a36d39613406f913e5aed57 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Jun 2023 13:48:19 -0400 Subject: [PATCH 03/19] fix: tests --- brillig_vm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index 4c0baf9b0..ac01803f8 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -1002,7 +1002,7 @@ mod tests { assert_eq!(vm.status, VMStatus::Finished); // Check result in memory - let result_values = vm.memory[0..4].to_vec(); + let result_values = vm.memory[0..output_string.len()].to_vec(); assert_eq!(result_values, output_string); // Ensure the foreign call counter has been incremented From edad61326f06948cd49283cd151a9701bf22a82f Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Jun 2023 13:56:54 -0400 Subject: [PATCH 04/19] fix: Spelling --- brillig_vm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index ac01803f8..1db7086e1 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -955,7 +955,7 @@ mod tests { // Our first string to use the identity function with let input_string = vec![Value::from(1u128), Value::from(2u128), Value::from(3u128), Value::from(4u128)]; - // Double the string (concate it with itself) + // Double the string (concatenate it with itself) let output_string: Vec = input_string.iter().cloned().chain(input_string.clone()).collect(); From 081cd7f6a683c648a18aaeb413684c8158a98cda Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Jun 2023 13:59:10 -0400 Subject: [PATCH 05/19] fix: Comment --- brillig_vm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index 1db7086e1..c10366b4b 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -943,7 +943,7 @@ mod tests { assert_eq!(vm.foreign_call_counter, 1); } - /// Calling a foreign call identity function that takes any string input and concatenates it with itself + /// Calling a simple foreign call function that takes any string input and concatenates it with itself #[test] fn foreign_call_opcode_vector_input_and_output() { let r_input_pointer = RegisterIndex::from(0); From feb6d9012a36e881172310fdfaa980b09ae18597 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Jun 2023 13:59:59 -0400 Subject: [PATCH 06/19] fix: Comment --- brillig_vm/src/opcodes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index 2df731e75..7911d4a7e 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -6,7 +6,7 @@ pub type Label = usize; /// Lays out various ways we might interpret memory when passing to a foreign call external from Brillig. /// -/// While we are usually are agnostic to how memory is passed within Brillig, +/// While we are usually agnostic to how memory is passed within Brillig, /// this needs to be encoded somehow when dealing with an external system. /// For simplicity, the extra type information is given right in the ForeignCall instructions. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy)] From 2c97e73cec7fbeb9b0b6f814d3cee68191182380 Mon Sep 17 00:00:00 2001 From: ludamad Date: Tue, 13 Jun 2023 14:02:20 -0400 Subject: [PATCH 07/19] fix: Comment --- brillig_vm/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index c10366b4b..c42d23c2d 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -959,7 +959,6 @@ mod tests { let output_string: Vec = input_string.iter().cloned().chain(input_string.clone()).collect(); - // Expected results are the same as the initial results // First call: let string_double_program = vec![ // input_pointer = 0 From dd05610dcdab4f1f383e42f772c829ab22f2293d Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 14 Jun 2023 11:00:40 +0100 Subject: [PATCH 08/19] update vector string concatenation test --- brillig_vm/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index c42d23c2d..269b2e99a 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -943,7 +943,7 @@ mod tests { assert_eq!(vm.foreign_call_counter, 1); } - /// Calling a simple foreign call function that takes any string input and concatenates it with itself + /// Calling a simple foreign call function that takes any string input, concatenates it with itself, and reverses the concatenation #[test] fn foreign_call_opcode_vector_input_and_output() { let r_input_pointer = RegisterIndex::from(0); @@ -956,8 +956,10 @@ mod tests { let input_string = vec![Value::from(1u128), Value::from(2u128), Value::from(3u128), Value::from(4u128)]; // Double the string (concatenate it with itself) - let output_string: Vec = + let mut output_string: Vec = input_string.iter().cloned().chain(input_string.clone()).collect(); + // Reverse the concatenated string + output_string.reverse(); // First call: let string_double_program = vec![ @@ -987,7 +989,7 @@ mod tests { vm.status, VMStatus::ForeignCallWait { function: "string_double".into(), - inputs: vec![input_string] + inputs: vec![input_string.clone()] } ); @@ -1001,7 +1003,8 @@ mod tests { assert_eq!(vm.status, VMStatus::Finished); // Check result in memory - let result_values = vm.memory[0..output_string.len()].to_vec(); + let result_values = + vm.memory[input_string.len()..(input_string.len() + output_string.len())].to_vec(); assert_eq!(result_values, output_string); // Ensure the foreign call counter has been incremented From 83c58dc66f9f9249f6d561b19695300e54fabc1f Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 14 Jun 2023 11:55:15 +0100 Subject: [PATCH 09/19] switch usage of nested vector to enum ForeignCallOutput --- acvm/src/pwg/mod.rs | 9 ++- brillig_vm/src/lib.rs | 132 +++++++++++++++++++++++++----------------- 2 files changed, 82 insertions(+), 59 deletions(-) diff --git a/acvm/src/pwg/mod.rs b/acvm/src/pwg/mod.rs index 2b79d5d96..5a8774a4b 100644 --- a/acvm/src/pwg/mod.rs +++ b/acvm/src/pwg/mod.rs @@ -535,9 +535,8 @@ mod tests { "Should be waiting for a single input" ); // As caller of VM, need to resolve foreign calls - let foreign_call_result = vec![Value::from( - foreign_call.foreign_call_wait_info.inputs[0][0].to_field().inverse(), - )]; + let foreign_call_result = + Value::from(foreign_call.foreign_call_wait_info.inputs[0][0].to_field().inverse()); // Alter Brillig oracle opcode with foreign call resolution let brillig: Brillig = foreign_call.resolve(foreign_call_result.into()); let mut next_opcodes_for_solving = vec![Opcode::Brillig(brillig)]; @@ -673,7 +672,7 @@ mod tests { let x_plus_y_inverse = foreign_call.foreign_call_wait_info.inputs[0][0].to_field().inverse(); // Alter Brillig oracle opcode - let brillig: Brillig = foreign_call.resolve(vec![Value::from(x_plus_y_inverse)].into()); + let brillig: Brillig = foreign_call.resolve(Value::from(x_plus_y_inverse).into()); let mut next_opcodes_for_solving = vec![Opcode::Brillig(brillig)]; next_opcodes_for_solving.extend_from_slice(&unsolved_opcodes[..]); @@ -699,7 +698,7 @@ mod tests { foreign_call.foreign_call_wait_info.inputs[0][0].to_field().inverse(); assert_ne!(x_plus_y_inverse, i_plus_j_inverse); // Alter Brillig oracle opcode - let brillig = foreign_call.resolve(vec![Value::from(i_plus_j_inverse)].into()); + let brillig = foreign_call.resolve(Value::from(i_plus_j_inverse).into()); let mut next_opcodes_for_solving = vec![Opcode::Brillig(brillig)]; next_opcodes_for_solving.extend_from_slice(&unsolved_opcodes[..]); diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index 269b2e99a..436f8a410 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -39,25 +39,31 @@ pub enum VMStatus { }, } -/// Represents the output of a [foreign call][Opcode::ForeignCall]. +/// Single output of a [foreign call][Opcode::ForeignCall]. +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +pub enum ForeignCallOutput { + Single(Value), + Array(Vec), +} + +/// Represents the full output of a [foreign call][Opcode::ForeignCall]. /// /// See [`VMStatus::ForeignCallWait`] for more information. #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] pub struct ForeignCallResult { /// Resolved output values of the foreign call. - /// Each output is its own list of values as an output can be either a single value or a memory pointer - pub values: Vec>, + pub values: Vec, } -impl From> for ForeignCallResult { - fn from(values: Vec) -> Self { - ForeignCallResult { values: vec![values] } +impl From for ForeignCallResult { + fn from(value: Value) -> Self { + ForeignCallResult { values: vec![ForeignCallOutput::Single(value)] } } } -impl From>> for ForeignCallResult { - fn from(values: Vec>) -> Self { - ForeignCallResult { values } +impl From> for ForeignCallResult { + fn from(values: Vec) -> Self { + ForeignCallResult { values: vec![ForeignCallOutput::Array(values)] } } } @@ -203,50 +209,66 @@ impl VM { let ForeignCallResult { values } = &self.foreign_call_results[self.foreign_call_counter]; - for (destination, values) in destinations.iter().zip(values) { + for (destination, output) in destinations.iter().zip(values) { match destination { - RegisterOrMemory::RegisterIndex(value_index) => { - assert_eq!( - values.len(), - 1, + RegisterOrMemory::RegisterIndex(value_index) => match output { + ForeignCallOutput::Single(value) => { + self.registers.set(*value_index, *value) + } + _ => unreachable!( "Function result size does not match brillig (expected 1 result)" - ); - self.registers.set(*value_index, values[0]) - } + ), + }, RegisterOrMemory::HeapArray(pointer_index, size) => { - assert_eq!( - values.len(), - *size, - "Function result size does not match brillig size" - ); - // Convert the destination pointer to a usize - let destination = self.registers.get(*pointer_index).to_usize(); - // Calculate new memory size - let new_size = std::cmp::max(self.memory.len(), destination + size); - // Expand memory to new size with default values if needed - self.memory.resize(new_size, Value::from(0_usize)); - // Write to our destination memory - for (i, value) in values.iter().enumerate() { - self.memory[destination + i] = *value; + match output { + ForeignCallOutput::Array(values) => { + assert_eq!( + values.len(), + *size, + "Function result size does not match brillig size" + ); + // Convert the destination pointer to a usize + let destination = self.registers.get(*pointer_index).to_usize(); + // Calculate new memory size + let new_size = + std::cmp::max(self.memory.len(), destination + size); + // Expand memory to new size with default values if needed + self.memory.resize(new_size, Value::from(0_usize)); + // Write to our destination memory + for (i, value) in values.iter().enumerate() { + self.memory[destination + i] = *value; + } + } + _ => { + unreachable!("Function result size does not match brillig size") + } } } RegisterOrMemory::HeapVector(pointer_index, size_index) => { - // Convert the size pointer to a usize - let size = self.registers.get(*size_index).to_usize(); - assert_eq!( - values.len(), - size, - "Function result size does not match brillig size register" - ); - // Convert the destination pointer to a usize - let destination = self.registers.get(*pointer_index).to_usize(); - // Calculate new memory size - let new_size = std::cmp::max(self.memory.len(), destination + size); - // Expand memory to new size with default values if needed - self.memory.resize(new_size, Value::from(0_usize)); - // Write to our destination memory - for (i, value) in values.iter().enumerate() { - self.memory[destination + i] = *value; + match output { + ForeignCallOutput::Array(values) => { + // Convert the size pointer to a usize + let size = self.registers.get(*size_index).to_usize(); + assert_eq!( + values.len(), + size, + "Function result size does not match brillig size register" + ); + // Convert the destination pointer to a usize + let destination = self.registers.get(*pointer_index).to_usize(); + // Calculate new memory size + let new_size = + std::cmp::max(self.memory.len(), destination + size); + // Expand memory to new size with default values if needed + self.memory.resize(new_size, Value::from(0_usize)); + // Write to our destination memory + for (i, value) in values.iter().enumerate() { + self.memory[destination + i] = *value; + } + } + _ => { + unreachable!("Function result size does not match brillig size") + } } } } @@ -872,9 +894,9 @@ mod tests { ); // Push result we're waiting for - vm.foreign_call_results.push(ForeignCallResult { - values: vec![vec![Value::from(10u128)]], // Result of doubling 5u128 - }); + vm.foreign_call_results.push( + Value::from(10u128).into(), // Result of doubling 5u128 + ); // Resume VM brillig_execute(&mut vm); @@ -927,7 +949,7 @@ mod tests { ); // Push result we're waiting for - vm.foreign_call_results.push(ForeignCallResult { values: vec![expected_result.clone()] }); + vm.foreign_call_results.push(expected_result.clone().into()); // Resume VM brillig_execute(&mut vm); @@ -994,7 +1016,9 @@ mod tests { ); // Push result we're waiting for - vm.foreign_call_results.push(ForeignCallResult { values: vec![output_string.clone()] }); + vm.foreign_call_results.push(ForeignCallResult { + values: vec![ForeignCallOutput::Array(output_string.clone())], + }); // Resume VM brillig_execute(&mut vm); @@ -1049,7 +1073,7 @@ mod tests { ); // Push result we're waiting for - vm.foreign_call_results.push(ForeignCallResult { values: vec![expected_result.clone()] }); + vm.foreign_call_results.push(expected_result.clone().into()); // Resume VM brillig_execute(&mut vm); @@ -1125,7 +1149,7 @@ mod tests { ); // Push result we're waiting for - vm.foreign_call_results.push(ForeignCallResult { values: vec![expected_result.clone()] }); + vm.foreign_call_results.push(expected_result.clone().into()); // Resume VM brillig_execute(&mut vm); From 75da5a89a667e347d55ecd4c87450278a810d0bb Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Jun 2023 07:55:50 -0400 Subject: [PATCH 10/19] Update brillig_vm/src/opcodes.rs Co-authored-by: Maxim Vezenov --- brillig_vm/src/opcodes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index 7911d4a7e..6952da4f8 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -16,8 +16,8 @@ pub enum RegisterOrMemory { /// For a foreign call output, this is written directly to the register. RegisterIndex(RegisterIndex), /// A fix-sized array passed starting from a Brillig register memory location. - /// In the case of a foreign call input, this is read from this Brillig memory location + usize more cells. - /// In the case of a foreign call output, this is written to this Brillig memory location with the usize being here just as a sanity check for the size write. + /// In the case of a foreign call input, the array is read from this Brillig memory location + usize more cells. + /// In the case of a foreign call output, the array is written to this Brillig memory location with the usize being here just as a sanity check for the size write. HeapArray(RegisterIndex, usize), /// A register-sized vector passed starting from a Brillig register memory location and with a register-held size /// In the case of a foreign call input, this is read from this Brillig memory location + as many cells as the 2nd register indicates. From c0c217038cad0590699aad6524132bc5f21fe137 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Jun 2023 07:57:05 -0400 Subject: [PATCH 11/19] Update brillig_vm/src/opcodes.rs Co-authored-by: Maxim Vezenov --- brillig_vm/src/opcodes.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index 6952da4f8..a0547992e 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -4,7 +4,8 @@ use serde::{Deserialize, Serialize}; pub type Label = usize; -/// Lays out various ways we might interpret memory when passing to a foreign call external from Brillig. +/// Lays out various ways an external foreign call's input and output data may be interpreted inside Brillig. +/// This data can either be an individual register value or memory. /// /// While we are usually agnostic to how memory is passed within Brillig, /// this needs to be encoded somehow when dealing with an external system. From c45862a9e342226489daf85d52c184787dcc4a12 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Jun 2023 07:57:15 -0400 Subject: [PATCH 12/19] Update brillig_vm/src/opcodes.rs Co-authored-by: Maxim Vezenov --- brillig_vm/src/opcodes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index a0547992e..e8b287b78 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -14,7 +14,7 @@ pub type Label = usize; pub enum RegisterOrMemory { /// An immediate value passed to or from an external call /// For a foreign call input, this is read directly from the register. - /// For a foreign call output, this is written directly to the register. + /// For a foreign call output, the value is written directly to the register. RegisterIndex(RegisterIndex), /// A fix-sized array passed starting from a Brillig register memory location. /// In the case of a foreign call input, the array is read from this Brillig memory location + usize more cells. From 0d2d60f4927c41054dc6c1ddfd7cc3862afde78e Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Jun 2023 07:58:14 -0400 Subject: [PATCH 13/19] Update lib.rs --- brillig_vm/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index 269b2e99a..6750e54d0 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -209,7 +209,7 @@ impl VM { assert_eq!( values.len(), 1, - "Function result size does not match brillig (expected 1 result)" + "Function result size does not match brillig bytecode (expected 1 result)" ); self.registers.set(*value_index, values[0]) } @@ -217,7 +217,7 @@ impl VM { assert_eq!( values.len(), *size, - "Function result size does not match brillig size" + "Function result size does not match brillig bytecode size" ); // Convert the destination pointer to a usize let destination = self.registers.get(*pointer_index).to_usize(); @@ -236,7 +236,7 @@ impl VM { assert_eq!( values.len(), size, - "Function result size does not match brillig size register" + "Function result size does not match brillig bytecode size register" ); // Convert the destination pointer to a usize let destination = self.registers.get(*pointer_index).to_usize(); From 543dfc25ad838c471fa3c7781fb603aee9e236d9 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Jun 2023 07:58:27 -0400 Subject: [PATCH 14/19] Update brillig_vm/src/opcodes.rs Co-authored-by: Maxim Vezenov --- brillig_vm/src/opcodes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index e8b287b78..ccb24539c 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -13,7 +13,7 @@ pub type Label = usize; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy)] pub enum RegisterOrMemory { /// An immediate value passed to or from an external call - /// For a foreign call input, this is read directly from the register. + /// For a foreign call input, the value is read directly from the register. /// For a foreign call output, the value is written directly to the register. RegisterIndex(RegisterIndex), /// A fix-sized array passed starting from a Brillig register memory location. From 21f1d2c6a943efb93515f0a11f4de5ffcdab3ce9 Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Jun 2023 07:58:47 -0400 Subject: [PATCH 15/19] Update brillig_vm/src/opcodes.rs Co-authored-by: Maxim Vezenov --- brillig_vm/src/opcodes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index ccb24539c..62493a4f0 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -21,8 +21,8 @@ pub enum RegisterOrMemory { /// In the case of a foreign call output, the array is written to this Brillig memory location with the usize being here just as a sanity check for the size write. HeapArray(RegisterIndex, usize), /// A register-sized vector passed starting from a Brillig register memory location and with a register-held size - /// In the case of a foreign call input, this is read from this Brillig memory location + as many cells as the 2nd register indicates. - /// In the case of a foreign call output, this is written to this Brillig memory location with the usize being here just as a sanity check for the size write. + /// In the case of a foreign call input, the vector is read from this Brillig memory location + as many cells as the 2nd register indicates. + /// In the case of a foreign call output, the vector is written to this Brillig memory location with the usize being here just as a sanity check for the size write. HeapVector(RegisterIndex, RegisterIndex), } From 7c996c49373abb052a095ddf322d4acf22374b7e Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Jun 2023 08:00:08 -0400 Subject: [PATCH 16/19] Update opcodes.rs --- brillig_vm/src/opcodes.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index 62493a4f0..34822525b 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -12,7 +12,8 @@ pub type Label = usize; /// For simplicity, the extra type information is given right in the ForeignCall instructions. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy)] pub enum RegisterOrMemory { - /// An immediate value passed to or from an external call + /// A single register value passed to or from an external call + /// It is an 'immediate' value - used without dereferencing memory. /// For a foreign call input, the value is read directly from the register. /// For a foreign call output, the value is written directly to the register. RegisterIndex(RegisterIndex), From dcb94edeefedf0b743468f4e74964d313aa421fb Mon Sep 17 00:00:00 2001 From: ludamad Date: Wed, 14 Jun 2023 22:08:08 -0400 Subject: [PATCH 17/19] fix: allow size returned from foreign call --- acvm/src/pwg/mod.rs | 18 +++++++++--------- brillig_vm/src/lib.rs | 11 +++-------- brillig_vm/src/opcodes.rs | 2 +- cspell.json | 1 + 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/acvm/src/pwg/mod.rs b/acvm/src/pwg/mod.rs index 5a8774a4b..dc4c9a607 100644 --- a/acvm/src/pwg/mod.rs +++ b/acvm/src/pwg/mod.rs @@ -310,7 +310,7 @@ mod tests { use std::collections::BTreeMap; use acir::{ - brillig_vm::{self, BinaryFieldOp, RegisterIndex, RegisterOrMemory, Value}, + brillig_vm::{self, BinaryFieldOp, ForeignCallInput, RegisterIndex, Value}, circuit::{ brillig::{Brillig, BrilligInputs, BrilligOutputs}, directives::Directive, @@ -483,8 +483,8 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(0))], }, ], predicate: None, @@ -610,13 +610,13 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(0))], }, brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(3))], - inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(2))], + destinations: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(3))], + inputs: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(2))], }, ], predicate: None, @@ -758,8 +758,8 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(0))], }, ], predicate: Some(Expression::default()), diff --git a/brillig_vm/src/lib.rs b/brillig_vm/src/lib.rs index 98584ba36..303c9eecd 100644 --- a/brillig_vm/src/lib.rs +++ b/brillig_vm/src/lib.rs @@ -247,18 +247,13 @@ impl VM { RegisterOrMemory::HeapVector(pointer_index, size_index) => { match output { ForeignCallOutput::Array(values) => { - // Convert the size pointer to a usize - let size = self.registers.get(*size_index).to_usize(); - assert_eq!( - values.len(), - size, - "Function result size does not match brillig bytecode size register" - ); + // Set our size in the size register + self.registers.set(*size_index, Value::from(values.len())); // Convert the destination pointer to a usize let destination = self.registers.get(*pointer_index).to_usize(); // Calculate new memory size let new_size = - std::cmp::max(self.memory.len(), destination + size); + std::cmp::max(self.memory.len(), destination + values.len()); // Expand memory to new size with default values if needed self.memory.resize(new_size, Value::from(0_usize)); // Write to our destination memory diff --git a/brillig_vm/src/opcodes.rs b/brillig_vm/src/opcodes.rs index 34822525b..cd531934a 100644 --- a/brillig_vm/src/opcodes.rs +++ b/brillig_vm/src/opcodes.rs @@ -23,7 +23,7 @@ pub enum RegisterOrMemory { HeapArray(RegisterIndex, usize), /// A register-sized vector passed starting from a Brillig register memory location and with a register-held size /// In the case of a foreign call input, the vector is read from this Brillig memory location + as many cells as the 2nd register indicates. - /// In the case of a foreign call output, the vector is written to this Brillig memory location with the usize being here just as a sanity check for the size write. + /// In the case of a foreign call output, the vector is written to this Brillig memory location and as 'size' cells, with size being stored in the second register. HeapVector(RegisterIndex, RegisterIndex), } diff --git a/cspell.json b/cspell.json index f03f326c7..8a4dc7645 100644 --- a/cspell.json +++ b/cspell.json @@ -20,6 +20,7 @@ "deflater", "endianness", "euclidian", + "funcs", "hasher", "keccak", "Merkle", From fa064db9d1eb1697cbab281c1591de566f9fab64 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Thu, 15 Jun 2023 10:20:35 +0000 Subject: [PATCH 18/19] use RegisterOrMemory not ForeignCallInput which does not exist --- acvm/src/pwg/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/acvm/src/pwg/mod.rs b/acvm/src/pwg/mod.rs index dc4c9a607..952d98519 100644 --- a/acvm/src/pwg/mod.rs +++ b/acvm/src/pwg/mod.rs @@ -310,7 +310,7 @@ mod tests { use std::collections::BTreeMap; use acir::{ - brillig_vm::{self, BinaryFieldOp, ForeignCallInput, RegisterIndex, Value}, + brillig_vm::{self, BinaryFieldOp, RegisterOrMemory, RegisterIndex, Value}, circuit::{ brillig::{Brillig, BrilligInputs, BrilligOutputs}, directives::Directive, @@ -483,8 +483,8 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], }, ], predicate: None, @@ -610,13 +610,13 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], }, brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(3))], - inputs: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(2))], + destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(3))], + inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(2))], }, ], predicate: None, @@ -758,8 +758,8 @@ mod tests { // Oracles are named 'foreign calls' in brillig brillig_vm::Opcode::ForeignCall { function: "invert".into(), - destinations: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(1))], - inputs: vec![ForeignCallInput::RegisterIndex(RegisterIndex::from(0))], + destinations: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(1))], + inputs: vec![RegisterOrMemory::RegisterIndex(RegisterIndex::from(0))], }, ], predicate: Some(Expression::default()), From ee0ef48dbdc09ce6b5bcc11bf618129166afd78f Mon Sep 17 00:00:00 2001 From: vezenovm Date: Thu, 15 Jun 2023 10:27:18 +0000 Subject: [PATCH 19/19] cargo fmt --- acvm/src/pwg/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acvm/src/pwg/mod.rs b/acvm/src/pwg/mod.rs index 952d98519..5a8774a4b 100644 --- a/acvm/src/pwg/mod.rs +++ b/acvm/src/pwg/mod.rs @@ -310,7 +310,7 @@ mod tests { use std::collections::BTreeMap; use acir::{ - brillig_vm::{self, BinaryFieldOp, RegisterOrMemory, RegisterIndex, Value}, + brillig_vm::{self, BinaryFieldOp, RegisterIndex, RegisterOrMemory, Value}, circuit::{ brillig::{Brillig, BrilligInputs, BrilligOutputs}, directives::Directive,