Commit Graph

54 Commits

Author SHA1 Message Date
therealyingtong c80ccba801 Witness cm_old using Point::new().
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 20:31:32 +01:00
therealyingtong a5a6e78d42 src/circuit.rs: Use NonIdentityPoint for all witnessed points.
The witnessed points are cm_old, g_d_old, pk_d_old, ak.

g_d_new and pk_d_new are currently also witnessed as affine points,
which diverges from the spec.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 13:13:25 -06:00
Sean Bowe f9aa765787 Add test against hardcoded pinned verification key 2021-09-28 12:54:13 -06:00
therealyingtong 1f2132a8c0 Use correct MERKLE_DEPTH_ORCHARD in proptests.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-09-16 21:37:59 +02:00
therealyingtong 2c551db32b Use gen_const_array_with_default where possible. 2021-09-16 18:20:51 +02:00
therealyingtong 291400ec33 Rename MerkleCrhOrchardOutput -> MerkleHashOrchard. 2021-09-16 15:38:01 +02: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
therealyingtong f75f890a64 Update tree::MerklePath::root to be total. 2021-09-16 15:36:24 +02:00
Jack Grigg 7fad21e7d6 Switch to `memuse` crate for measuring heap allocations 2021-09-05 01:33:27 +01:00
Daira Hopwood 145da9c510 Update to assign_table API.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-07-27 18:32:32 +01:00
therealyingtong 3f506a0129 circuit.rs: Minor cleanups and column optimisations.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-07-27 15:41:26 +08:00
therealyingtong b3ccd3f0dd Use halo2 selector optimizations. 2021-07-27 03:14:34 +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 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 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
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
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 f31dd28a8e Circuit::synthesize(): Diversified address integrity. 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 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
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
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
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
Jack Grigg 62642fd804 Add `Bundle<Authorized, _>::verify_proof` API 2021-06-21 13:38:43 +01: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
Jack Grigg dfa3fbb19b Migrate to latest revision of halo2 2021-06-01 17:37:44 +01:00
Jack Grigg cdfd2ab0f9 Remove clones from types that now impl Copy 2021-05-28 12:10:54 +01:00
Kris Nuttycombe 800e540875 Make the `Bundle` type implement `Clone`
This is required for proptest generation that handles shrinking
correctly in librustzcash.
2021-05-13 15:35:44 -06:00
Kris Nuttycombe e72d74ccd6 Remove extraneous pub exports from the root. 2021-05-05 11:46:24 -06:00
Kris Nuttycombe 7ea8900a58 Implement AsRef for Proof 2021-05-05 11:39:07 -06:00
Kris Nuttycombe 25c90dda4b Add fast generation for not-consensus-valid authorized bundles and actions. 2021-04-29 16:14:16 -06:00
Kris Nuttycombe 4d89d45332 Add proptest generators for action and bundle types. 2021-04-28 18:04:17 -06:00
Kris Nuttycombe a5c9fb953b Add accessors necessary for zip-225 write. 2021-04-28 18:02:36 -06:00
Kris Nuttycombe e743198a50 Expose constructors required for ZIP-225 parsing. 2021-04-28 18:02:36 -06:00