Skip to content

Commit

Permalink
fix small refactor and use single constant for pedantic_solving in me…
Browse files Browse the repository at this point in the history
…mory_op tests
  • Loading branch information
michaeljklein committed Dec 11, 2024
1 parent 7c7766a commit 8796f15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
15 changes: 7 additions & 8 deletions acvm-repo/acvm/src/pwg/memory_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ mod tests {

use super::MemoryOpSolver;

// use pedantic_solving for tests
const PEDANTIC_SOLVING: bool = true;

#[test]
fn test_solver() {
let mut initial_witness = WitnessMap::from(BTreeMap::from_iter([
Expand All @@ -153,9 +156,8 @@ mod tests {
block_solver.init(&init, &initial_witness).unwrap();

for op in trace {
let pedantic_solving = true;
block_solver
.solve_memory_op(&op, &mut initial_witness, &None, pedantic_solving)
.solve_memory_op(&op, &mut initial_witness, &None, PEDANTIC_SOLVING)
.unwrap();
}

Expand All @@ -181,9 +183,8 @@ mod tests {
let mut err = None;
for op in invalid_trace {
if err.is_none() {
let pedantic_solving = true;
err = block_solver
.solve_memory_op(&op, &mut initial_witness, &None, pedantic_solving)
.solve_memory_op(&op, &mut initial_witness, &None, PEDANTIC_SOLVING)
.err();
}
}
Expand Down Expand Up @@ -217,13 +218,12 @@ mod tests {
let mut err = None;
for op in invalid_trace {
if err.is_none() {
let pedantic_solving = true;
err = block_solver
.solve_memory_op(
&op,
&mut initial_witness,
&Some(Expression::zero()),
pedantic_solving,
PEDANTIC_SOLVING,
)
.err();
}
Expand Down Expand Up @@ -255,13 +255,12 @@ mod tests {
let mut err = None;
for op in invalid_trace {
if err.is_none() {
let pedantic_solving = true;
err = block_solver
.solve_memory_op(
&op,
&mut initial_witness,
&Some(Expression::zero()),
pedantic_solving,
PEDANTIC_SOLVING,
)
.err();
}
Expand Down
19 changes: 10 additions & 9 deletions acvm-repo/acvm/src/pwg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ pub enum OpcodeResolutionError<F> {
AcirMainCallAttempted { opcode_location: ErrorLocation },
#[error("{results_size:?} result values were provided for {outputs_size:?} call output witnesses, most likely due to bad ACIR codegen")]
AcirCallOutputsMismatch { opcode_location: ErrorLocation, results_size: u32, outputs_size: u32 },
#[error("(--pedantic): Predicates are expected to be 0 or 1, but found: {predicate_value}")]
PredicateLargerThanOne { opcode_location: ErrorLocation, predicate_value: F },
#[error("(--pedantic): Predicates are expected to be 0 or 1, but found: {pred_value}")]
PredicateLargerThanOne { opcode_location: ErrorLocation, pred_value: F },
}

impl<F> From<BlackBoxResolutionError> for OpcodeResolutionError<F> {
Expand Down Expand Up @@ -768,16 +768,17 @@ pub(crate) fn is_predicate_false<F: AcirField>(
let pred_value = get_value(pred, witness)?;
let predicate_is_false = pred_value.is_zero();
if pedantic_solving {
// We expect that the predicate should resolve to either 0 or 1.
if !predicate_is_false && !predicate.is_one() {
let opcode_location = *opcode_location;
return Err(OpcodeResolutionError::PredicateLargerThanOne {
opcode_location,
predicate_value,
})
// We expect that the predicate should resolve to either 0 or 1.
if !predicate_is_false && !pred_value.is_one() {
let opcode_location = *opcode_location;
return Err(OpcodeResolutionError::PredicateLargerThanOne {
opcode_location,
pred_value,
});
}
}
Ok(predicate_is_false)
}
// If the predicate is `None`, then we treat it as an unconditional `true`
None => Ok(false),
}
Expand Down

0 comments on commit 8796f15

Please sign in to comment.