Commit Graph

600 Commits

Author SHA1 Message Date
therealyingtong 3feda9724c sinsemilla::note_commit.rs: Helper module for NoteCommit. 2021-07-21 20:35:43 +08:00
therealyingtong f31dd28a8e Circuit::synthesize(): Diversified address integrity. 2021-07-21 20:35:43 +08:00
therealyingtong 1e35b2b4fa commit_ivk.rs: Test canonicity check for different ak, nk values. 2021-07-21 20:35:43 +08:00
therealyingtong 7968c3b47e sinsemilla::commit_ivk.rs: Helper module for CommitIvk. 2021-07-21 20:35:43 +08:00
therealyingtong f431100a7a Circuit::synthesize(): Spend authority. 2021-07-21 20:35:43 +08:00
therealyingtong 48b862f13f Circuit::synthesize(): Nullifier integrity. 2021-07-21 20:35:43 +08:00
therealyingtong 626ee482bf Circuit::synthesize(): Value commitment integrity. 2021-07-21 20:35:43 +08:00
therealyingtong 4ba8762dcd Circuit::synthesize(): Merkle path validity. 2021-07-21 20:35:43 +08:00
therealyingtong b64fd5ac81 Circuit::synthesize(): Witness private variables.
Load private variables that are used across multiple checks into
the circuit.
2021-07-21 20:35:43 +08:00
therealyingtong 23af4d72ee Circuit::synthesize(): Load the Sinsemilla generator lookup table. 2021-07-21 20:35:43 +08:00
therealyingtong a369004037 Circuit::configure(): Define Config and configure Circuit.
The Action Circuit configuration uses 10 advice columns. It contains:
- a single EccConfig (10 advice columns);
- two SinsemillaConfigs (5 advice columns each);
- two MerkleConfigs (5 advice columns each);
- a PoseidonConfig, (4 advice columns);
- a PLONKConfig for standard PLONK operations (3 advice columns);
and some infrastructure to handle public inputs (subject to change
at the time of commit).

The 5-column configs are placed side-by-side in the circuit to
optimize space usage.

Gate creation is delegated to the configure() function of each
respective Chip.
2021-07-21 20:35:43 +08:00
therealyingtong 07770a0be0 builder.rs: Update ActionInfo::build() to fill in Circuit fields. 2021-07-21 20:35:43 +08:00
therealyingtong bdf2d6d9f8 circuit.rs: Define Circuit fields, impl Default for Circuit
The Default Circuit sets all fields to None. This is used as a
placeholder in src/builder.rs.

The circuit in the Circuit::round_trip() test has been filled in.
2021-07-21 20:35:43 +08:00
therealyingtong 8402c9d479 gadget::sinsemilla.rs: Make running sum available at gadget level.
The interstitial values of the Sinsemilla running sum are used in
checking canonicity of the field elements input to the hash.
2021-07-21 20:35:43 +08:00
therealyingtong 3a75f875a4 poseidon::pow5t3.rs: Take partial_sbox advice column as input.
This was previously creating an extra advice column. Instead, we
should pass in all required advice columns as inputs.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-21 20:35:43 +08:00
therealyingtong d16b83816b Implement needed getters and conversions in other modules. 2021-07-21 20:35:43 +08:00
Kris Nuttycombe 8971b37af3 Use NOTE_COMMITMENT_PERSONALIZATION constant for CommitDomain initialization. 2021-07-19 20:39:39 -06:00
str4d bd28b46163
Merge pull request #150 from zcash/bump-halo2-again
Migrate to latest `halo2` API
2021-07-19 13:56:59 +01:00
str4d 38f9e3076f
Update code comments after review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: ying tong <yingtong@z.cash>
2021-07-19 13:56:18 +01:00
str4d 146156abb6
Merge pull request #118 from zcash/sinsemilla-chip-commit
Sinsemilla chip with Commit Domain
2021-07-19 13:27:08 +01:00
str4d f44c4161af
Adjust documentation of `CommitDomains::r`
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-19 13:26:03 +01:00
therealyingtong a17a9301d7 sinsemilla::tests: Witness and constrain expected result of commit. 2021-07-19 20:03:13 +08:00
therealyingtong 8ce0725043 gadget::sinsemilla.rs: Add SinsemillaCommit test. 2021-07-19 20:03:13 +08:00
therealyingtong df4bf422f5 gadget::sinsemilla.rs: Add CommitDomain
SinsemillaInstructions gains several associated types specific to
SinsemillaCommit.
2021-07-19 20:03:12 +08:00
Jack Grigg 1dca72a1cc Migrate to latest `halo2` test API 2021-07-19 12:58:05 +01:00
Jack Grigg 654f1b4613 Add selector to dummy circuit
We need to ensure that no gates are active on the blinding factor rows.
2021-07-19 12:53:38 +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 1b615a40ee Fix documentation in decompose_running_sum. 2021-07-19 19:14:32 +08:00
therealyingtong c444ddebf8 Documentation and variable naming cleanups.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-19 18:48:49 +08: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
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 90474995a7 Add mul_short::tests cases and address review comments.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-17 00:44:56 +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 1681463856 mul_fixed::short::tests: Test negative mul_with_double case. 2021-07-15 20:51:43 +08:00
therealyingtong e21b193a17 mul_fixed::short::tests: Test invalid magnitude and sign.
Check that a magnitude larger than 64 bits results in a constraint
failure.
Check that a sign other than +/- 1 results in a constrain failure.
2021-07-15 20:51:42 +08:00
therealyingtong a8bd2d6abf mul_fixed::short: Copy (magnitude, sign) instead of witnessing Scalar.
In the Orchard circuit, the short signed scalar is v_old - v_new,
which will be witnessed as two cells: a 64-bit magnitude, and a
sign that is +/- 1.
2021-07-15 20:46:51 +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
Jack Grigg ac70a6bfdf test: Print Merkle path test circuit layout
Requires fixing an unnecessary unwrap in the test circuit's synthesis.
2021-07-15 11:25:22 +01:00
Jack Grigg d47a7d2105 Migrate to latest halo2 Circuit APIs
- The `Circuit` trait now has a `FloorPlanner` associated type.
- `circuit_layout` has been replaced by `CircuitLayout`.
2021-07-15 11:22:25 +01:00
str4d cc3e1ad0b4
Merge pull request #111 from zcash/ecc-mul
[ECC chip] Fixed- and variable-base scalar multiplication
2021-07-15 11:16:12 +01:00
therealyingtong 425ee6e038 Docfixes and minor refactors.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-15 12:27:12 +08:00
therealyingtong b696163e31 mul.rs: Explain ordering of mul::incomplete advice columns. 2021-07-14 18:30:43 +08:00
therealyingtong 0ade539441 utilities::tests::test_range_check(): Test range_check() helper.
Verify that this constraint fails when the witnessed value is out
of range.
2021-07-09 23:17:42 +08:00
therealyingtong 6c41c72e66 utilities::range_check: Correct range_check expression
Previously, we were multiplying the expression by 0, which led it
to always evaluate to true.
2021-07-09 22:03:26 +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
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 ae4e54dce8 gadget::utilities: Add test cases for bitrange_subset() helper. 2021-07-08 16:29:07 +08:00
therealyingtong 5c38f53b58 mul::tests: Witness expected point and constrain result to be equal. 2021-07-08 15:17:52 +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 b69094036c chip::mul_fixed.rs: Make q_mul_fixed a selector instead of fixed column. 2021-07-07 23:12:31 +08:00
therealyingtong 23f2ed5abe gadget::utilities.rs: Add bitrange_subset() helper. 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 9fd4d7df27 Cleanups and clippy fixes.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-07 23:10:59 +08:00
therealyingtong 2536555299 mul_fixed: Constrain interpolated window mul to be on curve.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-07 23:10:59 +08:00
Jack Grigg 67caed52eb mul::incomplete: Constrain final iteration correctly
The differences between the final iteration and prior iterations are:
- The final iteration does not constrain (x_T, y_T) to propagate down.
- The final iteration constrains an assigned y_A output instead of a
  derived y_A from the next iteration's variables.

We also swap the init_y constraint to match the book.

Co-authored-by: therealyingtong <yingtong@z.cash>
2021-07-07 23:10:59 +08:00
therealyingtong 33b66ab796 tests::print_ecc_chip(): Print ECC chip.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-07 23:10:59 +08:00
therealyingtong 3f961ab29a mul::process_lsb(): Clean up assignments and boolean-constrain LSB.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-07 23:10:59 +08:00
therealyingtong 6ffd867e23 mul::complete.rs: Constrain negation of (x_p, y_p) in double-and-add.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-07 23:10:59 +08:00
therealyingtong e75c176181 mul::incomplete.rs: Make offsets more intuitive 2021-07-07 23:10:59 +08:00
therealyingtong 4d69dec00f mul::incomplete.rs: Constrain first and last y_a values.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-07 23:10:59 +08:00
therealyingtong b363492a35 ecc::chip.rs: Introduce circuit-wide "constants" fixed column
At certain points in the circuit, we need to constrain cells in
advice columns to equal a fixed constant. Instead of defining a
new fixed column for each constant, we pass around a single
shared by all chips, that is included in the permutation over all
advice columns.

This lets us load all needed constants into a single column and
directly constrain advice cells with an equality constraint.
2021-07-07 23:10:59 +08:00
therealyingtong 69d6629ac6 chip::mul.rs: Enforce LSB if/else condition
On the LSB of the scalar, we assign a point (x,y) = (x_p, -y_p)
if LSB = 0, and (0,0) otherwise. This if/else condition must be
enforced.

Co-authored-by: Sean Bowe <ewillbefull@gmail.com>
2021-07-07 23:10:59 +08:00
Jack Grigg e726fee19b mul_fixed: Avoid computing fixed constants during proving
This decreases proving time in the Action circuit by 17%.
2021-07-07 23:10:59 +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 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
therealyingtong 37074c64f5 mul_fixed::short: Check that last window is either 0 or 1.
The magnitude of the short signed scalar must be 64 bits. We decompose
the magnitude into 22 3-bit windows and check that each window is in
the 3-bit range.

However, since the first 21 windows have already accounted for 63 bits,
the last window is constrained to be a single bit.
2021-07-07 23:10:59 +08:00
therealyingtong 747f71ca80 constants.rs: Add unit tests for T_P, T_Q constants. 2021-07-07 23:10:59 +08:00
therealyingtong 5ae9890913 mul::overflow.rs: Overflow check in variable-base scalar mul
Simplify the canonicity check for variable-base scalar multiplication,
by range-checking the low 130 bits rather than the low 127 bits.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: ying tong <yingtong@z.cash>
2021-07-07 23:10:59 +08:00
therealyingtong a3ca27b756 ecc::tests: Add tests for variable- and fixed-base scalar mul. 2021-07-07 23:10:59 +08:00
therealyingtong ae25310385 chip::mul_fixed.rs: Implement fixed-base scalar mul instruction.
Fixed-base scalar mul makes use of the add_incomplete and add
instructions internally. The full-width and short signed share
some common logic, which is captured in chip::mul_fixed.rs.

The signed short variant introduces additional logic to handle
the scalar's sign. This is done in the submodule mul_fixed::short.
2021-07-07 23:10:59 +08:00
therealyingtong a263774abf chip::witness_scalar_fixed.rs: Implement witness_scalar_fixed instruction.
A scalar used in fixed-base scalar mul needs to be decomposed into
windows to use with the fixed-base window table. Both full-width
and short signed scalars share some logic (captured in the function
decompose_scalar_fixed()).

A short signed scalar introduces additional logic: its magnitude is
decomposed, and its sign is separately witnessed. This is handled
in the submodule witness_scalar_fixed::short.
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 64a2b02d42 ecc::chip.rs: Witness scalar for variable-base scalar mul 2021-07-07 23:10:59 +08:00
therealyingtong 0f60a81485 ecc::chip.rs: Add EccScalarFixed, EccScalarFixedShort structs 2021-07-07 23:10:59 +08:00
Kris Nuttycombe 64c5b25d1c Rename OrchardIncrementalTreeDigest to MerkleCrhOrchardOutput 2021-07-01 12:09:24 -06:00
Kris Nuttycombe fd94759fab Implements the updated, total definition of MerkleCRH^Orchard
See https://github.com/zcash/zips/pull/530
2021-07-01 12:09:24 -06:00
Kris Nuttycombe aa0c0ecbec Implement ZIP-244 txid and authorizing commitments. 2021-07-01 10:10:24 -06:00
Kris Nuttycombe ab2622f59c Make note encryption OrchardDomain type public. 2021-06-30 12:47:37 -06:00
Kris Nuttycombe 234eed9cbb
Update src/note_encryption.rs
Co-authored-by: str4d <jack@electriccoin.co>
2021-06-30 11:58:28 -06:00
Kris Nuttycombe 1e95360a74 Add for_action method for constructing an OrchardDomain 2021-06-30 11:21:07 -06:00
therealyingtong 74456acea1 primitives::sinsemilla.rs: Document panic in hash()
Document that hash() panics if a message is longer than K * C.
2021-06-30 20:01:05 +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
str4d bb159a2ccf
Merge pull request #98 from zcash/merkle-chip
Merkle hash chip
2021-06-29 23:09:15 +01:00
Jack Grigg 7c38f149ac rustfmt 2021-06-29 22:46:07 +01:00
str4d cbded2b821
Optimize transpose_option_array 2021-06-29 22:43:50 +01:00
str4d 8dfcd7d49b
Remove unused lookup_config in MerkleConfig 2021-06-29 22:41:01 +01:00
str4d 9f1bd64fe9
Merge pull request #133 from zcash/patch-sinsemilla
Introduce `LookupRangeCheckConfig`s for each Sinsemilla advice column
2021-06-29 10:43:30 +01:00
str4d 3ecd0a122c
Merge pull request #132 from zcash/patch-lookup-range-check
Add short range check to `lookup_range_check` util
2021-06-29 10:38:14 +01:00
therealyingtong 3806a9d6f0 Further cleanups and docfixes.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-29 12:08:31 +08:00
therealyingtong d68eb6583d Docfixes, variable renames, cleanups
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-29 12:08:31 +08:00
therealyingtong 32e564a963 Constrain b_1 + 2^5 b_2 = z1_b in decomposition gate. 2021-06-29 12:08:31 +08:00
therealyingtong db45c81ea6 sinsemilla::merkle.rs: Add test for MerkleChip. 2021-06-29 12:08:31 +08:00
therealyingtong f30de79fc6 sinsemilla::merkle.rs: Implement MerkleInstructions for MerkleChip.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-29 12:08:31 +08:00
therealyingtong 569eb4baa6 sinsemilla::merkle.rs: Configure MerkleChip
MerkleChip::configure() takes a SinsemillaConfig as input.
2021-06-29 12:08:31 +08:00
therealyingtong 6976e2baeb sinsemilla::merkle.rs: Derive SinsemillaInstructions, CondSwapInstructions for MerkleChip 2021-06-29 12:08:31 +08:00
therealyingtong 68878d88b1 sinsemilla::merkle.rs: Add MerkleChip 2021-06-29 12:08:31 +08:00
therealyingtong d090da0159 sinsemilla::merkle.rs: Add MerkleInstructions.
This has three const generic parameters: PATH_LENGTH, K, MAX_WORDS.
PATH_LENGTH is the length of the Merkle path being hashed. K and
MAX_WORDS parameterize the internal Sinsemilla instance used in
hashing the path.
2021-06-29 12:08:31 +08:00
therealyingtong 1ac3541505 Add spec::i2lebsp and constants::MERKLE_DEPTH_ORCHARD 2021-06-29 12:07:49 +08:00
therealyingtong 12cef17559 Cleanups and minor refactors.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-29 12:02:54 +08:00
ying tong 209e6a1132
Docfixes.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: str4d <jack@electriccoin.co>
2021-06-29 09:51:02 +08:00
Jack Grigg 3badd42d15 nonempty 0.7
We can now correctly measure the heap-allocated memory used by a bundle.
2021-06-28 20:57:49 +01:00
str4d 1f861423c2
Merge pull request #122 from nuttycom/incremental_merkle_tree
Add Orchard incremental merkle tree digests.
2021-06-28 19:12:13 +01:00
Jack Grigg 9bf066ef8b rustfmt 2021-06-28 18:48:58 +01:00
str4d 93ab753b8c
Apply string fixes from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-28 18:47:02 +01:00
Kris Nuttycombe ffafb6308c Fix clippy complaints. 2021-06-28 10:56:25 -06:00
Kris Nuttycombe 0d078c8a90 Rustfmt 2021-06-28 10:01:13 -06:00
therealyingtong 9b47bd0db4 sinsemilla::tests: Use separate constants columns for chips.
To be replaced by the public inputs API.
2021-06-25 15:07:27 +08:00
therealyingtong 2ec30943b3 Configure each Sinsemilla advice column for use with a K-bit lookup.
Inputs to Sinsemilla often need to be decomposed and range-constrained.
2021-06-25 15:07:27 +08:00
therealyingtong bdcdb8ac13 Move witness_message() and witness_message_piece_bitstring() to gadget level
These instructions were not making any assignments; instead, they
were calling through to witness_message_piece_field().

This PR also renames the witness_message_piece_field() instruction
to witness_message_piece().
2021-06-25 15:07:27 +08:00
therealyingtong 6fdee71667 Adjustments to APIs in sinsemilla::chip and sinsemilla::message. 2021-06-25 15:07:27 +08:00
therealyingtong c43c91b796 gadget::utilities: Adjustments to utilities gadgets and helpers. 2021-06-25 15:05:39 +08:00
therealyingtong 3840f280d7 lookup_range_check.rs: Add short range check lookup.
Also introduce a "strict" mode for the full-length lookup, where
"true" requires the field element to be within num_words * K bits,
whereas "false" does not.
2021-06-25 15:05:39 +08:00
Kris Nuttycombe e37cec1e53 Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
2021-06-24 12:39:28 -06:00
Kris Nuttycombe fc41db1ab5 Add UNCOMMITTED_ORCHARD constant. 2021-06-24 12:33:02 -06:00
Kris Nuttycombe 90d0c254cf Account for non-canonical base in serde deserialization. 2021-06-24 09:57:35 -06:00
Kris Nuttycombe 78adc9c810 Anchor computation is partial. 2021-06-24 09:43:10 -06:00
Kris Nuttycombe f22907a4d7 Use constants for value commitment hash-to-curve.
Fixes #76
2021-06-23 18:04:17 -06:00
Kris Nuttycombe 52394b8e8d Add test for incremental Merkle tree root calculation.
Fix indexing in perfect subtree computation test for auth paths.
2021-06-23 15:57:33 -06:00
Kris Nuttycombe 1b42ae707b Make proptest bundle size configurable. 2021-06-23 15:57:33 -06:00
Kris Nuttycombe c876f74ab1 Fix level/layer confusion. 2021-06-23 15:57:33 -06:00
Kris Nuttycombe 4888f0d16c Rename Level -> Altitude 2021-06-23 15:57:33 -06:00
Kris Nuttycombe e3abbf9a42 Add serde support for OrchardIncrementalTreeDigest 2021-06-23 15:57:33 -06:00
Kris Nuttycombe 7e79fd4b1c Add necessary trait impls for OrchardIncrementalTreeDigest
Required to make the wrapper type usable for digests in
a serializable incremental merkle tree.
2021-06-23 15:57:33 -06:00
Kris Nuttycombe ce4697aca5 Add construction of OrchardIncrementalTreeDigest 2021-06-22 18:14:27 -06:00
Kris Nuttycombe 4bb252eb0c Add Orchard incremental merkle tree digests. 2021-06-22 18:14:27 -06:00
str4d 71756cffda
Merge pull request #128 from zcash/bundle-dynamic-usage
Add `Bundle<Authorized, _>::dynamic_usage` method
2021-06-22 17:46:15 +01:00
str4d 66340e2655
Merge pull request #67 from zcash/sinsemilla-chip-config
Sinsemilla chip with HashDomain
2021-06-22 16:20:35 +01:00
Jack Grigg 06f7d7fbe0 Add `Bundle<Authorized, _>::dynamic_usage` method
This will be used by `zcashd` as part of tracking the memory usage of
transactions.
2021-06-22 16:06:49 +01:00
Daira Hopwood 81fb944997 Make this crate clippy clean for warnings on nightly.
One .clone() removal; all of the other changes are removing needless borrows that are immediately
dereferenced: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-06-21 18:04:00 +01:00
Daira Hopwood 8af84479b3 Rename "Sinsemilla gate" constraint to "y check".
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-06-21 17:04:47 +01:00
Jack Grigg 62642fd804 Add `Bundle<Authorized, _>::verify_proof` API 2021-06-21 13:38:43 +01:00
therealyingtong bd08808566 SinsemillaChip::configure(): Merge "Initial y_q" gate with main gate
This allows the MockProver to see the fixed_y_q query as semantically
connected to q_sinsemilla1.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-20 20:56:56 +08:00
Jack Grigg a01c2ee829 test: Print layout for Sinsemilla test circuit 2021-06-20 11:51:33 +01:00
str4d 5f5238f411
Doc comment fixes 2021-06-20 11:30:43 +01:00
therealyingtong 002596f6cd Docfixes and cleanups.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-20 12:11:01 +08:00
therealyingtong 744f3d1653 SinsemillaChip::configure(): Combine and label gates.
The gates "Secant line" and "Sinsemilla gate" were using the same
selectors and could be combined.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-20 11:26:59 +08:00
therealyingtong eccd72fcd0 hash_piece(): Remove (correct) duplicate assignment of x_a.
hash_piece() is an internal API, which means its caller hash_message()
is working in the same region. We rely on the caller to have already
assigned each piece's initial x_a at the correct offset before making
the call to hash_piece().

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-20 11:14:02 +08:00
therealyingtong 9ce29d9d4d hash_to_point(): Introduce final_piece boolean flag
This toggles the assignment of q_s2 on the last row of each piece.
We assign q_s2 = 2 on the last row of the final piece, and q_s2 = 0
on the last row of other pieces.

This allows us to process the final_piece in the main loop together
with the other pieces.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-20 11:00:14 +08:00
therealyingtong 031bb0bc87 SinsemillaChip::configure(): Introduce closures for Y_A and x_r
These expressions are derived multiple times in the gates.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-20 10:43:24 +08:00
therealyingtong 9072ed437d generator_table.rs: Fix bug in y_p lookup expression.
Also, GeneratorTable::configure() was not being called in the main
SinsemillaChip::configure(), which meant the lookup argument had
not been activated. This has now been fixed.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-20 10:34:03 +08:00
therealyingtong 2f6ca9e6de generator_table.rs: Enforce z_n = 0 for the last message piece. 2021-06-19 22:39:19 +08:00
therealyingtong 158ab865f8 gadget::sinsemilla.rs: Add Sinsemilla test. 2021-06-19 18:17:11 +08:00
therealyingtong eba2172f4f chip::hash_to_point.rs: Implement hash_to_point instruction. 2021-06-19 18:17:10 +08:00
therealyingtong f122e481a7 sinsemilla::chip.rs: Configure Sinsemilla gates. 2021-06-19 18:17:09 +08:00
therealyingtong 7cddc9b587 sinsemilla::chip.rs: Implement witness_message_* APIs.
witness_message() witnesses a full message given a bitstring.

The other two APIs, witness_message_piece_bitstring() and
witness_message_piece_field(), both witness a message piece, i.e.
part of a message that fits within a single base field element.

witness_message_piece_bitstring() takes in a bitstring, while
witness_message_piece_field() takes in a field element. In the
latter case, the number of words encoded must be specified.
2021-06-19 18:14:22 +08:00
therealyingtong 74e617b46d chip::generator_table.rs: Load Sinsemilla generator lookup table.
The 2^K table of generators used in the Sinsemilla hash. These
are loaded into a lookup table.
2021-06-19 18:14:22 +08:00
therealyingtong ebb7dae063 sinsemilla::chip.rs: Add Sinsemilla chip.
The chip that will implement SinsemillaInstructions.
2021-06-19 18:14:22 +08:00
therealyingtong e2859df4eb sinsemilla::message.rs: Add message module.
This defines a Sinsemilla message in terms of pieces and subpieces.
This is useful when decomposing field elements and packing them
into K-bit messages.
2021-06-19 18:14:22 +08:00
therealyingtong af2ac762f4 gadget::sinsemilla.rs: Add Sinsemilla instructions.
SinsemillaInstructions has two const generic parameters: K, which
is the number of bits in each word of the hash, and MAX_WORDS,
which is the maximum number of words the hash can process.

For Orchard, K = 10, MAX_WORDS = 253.
2021-06-19 18:14:22 +08:00
therealyingtong 83eddd8857 ecc::chip.rs: Add Point::from_coordinates_unchecked() API
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-19 18:14:22 +08:00
Daira Hopwood 1c19bea842 Fix clippy lints.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-06-16 19:13:40 +01:00
Jack Grigg 5264d53498 impl Copy for Anchor 2021-06-15 15:42:06 +01:00
Jack Grigg 019ae7da8e Anchor::{from_bytes, to_bytes} 2021-06-15 15:41:57 +01:00
Daira Hopwood e412a5a25b
Merge pull request #115 from zcash/anchor-type
Store anchors as pallas::Base instead of [u8; 32]
2021-06-15 14:18:48 +01:00
Jack Grigg e90a5972f1 redpallas: Expose batch validation API 2021-06-14 21:41:12 +01:00
Jack Grigg eec17a9174 Add a `Bundle::binding_validating_key` method
This derives the `bvk` for validating `Authorized::binding_signature`.
2021-06-14 21:40:28 +01:00
ebfull ee26116fcf
Merge pull request #114 from zcash/util-range-check
utilities::lookup_range_check: Add LookupRangeCheck helper
2021-06-14 10:56:52 -06:00
therealyingtong f5bf0c1ef3 lookup_range_check.rs: Docfixes and minor refactors. 2021-06-15 00:18:38 +08:00
therealyingtong 60861b7245 sinsemilla::constants.rs: Add INV_TWO_POW_K = 1 / 2^K constant. 2021-06-15 00:18:38 +08:00
str4d 1182d8d5a7
Merge pull request #99 from zcash/note-encryption
Note encryption
2021-06-14 17:16:54 +01:00
ebfull 4a52d771b1
Merge pull request #113 from zcash/constants-concrete-type
`constants::load.rs`: Use concrete `pallas::Affine` type for generators
2021-06-14 09:25:17 -06:00
therealyingtong c25526e216 lookup_range_check.rs: Delete wrong comment. 2021-06-14 19:55:51 +08:00
therealyingtong 8a8df98a50 add_incomplete::tests: Constrain output of `P + Q` test.
Also minor docfixes and refactors.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-14 00:19:21 +08:00
therealyingtong 70ec5755cf lookup_range_check.rs: Add documentation and minor refactors.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-13 23:24:19 +08:00
therealyingtong b7b8126ccf spec.rs: Add lebs2ip function bounded on const generic L.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-13 23:20:59 +08:00
therealyingtong 7341996d2c gadget::ecc.rs: Add EccInstructions::constrain_equal() instruction.
This allows us to constrain two points to be equal in value at the
gadget level.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-13 21:26:30 +08:00
therealyingtong b299a51b31 lookup_range_check.rs: Downgrade from Chip to Config.
We need to be able to toggle the lookup on and off on specific
offsets. These offsets are often assigned outside the logic of
the decomposition.
2021-06-13 09:40:50 +08:00
therealyingtong cdab5bf8c4 gadget::utilities.rs: Remove Chip bound on UtilitiesInstructions. 2021-06-13 09:40:20 +08:00
Jack Grigg de78186503 Store anchors as pallas::Base instead of [u8; 32]
This matches what we store in `MerklePath`, and better enforces the
required type.
2021-06-12 21:35:37 +01:00
therealyingtong e83880841a utilities::lookup_range_check: Add LookupRangeCheck chip
This decomposes a field element into K-bit words and constrains each
word's range by looking it up in a K-bit lookup table.

The field element is broken down using a running sum. All interstitial
values of the running sum are returned.
2021-06-12 22:46:31 +08:00
therealyingtong a11c2066ef chip::add.rs: Use Expression::square() + other minor refactors
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-12 20:25:12 +08:00
therealyingtong e259bb3846 ecc::chip.rs: Use concrete pallas::Affine for Chip impl.
The EccInstructions trait is still generic over C: CurveAffine;
however, the EccChip implementation is specific to the pasta
curves.
2021-06-12 20:25:09 +08:00
therealyingtong aec7a7f850 ecc::chip.rs: Stub out scalar-mul-related structs and types.
These will be updated or restored in #111.
2021-06-12 20:24:14 +08:00
ying tong e1779dab70 Docfixes and minor refactors.
Co-authored-by: str4d <jack@electriccoin.co>
2021-06-12 12:41:27 +08:00
therealyingtong 6dabb16edc chip::add.rs: Use batch inversion for alpha, beta, gamma, delta 2021-06-12 12:41:27 +08:00
therealyingtong f655e38e3e chip::add_incomplete.rs: Remove superfluous check.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-12 12:41:27 +08:00
therealyingtong aff56e6763 ecc::chip.rs: Make EccPoint.x, EccPoint.y private fields
Also add public getters x() and y().

Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-12 12:41:27 +08:00
therealyingtong 433791fcb0 chip::witness_point.rs: Allow witnessing the identity. 2021-06-12 12:41:27 +08:00
therealyingtong 36d7888c1c ecc.rs: Add tests for complete and incomplete addition. 2021-06-12 12:41:27 +08:00
therealyingtong 6491ea90dd ecc::chip.rs: Bound EccConfig on <C: CurveAffine>. 2021-06-12 12:41:27 +08:00
therealyingtong e802e2917a chip::add.rs: Implement complete addition instruction. 2021-06-12 12:41:27 +08:00
therealyingtong 7dc11b95d2 chip::add_incomplete.rs: Implement add_incomplete() instruction 2021-06-12 12:41:27 +08:00
therealyingtong 7eb86eb0c2 chip::witness_point.rs: Implement witness_point() instruction. 2021-06-12 12:41:27 +08:00
therealyingtong 6627b2258f ecc::chip.rs: Add ECC chip.
Implement witness_scalar_var() and extract_p() instructions inline.
2021-06-12 12:41:27 +08:00
therealyingtong e15648cb67 gadget::ecc: Remove representations of fixed points in the circuit
Fixed points are represented by precomputed window tables. These
are not "initialized" in the circuit at any single point, but are
loaded into fixed columns at the offsets where the fixed points
are used.

Thus, we don't need FixedPoint and get_fixed() in the circuit.
Similarly, we can remove FixedPointShort and get_fixed_short().
2021-06-12 12:41:27 +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
Jack Grigg 769be6c080 Note encryption test vectors 2021-06-11 23:55:17 +01:00