-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MockProver::assert_satisfied
with pretty-printed failures
#480
Conversation
b3f2c7f
to
cbcaf58
Compare
Codecov Report
@@ Coverage Diff @@
## main #480 +/- ##
==========================================
- Coverage 67.96% 65.85% -2.12%
==========================================
Files 47 49 +2
Lines 5891 6088 +197
==========================================
+ Hits 4004 4009 +5
- Misses 1887 2079 +192
Continue to review full report at Codecov.
|
9fadbd1
to
2fe6f57
Compare
This is equivalent to `assert_eq!(mock_prover.verify(), Ok(()))`, but pretty-prints the verification failures instead of debug-printing them. In its initial state, it just prints the `Display` impl.
An example failure, shown via `assert_eq!(err, Ok(()))`: ``` left: `Err([ConstraintNotSatisfied { constraint: Constraint { gate: Gate { index: 0, name: "R1CS constraint" }, index: 0, name: "buggy R1CS" }, location: InRegion { region: Region { index: 0, name: "Example region" }, offset: 1 }, cell_values: [(VirtualCell { name: "", column: Column { column_type: Advice, index: 0 }, rotation: 0 }, "0x2"), (VirtualCell { name: "", column: Column { column_type: Advice, index: 1 }, rotation: -1 }, "0x4"), (VirtualCell { name: "", column: Column { column_type: Advice, index: 2 }, rotation: 1 }, "0x8")] }])`, right: `Ok(())`', ``` Via `impl Display for VerifyFailure`: ``` Constraint 0 ('buggy R1CS') in gate 0 ('R1CS constraint') is not satisfied in Region 0 ('Example region') at offset 1 - Column('Advice', 0)@0 = 0x2 - Column('Advice', 1)@-1 = 0x4 - Column('Advice', 2)@1 = 0x8 ``` Via `VerifyFailure::emit`: ``` error: constraint not satisfied Cell layout in region 'Example region': | Offset | A0 | A1 | A2 | +--------+----+----+----+ | 0 | | x1 | | | 1 | x0 | | | <--{ Gate 'R1CS constraint' applied here | 2 | | | x2 | Constraint 'buggy R1CS': S0 * (x0 * x1 + x2) = 0 Assigned cell values: x0 = 0x2 x1 = 0x4 x2 = 0x8 ```
The `dev::tests::bad_lookup` test case, shown via `assert_eq!(err, Ok(()))`: ``` left: `Err([Lookup { lookup_index: 0, location: InRegion { region: Region { index: 2, name: "Faulty synthesis" }, offset: 1 } }])`, right: `Ok(())`', ``` Via `impl Display for VerifyFailure`: ``` Lookup 0 is not satisfied in Region 2 ('Faulty synthesis') at offset 1 ``` Via `VerifyFailure::emit`: ``` error: lookup input does not exist in table (L0) ∉ (F0) Lookup inputs: L0 = x1 * x0 + (1 - x1) * 0x2 ^ | Cell layout in region 'Faulty synthesis': | | Offset | A0 | F1 | | +--------+----+----+ | | 1 | x0 | x1 | <--{ Lookup inputs queried here | | Assigned cell values: | x0 = 0x5 | x1 = 1 ```
The `dev::tests::unassigned_cell` test case, shown via `assert_eq!(err, Ok(()))`: ``` left: `Err([CellNotAssigned { gate: Gate { index: 0, name: "Equality check" }, region: Region { index: 0, name: "Faulty synthesis" }, gate_offset: 1, column: Column { index: 1, column_type: Advice }, offset: 1 }])`, right: `Ok(())`', ``` Via `impl Display for VerifyFailure`: ``` Region 0 ('Faulty synthesis') uses Gate 0 ('Equality check') at offset 1, which requires cell in column Column { index: 1, column_type: Advice } at offset 1 to be assigned. ``` Via `VerifyFailure::emit`: ``` error: cell not assigned Cell layout in region 'Faulty synthesis': | Offset | A0 | A1 | +--------+----+----+ | 0 | x0 | | | 1 | | X | <--{ X marks the spot! 🦜 Gate 'Equality check' (applied at offset 1) queries these cells. ```
2fe6f57
to
57596ca
Compare
Rebased to fix merge conflicts in the changelog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 🦜
Idea: we could add pretty-printing as a feature of MockProver, not just in case of failures. |
if a.contains(' ') { | ||
format!("-({})", a) | ||
} else { | ||
format!("-{}", a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't contain space, so technically you could end up with --x
instead of -(-x)
. It probably doesn't matter; I can't see a case where the result would be ambiguous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
re-utACK 69c138c |
This is equivalent to
assert_eq!(mock_prover.verify(), Ok(()))
, but pretty-prints the verification failures instead of debug-printing them.This PR has special handling for the following failure cases:
VerifyFailure::CellNotAssigned
VerifyFailure::ConstraintNotSatisfied
VerifyFailure::Lookup
All other failure cases print the
Display
impl.Closes #477.