Skip to content

Commit

Permalink
feat: hacky integration of new ACVM solver
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jul 5, 2023
1 parent 753e52f commit ad54873
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
12 changes: 6 additions & 6 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +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" }
acvm = { git = "https://github.com/noir-lang/acvm", rev = "fefa4fbf52f92050946f2ff605798e032a4b91c9" }
acvm-backend-barretenberg = { git = "https://github.com/noir-lang/acvm-backend-barretenberg", rev = "447515eff1bed7522c55ec24053b9168bf628553" }
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
18 changes: 10 additions & 8 deletions crates/nargo/src/ops/execute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use acvm::acir::brillig_vm::ForeignCallResult;
use acvm::pwg::{ForeignCallWaitInfo, PartialWitnessGeneratorStatus, ACVM};
use acvm::pwg::{ACVMStatus, ForeignCallWaitInfo, ACVM};
use acvm::BlackBoxFunctionSolver;
use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap};

Expand All @@ -15,15 +15,17 @@ pub fn execute_circuit<B: BlackBoxFunctionSolver + Default>(
// 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
loop {
let solver_status = acvm.solve()?;
let solver_status = acvm.solve();

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);
ACVMStatus::Solved => break,
ACVMStatus::InProgress => {
unreachable!("Execution should not stop while in `InProgress` state.")
}
ACVMStatus::Failure(error) => return Err(error.into()),
ACVMStatus::RequiresForeignCall(unresolved_brillig_call) => {
let foreign_call_result =
execute_foreign_call(&unresolved_brillig_call.foreign_call_wait_info);
acvm.resolve_pending_foreign_call(foreign_call_result);
}
}
Expand Down
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
10 changes: 5 additions & 5 deletions crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn permutation_layer(
mod test {
use acvm::{
acir::native_types::WitnessMap,
pwg::{OpcodeResolutionError, PartialWitnessGeneratorStatus, ACVM},
pwg::{ACVMStatus, OpcodeResolutionError, ACVM},
BlackBoxFunctionSolver, FieldElement,
};

Expand Down Expand Up @@ -192,11 +192,11 @@ mod test {
}
// compute the network output by solving the constraints
let backend = MockBackend {};
let acvm = ACVM::new(backend, eval.opcodes.clone(), initial_witness);
let solver_status = acvm.solve().expect("Could not solve permutation constraints");
assert_eq!(solver_status, PartialWitnessGeneratorStatus::Solved, "Incomplete solution");
let solved_witness = acvm.finalize();
let mut acvm = ACVM::new(backend, eval.opcodes.clone(), initial_witness);
let solver_status = acvm.solve();
assert_eq!(solver_status, ACVMStatus::Solved, "Incomplete solution");

let solved_witness = acvm.finalize();
let mut b_val = Vec::new();
for i in 0..output.len() {
b_val.push(solved_witness[&b_wit[i]]);
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn compile(args: JsValue) -> JsValue {
// For now we default to plonk width = 3, though we can add it as a parameter
let language = acvm::Language::PLONKCSat { width: 3 };
let mut driver = noirc_driver::Driver::new(
&language,
language,
#[allow(deprecated)]
Box::new(acvm::pwg::default_is_opcode_supported(language.clone())),
);
Expand Down

0 comments on commit ad54873

Please sign in to comment.