Commit Graph

840 Commits

Author SHA1 Message Date
ying tong 9a44a14863
Merge pull request #160 from zcash/book-recombine-sinsemilla-selectors
[book] Recombine Sinsemilla q_S1, q_S2, q_S3 selectors.
2021-07-25 21:16:12 +08:00
therealyingtong d9351df544 sinsemilla::commit_ivk: Use 9 advice columns instead of 10
Change the region layout to only use 9 advice columns instead of 10.
Also rename variables to match the book.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-25 21:10:13 +08:00
therealyingtong 5999d4be6d sinsemilla::commit_ivk.rs: Change z14_c -> z13_c
This matches the constraint specified in the book.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-25 21:10:13 +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 7af1ae5b52 note_commit: Decompose q_canon into two binary selectors.
Previously, q_canon was a non-binary fixed column that was set to
either {1, 2}. It has been decomposed into two binary selectors.
2021-07-25 21:10:13 +08:00
therealyingtong 76c73531c8 lookup_range_check: Replace short_lookup_bitshift with selector.
Previously, the short_lookup_bitshift fixed column was a non-binary
selector that both provided a constant value and toggled a gate.

Now, the constant value is copied in from the global constants API,
and the toggle is handled by a q_lookup_bitshift selector.
2021-07-25 21:10:13 +08:00
therealyingtong 283b45169a merkle: Replace l_plus_1 with l
Since l_plus_1 is no longer used as a selector, we can directly
use the value l in the gate.
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 f6c951d975 sinsemilla: Decompose fixed_y_q into binary selector and constant.
Previously, fixed_y_q was a non-binary selector that both loaded
the y_Q value and toggled the y_Q gate.

Now, the gate is toggled by a q_s4 simple selector, while the value
is loaded into a separate fixed column.
2021-07-25 21:10:01 +08:00
therealyingtong 5dc5e6479a [book] Recombine Sinsemilla q_S1, q_S2, q_S3 selectors.
Since q_S1, q_S2, q_S3 are not simple selectors, they cannot be
automatically combined. We manually combine them here.
2021-07-25 20:28:05 +08:00
ying tong a2ed3f1b52
Merge pull request #155 from zcash/book-selector-optimisations
[Book] Undo selector optimisations
2021-07-25 00:57:35 +08:00
ying tong 3d56fb0716
Merge pull request #146 from zcash/book-short-scalar-mul
[book] Update constraints for short signed fixed-base mul.
2021-07-25 00:54:32 +08:00
therealyingtong 782a70a786 [book] Minor fixes.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-25 00:52:38 +08:00
ying tong ce881bc4fe
[book] Formatting fix. 2021-07-25 00:40:44 +08:00
therealyingtong 78b0ec4e7b [book] Sinsemilla: reintroduce fixed_y_q column.
Loading fixed_y_q into an advice column introduces an additional
row. Instead, we load it into a fixed column.

Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-24 23:15:17 +08:00
ying tong 6c55e1a7e3
[book] Fix updates to Sinsemilla writeup. 2021-07-23 20:34:16 +08:00
therealyingtong cba0d8672b Remove standard PLONK helper.
The Action circuit only used standard PLONK in one place. Since it
used non-binary selectors, it cannot be optimised by the halo2
selector optimisations. We now replace it with a custom gate which
uses a binary selector.
2021-07-23 17:58:58 +08: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 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
therealyingtong 7866623a1b [book] Undo selector optimisation in variable-base scalar mul
Previously, we were using a non-binary selector q_mul = {1, 2, 3}
to switch between three cases. Now, we replace this with three
binary selectors.
2021-07-22 22:39:17 +08:00
therealyingtong c5cda9481d [book] Undo selector optimisations in Sinsemilla
- Instead of defining a synthetic q_S3 based on a combination of
  of q_S1, q_S2, we simply create another selector q_S3.
- Instead of using fixed_y_q as a nonbinary selector, replace it
  with q_S4 and copy the fixed value into a row above.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-07-22 22:19:01 +08:00
Jack Grigg 43d187283e Use an existing fixed column for Action circuit global constants 2021-07-21 17:20:39 +01:00
Jack Grigg 9d6ae478b3 Switch to `floor_planner::V1`
This correctly lays out the circuit in 2^11 rows.
2021-07-21 17:19:15 +01:00
Jack Grigg 3462d3e051 Optimise layout of witnessed Sinsemilla message pieces
The Sinsemilla chip witnesses message pieces in individual regions, and
then copies them into the `hash_piece` region to initialize the running
sum. Previously these occured in the same column, but we can reduce the
utilized rows of the Action circuit by moving these into a less-used
column.

If https://github.com/zcash/halo2/issues/334 is implemented, this change
would be unnecessary, as the witnessed message piece regions would never
be assigned into the circuit.
2021-07-21 16:56:06 +01: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
therealyingtong a10aefc8c1 circuit.rs: Implement enable spends and enable outputs logic.
The utilities::enable_flag gadget has been deleted, since the
public inputs API makes it more convenient to inline the gate.
2021-07-21 20:35:43 +08:00
therealyingtong 6f4b5b0340 circuit.rs: Constrain derived circuit values to equal public inputs. 2021-07-21 20:35:43 +08:00
therealyingtong 059af49f46 Circuit::synthesize: New note commitment integrity. 2021-07-21 20:35:43 +08:00
therealyingtong 1a1a65af4a Circuit::synthesize(): Old note commmitment integrity. 2021-07-21 20:35:43 +08:00
therealyingtong 84172e0326 note_commit.rs: Test canonicity check for different input values. 2021-07-21 20:35:43 +08:00
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