Commit Graph

932 Commits

Author SHA1 Message Date
str4d 54cdc051fe
Merge pull request #237 from zcash/orchard-mainnet-circuit
Orchard proposed mainnet circuit
2021-12-20 17:49:57 +00:00
str4d 40cc3cb728
Merge pull request #267 from zcash/crate-cleanups
Crate cleanups
2021-12-20 17:35:53 +00:00
Jack Grigg d11fbd4a56 Remove `ValueSum::from_raw`
There is no reason for crate users to be constructing `ValueSum`
directly. We no longer use it to represent `valueBalanceOrchard`,
instead requiring the user to specify their own type.
2021-12-20 16:08:44 +00:00
Jack Grigg 04af08d343 Fix documentation of `orchard::value` module
Closes zcash/orchard#142.
2021-12-20 16:05:33 +00:00
Jack Grigg d84764f2db Remove outdated doc comment on `MerkleHashOrchard`
Closes zcash/orchard#245.
2021-12-20 15:24:48 +00:00
Jack Grigg 0e1220acc9 Merge branch 'main' into orchard-mainnet-circuit 2021-12-20 15:20:33 +00:00
str4d a061a861b3
Merge pull request #266 from zcash/release-0.1.0-beta.1
Release 0.1.0-beta.1
2021-12-17 22:30:14 +00:00
Jack Grigg f98431175a orchard 0.1.0-beta.1 2021-12-17 22:10:35 +00:00
Jack Grigg 369b99ee3f Add `doc_cfg` annotations 2021-12-17 22:08:58 +00:00
Jack Grigg bb04300059 zcash_note_encryption 0.1 2021-12-17 22:08:23 +00:00
Jack Grigg af236a34ad blake2b_simd 1 2021-12-17 17:06:37 +00:00
Jack Grigg f468e604e3 pprof 0.6 2021-12-17 17:05:23 +00:00
Jack Grigg 4af28cb6d4 incrementalmerkletree 0.2 2021-12-17 16:39:48 +00:00
str4d cad50e7611
Merge pull request #265 from zcash/zcash_note_encryption-api-cleanups
Migrate to latest `zcash_note_encryption` API
2021-12-17 13:43:07 +00:00
Jack Grigg 4b0b32275f Migrate to latest `zcash_note_encryption` API 2021-12-17 05:31:24 +00:00
ebfull 4592c2f275
Merge pull request #262 from zcash/261-ak_P-reject-identity
Reject the identity in `SpendValidatingKey::from_bytes`
2021-12-16 08:19:58 -07: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
str4d a5de219cee
Merge pull request #258 from zcash/ci-benchmarks
CI: Benchmark tweaks
2021-12-15 23:14:33 +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
Jack Grigg 044844c0a0 Reject the identity in `SpendValidatingKey::from_bytes`
`ak_P` is not allowed to be the identity in the Orchard protocol. We
were enforcing this by construction in most places, except for the
parsing of an Orchard full viewing key.

Closes zcash/orchard#261.
2021-12-15 13:48:59 +00:00
str4d 8a4f4e347b
Merge pull request #259 from zcash/222-rewrite-poseidon
Rewrite Poseidon implementation
2021-12-15 13:28:26 +00:00
Jack Grigg 8fe178e433 poseidon: Seal the sponge modes
A sponge can only have two modes: absorbing, and squeezing.
2021-12-15 13:08:08 +00:00
str4d 5948a4977a
poseidon: Update code comments
Also fixes some clippy lints (public docs linking to private items).

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-12-15 13:04:54 +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 eca0dd7177 CI: Switch to storing benchmarks in gh-pages branch 2021-12-09 21:43:56 +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
str4d e4f338e758
Merge pull request #250 from zcash/update-halo2-assignedcell
Migrate to halo2 version with `AssignedCell`
2021-12-09 15:30:40 +00:00
Jack Grigg 84aa43fe8b bench: Fix circuit benchmarks
Criterion's benchmark grouping does not match on group names; it only
groups benchmarks that are run prior to that specific benchmark group
instance being dropped. Since each benchmark group holds a mutable
reference to the criterion instance, this means we can't have multiple
active groups collecting measurements. Instead, we need to collect the
proving benchmarks for all recipient numbers, followed by verification
benchmarks.
2021-12-09 13:18:39 +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
Jack Grigg a44253acc7 ecc::chip: Define a `MagnitudeSign` type alias
This fixes some "complex type" clippy lints, and also will make it
easier to change it to a better-typed struct later.
2021-12-08 02:23:51 +00:00
Jack Grigg bacdf67428 Remove the `CellValue` type
In order to make the changeover easier to review, we redefined
`CellValue<F>` to be `AssignedCell<F, F>`. Now we remove that type and
rename throughout the codebase.
2021-12-08 02:10:17 +00:00
Jack Grigg 65a89f099b Replace `gadget::utilities::copy` with `AssignedCell::copy_advice`
Also replaces other copy-advice implementations that weren't using
`copy`.
2021-12-08 01:50:02 +00:00
Jack Grigg 3079800f42 Remove `Var::new` trait method
As the underlying `Region` methods now return `AssignedCell` instead of
`Cell`, we can simplify all the places where we then constructed a
`CellValue` struct.
2021-12-08 01:48:17 +00:00
Jack Grigg 9b41a06363 Migrate to halo2 version with `AssignedCell`
We change `CellValue` into a typedef of `AssignedCell` to simplify the
migration in this commit.

The migration from `CellValue` to `AssignedCell` requires several other
changes:

- `<CellValue as Var>::value()` returned `Option<F>`, whereas
  `AssignedCell::<F, F>::value()` returns `Option<&F>`. This means we
  need to dereference, use `Option::cloned`, or alter functions to take
  `&F` arguments.
- `StateWord` in the Poseidon chip has been changed to a newtype around
  `AssignedCell` (the chip was written before `CellValue` existed).
2021-12-08 01:45:00 +00:00
Jack Grigg 5cb838f1a2 circuit: Remove `Copy` impl from `poseidon::pow5::StateWord`
We will be making it a newtype around `halo2::circuit::AssignedCell`,
which does not impl `Copy`.
2021-12-08 01:44:09 +00:00
Jack Grigg e99fc92e4b circuit: Use `Field::is_zero_vartime` 2021-12-08 01:44:08 +00:00
Jack Grigg 50b4600a1a circuit: Remove `Copy` impl from `CellValue`
We will be replacing it with `halo2::circuit::AssignedCell`, which does
not impl `Copy`.
2021-12-08 01:43:00 +00:00
str4d 55567f31ed
Merge pull request #248 from zcash/ecc-config-refactor
circuit: Refactor `EccConfig` away from `impl From<EccConfig>`.
2021-12-08 01:40:14 +00:00
str4d a38e2ff728
Ensure lo and hi incomplete ranges line up
The previous code assumed that `pallas::Scalar::NUM_BITS` was odd, which is true, but might not remain so after a future generalisation refactor.
2021-12-08 01:00:18 +00:00
str4d 99b767a3a1
Merge pull request #252 from zcash/circuit-pin-proof-size
circuit: Pin the proof size
2021-12-06 20:03:22 +00:00