Commit Graph

104 Commits

Author SHA1 Message Date
Jack Grigg 9b41a06363 Migrate to halo2 version with `AssignedCell`
We change `CellValue` into a typedef of `AssignedCell` to simplify the
migration in this commit.

The migration from `CellValue` to `AssignedCell` requires several other
changes:

- `<CellValue as Var>::value()` returned `Option<F>`, whereas
  `AssignedCell::<F, F>::value()` returns `Option<&F>`. This means we
  need to dereference, use `Option::cloned`, or alter functions to take
  `&F` arguments.
- `StateWord` in the Poseidon chip has been changed to a newtype around
  `AssignedCell` (the chip was written before `CellValue` existed).
2021-12-08 01:45:00 +00:00
Jack Grigg e99fc92e4b circuit: Use `Field::is_zero_vartime` 2021-12-08 01:44:08 +00:00
Jack Grigg 50b4600a1a circuit: Remove `Copy` impl from `CellValue`
We will be replacing it with `halo2::circuit::AssignedCell`, which does
not impl `Copy`.
2021-12-08 01:43:00 +00:00
str4d a38e2ff728
Ensure lo and hi incomplete ranges line up
The previous code assumed that `pallas::Scalar::NUM_BITS` was odd, which is true, but might not remain so after a future generalisation refactor.
2021-12-08 01:00:18 +00:00
therealyingtong c00ee1707e mul_fixed::base_field_elem: Refactor base_field_elem::Config.
This commit does not result in circuit changes.
2021-12-04 04:45:06 +00:00
therealyingtong 687e220c36 mul_fixed::short: Refactor short::Config.
This commit does not result in circuit changes.
2021-12-04 04:45:06 +00:00
therealyingtong 165c9b6941 mul_fixed::full_width: Refactor full_width::Config.
This commit does not result in circuit changes.
2021-12-04 04:45:06 +00:00
therealyingtong f472a16b32 chip::mul_fixed: Move running_sum_config into mul_fixed::Config. 2021-12-04 04:45:06 +00:00
therealyingtong 1a7e832ed4 chip::mul_fixed: Refactor mul_fixed::Config.
This commit does not introduce circuit changes.
2021-12-04 04:45:06 +00:00
therealyingtong a7dad1d611 chip::mul: Refactor mul::Config.
This commit does not introduce additional circuit changes.
2021-12-04 04:45:05 +00:00
therealyingtong 440cd14dbb mul::overflow: Refactor overflow::Config.
This is only used in chip::mul::Config. In a subsequent commit,
this will be configured from mul::Config instead of from
ecc::chip::Config.

This commit does not result in circuit changes.
2021-12-04 04:44:41 +00:00
therealyingtong 931d61a863 mul::complete: Refactor complete::Config.
This is only used in chip::mul::Config. In a subsequent commit,
this will be configured from mul::Config instead of from
ecc::chip::Config.

This commit does not result in circuit changes.
2021-12-04 04:41:52 +00:00
therealyingtong 22f57005a9 mul::incomplete: Refactor incomplete::Config.
This is only used in chip::mul::Config. In a subsequent commit,
this will be configured from mul::Config instead of from
ecc::chip::Config.

This commit does not result in circuit changes.
2021-12-04 04:39:41 +00:00
Jack Grigg 0ede6b2301 mul::Config: Reorder gate definitions
We are about to extract the sub-configs from mul::Config and refactor
them. Doing so would have moved their gate definitions past the one gate
that isn't created in a sub-config. Reordering the definitions here will
make the subsequent refactor diffs simpler to review.
2021-12-04 04:38:08 +00:00
therealyingtong 2ec480ef6b utilities::lookup_range_check: Derive Copy for LookupRangeCheckConfig. 2021-12-02 14:55:37 -05:00
therealyingtong 4fe6fb8bf2 chip::add: Refactor add::Config.
This is also used in mul and mul_fixed.
2021-12-02 14:55:36 -05:00
therealyingtong 13faedc7cc chip::add_incomplete: Refactor add_incomplete::Config.
This is also used in mul_fixed.
2021-12-02 14:54:13 -05:00
therealyingtong 9d8fee29c7 chip::witness_point: Refactor witness_point::Config. 2021-12-02 14:51:33 -05:00
therealyingtong 1a7a1255c8 mul::complete.rs: Use ternary helper in complete addition part of variable-base scalar mul. 2021-11-30 13:02:25 -05:00
therealyingtong 9513efd6f3 ecc::chip::mul.rs: Use ternary helper in variable-base scalar mul. 2021-11-30 12:52:15 -05:00
therealyingtong 409bbf36a0 mul::complete: Replace k_minus_one with one_minus_k. 2021-11-29 21:45:49 -05:00
therealyingtong 303bdc3f65 Replace local bool_check expressions with utilities::bool_check(). 2021-11-29 21:45:48 -05:00
Jack Grigg 99d03e0d25 Migrate to latest halo2 revision 2021-11-26 16:24:26 +00:00
Jack Grigg 631182fb77 Update selector columns in expected-failure tests
The addition of the non-identity selector caused the layouter to reorder
some of the selectors in the ECC gadget test circuit.
2021-09-28 21:49:06 +01:00
str4d aec3b1d52d Remove unnecessary clones in closure 2021-09-28 20:31:32 +01:00
therealyingtong 52f53f3425 Remove IsIdentity trait from public EccInstructions.
We only need is_identity() in tests and can implement it on the
concrete EccPoint type. This method is flagged off by #[cfg(test)].

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 20:31:32 +01:00
therealyingtong b0de6afd7c Reintroduce Point::new() API and constraints.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 20:31:32 +01:00
therealyingtong 8c8a12a8df Minor fixes.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-09-28 13:13:25 -06:00
therealyingtong 8ad3003e27 Remove Point::new() API and introduce is_identity() instruction.
Also remove the q_point selector and gate from the circuit.
2021-09-28 13:13:25 -06:00
therealyingtong ec27989b9b Clippy and formatting fixes.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 13:13:25 -06:00
therealyingtong 258fe5796b ecc::chip: Propagate changes to sub-chips.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 13:13:25 -06:00
therealyingtong df26a6c674 chip::witness_point.rs: Constraints for non-identity point.
The point_non_id() method returns an error if the given point is
the identity.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 13:13:25 -06:00
Jack Grigg 9af22a8cbc circuit: Add region layout diagrams for y_switch constraint
Helps to see why we can't optimise it to remove the `prev` query.
2021-07-29 20:57:33 +01:00
Jack Grigg 0009070358 circuit: Rotate`q_mul_lsb` selector up by one row
This ensures the "LSB check" gate only queries `cur` and `next` rows.
2021-07-29 14:56:56 +01:00
Jack Grigg 16e9076080 Add names to some nameless constraints 2021-07-29 14:56:56 +01:00
Daira Hopwood 145da9c510 Update to assign_table API.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-07-27 18:32:32 +01:00
therealyingtong b3ccd3f0dd Use halo2 selector optimizations. 2021-07-27 03:14:34 +08:00
therealyingtong 4d1cd2651a Return full running sum [z_0, ..., z_W] from lookup_range_check and decompose_running_sum.
Previously, these two helpers were returning different outputs.
They have now been standardised to return only the full running
sum.

Note the z_0 is the original element being decomposed by the
helper.
2021-07-25 21:10:13 +08:00
Jack Grigg 092cc389bb More small circuit optimisations
- Placing the Poseidon `state` columns after the `partial_sbox` column
  instead of before it causes them to line up with vast stretch of free
  space, enabling the pad-and-add region to be layed out there.

- Using the `Region::assign_advice_from_constant` API to initialise the
  Poseidon state removes fixed-column contention between that region and
  fixed-base scalar multiplication, enabling it to also be layed out
  within the free space.
  - If https://github.com/zcash/halo2/issues/334 were implemented then
    this region would disappear.

- The overflow check in variable-base scalar mul is also moved into the
  columns with free space.
2021-07-25 21:10:13 +08:00
therealyingtong 29f185014f merkle: Replace l_plus_1 fixed column with q_decompose selector.
Previously, l_plus_1 was a non-binary fixed column, used to
1. provide the value of l + 1; and
2. toggle the decomposition gate.

Now, the value is copied in from the global constants column, and
the toggle is handled by a binary q_decompose selector.
2021-07-25 21:10:13 +08:00
therealyingtong f532ecec10 mul::incomplete.rs: Decompose q_mul into binary selectors.
Previously, q_mul was a non-binary selector that could be set to
1, 2, or 3. We now decompose it into three binary selectors
q_mul_{1,2,3}.
2021-07-25 21:10:13 +08:00
therealyingtong 8cf7a6872c Minor refactors, text fixes, and docfixes.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-23 00:15:54 +08:00
Jack Grigg bf72e308bd De-duplicate LookupRangeCheckConfig
We were configuring multiple instances of this across all of the advice
columns, in order to spread their assignments. However, we are actually
more constrained by columns than rows, and we have comparatively few
rows of range check logic required for the Action circuit.

We now use a single LookupRangeCheckConfig for the entire circuit. The
reduction in lookup arguments and fixed columns cuts the proof size in
half (now at 6048 bytes when using `floor_planner::V1`).

Co-authored-by: therealyingtong <yingtong@z.cash>
2021-07-21 16:03:54 +01:00
Jack Grigg 5e6c8ae380 Optimise location of Poseidon within Action circuit
- Move Poseidon into the right-hand advice columns. The Action circuit
  has 33 Sinsemilla invocations with 510-bit inputs (the 32 Merkle path
  hashes, and Commit^ivk). Poseidon fits within the row count of one of
  these invocations, so we can run it in parallel with these.

- Share fixed columns between ECC and Poseidon chips. Poseidon requires
  four advice columns, while ECC incomplete addition requires six, so we
  could choose to configure them in parallel. However, we only use a
  single Poseidon invocation, and we have the rows to accomodate it
  serially with fixed-base scalar mul. Sharing the ECC chip's 8 Lagrange
  coefficient fixed columns instead reduces the proof size.

  - We position Poseidon in the right-most 6 fixed columns, anticipating
    a further optimisation to Sinsemilla that will occupy the left-most
    2 fixed columns.
2021-07-21 16:03:54 +01:00
therealyingtong d80333799d Combine constants fixed columns using assign_advice_from_constant.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-21 20:35:43 +08:00
Jack Grigg 1dca72a1cc Migrate to latest `halo2` test API 2021-07-19 12:58:05 +01:00
Jack Grigg 15f9d254d9 Migrate to latest `halo2` API
- `halo2::plonk::{create_proof, verify_proof}` now take instance columns
  as slices of values.
- `halo2::plonk::Permutation` has been replaced by a global permutation,
  to which columns can be added with `ConstraintSystem::enable_equality`.
- The introduction of blinding rows means that various tests now require
  larger circuit parameters.
2021-07-19 12:53:38 +01:00
therealyingtong fe95122ef7 mul_fixed::base_field_elem: Remove duplicate coords check gate.
The coordinate check for an element decomposed using a running sum
is enforced by mul_fixed::Config::running_sum_coords_gate().

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-19 18:08:22 +08:00
therealyingtong 91b8ea20e4 mul_fixed::short.rs: Fix magnitude bound in test.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-18 00:13:23 +08:00
therealyingtong 90b59baca5 mul_fixed: Remove unused selectors and duplicate gates.
Selectors previously used in the witness_scalar_* APIs, such as
q_scalar_fixed and q_scalar_fixed_short, are now removed. The
remaining selectors have been renamed for clarity.

The coordinates check for scalars decomposed using a running sum
has been moved into the mul_fixed.rs file, instead of being
duplicated in both mul_fixed::base_field_elem and mul_fixed::short.

The decompose_scalar_fixed() method is now only used in
mul_fixed::full_width, and has been moved there.
2021-07-18 00:10:15 +08:00