Skip to content

Commit

Permalink
feat!: update to ACVM 0.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jul 5, 2023
1 parent e55b5a8 commit fcc4e3e
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 120 deletions.
22 changes: 10 additions & 12 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ wasm-bindgen = { version = "0.2.83", features = ["serde-serialize"] }
wasm-bindgen-test = "0.3.33"

[patch.crates-io]
acvm = { git = "https://github.com/noir-lang/acvm", rev = "f1c7940f4ac618c7b440b6ed30199f85cbe72cca" }
acvm-backend-barretenberg = { git = "https://github.com/noir-lang/acvm-backend-barretenberg", rev = "c1575d20d9e7c664e71a79512ad3329c0d8a6a4d" }
async-lsp = { git = "https://github.com/oxalica/async-lsp", rev = "09dbcc11046f7a188a80137f8d36484d86c78c78" }
4 changes: 2 additions & 2 deletions crates/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn on_code_lens_request(
async move {
// TODO: Requiring `Language` and `is_opcode_supported` to construct a driver makes for some real stinky code
// The driver should not require knowledge of the backend; instead should be implemented as an independent pass (in nargo?)
let mut driver = Driver::new(&Language::R1CS, Box::new(|_op| false));
let mut driver = Driver::new(Language::R1CS, Box::new(|_op| false));

let file_path = &params.text_document.uri.to_file_path().unwrap();

Expand Down Expand Up @@ -224,7 +224,7 @@ fn on_did_save_text_document(
) -> ControlFlow<Result<(), async_lsp::Error>> {
// TODO: Requiring `Language` and `is_opcode_supported` to construct a driver makes for some real stinky code
// The driver should not require knowledge of the backend; instead should be implemented as an independent pass (in nargo?)
let mut driver = Driver::new(&Language::R1CS, Box::new(|_op| false));
let mut driver = Driver::new(Language::R1CS, Box::new(|_op| false));

let file_path = &params.text_document.uri.to_file_path().unwrap();

Expand Down
90 changes: 43 additions & 47 deletions crates/nargo/src/ops/execute.rs
Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
use acvm::acir::circuit::Opcode;
use acvm::pwg::{solve, Blocks, PartialWitnessGeneratorStatus, UnresolvedBrilligCall};
use acvm::PartialWitnessGenerator;
use acvm::acir::brillig_vm::ForeignCallResult;
use acvm::pwg::{ForeignCallWaitInfo, PartialWitnessGeneratorStatus, ACVM};
use acvm::BlackBoxFunctionSolver;
use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap};

use crate::NargoError;

pub fn execute_circuit(
backend: &impl PartialWitnessGenerator,
pub fn execute_circuit<B: BlackBoxFunctionSolver + Default>(
_backend: &B,
circuit: Circuit,
mut initial_witness: WitnessMap,
initial_witness: WitnessMap,
) -> Result<WitnessMap, NargoError> {
let mut blocks = Blocks::default();
let solver_status = solve(backend, &mut initial_witness, &mut blocks, circuit.opcodes)?;
let mut acvm = ACVM::new(B::default(), circuit.opcodes, initial_witness);

// TODO(#1615): Nargo only supports "oracle_print_**_impl" functions that print a singular value or an array and nothing else
// This should be expanded in a general logging refactor
if let PartialWitnessGeneratorStatus::RequiresOracleData {
unresolved_brillig_calls,
required_oracle_data,
unsolved_opcodes,
} = solver_status
{
if !required_oracle_data.is_empty() {
unreachable!("oracles are not supported by nargo execute")
}
for unresolved_brillig_call in unresolved_brillig_calls {
let UnresolvedBrilligCall { foreign_call_wait_info, mut brillig } =
unresolved_brillig_call;
loop {
let solver_status = acvm.solve()?;

// Execute foreign calls
// TODO(#1615): "oracle_print_impl" and "oracle_print_array_impl" are just identity funcs
if foreign_call_wait_info.function == "oracle_print_impl" {
let values = &foreign_call_wait_info.inputs[0];
println!("{:?}", values[0].to_field().to_hex());
brillig.foreign_call_results.push(foreign_call_wait_info.inputs[0][0].into());
} else if foreign_call_wait_info.function == "oracle_print_array_impl" {
let mut outputs_hex = Vec::new();
for values in foreign_call_wait_info.inputs.clone() {
for value in values {
outputs_hex.push(value.to_field().to_hex());
}
}
// Join all of the hex strings using a comma
let comma_separated_elements = outputs_hex.join(", ");
let output_witnesses_string = "[".to_owned() + &comma_separated_elements + "]";
println!("{output_witnesses_string}");
brillig.foreign_call_results.push(foreign_call_wait_info.inputs[0][0].into());
match solver_status {
PartialWitnessGeneratorStatus::Solved => break,
PartialWitnessGeneratorStatus::RequiresForeignCall => {
let foreign_call =
acvm.get_pending_foreign_call().expect("Should be waiting on a foreign call");

let foreign_call_result = execute_foreign_call(foreign_call);
acvm.resolve_pending_foreign_call(foreign_call_result);
}
}
}

let mut next_opcodes_for_solving = vec![Opcode::Brillig(brillig)];
next_opcodes_for_solving.extend_from_slice(&unsolved_opcodes[..]);
let solved_witness = acvm.finalize();
Ok(solved_witness)
}

let solver_status =
solve(backend, &mut initial_witness, &mut blocks, next_opcodes_for_solving)?;
if matches!(solver_status, PartialWitnessGeneratorStatus::RequiresOracleData { .. }) {
todo!("Add multiple foreign call support to nargo execute")
// TODO 1557
fn execute_foreign_call(foreign_call: &ForeignCallWaitInfo) -> ForeignCallResult {
// TODO(#1615): "oracle_print_impl" and "oracle_print_array_impl" are just identity funcs

Check warning on line 37 in crates/nargo/src/ops/execute.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (funcs)
match foreign_call.function.as_str() {
"oracle_print_impl" => {
let values = &foreign_call.inputs[0];
println!("{:?}", values[0].to_field().to_hex());
values[0].into()
}
"oracle_print_array_impl" => {
let mut outputs_hex = Vec::new();
for values in &foreign_call.inputs {
for value in values {
outputs_hex.push(value.to_field().to_hex());
}
}
// Join all of the hex strings using a comma
let comma_separated_elements = outputs_hex.join(", ");
let output_witnesses_string = "[".to_owned() + &comma_separated_elements + "]";
println!("{output_witnesses_string}");

foreign_call.inputs[0][0].into()
}
_ => panic!("unexpected foreign call type"),
}

Ok(initial_witness)
}
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod tests {
/// This is used for tests.
fn file_compiles<P: AsRef<Path>>(root_file: P) -> bool {
let mut driver = Driver::new(
&acvm::Language::R1CS,
acvm::Language::R1CS,
#[allow(deprecated)]
Box::new(acvm::pwg::default_is_opcode_supported(acvm::Language::R1CS)),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'a> Resolver<'a> {
np_language: Language,
is_opcode_supported: Box<dyn Fn(&Opcode) -> bool>,
) -> Result<Driver, DependencyResolutionError> {
let mut driver = Driver::new(&np_language, is_opcode_supported);
let mut driver = Driver::new(np_language, is_opcode_supported);
let (entry_path, crate_type) = super::lib_or_bin(dir_path)?;

let manifest_path = super::find_package_manifest(dir_path)?;
Expand Down
14 changes: 6 additions & 8 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ pub type Warnings = Vec<FileDiagnostic>;
pub type ErrorsAndWarnings = Vec<FileDiagnostic>;

impl Driver {
pub fn new(language: &Language, is_opcode_supported: Box<dyn Fn(&Opcode) -> bool>) -> Self {
Driver { context: Context::default(), language: language.clone(), is_opcode_supported }
pub fn new(language: Language, is_opcode_supported: Box<dyn Fn(&Opcode) -> bool>) -> Self {
Driver { context: Context::default(), language, is_opcode_supported }
}

// TODO(#1599): Move control of the FileManager into nargo
Expand All @@ -86,7 +86,7 @@ impl Driver {
// with the restricted version which only uses one file
pub fn compile_file(
root_file: PathBuf,
language: &Language,
language: Language,
is_opcode_supported: Box<dyn Fn(&Opcode) -> bool>,
) -> Result<(CompiledProgram, Warnings), ErrorsAndWarnings> {
let mut driver = Driver::new(language, is_opcode_supported);
Expand Down Expand Up @@ -345,20 +345,18 @@ impl Driver {
) -> Result<CompiledProgram, FileDiagnostic> {
let program = monomorphize(main_function, &self.context.def_interner);

let np_language = self.language.clone();

let circuit_abi = if options.experimental_ssa {
experimental_create_circuit(
program,
np_language,
self.language,
&self.is_opcode_supported,
options.show_ssa,
options.show_output,
)
} else {
create_circuit(
program,
np_language,
self.language,
&self.is_opcode_supported,
options.show_ssa,
options.show_output,
Expand Down Expand Up @@ -408,6 +406,6 @@ impl Driver {
impl Default for Driver {
fn default() -> Self {
#[allow(deprecated)]
Self::new(&Language::R1CS, Box::new(acvm::pwg::default_is_opcode_supported(Language::R1CS)))
Self::new(Language::R1CS, Box::new(acvm::pwg::default_is_opcode_supported(Language::R1CS)))
}
}
2 changes: 1 addition & 1 deletion crates/noirc_driver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
const ROOT_DIR_MAIN: &str = "example_real_project/main.nr";

let mut driver = Driver::new(
&Language::R1CS,
Language::R1CS,
#[allow(deprecated)]
Box::new(acvm::pwg::default_is_opcode_supported(Language::R1CS)),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use crate::ssa_refactor::ir::{
types::{NumericType, Type},
value::{Value, ValueId},
};
use acvm::acir::brillig_vm::{BinaryFieldOp, BinaryIntOp, RegisterIndex, RegisterOrMemory};
use acvm::acir::brillig_vm::{
BinaryFieldOp, BinaryIntOp, HeapArray, RegisterIndex, RegisterOrMemory,
};
use acvm::FieldElement;
use iter_extended::vecmap;

Expand Down Expand Up @@ -440,7 +442,9 @@ impl<'block> BrilligBlock<'block> {
let typ = dfg[value_id].get_type();
match typ {
Type::Numeric(_) => RegisterOrMemory::RegisterIndex(register_index),
Type::Array(_, size) => RegisterOrMemory::HeapArray(register_index, size),
Type::Array(_, size) => {
RegisterOrMemory::HeapArray(HeapArray { pointer: register_index, size })
}
_ => {
unreachable!("type not supported for conversion into brillig register")
}
Expand Down
6 changes: 3 additions & 3 deletions crates/noirc_evaluator/src/brillig/brillig_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ mod tests {
use std::vec;

use acvm::acir::brillig_vm::{
BinaryIntOp, ForeignCallOutput, ForeignCallResult, RegisterIndex, RegisterOrMemory,
Registers, VMStatus, Value, VM,
BinaryIntOp, ForeignCallOutput, ForeignCallResult, HeapVector, RegisterIndex,
RegisterOrMemory, Registers, VMStatus, Value, VM,
};

use crate::brillig::brillig_ir::{BrilligContext, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE};
Expand Down Expand Up @@ -749,7 +749,7 @@ mod tests {
context.foreign_call_instruction(
"make_number_sequence".into(),
&[RegisterOrMemory::RegisterIndex(r_input_size)],
&[RegisterOrMemory::HeapVector(r_stack, r_output_size)],
&[RegisterOrMemory::HeapVector(HeapVector { pointer: r_stack, size: r_output_size })],
);
// push stack frame by r_returned_size
context.binary_instruction(
Expand Down
12 changes: 7 additions & 5 deletions crates/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
///! This module contains functions for producing a higher level view disassembler of Brillig.
use super::BrilligBinaryOp;
use crate::brillig::brillig_ir::{ReservedRegisters, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE};
use acvm::acir::brillig_vm::{BinaryFieldOp, BinaryIntOp, RegisterIndex, RegisterOrMemory, Value};
use acvm::acir::brillig_vm::{
BinaryFieldOp, BinaryIntOp, HeapArray, HeapVector, RegisterIndex, RegisterOrMemory, Value,
};

/// Controls whether debug traces are enabled
const ENABLE_DEBUG_TRACE: bool = true;
Expand Down Expand Up @@ -100,11 +102,11 @@ impl DebugToString for RegisterOrMemory {
fn debug_to_string(&self) -> String {
match self {
RegisterOrMemory::RegisterIndex(index) => index.debug_to_string(),
RegisterOrMemory::HeapArray(index, size) => {
format!("{}[0..{}]", index.debug_to_string(), size)
RegisterOrMemory::HeapArray(HeapArray { pointer, size }) => {
format!("{}[0..{}]", pointer.debug_to_string(), size)
}
RegisterOrMemory::HeapVector(index, size_register) => {
format!("{}[0..*{}]", index.debug_to_string(), size_register.debug_to_string())
RegisterOrMemory::HeapVector(HeapVector { pointer, size }) => {
format!("{}[0..*{}]", pointer.debug_to_string(), size.debug_to_string())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ pub(crate) fn evaluate(
ctx.get_as_constant(args[1]).expect("domain separator to be comptime");
BlackBoxFuncCall::Pedersen {
inputs: resolve_array(&args[0], acir_gen, ctx, evaluator),
outputs: outputs.to_vec(),
outputs: (outputs[0], outputs[1]),
domain_separator: separator.to_u128() as u32,
}
}
BlackBoxFunc::FixedBaseScalarMul => BlackBoxFuncCall::FixedBaseScalarMul {
input: resolve_variable(&args[0], acir_gen, ctx, evaluator).unwrap(),
outputs: outputs.to_vec(),
outputs: (outputs[0], outputs[1]),
},
BlackBoxFunc::SchnorrVerify => BlackBoxFuncCall::SchnorrVerify {
public_key_x: resolve_variable(&args[0], acir_gen, ctx, evaluator).unwrap(),
Expand Down
Loading

0 comments on commit fcc4e3e

Please sign in to comment.