Skip to content

Commit

Permalink
feat: update to ACVM 0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Apr 27, 2023
1 parent 0f817df commit be16e46
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 129 deletions.
108 changes: 12 additions & 96 deletions Cargo.lock

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

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

[workspace.dependencies]
acvm = "0.9.0"
#acvm = "0.9.0"
acvm = { git = "https://github.com/noir-lang/acvm", rev = "15d3c5a9be2dd92f266fcb7e672da17cada9fec5", features = ["bn254"] }
arena = { path = "crates/arena" }
fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
Expand Down
7 changes: 3 additions & 4 deletions crates/nargo/src/ops/execute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use acvm::PartialWitnessGenerator;
use acvm::{acir::circuit::Circuit, pwg::block::Blocks};
use acvm::{PartialWitnessGenerator, PartialWitnessGeneratorStatus};
use noirc_abi::WitnessMap;

use crate::NargoError;
Expand All @@ -10,9 +10,8 @@ pub fn execute_circuit(
mut initial_witness: WitnessMap,
) -> Result<WitnessMap, NargoError> {
let mut blocks = Blocks::default();
let (unresolved_opcodes, oracles) =
backend.solve(&mut initial_witness, &mut blocks, circuit.opcodes)?;
if !unresolved_opcodes.is_empty() || !oracles.is_empty() {
let solver_status = backend.solve(&mut initial_witness, &mut blocks, circuit.opcodes)?;
if matches!(solver_status, PartialWitnessGeneratorStatus::RequiresOracleData { .. }) {
todo!("Add oracle support to nargo execute")
}

Expand Down
2 changes: 1 addition & 1 deletion crates/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ termcolor = "1.1.2"
color-eyre = "0.6.2"

# Backends
acvm-backend-barretenberg = { git = "https://github.com/noir-lang/aztec_backend", rev = "ba1d0d61b94de91b15044d97608907c21bfb5299", default-features=false }
acvm-backend-barretenberg = { git = "https://github.com/noir-lang/aztec_backend", rev = "880210c5dcb55d29437a68c11913406704a0eb71", default-features=false }

[dev-dependencies]
tempdir = "0.3.7"
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Evaluator {
let inter_var_witness = self.add_witness_to_cs();

// Link that witness to the arithmetic gate
let constraint = &arithmetic_gate - &inter_var_witness;
let constraint = &arithmetic_gate - inter_var_witness;
self.opcodes.push(AcirOpcode::Arithmetic(constraint));
inter_var_witness
}
Expand Down
20 changes: 10 additions & 10 deletions crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) fn mul_with_witness(
let a_arith;
let a_arith = if !a.mul_terms.is_empty() && !b.is_const() {
let a_witness = evaluator.create_intermediate_variable(a.clone());
a_arith = Expression::from(&a_witness);
a_arith = Expression::from(a_witness);
&a_arith
} else {
a
Expand All @@ -42,7 +42,7 @@ pub(crate) fn mul_with_witness(
a_arith
} else {
let b_witness = evaluator.create_intermediate_variable(b.clone());
b_arith = Expression::from(&b_witness);
b_arith = Expression::from(b_witness);
&b_arith
}
} else {
Expand All @@ -54,9 +54,9 @@ pub(crate) fn mul_with_witness(
//a*b
pub(crate) fn mul(a: &Expression, b: &Expression) -> Expression {
if a.is_const() {
return b * &a.q_c;
return b * a.q_c;
} else if b.is_const() {
return a * &b.q_c;
return a * b.q_c;
} else if !(a.is_linear() && b.is_linear()) {
unreachable!("Can only multiply linear terms");
}
Expand Down Expand Up @@ -125,9 +125,9 @@ pub(crate) fn subtract(a: &Expression, k: FieldElement, b: &Expression) -> Expre
// TODO in either case, we can put this in ACIR, if its useful
pub(crate) fn add(a: &Expression, k: FieldElement, b: &Expression) -> Expression {
if a.is_const() {
return (b * &k) + &a.q_c;
return (b * k) + a.q_c;
} else if b.is_const() {
return a.clone() + &(k * b.q_c);
return a.clone() + (k * b.q_c);
}

let mut output = Expression::from_field(a.q_c + k * b.q_c);
Expand Down Expand Up @@ -497,7 +497,7 @@ pub(crate) fn evaluate_truncate(
if let Some(a_c) = lhs.to_const() {
let mut a_big = BigUint::from_bytes_be(&a_c.to_be_bytes());
a_big %= exp_big;
return Expression::from(&FieldElement::from_be_bytes_reduce(&a_big.to_bytes_be()));
return Expression::from(FieldElement::from_be_bytes_reduce(&a_big.to_bytes_be()));
}
let exp = FieldElement::from_be_bytes_reduce(&exp_big.to_bytes_be());

Expand All @@ -524,7 +524,7 @@ pub(crate) fn evaluate_truncate(
let my_constraint = add(&res, -FieldElement::one(), lhs);
evaluator.push_opcode(AcirOpcode::Arithmetic(my_constraint));

Expression::from(&b_witness)
Expression::from(b_witness)
}

pub(crate) fn evaluate_udiv(
Expand Down Expand Up @@ -552,8 +552,8 @@ pub(crate) fn evaluate_udiv(
//range check q<=a
try_range_constraint(q_witness, bit_size, evaluator);
// a-b*q-r = 0
let mut d = mul_with_witness(evaluator, rhs, &Expression::from(&q_witness));
d = add(&d, FieldElement::one(), &Expression::from(&r_witness));
let mut d = mul_with_witness(evaluator, rhs, &Expression::from(q_witness));
d = add(&d, FieldElement::one(), &Expression::from(r_witness));
d = mul_with_witness(evaluator, &d, predicate);
let div_euclidean = subtract(&pa, FieldElement::one(), &d);

Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/acir_gen/internal_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl InternalVar {
/// Expression, this method is infallible.
pub(crate) fn from_witness(witness: Witness) -> InternalVar {
InternalVar {
expression: Expression::from(&witness),
expression: Expression::from(witness),
cached_witness: Some(witness),
id: None,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_evaluator/src/ssa/acir_gen/operations/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ pub(crate) fn evaluate(
if r_value.is_zero() {
panic!("Panic - division by zero");
} else {
(l_c.expression() * &r_value.inverse()).into()
(l_c.expression() * r_value.inverse()).into()
}
} else {
//TODO avoid creating witnesses here.
let x_witness = acir_gen.var_cache.get_or_compute_witness(r_c, evaluator).expect("unexpected constant expression");
let inverse = Expression::from(&constraints::evaluate_inverse(
let inverse = Expression::from(constraints::evaluate_inverse(
x_witness, &predicate, evaluator,
));
InternalVar::from(constraints::mul_with_witness(
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_evaluator/src/ssa/acir_gen/operations/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ pub(super) fn evaluate_bitwise(
constraints::subtract(
&Expression::from_field(max),
FieldElement::one(),
&Expression::from(&result),
&Expression::from(result),
)
} else {
Expression::from(&result)
Expression::from(result)
}
}
4 changes: 2 additions & 2 deletions crates/noirc_evaluator/src/ssa/acir_gen/operations/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub(super) fn evaluate_neq(
.get_or_compute_witness(x, evaluator)
.expect("unexpected constant expression");

return Expression::from(&constraints::evaluate_zero_equality(x_witness, evaluator));
return Expression::from(constraints::evaluate_zero_equality(x_witness, evaluator));
}

// Arriving here means that `lhs` and `rhs` are not Arrays
Expand All @@ -95,7 +95,7 @@ pub(super) fn evaluate_neq(
.var_cache
.get_or_compute_witness(x, evaluator)
.expect("unexpected constant expression");
Expression::from(&constraints::evaluate_zero_equality(x_witness, evaluator))
Expression::from(constraints::evaluate_zero_equality(x_witness, evaluator))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub(crate) fn evaluate(
}
outputs =
prepare_outputs(&mut acir_gen.memory, instruction_id, array.len, ctx, evaluator);
let out_expr: Vec<Expression> = outputs.iter().map(|w| w.into()).collect();
let out_expr: Vec<Expression> = outputs.iter().map(|w| (*w).into()).collect();
for i in 0..(out_expr.len() - 1) {
bound_constraint_with_offset(
&out_expr[i],
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/acir_gen/operations/not.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn evaluate(
let l_c = var_cache.get_or_compute_internal_var_unwrap(*value, evaluator, ctx);
Some(
constraints::subtract(
&Expression::from(&FieldElement::from(a)),
&Expression::from(FieldElement::from(a)),
FieldElement::one(),
l_c.expression(),
)
Expand Down
Loading

0 comments on commit be16e46

Please sign in to comment.