Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Dec 10, 2024
1 parent 9a44d2a commit a1d4eee
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions acvm-repo/acvm/src/compiler/optimizers/merge_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,50 @@ mod tests {
check_circuit(circuit);
}

#[test]
fn does_not_eliminate_witnesses_returned_from_circuit() {
let opcodes = vec![
Opcode::AssertZero(Expression {
mul_terms: vec![(FieldElement::from(-1i128), Witness(0), Witness(0))],
linear_combinations: vec![(FieldElement::from(1i128), Witness(1))],
q_c: FieldElement::zero(),
}),
Opcode::AssertZero(Expression {
mul_terms: Vec::new(),
linear_combinations: vec![
(FieldElement::from(-1i128), Witness(1)),
(FieldElement::from(1i128), Witness(2)),
],
q_c: FieldElement::zero(),
}),
];
// Witness(1) could be eliminated because it's only used by 2 opcodes.

let mut private_parameters = BTreeSet::new();
private_parameters.insert(Witness(0));

let mut return_values = BTreeSet::new();
return_values.insert(Witness(1));
return_values.insert(Witness(2));

let circuit = Circuit {
current_witness_index: 2,
expression_width: ExpressionWidth::Bounded { width: 4 },
opcodes,
private_parameters,
public_parameters: PublicInputs::default(),
return_values: PublicInputs(return_values),
assert_messages: Default::default(),
};

let mut merge_optimizer = MergeExpressionsOptimizer::new();
let acir_opcode_positions = vec![0; 20];
let (opcodes, _) =
merge_optimizer.eliminate_intermediate_variable(&circuit, acir_opcode_positions);

assert_eq!(opcodes.len(), 2);
}

#[test]
fn does_not_attempt_to_merge_into_previous_opcodes() {
let opcodes = vec![
Expand Down

0 comments on commit a1d4eee

Please sign in to comment.