Skip to content
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

Merged
merged 11 commits into from
Apr 20, 2022

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Feb 1, 2022

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.

@str4d str4d added A-dev-tooling Area: Developer tooling A-errors Area: Error handling labels Feb 1, 2022
@str4d str4d force-pushed the 477-mockprover-pretty-failures branch from b3f2c7f to cbcaf58 Compare February 1, 2022 14:57
@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2022

Codecov Report

Merging #480 (9fadbd1) into main (bb56139) will decrease coverage by 2.11%.
The diff coverage is 15.92%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
halo2_proofs/src/dev/failure/emitter.rs 0.00% <0.00%> (ø)
halo2_proofs/src/dev/metadata.rs 12.50% <ø> (ø)
halo2_proofs/src/dev/failure.rs 12.75% <12.75%> (ø)
halo2_proofs/src/dev.rs 72.14% <47.05%> (+2.40%) ⬆️
halo2_proofs/src/dev/util.rs 20.00% <100.00%> (+20.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb56139...9fadbd1. Read the comment docs.

@str4d str4d force-pushed the 477-mockprover-pretty-failures branch 6 times, most recently from 9fadbd1 to 2fe6f57 Compare February 2, 2022 13:27
@str4d str4d marked this pull request as ready for review February 2, 2022 13:33
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.
```
@str4d str4d force-pushed the 477-mockprover-pretty-failures branch from 2fe6f57 to 57596ca Compare February 16, 2022 13:58
@str4d
Copy link
Contributor Author

str4d commented Feb 16, 2022

Rebased to fix merge conflicts in the changelog.

@therealyingtong therealyingtong self-requested a review March 22, 2022 11:31
Copy link
Collaborator

@therealyingtong therealyingtong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 🦜

@therealyingtong
Copy link
Collaborator

Idea: we could add pretty-printing as a feature of MockProver, not just in case of failures.

@r3ld3v r3ld3v requested a review from daira April 14, 2022 14:22
halo2_proofs/src/dev.rs Outdated Show resolved Hide resolved
if a.contains(' ') {
format!("-({})", a)
} else {
format!("-{}", a)
Copy link
Contributor

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.

Copy link
Contributor

@daira daira left a 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>
@daira
Copy link
Contributor

daira commented Apr 19, 2022

re-utACK 69c138c

@str4d str4d merged commit 46ba444 into main Apr 20, 2022
@str4d str4d deleted the 477-mockprover-pretty-failures branch April 20, 2022 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dev-tooling Area: Developer tooling A-errors Area: Error handling S-committed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a helper for checking MockProver::verify results
5 participants