Commit Graph

45 Commits

Author SHA1 Message Date
Kris Nuttycombe 110ad5c642 Make the `MERKLE_DEPTH_ORCHARD` constant public. 2024-01-05 13:41:19 -07:00
Jack Grigg 3beea4adb7 Migrate to `ff 0.13`
Closes zcash/orchard#371.
2023-03-09 21:14:41 +00: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 06ad0b6925 ecc: Introduce FixedPoints trait with Full, Base, Short associated types. 2022-01-19 00:43:52 +08:00
Jack Grigg 5dd7de3cc7 Remove all uses of `PrimeField::Repr` in generic code
`PrimeField::from_repr` explicitly leaves the endianness opaque. We
therefore can't use it in places we were using `FieldExt::from_bytes`
(which was specifically little-endian) generically, but the previous
commit replaced it everywhere. We now handle generic contexts on a
case-by-case basis:

- Where we needed to convert bitstrings into field elements, we now use
  double-and-add on the field elements directly instead of on bytes.
  This is less efficient, but visible correct (and a future change to
  the `ff` crate APIs could enable the more efficient version).

- `INV_TWO_POW_K`, which is pre-computed for `pallas::Base`, was being
  incorrectly used in a field-generic circuit. We now compute it live.

- `test_zs_and_us` was only used in tests, and hard-coded a field
  element encoding length of 32 bytes. It now uses Pallas concretely.
2021-12-15 15:28:32 +00: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
str4d bb90f2eb7d
Merge pull request #101 from zcash/action-circuit
Action circuit
2021-07-27 09:49:23 +01: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 f31dd28a8e Circuit::synthesize(): Diversified address integrity. 2021-07-21 20:35:43 +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 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 747f71ca80 constants.rs: Add unit tests for T_P, T_Q constants. 2021-07-07 23:10:59 +08:00
therealyingtong cc9dd20536 chip::mul.rs: Implement variable-base scalar mul instruction.
This uses the complete addition instruction internally. The module
is split up into mul::incomplete.rs and mul::complete.rs, where
mul::incomplete handles the incomplete additions used in the
starting rounds of the variable-base scalar mul algorithm, and
mul::complete handles the complete additions in the final rounds.

Incomplete additions are broken into "hi" and "lo" halves and
processed on the same rows across different columns. This is an
optimization to make full use of the advice columns in this
instruction.
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
Kris Nuttycombe f22907a4d7 Use constants for value commitment hash-to-curve.
Fixes #76
2021-06-23 18:04:17 -06: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
therealyingtong 2d0afe9357 constants.rs: Introduce L_ORCHARD_MERKLE constant
Also test that L_ORCHARD_BASE, L_ORCHARD_SCALAR, L_ORCHARD_MERKLE
are consistent with the Pallas curve.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-10 10:33:06 +08:00
therealyingtong b33248bdb0 src::tree.rs: Implement MerklePath.root() method.
Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
2021-06-08 22:31:24 +08:00
str4d 243f862617
Fix clippy lints
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-05 13:18:14 +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
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 077f809df7 Cleanups from code review
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-05-13 10:48:10 +08:00
therealyingtong e82a76da2a Remove unused OrchardFixedBases trait 2021-05-06 12:52:52 +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 119d721ecd Use ArrayVec
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-05-03 23:58:41 +08:00
ying tong 1ee5392163
Documentation fixes
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-05-03 22:28:22 +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 69d4c4c35a Round up division for NUM_WINDOWS 2021-04-28 20:53:14 +08:00
therealyingtong 70ce1ca53f Impl PartialOrd and Ord for OrchardFixedBases 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 e4d6af620f Add l_value to constants 2021-04-28 20:53:14 +08:00
therealyingtong 3381b15cd9 Use fixed-size array for windows in tables
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-04-28 20:53:14 +08:00
therealyingtong d915097407 Implement Hash, PartialEq, Eq for OrchardFixedBases 2021-04-28 20:53:14 +08:00
therealyingtong 2c11f3a048 Add Orchard fixed bases and tests 2021-04-28 20:53:14 +08:00
therealyingtong 91fd290ffc Add SWU hash-to-curve personalizations 2021-04-28 20:53:14 +08:00
Jack Grigg 46bf89c122 Update ivk derivation to match latest protocol spec draft 2021-03-16 09:33:07 +13:00
Jack Grigg f0779792bc Orchard key components 2021-03-05 23:28:16 +00:00