Commit Graph

25 Commits

Author SHA1 Message Date
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 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 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 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 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 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
therealyingtong 179cd8e940 base_field_elem: Remove z_85_alpha = 0 check from canonicity gate.
The decompose_running_sum gadget in strict mode already enforces
this check.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-18 00:09:39 +08:00
therealyingtong e846536b4e decompose_running_sum: Remove NUM_WINDOWS, WORD_NUM_BITS const generics
These are now provided as inputs to the witness_decompose() and
copy_decompose() methods. This allows us to reuse the same config
for different word/window lengths, avoiding a duplicate constraint
creation.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-17 12:10:13 +08:00
therealyingtong 32f3068886 ecc.rs: Add MulFixedBaseField type.
In the Orchard protocol, only the NullifierK fixed base in used in
scalar multiplication with a base field element.

The mul_fixed_base_field_elem() API does not have to accept fixed
bases other than NullifierK; conversely, NullifierK does not have
to work with the full-width mul_fixed() API.
2021-07-15 20:51:52 +08:00
therealyingtong 426f954b1d gadget::ecc.rs: Inline witness_scalar_* APIs.
Witness a scalar in the region where it is used for multiplication,
instead of witnessing it separately and then copying it in.
2021-07-15 20:46:46 +08:00
therealyingtong 32f28ed4b0 gadget::ecc.rs: Bound EccInstructions on UtilitiesInstructions. 2021-07-15 20:46:40 +08:00
therealyingtong 7b497c53a3 mul_fixed::base_field_elem: Use decompose_running_sum helper. 2021-07-15 20:46:22 +08:00
therealyingtong ee062bae3d gadget::utilities: Add decompose_running_sum helper.
This decomposes a field element into K-bit windows using a
running sum. Each step of the running sum is range-constrained.
In strict mode, the final output of the running sum is constrained
to be zero.

This helper asserts K <= 3.
2021-07-15 20:46:21 +08:00
therealyingtong 8a9f8218e9 mul_fixed::base_field_elem: Remove double-enable of base_field_fixed_mul.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-09 10:23:40 +08:00
therealyingtong e2ea443fad mul_fixed::*::tests: Witness expected point and constrain result to be equal. 2021-07-08 15:06:47 +08:00
therealyingtong 22ec16f129 Minor refactors, cleanups, clippy fixes, docfixes.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-08 13:31:56 +08:00
therealyingtong 96863c9f73 mul_fixed::*: Use a separate region for complete addition assignment.
The mul_fixed regions use complete addition on the last window,
and incomplete addition on all other windows. However, the complete
addition does not depend on any offsets in the incomplete addition
region, and can be separated into a disjoint region. Since incomplete
addition uses only four advice columns, while complete addition uses
nine, separating the regions would allow the layouter to optimise
their placement.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-08 12:04:43 +08:00
therealyingtong d0e34cd204 mul_fixed::base_field_elem: Eliminate alpha_0 lookup decomposition.
We can use the three-bit existing running sum decomposition to
constrain alpha_0 to be within 130 bits. This removes the need for
a 10-bit lookup decomposition of alpha_0.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-08 11:24:18 +08:00
therealyingtong f42d48b8a4 mul_fixed::base_field_elem: Fix two_pow_130 expression.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-08 08:49:46 +08:00
therealyingtong ae72501b70 mul_fixed::base_field_elem: Add constraint alpha_2 = 0 => alpha_1 = 0.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-07 23:12:31 +08:00
therealyingtong 72e469ee10 mul_fixed::base_field_elem.rs: Check canonicity of base field element used in fixed-base scalar mul.
When using a base field element as the scalar in fixed-base mul,
we check the canonicity of its decomposition.
2021-07-07 23:12:31 +08:00
therealyingtong 2d343af068 Update mul_fixed_* APIs to take Layouter instead of Region.
These APIs are not called internally.
2021-07-07 23:10:59 +08:00
therealyingtong d550e156d9 mul_fixed_*::tests: Constrain zero outputs in mul_fixed tests.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-07 23:10:59 +08:00
therealyingtong 09b4da197d base_field_elem.rs: Support fixed-base mul using base field element.
In Orchard nullifier derivation, we multiply the fixed base
K^Orchard by a value encoded as a base field element. This commit
introduces an API that allows using a base field element as the
"scalar" in fixed-base scalar multiplication.

The API currently assumes that the base field element is output by
another instruction (i.e. there is no instruction to directly
witness it).
2021-07-07 23:10:59 +08:00