Commit Graph

169 Commits

Author SHA1 Message Date
str4d 8abd7b74db
Merge pull request #417 from zcash/fix-assigned-usage
Expand `Assigned<F>` APIs
2022-03-22 19:46:51 +00:00
str4d 642efc1536
Merge pull request #521 from zcash/reconstruct-selectors
Remove selector_map from pinned verification key and remove VerificationKey serialization
2022-03-18 00:14:36 +00:00
Jack Grigg c6b4fcaf34 Fix docs.rs build
The published source code for each package needs to include the required
header file, and the path to that header file needs to be relative to
the package source (not the repository source). We therefore need to
have the header file present in each workspace package.

Closes zcash/halo2#506.
2022-03-17 19:14:11 +00:00
Sean Bowe f46d77763e
Remove logic for reading and writing VerificationKey to/from buffers. 2022-03-16 14:19:33 -06:00
Sean Bowe 819bc3c2f5
Stop placing the selector_map (which is an internal API detail) in the pinned verification key. 2022-03-16 14:19:13 -06:00
Sean Bowe e10f4e1d0e
Add mechanism for generating a new proof in test. 2022-03-16 12:53:04 -06:00
Brechtpd e2e04e1415 Parallelized eval_polynomial/evaluate_vanishing_polynomial 2022-03-16 02:23:22 +01:00
Brechtpd 8912c0bd7d misc small improvements 2022-03-15 19:33:10 +01:00
Brechtpd 7cc22cfa03 Poly optimizations 2022-03-15 04:36:16 +01:00
kilic 09758e585c use _diff suffix 2022-03-13 23:10:13 +03:00
kilic 5b04d737cf shplonk: save a scalar mul in verifier side 2022-03-12 16:24:21 +03:00
kilic ee6a48c459 shplonk::verifier Batch remainders contributions 2022-03-11 20:56:46 +03:00
kilic 6c879b7609 Remove diff indicies from rotation set
Better testing of intermadiate set construction

Refactor intermediate set construction
2022-03-06 20:17:09 +03:00
TrapdoorHeader e948e10202 fix clippy error 2022-03-06 20:17:09 +03:00
TrapdoorHeader 8c39f89054 use Rotation to sort the opening points s.t. the ordering is static
Signed-off-by: TrapdoorHeader <support@trapdoortech.com>
2022-03-06 20:17:09 +03:00
Zhang Zhuo 2b4ebd36d8 MockProver: allow different gate_row_ids and lookup_input_row_ids for verify_at_rows 2022-03-01 12:00:48 +08:00
Zhang Zhuo 4604e7b80c fix 2022-02-26 17:10:08 +08:00
Zhang Zhuo b011557267 feat: add verify_at_rows in MockProver for testing speed 2022-02-26 16:32:57 +08:00
kilic caa6f90608 Add vanishing polynomial evaluator 2022-02-22 14:09:20 +03:00
Daira Hopwood b48b032041
Minor simplification 2022-02-16 17:14:41 +00:00
Chih Cheng Liang 6f8a605821
Merge pull request #29 from lispc/debug/better_lookup_err3
dev: add name for lookup
2022-02-16 23:14:40 +08:00
Jack Grigg 57596cab36 dev: Add a custom `VerifyFailure::CellNotAssigned` emitter
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.
```
2022-02-16 13:57:53 +00:00
Jack Grigg 369ff521d3 dev: Store gate offset in `VerifyFailure::CellNotAssigned` 2022-02-16 13:57:53 +00:00
Jack Grigg c19a1ade2a dev: Add a custom `VerifyFailure::Lookup` emitter
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
```
2022-02-16 13:56:17 +00:00
Jack Grigg 62eea4c457 dev: Move cell loaders into `dev::util` 2022-02-16 13:56:17 +00:00
Jack Grigg 44e3cf8c61 dev: Move expression stringifier into `dev::failure::emitter` 2022-02-16 13:56:17 +00:00
Jack Grigg 212e3d07ce dev: Move cell layout emitter into a submodule 2022-02-16 13:56:17 +00:00
Jack Grigg 8e1fb87a33 dev: Add a custom `VerifyFailure::ConstraintNotSatisfied` emitter
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
```
2022-02-16 13:56:17 +00:00
Jack Grigg 5cdc029bb4 dev: Add `MockProver::assert_satisfied`
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.
2022-02-16 13:56:17 +00:00
Jack Grigg 0e08903669 dev: Move `VerifyFailure` and `FailureLocation` into submodule 2022-02-16 13:55:29 +00:00
kilic 8b616c33e0 Remove commented out code 2022-02-15 17:41:33 +03:00
Zhang Zhuo ca8cad0e62 format 2022-02-15 20:14:01 +08:00
Zhang Zhuo 67437b222d fix examples 2022-02-15 14:53:25 +08:00
Zhang Zhuo 2a49e2a2bb dev: add name for lookup 2022-02-15 14:52:35 +08:00
Zhang Zhuo e2a01d23db dev: add name for lookup 2022-02-15 11:57:57 +08:00
Daira Hopwood e7ffefdbe2 MockProver: Optimize repetitions of the last usable row, not the zero row.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-02-15 00:30:54 +00:00
Daira Hopwood 7107b8353a MockProver: Use a sorted scan to check that lookup inputs
are contained in the table, fixing a performance regression.
This includes an optimization for "fill rows", which are
assumed in this commit to be all-zeros.

closes #398

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-02-14 23:54:06 +00:00
Jack Grigg f642727e51 halo2_proofs 0.1.0-beta.2 2022-02-14 21:58:20 +00:00
Jack Grigg 1d2f698aca Update license dates and links 2022-02-14 21:58:20 +00:00
Jack Grigg e0cc7b39d3 Update changelogs 2022-02-14 21:29:42 +00:00
Sean Bowe 0b73c74f72
Address comments brought up by @str4d. 2022-02-14 10:44:14 -07:00
Sean Bowe f2daf91315
halo2_proofs: change IPA check equation to match the book
The verifier's check in the inner product argument used to assume that the
G'_0 value had an additional (trivial) blinding factor term, which makes
it slightly easier to reason that it never is the point at infinity.
However, we never sample challenges that are zeroes (both for security
and completeness reasons) so this element would never be the point at
infinity anyway. Thus, we can simplify the check with the added benefit of
matching the book's description of the protocol.
2022-02-14 09:37:57 -07:00
ebfull 8c0deb10aa
Merge pull request #495 from zcash/book-consistency
halo2_proofs: rename variables for consistency
2022-02-14 09:24:20 -07:00
Sean Bowe 90bebdf29a
halo2_proofs: add hardcoded proof to plonk_api test for backwards compatibility testing 2022-02-14 08:48:03 -07:00
kilic 641b4b5f94 Apply clippy and fmt 2022-02-14 14:31:04 +03:00
kilic a892dd56e9 Make shplonk default 2022-02-12 20:56:25 +03:00
kilic e73c1b2582 Fix typos 2022-02-12 20:56:25 +03:00
kilic c67e7d9f25 Minor cleanups 2022-02-12 20:56:25 +03:00
kilic bebee898fe Add lookup_any 2022-02-12 20:56:25 +03:00
kilic 0e9b075c3a Change multiopen commitment scheme to KZG 2022-02-12 20:56:25 +03:00
Sean Bowe 289f24bb8b
Improvements due to @daira's code review. 2022-02-11 08:50:55 -07:00
Sean Bowe a129490517
Minor changes 2022-02-10 08:08:20 -07:00
Sean Bowe a4d3c328b9
halo2_proofs: rename variables for consistency
This changes variable names in the multiopen and commitment opening implementations
and the book's protocol description to keep names and indicies consistent with one
another.

Co-Authored-By: Jack Grigg <jack@electriccoin.co>
2022-02-09 13:37:50 -07:00
Dimitris Apostolou e2f88e450b
Fix typos 2022-02-03 18:01:22 +02:00
Jack Grigg 9a12beee73 halo2_gadgets: Rename `halo2` to `halo2_proofs`
The previous commit renamed `halo2_proofs` back to `halo2` temporarily
to keep the commit size down. This commit performs the rename in a
single pass.
2022-01-27 23:32:04 +00:00
str4d bb56139414
Merge pull request #472 from zcash/separate-single-and-batch-verification
halo2_proofs: Improve `plonk::verify_proof` API
2022-01-27 01:19:34 +00:00
Jack Grigg 4d336f2707 halo2_proofs: Improve `plonk::verify_proof` API
Previously `plonk::verify_proof` took an `MSM` as an argument, to enable
batch verification. However, this also required that it take a source of
randomness in order to enforce separation of proofs within a batch. This
made single-proof verification unnecessarily non-deterministic.

We now have a `VerificationStrategy` trait encapsulating the necessary
details, and separate `SingleVerifier` and `BatchVerifier` structs for
the specific variants. Proof verifiers no longer need to create and
manage the `MSM` themselves, and single-proof verifiers no longer need
to supply a source of randomness.

Co-authored-by: Sean Bowe <sean@electriccoin.co>
2022-01-27 00:20:56 +00:00
Jack Grigg d3faddc53c Fix `impl Debug for poly::Ast`
The auto-derived implementation would only work if the evaluation
context implemented `Debug`, which closures never do.
2022-01-27 00:13:17 +00:00
Jack Grigg 507be292b8 Fix `poly::Evaluator` short-chunk bug
Previously we were passing through the chunk size and index to each
thread's evaluation context, but this was insufficient for them to
determine whether or not they were processing the final chunk, or if
the final chunk was short. This led to constant and linear term chunks
being created with the full chunk size, even if the last chunk was
short. If this longer-than-short chunk reached the root of the AST, it
triggered a panic in the final `copy_from_slice()`.

The bug was obscured in two ways:
- Currently polynomials always have a power-of-two length, and on CPUs
  with power-of-two threads this meant we never produced short chunks.
- The way that subsequent operations like `Ast::Add` were implemented
  meant that if a constant or linear term occurred on the right-hand
  side of an operation, the longer chunks were masked to the short chunk
  length.

We fix this by passing the polynomial length into each thread's context,
so that we can compute the correct length for the final chunk.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-01-27 00:13:17 +00:00
Jack Grigg 8cfa0bd399 Add a test exposing the `poly::Evaluator` short-chunk bug
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-01-27 00:13:17 +00:00
Jack Grigg b7944e5c40 Make `Assigned::Zero` slightly less likely in `Assigned` proptest 2022-01-21 13:57:25 +00:00
Jack Grigg 05a4d26bea Add unary operators to `Assigned` proptest 2022-01-21 13:57:25 +00:00
Jack Grigg a7e45495cf Add `Assigned::{double, square, cube}` methods 2022-01-21 13:57:25 +00:00
Jack Grigg 50b8e05913 Add other `Add*, Sub*, Mul*` variant impls to `Assigned<F>` 2022-01-21 13:57:25 +00:00
Jack Grigg 8d00acace5 `impl<F: Field> Eq for Assigned<F>` 2022-01-21 13:57:24 +00:00
Jack Grigg 927463f76a Add `Assigned::is_zero_vartime` method 2022-01-21 13:57:24 +00:00
Jack Grigg 9d0e0b7be9 Add `AssignedCell<Assigned<F>, F>::evaluate()` method
We don't want to provide a generic `map` function, since that would
enable users to arbitrarily alter the value connected to a given cell.
If a new value is being produced, that should either happen outside of
the context of a cell (e.g. intermediate values from witness generation)
or in the context of a newly-assigned cell.

However, in the case of the `Assigned<F>` type, we do need the ability
to evaluate the deferred inversion in some cases (e.g. to then operate
on the bits of the value). So for this `AssignedCell` specialization, we
provide a pass-through `evaluate()` method that otherwise preserves the
cell-value connection.
2022-01-21 13:57:24 +00:00
Jack Grigg 93ee7143fe `impl From<&Assigned<F>> for Assigned<F>`
In zcash/halo2#383 we altered the bounds on region assignment methods
like `Region::assign_advice` to constrain the value closure's result on
`for<'vr> Assigned<F>: From<&'vr VR>` instead of `VR: Into<Assigned<F>>`.
This had the unintended side-effect that `Assigned<F>` could no longer
be returned from the closure, because we were previously relying on the
implicit `impl From<T> for T` provided by Rust, which no longer fits the
bound. This commit adds the missing from-reference impl to restore
functionality, re-enabling inversion deferrment.
2022-01-21 13:57:24 +00:00
Jack Grigg 3c6558f049 Move `halo2` code into `halo2_proofs` crate 2022-01-20 18:50:43 +00:00