Panic when error is expected
shriphani opened this issue · 2 comments
shriphani commented
Hi,
I'm using plonky2 for some very straightforward stuff and this snippet below panics - I'd like circuit_data.prove
to throw an error instead. Am I using builder.and
incorrectly? Is there a correct way to do this? Thanks.
use plonky2::{
field::goldilocks_field::GoldilocksField,
iop::witness::{PartialWitness, WitnessWrite},
plonk::{
circuit_builder::CircuitBuilder,
circuit_data::{CircuitConfig, CircuitData},
config::PoseidonGoldilocksConfig,
},
};
fn main() {
let config = CircuitConfig::standard_recursion_config();
let mut builder = CircuitBuilder::<GoldilocksField, 2>::new(config);
let bools = vec![true, false, true, false, true];
let constraints = vec![
builder.add_virtual_bool_target_safe(),
builder.add_virtual_bool_target_safe(),
builder.add_virtual_bool_target_safe(),
builder.add_virtual_bool_target_safe(),
builder.add_virtual_bool_target_safe(),
];
let mut pw = PartialWitness::new();
pw.set_bool_target(constraints[0], bools[0]);
pw.set_bool_target(constraints[1], bools[1]);
pw.set_bool_target(constraints[2], bools[2]);
pw.set_bool_target(constraints[3], bools[3]);
pw.set_bool_target(constraints[4], bools[4]);
let mut fold_and_result = builder.constant_bool(true);
for bool_tgt in constraints {
fold_and_result = builder.and(fold_and_result, bool_tgt);
}
let expected_result = builder.one();
builder.connect(expected_result, fold_and_result.target);
let circuit_data: CircuitData<GoldilocksField, PoseidonGoldilocksConfig, 2> = builder.build();
// shouldn't be able to prove - but this panics
assert!(circuit_data.prove(pw).is_err());
}
When run:
➜ plonky-panic-test git:(master) cargo run --release
Compiling plonky-panic-test v0.1.0 (/Users/shriphanipalakodety/onai/plonky-panic-test)
Finished `release` profile [optimized] target(s) in 1.95s
Running `target/release/plonky-panic-test`
thread 'main' panicked at /Users/shriphanipalakodety/.cargo/registry/src/index.crates.io-6f17d22bba15001f/plonky2-0.2.2/src/iop/witness.rs:324:13:
assertion `left == right` failed: Partition containing Wire(Wire { row: 1, column: 15 }) was set twice with different values: 1 != 0
left: 0
right: 1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
➜ plonky-panic-test git:(master) ✗
Nashtare commented
Hi!
I believe you're using one of the existing releases of plonky2
. What you're describing has been addressed already in #1611, but hasn't been released yet.
shriphani commented
Ok thanks I'll grab it when it is released.