Commit Graph

45 Commits

Author SHA1 Message Date
Jack Grigg 311190c2d6 Migrate to final `halo2_gadgets` pre-release revision
Includes API changes made in zcash/halo2#573.
2022-05-10 21:55:20 +00:00
str4d 15007026b1
Merge pull request #325 from zcash/fix-lints
Fix lints
2022-05-06 20:51:43 +01:00
Jack Grigg 6d6832f3f1 Fix clippy lints 2022-05-06 19:33:10 +00:00
therealyingtong 4e6200796e Implement new FixedPoint trait for OrchardFixedBasesFull. 2022-05-06 18:58:18 +00:00
Jack Grigg 4ec036c851 Remove unnecessary usage of `Vec` 2022-04-28 21:26:23 +00:00
Jack Grigg 4574d4793a Migrate to 2021 edition 2022-04-28 17:23:30 +00:00
therealyingtong f74cb9e4d3 Delete gadgets and their primitives; add `halo2_gadgets` dependency. 2022-01-29 01:57:01 +08:00
therealyingtong 91bc1edf8f constants::sinsemilla: Remove Q_ and S_PERSONALIZATION.
These are part of the sinsemilla gadget and are not Orchard-specific.
They will live in primitives::sinsemilla.
2022-01-27 21:14:15 +08:00
therealyingtong 28f2d7a84b Provide compute_lagrange_coeffs() functionality in ECCChip.
This involves moving helper functions from src/constants to a new
module, ecc::chip::constants.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2022-01-27 21:14:15 +08:00
therealyingtong 1a3cbeb896 Refactor src/constants and primitives::sinsemilla::constants. 2022-01-19 00:46:12 +08:00
therealyingtong d37db53e0b Implement utility functions inside `gadgets` module.
Instead of importing utility functions from the `orchard` crate,
the `gadgets` module now implements its own:

- lebs2ip
- i2lebsp
- decompose_word
2022-01-19 00:45:18 +08:00
Jack Grigg 0378898289 Replace `FieldExt::{from, to}_bytes` with `PrimeField::{from, to}_repr` 2021-12-09 15:39:37 +00:00
Jack Grigg 6f0cab5ffd Replace `FieldExt::from_u64` with `PrimeField: From<u64>` 2021-12-09 15:38:36 +00:00
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
therealyingtong e9dc2f747f Move hash_with_l() logic into MerkleCrhOrchardOutput::combine().
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-09-16 15:37:22 +02:00
Kris Nuttycombe b86967bc57
Merge pull request #135 from zcash/patch-ncc
Partial fixes from NCC draft report
2021-07-22 15:25:05 -06: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 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 32ea1cce27 constants::util::evaluate(): Replace fold() with reduce().
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-09 10:42:45 +08:00
Jack Grigg b15343f6f7 Add `OrchardFixedBasesFull::{generator, u}` methods
Using these in `OrchardFixedBases::{generator, u}` instead of the
`impl From<OrchardFixedBasesFull> for OrchardFixedBase` means we avoid
computing the Lagrange coefficients for the generator (which were then
immediately dropped).

This decreases proving time in the Action circuit by 53%.
2021-07-07 23:10:59 +08:00
therealyingtong ba7e1892de Minor fixes involving constants.
- document that find_zs_and_us is not meant to be used anywhere
- use F::zero() instead of F::default() in constants/util.rs
- use personalisations from constants in spec.rs
2021-06-30 20:00:36 +08:00
therealyingtong ddb9500991 constants::load.rs: Use concrete pallas::Affine type for generators
The Orchard fixed bases are Pallas curve points and are not generic
over other curves.
2021-06-12 12:36:43 +08:00
str4d d8f2af8983 Simplify `gen_const_array` implementation
Also includes a performance improvement to `i2lebsp_k`.
2021-06-11 20:46:30 +01:00
therealyingtong 18535894d6 constants::util.rs: Factor out gen_fixed_array() method. 2021-06-10 10:03:15 +08:00
str4d cd1e72bbcd
Merge pull request #106 from zcash/refactor-constants
Refactor `constants` to add `constants::load`
2021-06-05 13:42:16 +01:00
str4d 243f862617
Fix clippy lints
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-05 13:18:14 +01:00
str4d d3da71a4fd
Merge pull request #105 from zcash/constants-spend-auth-g
Add SpendAuthG fixed base
2021-06-05 12:09:51 +01:00
therealyingtong 9f27049c84 Add constants::load.rs
This makes it easier to load constants into the ECC chip.
2021-06-05 13:18:24 +08:00
therealyingtong 1d46a2d3e7 Add SpendAuthG fixed base.
Used in spend authority randomization where rk = ak + [alpha]SpendAuthG.
2021-06-05 13:16:56 +08:00
Jack Grigg bea8a9b7ff Migrate to bitvec 0.22, ff 0.10, group 0.10, pasta_curves 0.1 2021-06-04 20:38:52 +01:00
therealyingtong fa9d8a992c Update constants 2021-06-02 22:51:37 +08:00
therealyingtong 0636a6f2ec Update window table formula.
Previously, the window table M for fixed-base scalar multiplication
computed M[w][k] = [(k+1)*(2^3)^w]B for each window w, where k is a
3-bit chunk in the scalar decomposition in the range [0..8).

However, in the case k_0 = 7, k_1= 0, the window table entries would
evaluate to:
* M[0][k_0] = [(7+1)*(2^3)^0]B = [8]B,
* M[1][k_1] = [(0+1)*(2^3)^1]B = [8]B,
which means the first addition would require complete addition.

To avoid this, we alter the formula to M[w][k] = [(k+2)*(2^3)^w]B.

We make a corresponding change to the formula for the last window
W. Previously, we had:
M[W][k] = [k * (2^3)^W - \sum((2^3)^j)]B, for j in [0..W-1).

Now, we have:
M[W][k] = [k * (2^3)^W - \sum(2^(3j+1))]B, for j in [0..W-1).
2021-06-02 22:51:37 +08:00
therealyingtong fb9da0b1b3 Address review comments.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-05-18 09:45:03 +08:00
therealyingtong 81d751d1b6 Add proptest for decompose_scalar_fixed() 2021-05-13 12:52:03 +08:00
therealyingtong 077f809df7 Cleanups from code review
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-05-13 10:48:10 +08:00
therealyingtong b5de8e6c27 Only store Z_SHORT and U_SHORT for value_commit_v
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-05-04 05:05:32 +08:00
therealyingtong 11d90692e1 Fix bugs in value_commit_v, value_commit_r generators
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-05-04 02:04:56 +08:00
therealyingtong de75c9538b Update constants after hash_to_field fix (zcash/pasta_curves@a119467) 2021-04-28 20:53:14 +08:00
therealyingtong 13d7da3c45 Replace OrchardFixedBases enum with newtypes
Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
2021-04-28 20:53:14 +08:00
therealyingtong e26b6c6123 Test every row in test_lagrange_coeffs() instead of using random scalar 2021-04-28 20:53:14 +08:00
therealyingtong ce6e59bdb8 Address review comments 2021-04-28 20:53:14 +08:00
therealyingtong 17b66e1c6a Remember u-values 2021-04-28 20:53:14 +08:00
therealyingtong 21060393fe Remove redundant imports 2021-04-28 20:53:14 +08:00
therealyingtong 6cc957e998 Add constants for short signed scalar mul 2021-04-28 20:53:14 +08:00
therealyingtong 2c11f3a048 Add Orchard fixed bases and tests 2021-04-28 20:53:14 +08:00