Skip to content

Commit 92617d8

Browse files
committed
Merge branch 'master' into aztec-packages
* master: (65 commits) chore: remove some `_else_condition` tech debt (#6522) chore: revert #6375 (#6552) feat: simplify constant MSM calls in SSA (#6547) chore(test): Remove duplicate brillig tests (#6523) chore: restructure `noirc_evaluator` crate (#6534) fix: take blackbox function outputs into account when merging expressions (#6532) chore: Add `Instruction::MakeArray` to SSA (#6071) feat(profiler): Reduce memory in Brillig execution flamegraph (#6538) chore: convert some tests to use SSA parser (#6543) chore(ci): bump mac github runner image to `macos-14` (#6545) chore(test): More descriptive labels in test matrix (#6542) chore: Remove unused methods from implicit numeric generics (#6541) fix: Fix poor handling of aliased references in flattening pass causing some values to be zeroed (#6434) fix: allow range checks to be performed within the comptime intepreter (#6514) fix: disallow `#[test]` on associated functions (#6449) chore(ssa): Skip array_set pass for Brillig functions (#6513) chore: Reverse ssa parser diff order (#6511) chore: Parse negatives in SSA parser (#6510) feat: avoid unnecessary ssa passes while loop unrolling (#6509) fix(tests): Use a file lock as well as a mutex to isolate tests cases (#6508) ...
2 parents 0317d46 + 5f730e8 commit 92617d8

File tree

104 files changed

+2345
-1974
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2345
-1974
lines changed

.github/workflows/publish-nargo.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ permissions:
2323

2424
jobs:
2525
build-apple-darwin:
26-
runs-on: macos-12
26+
runs-on: macos-14
2727
env:
2828
CROSS_CONFIG: ${{ github.workspace }}/.github/Cross.toml
2929
NIGHTLY_RELEASE: ${{ inputs.tag == '' }}
@@ -41,7 +41,7 @@ jobs:
4141
- name: Setup for Apple Silicon
4242
if: matrix.target == 'aarch64-apple-darwin'
4343
run: |
44-
sudo xcode-select -s /Applications/Xcode_13.2.1.app/Contents/Developer/
44+
sudo xcode-select -s /Applications/Xcode_15.4.0.app/Contents/Developer/
4545
echo "SDKROOT=$(xcrun -sdk macosx$(sw_vers -productVersion) --show-sdk-path)" >> $GITHUB_ENV
4646
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx$(sw_vers -productVersion) --show-sdk-platform-version)" >> $GITHUB_ENV
4747

acvm-repo/acvm/src/compiler/optimizers/merge_expressions.rs

+56-11
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,12 @@ impl MergeExpressionsOptimizer {
152152

153153
// Returns the input witnesses used by the opcode
154154
fn witness_inputs<F: AcirField>(&self, opcode: &Opcode<F>) -> BTreeSet<Witness> {
155-
let mut witnesses = BTreeSet::new();
156155
match opcode {
157156
Opcode::AssertZero(expr) => CircuitSimulator::expr_wit(expr),
158157
Opcode::BlackBoxFuncCall(bb_func) => bb_func.get_input_witnesses(),
159158
Opcode::MemoryOp { block_id: _, op, predicate } => {
160159
//index et value, et predicate
161-
let mut witnesses = BTreeSet::new();
162-
witnesses.extend(CircuitSimulator::expr_wit(&op.index));
160+
let mut witnesses = CircuitSimulator::expr_wit(&op.index);
163161
witnesses.extend(CircuitSimulator::expr_wit(&op.value));
164162
if let Some(p) = predicate {
165163
witnesses.extend(CircuitSimulator::expr_wit(p));
@@ -171,6 +169,7 @@ impl MergeExpressionsOptimizer {
171169
init.iter().cloned().collect()
172170
}
173171
Opcode::BrilligCall { inputs, outputs, .. } => {
172+
let mut witnesses = BTreeSet::new();
174173
for i in inputs {
175174
witnesses.extend(self.brillig_input_wit(i));
176175
}
@@ -180,12 +179,9 @@ impl MergeExpressionsOptimizer {
180179
witnesses
181180
}
182181
Opcode::Call { id: _, inputs, outputs, predicate } => {
183-
for i in inputs {
184-
witnesses.insert(*i);
185-
}
186-
for i in outputs {
187-
witnesses.insert(*i);
188-
}
182+
let mut witnesses: BTreeSet<Witness> = BTreeSet::from_iter(inputs.iter().copied());
183+
witnesses.extend(outputs);
184+
189185
if let Some(p) = predicate {
190186
witnesses.extend(CircuitSimulator::expr_wit(p));
191187
}
@@ -233,15 +229,15 @@ mod tests {
233229
acir_field::AcirField,
234230
circuit::{
235231
brillig::{BrilligFunctionId, BrilligOutputs},
236-
opcodes::FunctionInput,
232+
opcodes::{BlackBoxFuncCall, FunctionInput},
237233
Circuit, ExpressionWidth, Opcode, PublicInputs,
238234
},
239235
native_types::{Expression, Witness},
240236
FieldElement,
241237
};
242238
use std::collections::BTreeSet;
243239

244-
fn check_circuit(circuit: Circuit<FieldElement>) {
240+
fn check_circuit(circuit: Circuit<FieldElement>) -> Circuit<FieldElement> {
245241
assert!(CircuitSimulator::default().check_circuit(&circuit));
246242
let mut merge_optimizer = MergeExpressionsOptimizer::new();
247243
let acir_opcode_positions = vec![0; 20];
@@ -251,6 +247,7 @@ mod tests {
251247
optimized_circuit.opcodes = opcodes;
252248
// check that the circuit is still valid after optimization
253249
assert!(CircuitSimulator::default().check_circuit(&optimized_circuit));
250+
optimized_circuit
254251
}
255252

256253
#[test]
@@ -293,6 +290,7 @@ mod tests {
293290
public_parameters: PublicInputs::default(),
294291
return_values: PublicInputs::default(),
295292
assert_messages: Default::default(),
293+
recursive: false,
296294
};
297295
check_circuit(circuit);
298296
}
@@ -345,7 +343,54 @@ mod tests {
345343
public_parameters: PublicInputs::default(),
346344
return_values: PublicInputs::default(),
347345
assert_messages: Default::default(),
346+
recursive: false,
348347
};
349348
check_circuit(circuit);
350349
}
350+
351+
#[test]
352+
fn takes_blackbox_opcode_outputs_into_account() {
353+
// Regression test for https://github.com/noir-lang/noir/issues/6527
354+
// Previously we would not track the usage of witness 4 in the output of the blackbox function.
355+
// We would then merge the final two opcodes losing the check that the brillig call must match
356+
// with `_0 ^ _1`.
357+
358+
let circuit: Circuit<FieldElement> = Circuit {
359+
current_witness_index: 7,
360+
opcodes: vec![
361+
Opcode::BrilligCall {
362+
id: BrilligFunctionId(0),
363+
inputs: Vec::new(),
364+
outputs: vec![BrilligOutputs::Simple(Witness(3))],
365+
predicate: None,
366+
},
367+
Opcode::BlackBoxFuncCall(BlackBoxFuncCall::AND {
368+
lhs: FunctionInput::witness(Witness(0), 8),
369+
rhs: FunctionInput::witness(Witness(1), 8),
370+
output: Witness(4),
371+
}),
372+
Opcode::AssertZero(Expression {
373+
linear_combinations: vec![
374+
(FieldElement::one(), Witness(3)),
375+
(-FieldElement::one(), Witness(4)),
376+
],
377+
..Default::default()
378+
}),
379+
Opcode::AssertZero(Expression {
380+
linear_combinations: vec![
381+
(-FieldElement::one(), Witness(2)),
382+
(FieldElement::one(), Witness(4)),
383+
],
384+
..Default::default()
385+
}),
386+
],
387+
expression_width: ExpressionWidth::Bounded { width: 4 },
388+
private_parameters: BTreeSet::from([Witness(0), Witness(1)]),
389+
return_values: PublicInputs(BTreeSet::from([Witness(2)])),
390+
..Default::default()
391+
};
392+
393+
let new_circuit = check_circuit(circuit.clone());
394+
assert_eq!(circuit, new_circuit);
395+
}
351396
}

acvm-repo/acvm/src/compiler/simulator.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use acir::{
22
circuit::{
33
brillig::{BrilligInputs, BrilligOutputs},
4+
directives::Directive,
45
opcodes::{BlockId, FunctionInput},
56
Circuit, Opcode,
67
},
@@ -83,6 +84,17 @@ impl CircuitSimulator {
8384
}
8485
true
8586
}
87+
Opcode::Directive(directive) => match directive {
88+
Directive::ToLeRadix { a, b, .. } => {
89+
if !self.can_solve_expression(a) {
90+
return false;
91+
}
92+
for w in b {
93+
self.mark_solvable(*w);
94+
}
95+
true
96+
}
97+
},
8698
Opcode::MemoryOp { block_id, op, predicate } => {
8799
if !self.can_solve_expression(&op.index) {
88100
return false;
@@ -234,6 +246,7 @@ mod tests {
234246
public_parameters,
235247
return_values: PublicInputs::default(),
236248
assert_messages: Default::default(),
249+
recursive: false,
237250
}
238251
}
239252

acvm-repo/bn254_blackbox_solver/src/embedded_curve_ops.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub fn multi_scalar_mul(
1616
scalars_hi: &[FieldElement],
1717
) -> Result<(FieldElement, FieldElement, FieldElement), BlackBoxResolutionError> {
1818
if points.len() != 3 * scalars_lo.len() || scalars_lo.len() != scalars_hi.len() {
19-
dbg!(&points.len(), &scalars_lo.len(), &scalars_hi.len());
2019
return Err(BlackBoxResolutionError::Failed(
2120
BlackBoxFunc::MultiScalarMul,
2221
"Points and scalars must have the same length".to_string(),

compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs compiler/noirc_evaluator/src/acir/acir_variable.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1-
use super::big_int::BigIntContext;
2-
use super::generated_acir::{BrilligStdlibFunc, GeneratedAcir, PLACEHOLDER_BRILLIG_INDEX};
3-
use crate::brillig::brillig_gen::brillig_directive;
4-
use crate::brillig::brillig_ir::artifact::GeneratedBrillig;
5-
use crate::errors::{InternalBug, InternalError, RuntimeError, SsaReport};
6-
use crate::ssa::acir_gen::{AcirDynamicArray, AcirValue};
7-
use crate::ssa::ir::dfg::CallStack;
8-
use crate::ssa::ir::types::Type as SsaType;
9-
use crate::ssa::ir::{instruction::Endian, types::NumericType};
10-
use acvm::acir::circuit::brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs};
11-
use acvm::acir::circuit::opcodes::{
12-
AcirFunctionId, BlockId, BlockType, ConstantOrWitnessEnum, MemOp,
13-
};
14-
use acvm::acir::circuit::{AssertionPayload, ExpressionOrMemory, ExpressionWidth, Opcode};
15-
use acvm::brillig_vm::{MemoryValue, VMStatus, VM};
16-
use acvm::BlackBoxFunctionSolver;
171
use acvm::{
18-
acir::AcirField,
192
acir::{
203
brillig::Opcode as BrilligOpcode,
21-
circuit::opcodes::FunctionInput,
4+
circuit::{
5+
brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs},
6+
opcodes::{
7+
AcirFunctionId, BlockId, BlockType, ConstantOrWitnessEnum, FunctionInput, MemOp,
8+
},
9+
AssertionPayload, ExpressionOrMemory, ExpressionWidth, Opcode,
10+
},
2211
native_types::{Expression, Witness},
23-
BlackBoxFunc,
12+
AcirField, BlackBoxFunc,
2413
},
14+
brillig_vm::{MemoryValue, VMStatus, VM},
15+
BlackBoxFunctionSolver,
2516
};
2617
use fxhash::FxHashMap as HashMap;
2718
use iter_extended::{try_vecmap, vecmap};
2819
use num_bigint::BigUint;
2920
use std::cmp::Ordering;
3021
use std::{borrow::Cow, hash::Hash};
3122

23+
use crate::brillig::brillig_ir::artifact::GeneratedBrillig;
24+
use crate::errors::{InternalBug, InternalError, RuntimeError, SsaReport};
25+
use crate::ssa::ir::{
26+
dfg::CallStack, instruction::Endian, types::NumericType, types::Type as SsaType,
27+
};
28+
29+
use super::big_int::BigIntContext;
30+
use super::generated_acir::{BrilligStdlibFunc, GeneratedAcir, PLACEHOLDER_BRILLIG_INDEX};
31+
use super::{brillig_directive, AcirDynamicArray, AcirValue};
32+
3233
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
3334
/// High level Type descriptor for Variables.
3435
///

compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs compiler/noirc_evaluator/src/acir/generated_acir.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
//! `GeneratedAcir` is constructed as part of the `acir_gen` pass to accumulate all of the ACIR
22
//! program as it is being converted from SSA form.
3-
use std::{collections::BTreeMap, u32};
3+
use std::collections::BTreeMap;
44

5-
use crate::{
6-
brillig::{brillig_gen::brillig_directive, brillig_ir::artifact::GeneratedBrillig},
7-
errors::{InternalError, RuntimeError, SsaReport},
8-
ssa::ir::{dfg::CallStack, instruction::ErrorType},
9-
};
105
use acvm::acir::{
116
circuit::{
127
brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs},
@@ -16,7 +11,17 @@ use acvm::acir::{
1611
native_types::Witness,
1712
BlackBoxFunc,
1813
};
19-
use acvm::{acir::native_types::Expression, acir::AcirField};
14+
use acvm::{
15+
acir::AcirField,
16+
acir::{circuit::directives::Directive, native_types::Expression},
17+
};
18+
19+
use super::brillig_directive;
20+
use crate::{
21+
brillig::brillig_ir::artifact::GeneratedBrillig,
22+
errors::{InternalError, RuntimeError, SsaReport},
23+
ssa::ir::dfg::CallStack,
24+
};
2025

2126
use iter_extended::vecmap;
2227
use noirc_errors::debug_info::ProcedureDebugId;
@@ -155,7 +160,7 @@ impl<F: AcirField> GeneratedAcir<F> {
155160
/// This means you cannot multiply an infinite amount of `Expression`s together.
156161
/// Once the `Expression` goes over degree-2, then it needs to be reduced to a `Witness`
157162
/// which has degree-1 in order to be able to continue the multiplication chain.
158-
pub(crate) fn create_witness_for_expression(&mut self, expression: &Expression<F>) -> Witness {
163+
fn create_witness_for_expression(&mut self, expression: &Expression<F>) -> Witness {
159164
let fresh_witness = self.next_witness_index();
160165

161166
// Create a constraint that sets them to be equal to each other

0 commit comments

Comments
 (0)