Commit Graph

2238 Commits

Author SHA1 Message Date
Jack Grigg 9a12beee73 halo2_gadgets: Rename `halo2` to `halo2_proofs`
The previous commit renamed `halo2_proofs` back to `halo2` temporarily
to keep the commit size down. This commit performs the rename in a
single pass.
2022-01-27 23:32:04 +00:00
Jack Grigg 5202ec6eda Integrate `halo2_gadgets` into the workspace
THe SHA-256 example gadget has been moved into the `halo2_gadgets` crate
behind an `unstable` feature flag.
2022-01-27 23:32:04 +00:00
Jack Grigg 7e9ced2eaa Merge `halo2_gadgets` from zcash/orchard into halo2_gadgets-import 2022-01-27 23:08:35 +00:00
Jack Grigg a2367abcaf Migrate to `halo2_gadgets` crate in subdir
- The crate module structure from `orchard` has been flattened.
- The book pages we want to include in `halo2` have been moved to their
  target location, to avoid any conflicts during the merge.
- Common files that already exist in zcash/halo2 have been removed.
2022-01-27 23:08:01 +00:00
Jack Grigg c4ef177e07 Implement in-crate gadget tests (independent of Orchard constants)
We define some simple fixed bases around the default Pallas generator,
and a simple Sinsemilla instantiation. The tests now compile and pass.

Co-authored-by: ying tong <yingtong@z.cash>
2022-01-27 23:08:01 +00:00
Jack Grigg c2866beb47 Delete Orchard-specific code, dependencies, and book pages
The tests do not compile as of this commit, due to Orchard-specific
constants being deleted, but everything else compiles.

Co-authored-by: ying tong <yingtong@z.cash>
2022-01-27 23:07:59 +00:00
str4d 159ab53da5
Merge pull request #186 from zcash/refactor-gadget-crates
Prepare to extract gadgets into crates
2022-01-27 17:53:18 +00:00
therealyingtong a2868262b3 Minor cleanups and fixes. 2022-01-28 00:45:44 +08:00
therealyingtong 91bc1edf8f constants::sinsemilla: Remove Q_ and S_PERSONALIZATION.
These are part of the sinsemilla gadget and are not Orchard-specific.
They will live in primitives::sinsemilla.
2022-01-27 21:14:15 +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
str4d bb56139414
Merge pull request #472 from zcash/separate-single-and-batch-verification
halo2_proofs: Improve `plonk::verify_proof` API
2022-01-27 01:19:34 +00:00
str4d a9a60cc6dd
Merge pull request #471 from zcash/poly-evaluator-thread-fix
Fix handling of short chunks in `poly::Evaluator`
2022-01-27 01:19:21 +00:00
Jack Grigg 4d336f2707 halo2_proofs: Improve `plonk::verify_proof` API
Previously `plonk::verify_proof` took an `MSM` as an argument, to enable
batch verification. However, this also required that it take a source of
randomness in order to enforce separation of proofs within a batch. This
made single-proof verification unnecessarily non-deterministic.

We now have a `VerificationStrategy` trait encapsulating the necessary
details, and separate `SingleVerifier` and `BatchVerifier` structs for
the specific variants. Proof verifiers no longer need to create and
manage the `MSM` themselves, and single-proof verifiers no longer need
to supply a source of randomness.

Co-authored-by: Sean Bowe <sean@electriccoin.co>
2022-01-27 00:20:56 +00:00
therealyingtong 85b481af35 sinsemilla::merkle: Remove MERKLE_DEPTH constant. 2022-01-27 08:14:41 +08:00
Jack Grigg d3faddc53c Fix `impl Debug for poly::Ast`
The auto-derived implementation would only work if the evaluation
context implemented `Debug`, which closures never do.
2022-01-27 00:13:17 +00:00
Jack Grigg 507be292b8 Fix `poly::Evaluator` short-chunk bug
Previously we were passing through the chunk size and index to each
thread's evaluation context, but this was insufficient for them to
determine whether or not they were processing the final chunk, or if
the final chunk was short. This led to constant and linear term chunks
being created with the full chunk size, even if the last chunk was
short. If this longer-than-short chunk reached the root of the AST, it
triggered a panic in the final `copy_from_slice()`.

The bug was obscured in two ways:
- Currently polynomials always have a power-of-two length, and on CPUs
  with power-of-two threads this meant we never produced short chunks.
- The way that subsequent operations like `Ast::Add` were implemented
  meant that if a constant or linear term occurred on the right-hand
  side of an operation, the longer chunks were masked to the short chunk
  length.

We fix this by passing the polynomial length into each thread's context,
so that we can compute the correct length for the final chunk.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-01-27 00:13:17 +00:00
Jack Grigg 8cfa0bd399 Add a test exposing the `poly::Evaluator` short-chunk bug
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2022-01-27 00:13:17 +00: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 191b5df0cb circuit.rs: Tidy up imports. 2022-01-27 08:09:29 +08:00
Jack Grigg b7944e5c40 Make `Assigned::Zero` slightly less likely in `Assigned` proptest 2022-01-21 13:57:25 +00:00
Jack Grigg 05a4d26bea Add unary operators to `Assigned` proptest 2022-01-21 13:57:25 +00:00
Jack Grigg a7e45495cf Add `Assigned::{double, square, cube}` methods 2022-01-21 13:57:25 +00:00
Jack Grigg 50b8e05913 Add other `Add*, Sub*, Mul*` variant impls to `Assigned<F>` 2022-01-21 13:57:25 +00:00
Jack Grigg 8d00acace5 `impl<F: Field> Eq for Assigned<F>` 2022-01-21 13:57:24 +00:00
Jack Grigg 927463f76a Add `Assigned::is_zero_vartime` method 2022-01-21 13:57:24 +00:00
Jack Grigg 9d0e0b7be9 Add `AssignedCell<Assigned<F>, F>::evaluate()` method
We don't want to provide a generic `map` function, since that would
enable users to arbitrarily alter the value connected to a given cell.
If a new value is being produced, that should either happen outside of
the context of a cell (e.g. intermediate values from witness generation)
or in the context of a newly-assigned cell.

However, in the case of the `Assigned<F>` type, we do need the ability
to evaluate the deferred inversion in some cases (e.g. to then operate
on the bits of the value). So for this `AssignedCell` specialization, we
provide a pass-through `evaluate()` method that otherwise preserves the
cell-value connection.
2022-01-21 13:57:24 +00:00
Jack Grigg 93ee7143fe `impl From<&Assigned<F>> for Assigned<F>`
In zcash/halo2#383 we altered the bounds on region assignment methods
like `Region::assign_advice` to constrain the value closure's result on
`for<'vr> Assigned<F>: From<&'vr VR>` instead of `VR: Into<Assigned<F>>`.
This had the unintended side-effect that `Assigned<F>` could no longer
be returned from the closure, because we were previously relying on the
implicit `impl From<T> for T` provided by Rust, which no longer fits the
bound. This commit adds the missing from-reference impl to restore
functionality, re-enabling inversion deferrment.
2022-01-21 13:57:24 +00:00
str4d d111807798
Merge pull request #465 from zcash/462-workspace
Refactor into workspace with `halo2` and `halo2_proofs`
2022-01-20 20:26:38 +00:00
Jack Grigg f79ec5cadd Recreate `halo2` as an empty library crate
This is now where the recursion logic will live.

Closes zcash/halo2#462.
2022-01-20 18:50:43 +00:00
Jack Grigg 3c6558f049 Move `halo2` code into `halo2_proofs` crate 2022-01-20 18:50:43 +00:00
str4d 36db257e82
Merge pull request #464 from L-as/main
Fix compilation with rustc 1.57.0
2022-01-20 18:24:53 +00:00
str4d 2dccf7f23b
Merge pull request #463 from zcash/ci-wasm
Fix WASM builder in CI
2022-01-20 17:59:57 +00:00
Jack Grigg 9e63eeff1b Enable `getrandom/js` feature flag for wasm32-unknown-unknown
Our dev-dependencies include getrandom, and the wasm32-unknown-unknown
target requires this getrandom feature flag in order to compile.
2022-01-20 17:42:15 +00:00
Jack Grigg 66a6537613 Pin bumpalo to `>=3,<3.9.0` for wasm32 targets
`bumpalo 3.9.0` raised its MSRV to 1.54; our current MSRV is 1.51.
2022-01-20 17:42:15 +00:00
Jack Grigg f5a8c9dff9 Depend on `rand_core` instead of `rand`
All non-test code no longer depends on `OsRng`, instead requiring the
caller to provide it.
2022-01-20 16:27:35 +00:00
Las Safin 1613445cdb
Fix compilation with rustc 1.57.0
The type inference algorithm seems to have been simplified,
meaning that the combination of T::from(x.into()) doesn't work anymore.

In any case, the code was also incomprehensible to a human, as it's not clear
by which "route" it does the transformation. It took me a few minutes to
figure out it's a `u64`.
2022-01-20 16:24:33 +00:00
str4d eb74bf6ccb
Merge pull request #447 from zcash/poly-ast-evaluator
Add `poly::Evaluator` for building polynomial operation ASTs
2022-01-20 01:42:57 +00:00
Jack Grigg 2102824599 Remove unused `Polynomial` operations with internal parallelism
These have been replaced by operations on either `poly::Ast` nodes, or
operations directly on chunks of polynomials within a higher-level
parallelism context.

Addition and scalar multiplication are (currently) still used in various
areas of the prover, so those are left in place.
2022-01-20 01:35:24 +00:00
Jack Grigg b3b783e0f4 Switch `poly::Ast` from `Box` to `Arc`
This saves a bunch of `Clone`s and `Drop`s, which were consuming
significant amounts of time in large circuits (Orchard), which meant we
didn't save as much time as we could :)
2022-01-19 21:00:18 +00: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
str4d 3e0449ed35
Merge pull request #271 from zcash/tests-pasta-prep
Migrate tests from `FieldExt::rand` to `Field::random`
2022-01-18 14:48:07 +00: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
Jack Grigg 556bb66a47 Parallelize `poly::Evaluator`
We now traverse `poly::Ast` `num_chunks + 1` times: once to collect the
polynomial rotations we need, and then once per chunk.
2022-01-17 14:01:44 +00:00
Jack Grigg 3c757dc593 Migrate `vanishing::Argument` to `poly::Evaluator` 2022-01-17 14:01:44 +00:00
Jack Grigg b7ea224389 Migrate `lookup::Argument::commit_permuted` to `poly::Evaluator` 2022-01-17 13:51:34 +00:00