snark icon indicating copy to clipboard operation
snark copied to clipboard

Constraint system that panics when an invalid constraint is added

Open weikengchen opened this issue 2 years ago • 0 comments

Summary

This issue is about a feature request on ConstraintSystem. Ideally, there is a debug mode. When it is on, it helps the developers find out which constraint is failing.

Problem Definition

After the namespaces disappear from arkworks-rs, it is harder to debug a constraint system that is not satisfactory, which often appears only when the verify function fails.

Proposal

A potential solution for debugging is as follows:

  • When we enforce a constraint (https://github.com/arkworks-rs/snark/blob/master/relations/src/r1cs/constraint_system.rs#L254), we immediately check if this constraint is satisfactory. If not, panic immediately. Note that this cannot be done in the setup mode.

  • An implementation of such checking has appeared in Aleo's snarkVM, which intentionally checks if a constraint is satisfactory and records the first unsatisfactory constraint. https://github.com/AleoHQ/snarkVM/blob/testnet2/r1cs/src/test_constraint_checker.rs#L120

Since such checking has an overhead, it is only turned on when debug mode is on, which by default is off.


For Admin Use

  • [x] Not duplicate issue
  • [x] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned

weikengchen avatar Sep 08 '21 06:09 weikengchen