Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: upgrade to acvm 0.8.0 #1047

Merged
merged 3 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ edition = "2021"
rust-version = "1.66"

[workspace.dependencies]
acvm = "0.6.0"
acvm = "0.8.0"
arena = { path = "crates/arena" }
fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
Expand Down
4 changes: 2 additions & 2 deletions crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ color-eyre = "0.6.2"


# Backends
aztec_backend = { optional = true, package = "barretenberg_static_lib", git = "https://github.com/noir-lang/aztec_backend", rev = "2cb523d2ab95249157b22e198d9dcd6841c3eed8" }
aztec_wasm_backend = { optional = true, package = "barretenberg_wasm", git = "https://github.com/noir-lang/aztec_backend", rev = "2cb523d2ab95249157b22e198d9dcd6841c3eed8" }
aztec_backend = { optional = true, package = "barretenberg_static_lib", git = "https://github.com/noir-lang/aztec_backend", rev = "26178359a2251e885f15f0a4d1a686afda04aec9" }
aztec_wasm_backend = { optional = true, package = "barretenberg_wasm", git = "https://github.com/noir-lang/aztec_backend", rev = "26178359a2251e885f15f0a4d1a686afda04aec9" }
marlin_arkworks_backend = { optional = true, git = "https://github.com/noir-lang/marlin_arkworks_backend", rev = "144378edad821bfaa52bf2cacca8ecc87514a4fc" }

[dev-dependencies]
Expand Down
11 changes: 10 additions & 1 deletion crates/nargo/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::Path;

use acvm::pwg::block::Blocks;
use acvm::PartialWitnessGenerator;
use clap::Args;
use noirc_abi::input_parser::{Format, InputValue};
Expand Down Expand Up @@ -67,7 +68,15 @@ pub(crate) fn execute_program(
let mut solved_witness = compiled_program.abi.encode(inputs_map, None)?;

let backend = crate::backends::ConcreteBackend;
backend.solve(&mut solved_witness, compiled_program.circuit.opcodes.clone())?;
let mut blocks = Blocks::default();
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
let (unresolved_opcodes, oracles) = backend.solve(
&mut solved_witness,
&mut blocks,
compiled_program.circuit.opcodes.clone(),
)?;
if !unresolved_opcodes.is_empty() || !oracles.is_empty() {
todo!("Add oracle support to nargo execute")
}

Ok(solved_witness)
}
26 changes: 17 additions & 9 deletions crates/nargo/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::BTreeMap, io::Write, path::Path};

use acvm::{PartialWitnessGenerator, ProofSystemCompiler};
use acvm::{pwg::block::Blocks, PartialWitnessGenerator, ProofSystemCompiler};
use clap::Args;
use noirc_driver::{CompileOptions, Driver};
use noirc_frontend::node_interner::FuncId;
Expand Down Expand Up @@ -79,6 +79,7 @@ fn run_test(
config: &CompileOptions,
) -> Result<(), CliError> {
let backend = crate::backends::ConcreteBackend;
let mut blocks = Blocks::default();

let program = driver
.compile_no_check(config, main)
Expand All @@ -88,13 +89,20 @@ fn run_test(

// Run the backend to ensure the PWG evaluates functions like std::hash::pedersen,
// otherwise constraints involving these expressions will not error.
if let Err(error) = backend.solve(&mut solved_witness, program.circuit.opcodes) {
let writer = StandardStream::stderr(ColorChoice::Always);
let mut writer = writer.lock();
writer.set_color(ColorSpec::new().set_fg(Some(Color::Red))).ok();
writeln!(writer, "failed").ok();
writer.reset().ok();
return Err(error.into());
match backend.solve(&mut solved_witness, &mut blocks, program.circuit.opcodes) {
Ok((unresolved_opcodes, oracles)) => {
if !unresolved_opcodes.is_empty() || !oracles.is_empty() {
todo!("Add oracle support to nargo test")
joss-aztec marked this conversation as resolved.
Show resolved Hide resolved
}
Ok(())
}
Err(error) => {
let writer = StandardStream::stderr(ColorChoice::Always);
let mut writer = writer.lock();
writer.set_color(ColorSpec::new().set_fg(Some(Color::Red))).ok();
writeln!(writer, "failed").ok();
writer.reset().ok();
Err(error.into())
}
}
Ok(())
}
4 changes: 2 additions & 2 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ impl Driver {
let program = monomorphize(main_function, &self.context.def_interner);

let np_language = self.language.clone();
let blackbox_supported = acvm::default_is_black_box_supported(np_language.clone());
let is_opcode_supported = acvm::default_is_opcode_supported(np_language.clone());

match create_circuit(
program,
np_language,
blackbox_supported,
is_opcode_supported,
options.show_ssa,
options.show_output,
) {
Expand Down
10 changes: 6 additions & 4 deletions crates/noirc_evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod ssa;
use acvm::{
acir::circuit::{opcodes::Opcode as AcirOpcode, Circuit, PublicInputs},
acir::native_types::{Expression, Witness},
compiler::transformers::IsBlackBoxSupported,
compiler::transformers::IsOpcodeSupported,
Language,
};
use errors::{RuntimeError, RuntimeErrorKind};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct Evaluator {
pub fn create_circuit(
program: Program,
np_language: Language,
is_blackbox_supported: IsBlackBoxSupported,
is_opcode_supported: IsOpcodeSupported,
enable_logging: bool,
show_output: bool,
) -> Result<(Circuit, Abi), RuntimeError> {
Expand All @@ -70,17 +70,19 @@ pub fn create_circuit(
// see https://github.com/noir-lang/acvm/pull/56
let mut param_witnesses = evaluator.param_witnesses;
let return_witnesses = param_witnesses.remove(MAIN_RETURN_NAME).unwrap_or_default();
let return_witnesses_set: BTreeSet<Witness> = return_witnesses.iter().copied().collect();

let abi = Abi { parameters, param_witnesses, return_type, return_witnesses };

let optimized_circuit = acvm::compiler::compile(
Circuit {
current_witness_index: witness_index,
opcodes: evaluator.opcodes,
public_inputs: PublicInputs(evaluator.public_inputs),
public_parameters: PublicInputs(evaluator.public_inputs),
return_values: PublicInputs(return_witnesses_set),
},
np_language,
is_blackbox_supported,
is_opcode_supported,
)
.map_err(|_| RuntimeErrorKind::Spanless(String::from("produced an acvm compile error")))?;

Expand Down
6 changes: 3 additions & 3 deletions crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use acvm::{
directives::Directive,
opcodes::{BlackBoxFuncCall, FunctionInput, Opcode as AcirOpcode},
},
native_types::{Expression, Linear, Witness},
native_types::{Expression, Witness},
},
FieldElement,
};
Expand Down Expand Up @@ -266,7 +266,7 @@ pub(crate) fn range_constraint(
let exp_big = BigUint::from(2_u128).pow(num_bits - 1);
let exp = FieldElement::from_be_bytes_reduce(&exp_big.to_bytes_be());
evaluator.push_opcode(AcirOpcode::Directive(Directive::Quotient {
a: Linear::from(witness).into(),
a: Expression::from(witness),
b: Expression::from_field(exp),
q: b_witness,
r: r_witness,
Expand Down Expand Up @@ -546,7 +546,7 @@ pub(crate) fn evaluate_udiv(
}));

//r<b
let r_expr = Expression::from(Linear::from_witness(r_witness));
let r_expr = Expression::from(r_witness);
try_range_constraint(r_witness, bit_size, evaluator);
bound_constraint_with_offset(&r_expr, rhs, predicate, bit_size, evaluator);
//range check q<=a
Expand Down
11 changes: 7 additions & 4 deletions crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ mod test {

use acvm::{
acir::{circuit::opcodes::BlackBoxFuncCall, native_types::Witness},
FieldElement, OpcodeResolutionError, PartialWitnessGenerator,
pwg::block::Blocks,
FieldElement, OpcodeResolution, OpcodeResolutionError, PartialWitnessGenerator,
};

use crate::{
Expand All @@ -131,7 +132,7 @@ mod test {
fn solve_black_box_function_call(
_initial_witness: &mut BTreeMap<Witness, FieldElement>,
_func_call: &BlackBoxFuncCall,
) -> Result<(), OpcodeResolutionError> {
) -> Result<OpcodeResolution, OpcodeResolutionError> {
unreachable!();
}
}
Expand Down Expand Up @@ -177,9 +178,11 @@ mod test {
}
// compute the network output by solving the constraints
let backend = MockBackend {};
backend
.solve(&mut solved_witness, eval.opcodes.clone())
let mut blocks = Blocks::default();
let (unresolved_opcodes, oracles) = backend
.solve(&mut solved_witness, &mut blocks, eval.opcodes.clone())
.expect("Could not solve permutation constraints");
assert!(unresolved_opcodes.is_empty() && oracles.is_empty(), "Incomplete solution");
let mut b_val = Vec::new();
for i in 0..output.len() {
b_val.push(solved_witness[&b_wit[i]]);
Expand Down
10 changes: 8 additions & 2 deletions crates/noirc_frontend/src/node_interner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::{BTreeMap, HashMap};

use acvm::acir::circuit::opcodes::BlackBoxFuncCall;
use acvm::acir::circuit::Opcode;
use acvm::Language;
use arena::{Arena, Index};
use fm::FileId;
Expand Down Expand Up @@ -583,12 +585,16 @@ impl NodeInterner {

#[allow(deprecated)]
pub fn foreign(&self, opcode: &str) -> bool {
let is_supported = acvm::default_is_black_box_supported(self.language.clone());
let is_supported = acvm::default_is_opcode_supported(self.language.clone());
let black_box_func = match acvm::acir::BlackBoxFunc::lookup(opcode) {
Some(black_box_func) => black_box_func,
None => return false,
};
is_supported(&black_box_func)
is_supported(&Opcode::BlackBoxFuncCall(BlackBoxFuncCall {
name: black_box_func,
inputs: Vec::new(),
outputs: Vec::new(),
}))
}

pub fn push_delayed_type_check(&mut self, f: TypeCheckFn) {
Expand Down