Commit Graph

32 Commits

Author SHA1 Message Date
Jack Grigg 97c27e3d5a Use complete addition in SinsemillaCommit
This is necessary because the blinding factor r can be zero with greater
than negligible probability in an adversarial case, which with incomplete
addition would cause the circuit to compute a commitment that is not on
the curve.
2021-09-28 13:13:25 -06:00
Daira Hopwood 6b6b515232 `hash_to_point` should return `Result<(Self::NonIdentityPoint, Vec<Self::RunningSum>), Error>`
because any exceptional case is treated as an error, and therefore the identity cannot be returned.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 13:13:25 -06:00
therealyingtong 8ad3003e27 Remove Point::new() API and introduce is_identity() instruction.
Also remove the q_point selector and gate from the circuit.
2021-09-28 13:13:25 -06:00
therealyingtong cdcfcbc0c2 gadget::sinsemilla: Propagate changes to the Sinsemilla gadget.
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-09-28 13:13:25 -06: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 b3ccd3f0dd Use halo2 selector optimizations. 2021-07-27 03:14:34 +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 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 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 3feda9724c sinsemilla::note_commit.rs: Helper module for NoteCommit. 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 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
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 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 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
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 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 12cef17559 Cleanups and minor refactors.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2021-06-29 12:02:54 +08: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 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
Jack Grigg a01c2ee829 test: Print layout for Sinsemilla test circuit 2021-06-20 11:51:33 +01:00
therealyingtong 158ab865f8 gadget::sinsemilla.rs: Add Sinsemilla test. 2021-06-19 18:17:11 +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