Commit Graph

499 Commits

Author SHA1 Message Date
ebfull ffe87e1fef
Merge pull request #293 from zcash/assigned-batch-inversions
Add support for batched inversion of cell assignments
2021-06-19 09:05:21 -06:00
Jack Grigg 088f912d34 Make Assigned an enum, to remove field comparisions from batch eval 2021-06-18 22:04:31 +01:00
Jack Grigg 5f8a61cb24 MockProver: Switch VerifyFailure::Cell to report offset within region
This is more useful for developers, as the absolute cell row may be
obfuscated by the layouter, whereas the offset within a row is controlled
by the developer.
2021-06-18 17:52:53 +01:00
Jack Grigg 181ade5e29 MockProver: Check cell assignment per-region instead of globally
Current layouters measure the shape of regions by looking at the cells
they assign. If a chip developer forgets to assign a cell in a region,
it is possible for active gates to "stick out" past the edge of a
measured region shape.

`MockProver` checks that all active gates have their cells assigned,
but this was previously checked globally. If a layouter happened to
position the buggy region such that the dangling gate overlapped an
assigned cell in in adjacent region, this check would pass.

In this commit, we extend the check to be per-region. We map enabled
selectors and assigned cells to a specific region, and then if a gate
is active within a region, we require that its cells be assigned within
that same region.

Closes zcash/halo2#297.
2021-06-18 17:51:44 +01:00
Jack Grigg 572d74e1a0 Add an Assigned::invert method 2021-06-12 19:36:37 +01:00
Jack Grigg 1d7060af8a Enable region assignments to defer inversions 2021-06-12 19:36:37 +01:00
Jack Grigg cbd198fc71 Batch invert cell assignments during keygen and proving 2021-06-12 19:34:13 +01:00
Jack Grigg d685c5c5e6 impl operators for Assigned
This enables chips to use this as an intermediate value while computing
witnesses.
2021-06-12 19:34:13 +01:00
Jack Grigg 251bc68c05 Introduce an Assigned struct into the Assignment trait APIs
Value closures can now return a `(numerator, denominator)` tuple, in
order to defer inversions until after assignment.
2021-06-12 19:34:13 +01:00
str4d 236115917d
Merge pull request #290 from zcash/v1-layouter
V1 layouter
2021-06-12 18:14:54 +01:00
str4d eae5049ba2
Merge pull request #291 from zcash/circuitlayout-builder
dev: CircuitLayout builder
2021-06-11 23:50:08 +01:00
therealyingtong c907ca5410 plonk::circuit.rs: Add Expression::square() method.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-11 12:31:27 +08:00
Jack Grigg faac7b798b dev: Render Selectors in a darker shade of blue
The regions are now rendered uniformly the same colour, by removing the
background bleed-through (which was more complex now that the fixed
columns are rendered in two colours).
2021-06-10 00:06:20 +01:00
Jack Grigg 49e18b2647 dev: Render labels last (so they are always the top layer) 2021-06-10 00:05:49 +01:00
Jack Grigg 53c43e85b2 Fix clippy lints 2021-06-08 12:40:16 +01:00
Jack Grigg d4984ebf53 dev: Enable CircuitLayout labels to be hidden 2021-06-08 12:26:37 +01:00
Jack Grigg 52be437509 dev: Add CircuitLayout viewport controls 2021-06-08 12:26:37 +01:00
Jack Grigg 3e82c7b232 dev: Move halo2::dev::circuit_layout to halo2::dev::CircuitLayout::render
This makes it easier to add configuration to the renderer.
2021-06-08 12:13:18 +01:00
Jack Grigg 7cca91331b Implement improved strategy for the V1 layouter
This layouter improves on the single-pass strategy in two ways:

- Regions are layed out with a "first fit" strategy (using the algorithm
  described in https://github.com/zcash/halo2/issues/93) instead of a
  "last fit" strategy. This enables gaps in the circuit to be filled.

- Regions are sorted by their "advice area" (columns * rows), and are
  then layed out biggest-first. This takes advantage of the regularity
  of circuits, and that the advice columns have the most contention. It
  also leads to larger gaps between early layed-out regions that are more
  easily filled by subsequent smaller regions.
2021-06-08 11:35:41 +01:00
Jack Grigg a94d4a9c01 Implement V1 layouter
The V1 layouter is a dual-pass layouter, that has visibility into the
entire `Circuit::synthesize` step.

This first commit implements the same strategy as `SingleChipLayouter`,
behaving as if it were a single-pass layouter.
2021-06-07 15:13:41 +01:00
Jack Grigg b00a0df392 Move SingleChipLayouter into a submodule
It is a single-pass layouter, but we won't rename it for now.
2021-06-07 14:52:25 +01:00
str4d d8e4f24df4
Merge pull request #287 from zcash/remove-selector-rotations
Remove rotations from Selectors
2021-06-05 23:36:37 +01:00
str4d 879509491f
Merge pull request #286 from zcash/constraint-annotations
Enable annotating individual constraints within gates
2021-06-05 23:36:28 +01:00
str4d 1dff93a8ad
dev: Update documentation for constraint_name
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-04 23:12:55 +01:00
Jack Grigg 0d8b3bab38 Remove rotations from Selectors
Enabling selectors to be used in gates at non-zero rotations leads to
confusing gates, and inhibits our ability to create visualizations of
circuits. In most cases, a gate can be rearranged so that the selectors
have no rotation; in cases where cross-gate selector optimisations are
required, these can still be implemented using fixed columns.
2021-06-04 16:18:51 +01:00
Jack Grigg 483c872cbe dev: Clarify gate name documentation 2021-06-04 15:18:52 +01:00
Jack Grigg 876587c818 Panic in ConstraintSystem::create_gate if it would contain no constraints
We use iterators to allow a gate to contain more than one constraint, but
it is a programming error for a gate to not contain any constraints.
2021-06-04 12:59:57 +01:00
Jack Grigg 6cf73391e8 Enable annotating individual constraints within gates
The closure passed to `ConstraintSystem::create_gate` can now return:

- Tuples of `(&'static str, Expression<F>)`
- Anything implementing `IntoIterator` (e.g. `Some(Expression<F>)`)
2021-06-04 03:49:21 +01:00
Jack Grigg ff2a500e9a dev: impl fmt::Display for VerifyFailure 2021-06-04 03:46:08 +01:00
Jack Grigg 47061ade3d dev: Report indices of unsatisfied constraints
Now that gates may contain multiple constraints, we need to inform
developers about which specific constraints are failing within gates.
2021-06-04 03:46:08 +01:00
Jack Grigg e01fb15018 dev: Fix bug in cell assignment checker
The simple example was broken because it uses an instance column in a
gate. MockProver now assumes all instance cells are assigned to, since
this happens outside the circuit and outside its purview.
2021-06-04 02:56:35 +01:00
Daira Hopwood e426fddd5e
Update arithmetic.rs 2021-06-04 00:17:05 +01:00
therealyingtong 684efbd6c1 plonk::circuit : Derive Eq for Permutation 2021-06-01 17:19:06 +01:00
str4d aac310c763
Merge pull request #274 from zcash/dev-check-cells-for-active-gates
MockProver: Check that cells for active gates are assigned to
2021-06-01 17:15:12 +01:00
str4d ea3d59756b
Merge pull request #273 from zcash/multiple-polys-per-gate
Allow multiple polynomial constraints per gate
2021-06-01 17:14:53 +01:00
str4d 845bf724ff
Merge pull request #272 from zcash/configure-api-changes
`Circuit` API changes
2021-06-01 17:14:39 +01:00
Jack Grigg 6dd3d1831b MockProver: Check that cells for active gates are assigned to 2021-05-27 18:10:23 +01:00
therealyingtong 5fc0e2a449 Cargo fmt 2021-05-28 00:40:39 +08:00
therealyingtong ea1af2c9c8 Use Horner's rule in eval_polynomial() 2021-05-28 00:32:18 +08:00
Jack Grigg 32896917d0 Add a failing test showing an undetected missed assignment 2021-05-27 15:02:01 +01:00
Jack Grigg 0f0dd8a26c Allow multiple polynomial constraints per gate
This enables a gate such as ECC complete addition to define its
constraints in terms of a common set of queried columns.
2021-05-27 15:01:46 +01:00
Jack Grigg e19407a749 Expose selector enablement to the Assignment backends 2021-05-27 12:51:25 +01:00
Jack Grigg 52396aaffc Rename "virtual registers" to "virtual cells"
This name makes more sense at present, given the current API.
2021-05-27 12:08:58 +01:00
Jack Grigg f314fe0156 Track which "virtual registers" are queried for custom gates 2021-05-27 01:47:13 +01:00
Jack Grigg 6bf0803fd9 Add a plonk::Gate struct
This will make it easier to track additional gate-related metadata.
2021-05-27 01:25:22 +01:00
Jack Grigg 4a2d0a0287 Move query APIs from `ConstraintSystem` to a new `Registers` struct
This simplifies the API of `ConstraintSystem`, by only exposing query
APIs in the contexts they are required (during the creation of custom
gates or lookup tables).
2021-05-27 01:25:22 +01:00
Jack Grigg 353a07cef1 `ConstraintSystem::lookup`: Move lookup queries into a closure
This matches `ConstraintSystem::create_gate`.

At the same time, we bind the input and table expressions together as a
"table map" by requiring the closure to return a vector of tuples. This
ensures they are always the same length.
2021-05-27 00:53:31 +01:00
ebfull 870a2f1e8a
Merge pull request #242 from zcash/challenge-space
Add support for full-field challenge space
2021-05-24 11:11:30 -06:00
therealyingtong ddde5f200c Remove unused Challenge trait. 2021-05-25 00:55:34 +08:00
Jack Grigg d58fed183c Fix warnings due to clippy::unknown_clippy_lints being renamed
We can remove these workarounds once our MSRV is 1.51+.
2021-05-18 20:19:54 +01:00