mirror of https://github.com/zcash/halo2.git
Move `halo2` code into `halo2_proofs` crate
This commit is contained in:
parent
36db257e82
commit
3c6558f049
|
@ -18,8 +18,8 @@ gadget to consume input in 32-bit chunks.
|
|||
The SHA-256 gadget requires a chip with the following instructions:
|
||||
|
||||
```rust
|
||||
# extern crate halo2;
|
||||
# use halo2::plonk::Error;
|
||||
# extern crate halo2_proofs;
|
||||
# use halo2_proofs::plonk::Error;
|
||||
# use std::fmt;
|
||||
#
|
||||
# trait Chip: Sized {}
|
||||
|
|
|
@ -5,7 +5,7 @@ circuits.
|
|||
|
||||
## Mock prover
|
||||
|
||||
`halo2::dev::MockProver` is a tool for debugging circuits, as well as cheaply verifying
|
||||
`halo2_proofs::dev::MockProver` is a tool for debugging circuits, as well as cheaply verifying
|
||||
their correctness in unit tests. The private and public inputs to the circuit are
|
||||
constructed as would normally be done to create a proof, but `MockProver::run` instead
|
||||
creates an object that will test every constraint in the circuit directly. It returns
|
||||
|
@ -23,10 +23,10 @@ sudo apt install cmake libexpat1-dev libfreetype6-dev
|
|||
|
||||
### Circuit layout
|
||||
|
||||
`halo2::dev::CircuitLayout` renders the circuit layout as a grid:
|
||||
`halo2_proofs::dev::CircuitLayout` renders the circuit layout as a grid:
|
||||
|
||||
```rust,ignore,no_run
|
||||
{{#include ../../../examples/circuit-layout.rs:dev-graph}}
|
||||
{{#include ../../../halo2_proofs/examples/circuit-layout.rs:dev-graph}}
|
||||
```
|
||||
|
||||
- Columns are laid out from left to right as instance, advice and fixed. The order of
|
||||
|
@ -42,7 +42,7 @@ sudo apt install cmake libexpat1-dev libfreetype6-dev
|
|||
|
||||
### Circuit structure
|
||||
|
||||
`halo2::dev::circuit_dot_graph` builds a [DOT graph string] representing the given
|
||||
`halo2_proofs::dev::circuit_dot_graph` builds a [DOT graph string] representing the given
|
||||
circuit, which can then be rendered with a variety of [layout programs]. The graph is built
|
||||
from calls to `Layouter::namespace` both within the circuit, and inside the gadgets and
|
||||
chips that it uses.
|
||||
|
@ -63,7 +63,7 @@ fn main() {
|
|||
};
|
||||
|
||||
// Generate the DOT graph string.
|
||||
let dot_string = halo2::dev::circuit_dot_graph(&circuit);
|
||||
let dot_string = halo2_proofs::dev::circuit_dot_graph(&circuit);
|
||||
|
||||
// Now you can either handle it in Rust, or just
|
||||
// print it out to use with command-line tools.
|
||||
|
|
|
@ -25,7 +25,7 @@ associated types for their inputs and outputs, to allow the implementations to r
|
|||
these in a way that makes the most sense for their optimization goals.
|
||||
|
||||
```rust,ignore,no_run
|
||||
{{#include ../../../examples/simple-example.rs:instructions}}
|
||||
{{#include ../../../halo2_proofs/examples/simple-example.rs:instructions}}
|
||||
```
|
||||
|
||||
## Define a chip implementation
|
||||
|
@ -34,7 +34,7 @@ For our circuit, we will build a [chip](../concepts/chips.md) that provides the
|
|||
numeric instructions for a finite field.
|
||||
|
||||
```rust,ignore,no_run
|
||||
{{#include ../../../examples/simple-example.rs:chip}}
|
||||
{{#include ../../../halo2_proofs/examples/simple-example.rs:chip}}
|
||||
```
|
||||
|
||||
Every chip needs to implement the `Chip` trait. This defines the properties of the chip
|
||||
|
@ -42,7 +42,7 @@ that a `Layouter` may rely on when synthesizing a circuit, as well as enabling a
|
|||
state that the chip requires to be loaded into the circuit.
|
||||
|
||||
```rust,ignore,no_run
|
||||
{{#include ../../../examples/simple-example.rs:chip-impl}}
|
||||
{{#include ../../../halo2_proofs/examples/simple-example.rs:chip-impl}}
|
||||
```
|
||||
|
||||
## Configure the chip
|
||||
|
@ -51,13 +51,13 @@ The chip needs to be configured with the columns, permutations, and gates that w
|
|||
required to implement all of the desired instructions.
|
||||
|
||||
```rust,ignore,no_run
|
||||
{{#include ../../../examples/simple-example.rs:chip-config}}
|
||||
{{#include ../../../halo2_proofs/examples/simple-example.rs:chip-config}}
|
||||
```
|
||||
|
||||
## Implement chip traits
|
||||
|
||||
```rust,ignore,no_run
|
||||
{{#include ../../../examples/simple-example.rs:instructions-impl}}
|
||||
{{#include ../../../halo2_proofs/examples/simple-example.rs:instructions-impl}}
|
||||
```
|
||||
|
||||
## Build the circuit
|
||||
|
@ -66,21 +66,21 @@ Now that we have the instructions we need, and a chip that implements them, we c
|
|||
build our circuit!
|
||||
|
||||
```rust,ignore,no_run
|
||||
{{#include ../../../examples/simple-example.rs:circuit}}
|
||||
{{#include ../../../halo2_proofs/examples/simple-example.rs:circuit}}
|
||||
```
|
||||
|
||||
## Testing the circuit
|
||||
|
||||
`halo2::dev::MockProver` can be used to test that the circuit is working correctly. The
|
||||
`halo2_proofs::dev::MockProver` can be used to test that the circuit is working correctly. The
|
||||
private and public inputs to the circuit are constructed as we will do to create a proof,
|
||||
but by passing them to `MockProver::run` we get an object that can test every constraint
|
||||
in the circuit, and tell us exactly what is failing (if anything).
|
||||
|
||||
```rust,ignore,no_run
|
||||
{{#include ../../../examples/simple-example.rs:test-circuit}}
|
||||
{{#include ../../../halo2_proofs/examples/simple-example.rs:test-circuit}}
|
||||
```
|
||||
|
||||
## Full example
|
||||
|
||||
You can find the source code for this example
|
||||
[here](https://github.com/zcash/halo2/tree/main/examples/simple-example.rs).
|
||||
[here](https://github.com/zcash/halo2/tree/main/halo2_proofs/examples/simple-example.rs).
|
||||
|
|
|
@ -6,15 +6,17 @@ and this project adheres to Rust's notion of
|
|||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
(relative to `halo2 0.1.0-beta.1`)
|
||||
|
||||
### Added
|
||||
- `halo2::dev::FailureLocation` (used in `VerifyFailure::Lookup`)
|
||||
- `halo2_proofs::dev::FailureLocation` (used in `VerifyFailure::Lookup`)
|
||||
|
||||
### Changed
|
||||
- `halo2` now depends on `rand_core` instead of `rand`, and requires the caller
|
||||
to provide the specific RNG implementation:
|
||||
- `halo2::plonk::{create_proof, verify_proof}` now take an argument
|
||||
- `halo2_proofs` now depends on `rand_core` instead of `rand`, and requires the
|
||||
caller to provide the specific RNG implementation:
|
||||
- `halo2_proofs::plonk::{create_proof, verify_proof}` now take an argument
|
||||
`R: rand_core::RngCore`.
|
||||
- `halo2::plonk::Error` has been overhauled:
|
||||
- `halo2_proofs::plonk::Error` has been overhauled:
|
||||
- `Error` now implements `std::fmt::Display` and `std::error::Error`.
|
||||
- `Error` no longer implements `PartialEq`. Tests can check for specific error
|
||||
cases with `assert!(matches!(..))`, or the `assert_matches` crate.
|
||||
|
@ -24,27 +26,24 @@ and this project adheres to Rust's notion of
|
|||
- `Error::SynthesisError` is now `Error::Synthesis`.
|
||||
- `Error::TranscriptError` is now `Error::Transcript`, and stores the
|
||||
underlying `io::Error`.
|
||||
- `halo2::dev::CircuitLayout::render` now takes `k` as a `u32`, matching the
|
||||
regular parameter APIs.
|
||||
- `halo2::dev::VerifyFailure` has been overhauled:
|
||||
- `halo2_proofs::dev::CircuitLayout::render` now takes `k` as a `u32`, matching
|
||||
the regular parameter APIs.
|
||||
- `halo2_proofs::dev::VerifyFailure` has been overhauled:
|
||||
- `VerifyFailure::Cell` has been renamed to `VerifyFailure::CellNotAssigned`.
|
||||
- `VerifyFailure::ConstraintNotSatisfied` now has a `cell_values` field,
|
||||
storing the values of the cells used in the unsatisfied constraint.
|
||||
- The `row` fields of `VerifyFailure::{ConstraintNotSatisfied, Lookup}` have
|
||||
been replaced by `location` fields, which can now indicate whether the
|
||||
location falls within an assigned region.
|
||||
- `halo2::plonk::ConstraintSystem::enable_equality` and
|
||||
`halo2::plonk::ConstraintSystem::query_any` now take `Into<Column<Any>>` instead
|
||||
of `Column<Any>` as a parameter to avoid excesive `.into()` usage.
|
||||
- `halo2_proofs::plonk::ConstraintSystem::enable_equality` and
|
||||
`halo2_proofs::plonk::ConstraintSystem::query_any` now take `Into<Column<Any>>`
|
||||
instead of `Column<Any>` as a parameter to avoid excesive `.into()` usage.
|
||||
|
||||
### Removed
|
||||
- `halo2::arithmetic::BatchInvert` (use `ff::BatchInvert` instead).
|
||||
- `impl Default for halo2::poly::Rotation` (use `Rotation::cur()` instead).
|
||||
- `halo2::poly`:
|
||||
- `halo2_proofs::arithmetic::BatchInvert` (use `ff::BatchInvert` instead).
|
||||
- `impl Default for halo2_proofs::poly::Rotation` (use `Rotation::cur()` instead).
|
||||
- `halo2_proofs::poly`:
|
||||
- `EvaluationDomain::{add_extended, sub_extended, mul_extended}`
|
||||
- `Polynomial::one_minus`
|
||||
- `impl Neg, Sub for Polynomial`
|
||||
- `impl Mul for Polynomial<_, ExtendedLagrangeCoeff>`
|
||||
|
||||
## [0.1.0-beta.1] - 2021-09-24
|
||||
Initial beta release!
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "halo2"
|
||||
name = "halo2_proofs"
|
||||
version = "0.1.0-beta.1"
|
||||
authors = [
|
||||
"Sean Bowe <sean@electriccoin.co>",
|
||||
|
@ -11,14 +11,14 @@ edition = "2018"
|
|||
description = """
|
||||
[BETA] Fast proof-carrying data implementation with no trusted setup
|
||||
"""
|
||||
license-file = "COPYING"
|
||||
license-file = "../COPYING"
|
||||
repository = "https://github.com/zcash/halo2"
|
||||
documentation = "https://docs.rs/halo2"
|
||||
documentation = "https://docs.rs/halo2_proofs"
|
||||
readme = "README.md"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"]
|
||||
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "../katex-header.html"]
|
||||
|
||||
[[bench]]
|
||||
name = "arithmetic"
|
|
@ -0,0 +1,32 @@
|
|||
# halo2_proofs [![Crates.io](https://img.shields.io/crates/v/halo2_proofs.svg)](https://crates.io/crates/halo2_proofs) #
|
||||
|
||||
**IMPORTANT**: This library is in beta, and should not be used in production software.
|
||||
|
||||
## [Documentation](https://docs.rs/halo2_proofs)
|
||||
|
||||
## Minimum Supported Rust Version
|
||||
|
||||
Requires Rust **1.51** or higher.
|
||||
|
||||
Minimum supported Rust version can be changed in the future, but it will be done with a
|
||||
minor version bump.
|
||||
|
||||
## Controlling parallelism
|
||||
|
||||
`halo2_proofs` currently uses [rayon](https://github.com/rayon-rs/rayon) for parallel
|
||||
computation. The `RAYON_NUM_THREADS` environment variable can be used to set the number of
|
||||
threads.
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2020-2021 The Electric Coin Company.
|
||||
|
||||
You may use this package under the Bootstrap Open Source Licence, version 1.0,
|
||||
or at your option, any later version. See the file [`COPYING`](COPYING) for
|
||||
more details, and [`LICENSE-BOSL`](LICENSE-BOSL) for the terms of the Bootstrap
|
||||
Open Source Licence, version 1.0.
|
||||
|
||||
The purpose of the BOSL is to allow commercial improvements to the package
|
||||
while ensuring that all improvements are open source. See
|
||||
[here](https://electriccoin.co/blog/introducing-tgppl-a-radically-new-type-of-open-source-license/)
|
||||
for why the BOSL exists.
|
|
@ -1,12 +1,11 @@
|
|||
#[macro_use]
|
||||
extern crate criterion;
|
||||
|
||||
extern crate halo2;
|
||||
use crate::arithmetic::small_multiexp;
|
||||
use crate::pasta::{EqAffine, Fp};
|
||||
use crate::poly::commitment::Params;
|
||||
use group::ff::Field;
|
||||
use halo2::*;
|
||||
use halo2_proofs::*;
|
||||
|
||||
use criterion::{black_box, Criterion};
|
||||
use rand_core::OsRng;
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
use halo2::arithmetic::CurveExt;
|
||||
use halo2::pasta::{pallas, vesta};
|
||||
use halo2_proofs::arithmetic::CurveExt;
|
||||
use halo2_proofs::pasta::{pallas, vesta};
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
bench_hash_to_curve(c);
|
|
@ -1,14 +1,13 @@
|
|||
#[macro_use]
|
||||
extern crate criterion;
|
||||
|
||||
extern crate halo2;
|
||||
use group::ff::Field;
|
||||
use halo2::arithmetic::FieldExt;
|
||||
use halo2::circuit::{Cell, Layouter, SimpleFloorPlanner};
|
||||
use halo2::pasta::{EqAffine, Fp};
|
||||
use halo2::plonk::*;
|
||||
use halo2::poly::{commitment::Params, Rotation};
|
||||
use halo2::transcript::{Blake2bRead, Blake2bWrite, Challenge255};
|
||||
use halo2_proofs::arithmetic::FieldExt;
|
||||
use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner};
|
||||
use halo2_proofs::pasta::{EqAffine, Fp};
|
||||
use halo2_proofs::plonk::*;
|
||||
use halo2_proofs::poly::{commitment::Params, Rotation};
|
||||
use halo2_proofs::transcript::{Blake2bRead, Blake2bWrite, Challenge255};
|
||||
use rand_core::OsRng;
|
||||
|
||||
use std::marker::PhantomData;
|
|
@ -1,5 +1,5 @@
|
|||
use ff::Field;
|
||||
use halo2::{
|
||||
use halo2_proofs::{
|
||||
arithmetic::FieldExt,
|
||||
circuit::{Cell, Layouter, Region, SimpleFloorPlanner},
|
||||
pasta::Fp,
|
||||
|
@ -307,7 +307,7 @@ fn main() {
|
|||
.titled("Example Circuit Layout", ("sans-serif", 60))
|
||||
.unwrap();
|
||||
|
||||
halo2::dev::CircuitLayout::default()
|
||||
halo2_proofs::dev::CircuitLayout::default()
|
||||
// You can optionally render only a section of the circuit.
|
||||
.view_width(0..2)
|
||||
.view_height(0..16)
|
|
@ -8,7 +8,7 @@ use std::{
|
|||
use ff::Field;
|
||||
use group::{Curve, Group};
|
||||
use gumdrop::Options;
|
||||
use halo2::{arithmetic::best_multiexp, pasta::pallas};
|
||||
use halo2_proofs::{arithmetic::best_multiexp, pasta::pallas};
|
||||
|
||||
struct Estimator {
|
||||
/// Scalars for estimating multiexp performance.
|
|
@ -1,8 +1,6 @@
|
|||
extern crate halo2;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use halo2::{
|
||||
use halo2_proofs::{
|
||||
arithmetic::FieldExt,
|
||||
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner},
|
||||
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Selector},
|
||||
|
@ -315,7 +313,7 @@ impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
|||
// ANCHOR_END: circuit
|
||||
|
||||
fn main() {
|
||||
use halo2::{dev::MockProver, pasta::Fp};
|
||||
use halo2_proofs::{dev::MockProver, pasta::Fp};
|
||||
|
||||
// ANCHOR: test-circuit
|
||||
// The number of rows in our circuit cannot exceed 2^k. Since our example
|
|
@ -1,8 +1,6 @@
|
|||
extern crate halo2;
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use halo2::{
|
||||
use halo2_proofs::{
|
||||
arithmetic::FieldExt,
|
||||
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner},
|
||||
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Instance, Selector},
|
||||
|
@ -514,7 +512,7 @@ impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
|
|||
#[allow(clippy::many_single_char_names)]
|
||||
fn main() {
|
||||
use group::ff::Field;
|
||||
use halo2::{dev::MockProver, pasta::Fp};
|
||||
use halo2_proofs::{dev::MockProver, pasta::Fp};
|
||||
use rand_core::OsRng;
|
||||
|
||||
// ANCHOR: test-circuit
|
|
@ -357,7 +357,7 @@ impl<F: Group + Field> Mul<F> for Value<F> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use halo2::{
|
||||
/// use halo2_proofs::{
|
||||
/// arithmetic::FieldExt,
|
||||
/// circuit::{Layouter, SimpleFloorPlanner},
|
||||
/// dev::{FailureLocation, MockProver, VerifyFailure},
|
|
@ -29,7 +29,7 @@ struct Gate {
|
|||
///
|
||||
/// ```
|
||||
/// use ff::Field;
|
||||
/// use halo2::{
|
||||
/// use halo2_proofs::{
|
||||
/// circuit::{Layouter, SimpleFloorPlanner},
|
||||
/// dev::CircuitGates,
|
||||
/// plonk::{Circuit, ConstraintSystem, Error},
|
|
@ -1,4 +1,4 @@
|
|||
//! # halo2
|
||||
//! # halo2_proofs
|
||||
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
// Build without warnings on stable 1.51 and later.
|
|
@ -203,9 +203,9 @@ impl TryFrom<Column<Any>> for Column<Instance> {
|
|||
///
|
||||
/// Selectors can be used to conditionally enable (portions of) gates:
|
||||
/// ```
|
||||
/// use halo2::poly::Rotation;
|
||||
/// # use halo2::pasta::Fp;
|
||||
/// # use halo2::plonk::ConstraintSystem;
|
||||
/// use halo2_proofs::poly::Rotation;
|
||||
/// # use halo2_proofs::pasta::Fp;
|
||||
/// # use halo2_proofs::plonk::ConstraintSystem;
|
||||
///
|
||||
/// # let mut meta = ConstraintSystem::<Fp>::default();
|
||||
/// let a = meta.advice_column();
|
||||
|
@ -226,9 +226,9 @@ impl TryFrom<Column<Any>> for Column<Instance> {
|
|||
/// Selectors are disabled on all rows by default, and must be explicitly enabled on each
|
||||
/// row when required:
|
||||
/// ```
|
||||
/// use halo2::{arithmetic::FieldExt, circuit::{Chip, Layouter}, plonk::{Advice, Column, Error, Selector}};
|
||||
/// use halo2_proofs::{arithmetic::FieldExt, circuit::{Chip, Layouter}, plonk::{Advice, Column, Error, Selector}};
|
||||
/// # use ff::Field;
|
||||
/// # use halo2::plonk::Fixed;
|
||||
/// # use halo2_proofs::plonk::Fixed;
|
||||
///
|
||||
/// struct Config {
|
||||
/// a: Column<Advice>,
|
|
@ -2,16 +2,16 @@
|
|||
#![allow(clippy::op_ref)]
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use halo2::arithmetic::FieldExt;
|
||||
use halo2::circuit::{Cell, Layouter, SimpleFloorPlanner};
|
||||
use halo2::dev::MockProver;
|
||||
use halo2::pasta::{Eq, EqAffine, Fp};
|
||||
use halo2::plonk::{
|
||||
use halo2_proofs::arithmetic::FieldExt;
|
||||
use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner};
|
||||
use halo2_proofs::dev::MockProver;
|
||||
use halo2_proofs::pasta::{Eq, EqAffine, Fp};
|
||||
use halo2_proofs::plonk::{
|
||||
create_proof, keygen_pk, keygen_vk, verify_proof, Advice, Circuit, Column, ConstraintSystem,
|
||||
Error, Fixed, TableColumn, VerifyingKey,
|
||||
};
|
||||
use halo2::poly::{commitment::Params, Rotation};
|
||||
use halo2::transcript::{Blake2bRead, Blake2bWrite, Challenge255};
|
||||
use halo2_proofs::poly::{commitment::Params, Rotation};
|
||||
use halo2_proofs::transcript::{Blake2bRead, Blake2bWrite, Challenge255};
|
||||
use rand_core::OsRng;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
|
@ -444,7 +444,7 @@ fn plonk_api() {
|
|||
let proof: Vec<u8> = transcript.finalize();
|
||||
assert_eq!(
|
||||
proof.len(),
|
||||
halo2::dev::CircuitCost::<Eq, MyCircuit<_>>::measure(K as usize, &circuit)
|
||||
halo2_proofs::dev::CircuitCost::<Eq, MyCircuit<_>>::measure(K as usize, &circuit)
|
||||
.proof_size(2)
|
||||
.into(),
|
||||
);
|
Loading…
Reference in New Issue