Commit Graph

341 Commits

Author SHA1 Message Date
Jack Grigg 311190c2d6 Migrate to final `halo2_gadgets` pre-release revision
Includes API changes made in zcash/halo2#573.
2022-05-10 21:55:20 +00:00
Jack Grigg 07a88ae9f9 Fix rustdoc lint 2022-05-06 19:33:10 +00:00
Jack Grigg 706cee42f5 Migrate to `ff 0.12` 2022-05-05 17:15:03 +00:00
Jack Grigg 8c7bb5b95d Rename `RangeConstrained::subset_of` to `bitrange_of` 2022-05-04 23:54:16 +00:00
Jack Grigg b46e4822d2 Update comments on `gadget::note_commit` 2022-05-04 03:01:17 +00:00
Jack Grigg 903f9e8160 Adjust APIs of NoteCommit circuit impl to separate gadget and chip
The separation isn't quite complete, as we removed the `GateCells`
abstraction, but it makes the outer APIs clearer.
2022-05-04 03:01:17 +00:00
Jack Grigg 8f15db1d01 Inline `NoteCommitConfig::assign_gate`
After the previous refactors, the `GateCells` struct now serves no
purpose. We also make a few type safety improvements at the same time.
2022-05-04 02:05:57 +00:00
Jack Grigg bf99f13282 Refactor NoteCommit message piece decompositions onto per-region structs 2022-05-04 02:05:57 +00:00
Jack Grigg 3ced2c9c0b Refactor NoteCommit region assignment onto per-region structs 2022-05-04 02:05:57 +00:00
Jack Grigg f7ed302547 Refactor NoteCommit gate configuration into per-region structs 2022-05-03 23:31:17 +00:00
Jack Grigg c4bf8105f2 Use `AssignedCell<NoteValue, _>` for circuit note values 2022-05-03 23:24:48 +00:00
Jack Grigg 0bad10d3eb Replace `UtilitiesInstructions` usage with a dedicated helper
The new helper enables returning typed `AssignedCell`s, rather than only
`AssignedCell<F, F>`.
2022-05-03 23:24:48 +00:00
Jack Grigg 314728aada Update comments on `gadget::commit_ivk` 2022-05-03 23:24:48 +00:00
Jack Grigg bd104360a7 Migrate to `halo2_gadgets::utilities::RangeConstrained` newtype 2022-05-03 23:24:48 +00:00
Jack Grigg 3e40780313 Adjust APIs of Commit^ivk circuit impl to separate gadget and chip 2022-05-02 12:36:37 +00:00
Jack Grigg 3b922f8f48 Extract a `ValueCommit^Orchard` gadget from the circuit 2022-04-29 20:05:00 +00:00
Jack Grigg dafb357dc0 Extract a `DeriveNullifier` gadget from the circuit
This introduces an `AddChip` implementing field element addition on a
single row, precisely matching what the nullifier integrity constraints
were relying on.
2022-04-29 20:03:17 +00:00
Jack Grigg b1ce38405a Use `core` instead of `std` where possible 2022-04-28 20:20:23 +00:00
Jack Grigg 52449ef88f Migrate to `halo2::plonk::Constraints` helper 2022-04-28 19:52:55 +00:00
Jack Grigg 4574d4793a Migrate to 2021 edition 2022-04-28 17:23:30 +00:00
therealyingtong f74cb9e4d3 Delete gadgets and their primitives; add `halo2_gadgets` dependency. 2022-01-29 01:57:01 +08:00
Jack Grigg 2b333d642c pasta_curves 0.3
The MSRV is now 1.54.0, because reddsa 0.2.0 included a fix to its
nightly CI that inadvertently bumped its MSRV.

The `halo2` crate is now the `halo2_proofs` crate, but we're avoiding
the cross-repo crate rename until after `halo2_gadgets` is extracted.

This also brings in the 20% prover performance improvement from
zcash/halo2#447.
2022-01-28 22:59:59 +08:00
therealyingtong a2868262b3 Minor cleanups and fixes. 2022-01-28 00:45:44 +08: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 85b481af35 sinsemilla::merkle: Remove MERKLE_DEPTH constant. 2022-01-27 08:14:41 +08:00
therealyingtong 31259d089c ecc::chip::mul_fixed: Reintroduce build_constants() closure for constants. 2022-01-27 08:11:52 +08:00
therealyingtong f0e9daf722 gadget::ecc: Clean up bounds four FixedPointBaseField, FixedPointShort. 2022-01-27 08:10:18 +08:00
therealyingtong a5cfd2cfc6 circuit::gadget: Remove Orchard-specific names from gadget consts.
- L_ORCHARD_BASE -> pallas::Base::NUM_BITS,
- L_ORCHARD_SCALAR -> pallas::Scalar::NUM_BITS,
- L_VALUE -> L_SCALAR_SHORT,
- MERKLE_DEPTH_ORCHARD -> MERKLE_DEPTH.
2022-01-19 00:47:01 +08:00
therealyingtong 1a3cbeb896 Refactor src/constants and primitives::sinsemilla::constants. 2022-01-19 00:46:12 +08:00
therealyingtong d37db53e0b Implement utility functions inside `gadgets` module.
Instead of importing utility functions from the `orchard` crate,
the `gadgets` module now implements its own:

- lebs2ip
- i2lebsp
- decompose_word
2022-01-19 00:45:18 +08:00
therealyingtong 06ad0b6925 ecc: Introduce FixedPoints trait with Full, Base, Short associated types. 2022-01-19 00:43:52 +08:00
therealyingtong 5f8716d66a gadget::sinsemilla: Move Orchard-specific inputs into src/circuit.
The sinsemilla submodules note_commit and commit_ivk are tailored
for input lengths specific to Orchard. They have been moved out of
the gadget folder and into the circuit folder.

This also involves changing the visibility of some getter functions
to be usable outside gadget::sinsemilla.
2022-01-19 00:43:52 +08:00
Jack Grigg a83a0b3fd0 Migrate tests from `FieldExt::rand` to `Field::random`
These were missed in zcash/orchard#254.
2022-01-18 14:30:55 +00:00
therealyingtong d4d167c216 Use MockProver::FailureLocation in gadget unit tests.
This was introduced in halo2#433.
2022-01-05 21:30:45 +08:00
therealyingtong f28edd886c Remove .into() from arguments to enable_equality().
As of halo2#416, this is handled internally by the function.
2022-01-05 21:30:45 +08:00
str4d b13b9677cf
Merge pull request #254 from zcash/pasta_curves-prep
Remove various usages of `FieldExt` methods
2021-12-16 12:07:50 +00:00
Jack Grigg ab930e8866 sinsemilla: Simplify assertions in `MessagePiece::from_bitstring`
Also fixes some incorrect code comments.

Closes zcash/orchard#263.
2021-12-15 22:15:00 +00:00
Jack Grigg 1be54d9f0d Use `<= PrimeField::CAPACITY` instead of `< PrimeField::NUM_BITS` 2021-12-15 15:42:05 +00: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
str4d a64e2d64a8
poseidon: Remove `M: SpongeMode` from `PhantomData`
`M` was at one point only used as a type marker, but now it stores per-mode state.

Co-authored-by: ying tong <yingtong@z.cash>
2021-12-15 13:01:53 +00:00
Jack Grigg 423006b905 poseidon: Remove redundant additions when squeezing sponge
In the previous commit, we fixed a bug where padding was being added to
the state when the sponge was in squeezing mode. But there's no need to
assign a circuit region in which we add constant zeroes to the state :)
2021-12-10 02:40:41 +00:00
Jack Grigg ae72813f77 poseidon: Fix padding to follow sponge construction
Sponge constructions pad the entire input message and then split it into
rate-sized chunks. The previous implementation was using an incorrect
duplex-like hybrid where padding was applied to each chunked input. We
now use an enum to distinguish message and padding words being absorbed
into the sponge.

This also fixes two previous bugs:
- If a `ConstantLength` hash had a length greater than the permutation's
  rate but not a multiple of it, no padding would be generated and the
  circuit would fail to create proofs.
- If a sponge usage required more output than the permutation's rate,
  the squeeze-side permutations would in some cases incorrectly apply
  padding, when it should instead use the prior state as-is. We now add
  zeroes instead.

This change doesn't alter the Orchard circuit, because it doesn't need
any padding cells, only takes a single field element as output, and
padding is still assigned in the same region as before.
2021-12-10 02:40:41 +00:00
Jack Grigg fdeb2fb817 poseidon: Add circuit test case that fails
This exposes a bug in the way padding was being handled by the invalid
sponge-duplex hybrid construction.
2021-12-10 02:40:41 +00:00
Jack Grigg bfc65d5985 poseidon: Remove `self` parameter from `Domain` trait methods
For almost all the sponge constructions defined in the Poseidon paper,
the domain can be defined completely statically. Variable-length hashing
requires knowledge of the message length, but that can be provided to
the fixed padding function in a subsequent commit, and in any case we
can't use variable-length inputs in a circuit.
2021-12-10 02:40:33 +00:00
Jack Grigg 9f654005c7 poseidon: Replace the `Duplex` struct with a `Sponge` struct
The `Sponge` struct's API correctly enforces the properties of a sponge:
it can absorb an arbitrary number of elements, and then squeeze an
arbitrary number of elements, but cannot absorb after it has squeezed.

Co-authored-by: ying tong <yingtong@z.cash>
2021-12-10 02:40:32 +00:00
Jack Grigg b827298d42 poseidon: Rename `SpongeState` to `SpongeRate` 2021-12-09 17:19:05 +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
Jack Grigg a4135dde24 ecc::chip: Fix `print_ecc_chip`
The ECC test chip performs various checks that assume the chip will only
be synthesized with witnesses. This assumption is broken by the chip
printer test, so we fix the assumption here.
2021-12-09 00:49:01 +00:00
Jack Grigg 6b84d0955a Fix "complex type" clippy lints 2021-12-08 04:11:57 +00:00