Skip to content

Commit 078c746

Browse files
authored
fix: don't allow unknown witnesses in CircuitSimulator write op (#11077)
1 parent 3abfbf8 commit 078c746

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl CircuitSimulator {
105105
self.mark_solvable(w);
106106
true
107107
} else {
108-
self.try_solve(&Opcode::AssertZero(op.value.clone()))
108+
self.can_solve_expression(&op.value)
109109
}
110110
}
111111
Opcode::MemoryInit { block_id, init, .. } => {
@@ -364,4 +364,30 @@ mod tests {
364364
let circuit = Circuit::from_str(src).unwrap();
365365
assert_eq!(CircuitSimulator::check_circuit(&circuit), Some(0));
366366
}
367+
368+
#[test]
369+
fn reports_some_when_write_has_a_single_unknown_witness_in_its_value() {
370+
let src = "
371+
private parameters: [w0, w1]
372+
public parameters: []
373+
return values: []
374+
INIT b0 = [w0]
375+
WRITE b0[w0] = w1 + w2
376+
";
377+
let circuit = Circuit::from_str(src).unwrap();
378+
assert_eq!(CircuitSimulator::check_circuit(&circuit), Some(1));
379+
}
380+
381+
#[test]
382+
fn reports_none_when_write_has_known_witnesses_in_its_value() {
383+
let src = "
384+
private parameters: [w0, w1, w2]
385+
public parameters: []
386+
return values: []
387+
INIT b0 = [w0]
388+
WRITE b0[w0] = w1 + w2
389+
";
390+
let circuit = Circuit::from_str(src).unwrap();
391+
assert_eq!(CircuitSimulator::check_circuit(&circuit), None);
392+
}
367393
}

0 commit comments

Comments
 (0)