Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve halo2 query calls #154

Conversation

CeciliaZ030
Copy link

@CeciliaZ030 CeciliaZ030 changed the title 61 improve halo2 query calls Improve halo2 query calls Mar 1, 2023
}

/// Return expression from column at the current row
pub fn expr<F: Field>(&self) -> Expression<F> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps cur is a more clear name for this method?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah probably a good idea to at least also expose it as an option. I like the option for expr as well because a lot of other data types already use that to convert something to an expression.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not obvious what a column.expr() should return, what does it mean to convert a column to a expression, in how many ways can be that interpreted? This method is doing a current row rotation and that is what it should say in my opinion

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we have a next and prev method, it is obvious in my opinion that the cur one is missing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. For me it would be natural to assume that expr() is kind of the default call, like in most languages you can do things like expr(rot: i32 = 0) where you don't have to specify the default value. But if it's confusing for other people better to drop it for sure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add both expr() and cur() so that they can be used interchangeably?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my opinion is to have only cur() for the current rotation. if there is another way to convert a column to an expression that it does not include a rotation, my opinion is that in that case expr could be useful but I cannot think of any rotation-less expression from a column

Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to agree with @leolara here.

expr() just doesn't tell you anything about the fact that you're querying nor at which rotation.

I'd maybe swap names for query_cur(), query_next(), query_prev() and query_n().

Another topic is why do we need to have Option<> for the query index. Why can't we have the raw num?

@leolara
Copy link

leolara commented Mar 3, 2023

I agree with @CPerezz also in the option issue. We should put our halo2 user hat in order to design external interfaces.

I am a user, I want to query a column:

For cur rotation: c.cur() is more readable than c.expr() or c.expr(None)

For arbitrary rotation: c.rot(n), c.rotation(n) or c.query(n) is more readable than c.expr(Some(n))

Also, it seems than c.next() and c.prev() is more readable than these alternatives.

I would even include a c.nextnext() and c.prevprev() although not very important.

@Brechtpd
Copy link

Brechtpd commented Mar 3, 2023

I'd maybe swap names for query_cur(), query_next(), query_prev() and query_n().

Indeed more clear, but also more verbose. Not sure what would be best, I tend to prefer shorter when something is used a lot so there's less stuff to read and more code fits on a single line.

Another topic is why do we need to have Option<> for the query index. Why can't we have the raw num?

An Expression can now exist without a valid query_index so it seemed safer to make this very clear by using an Option. But if we make sure the query index is always only accessible by halo2 internally we could also just use some dummy value instead.

@leolara
Copy link

leolara commented Mar 3, 2023

I don't understand `An Expression can now exist without a valid query_index, I guess a query_index is a rotation? I don't know.

I think that can be one of the problems as a user of halo2, the programmer interface seems to come from internals that I don't know.

As I user of halo2, I would like to have .cur, .next, .prev and .rot. That should not be influenced by how halo2 works internally. It is about user ergonomics, in my opinion.

We should design the language that the zk circuits programmers need, for his/her experience, and then translate it to how halo2 works internally. Otherwise it is akin of programming in Assembly, where you need to understand the computer internals to code a text editor.

For a zk circuit developer halo2 is the "hardware" on which to run zk circuits, and the zk circuit language to describe it should make sense from his/her point of view and then being translated to the "hardware" machine code language.

@Brechtpd
Copy link

Brechtpd commented Mar 3, 2023

I don't understand `An Expression can now exist without a valid query_index, I guess a query_index is a rotation? I don't know.

It's just an index in an array of all (column, rotation) pairs. So only for internal use, and I checked and doesn't seem to be accessible by users.

As I user of halo2, I would like to have .cur, .next, .prev and .rot. That should not be influenced by how halo2 works internally. It is about user ergonomics, in my opinion.

Agreed, that's why the current query interface where people have to manually query expressions from meta is not great because users indeed mostly do not really need to care about that, they just want to use some data from a column at some rotation.

We should design the language that the zk circuits programmers need, for his/her experience, and then translate it to how halo2 works internally. Otherwise it is akin of programming in Assembly, where you need to understand the computer internals to code a text editor.

I think this PR is a small step forward for that, in that it moves the querying from the user's responsibility to something halo2 will do for you.

For a zk circuit developer halo2 is the "hardware" on which to run zk circuits, and the zk circuit language to describe it should make sense from his/her point of view and then being translated to the "hardware" machine code language.

Sure, but is that something halo2 itself needs to do? I think halo2 just needs to expose the basic stuff in a nice way and I think we're good, as long as the API for that is reasonable people can build abstractions on top of it as they would see fit without having to do modify halo2 itself. That is the reason I wanted to have this change, not because I'm necessarily looking forward to directly use this API, but mainly because it will make abstractions on top the halo2 easier to write. Most of this querying should probably still be abstracted away to something higher level (like the Cells of a CellManager).

@Brechtpd
Copy link

Brechtpd commented Mar 3, 2023

This PR also solves the problem found here in a more general way: privacy-scaling-explorations/zkevm-circuits#852 (comment). Querying a cell from a column already added the query to the internal halo2 structures, even if you didn't actually end up using it! The change it this PR makes it so the cost for the query is only paid when it is actually used.

@CPerezz
Copy link
Member

CPerezz commented Mar 7, 2023

@Brechtpd @CeciliaZ030 after re-reading (I've been quite bussy, apologies),
The biggest concern I have is that this will change the syntax of all the circuits breaking all compatibility with upstream circuits/chips code. And this is something I want @han0110 @kilic @ed255 @ChihChengLiang and @davidnevadoc to aggre with.

If they agree, can we go for cur(), prev(), next() & n() for the query and try to avoid the Option and use a dummy val for the query_index that doesn't exist??

@leolara
Copy link

leolara commented Mar 7, 2023

My understanding is that the meta.query_* will still work. won't?

Copy link

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass and focused on backward compatibility.

halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
halo2_proofs/src/plonk/circuit.rs Show resolved Hide resolved
halo2_proofs/src/plonk/circuit.rs Show resolved Hide resolved
halo2_proofs/src/plonk/circuit.rs Show resolved Hide resolved
Copy link
Member

@ed255 ed255 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good to me! I like this change and I vote to accept this proposal! This feature will not require changes in our existing circuit code, which is really nice. It may break some tests, as Han pointed out, from these two facts:

  • Order of gate.queried_cells may change, which means MockProver can reports failures in a different order.
  • query index is now an Option, which changes the default Debug implementation.

Both issues have solutions already proposed by Han; which I think should be considered.

Regarding the naming of the new query methods, I also agree with Leo and Carlos, I think cur is much less confusing than expr for column query at rotation 0. I would like to see these methods: cur(), next(), prev() and rot(i32).

I understand the reasoning behind wanting an expr() method, but I think it would only make sense if there was an intermediate Query type, so then we would have:

col.cur().expr();
col.next().expr();
col.prev().expr();
col.rot(4).expr();

Nevertheless I'm not proposing this option because it's very verbose.

I think it's good to keep the index: Option<usize> because it will cause a panic if the lazy cell query has not been performed when the index is needed. Using a default value would produce a silent error for such a bug.

Comment on lines 803 to 808
let col = Column {
index: query.column_index,
column_type: Fixed,
};
cells.queried_cells.push((col, query.rotation).into());
query.index = Some(cells.meta.query_fixed_index(col, query.rotation));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following Han's comment here https://github.com/privacy-scaling-explorations/halo2/pull/154/files#r1127741332
We could wrap this over if query.index.is_none() { ... }.
The same applies for Advice and Instance.

halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
@CeciliaZ030
Copy link
Author

@ed255

Without the change you request, the only breaking change would be that whenever the MockProver returns a list of failures, the order of such failures will change right? Is there any other change?

Now that I have reverted changes in meta.query_X as opposed to col.cur(), so for old code which uses VirtualCells the order will stay the same.

Are you thinking maybe on tests that produce MockProver failures and then do assert_eq on the string-formatted error?

For error format, I changed the Debug impl following @han0110 's comment, right now the failures should print out plain old information.

Copy link

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Some leftover need to be remove and also need a extra fmt.

halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
@han0110
Copy link

han0110 commented Mar 10, 2023

Need one extra format to pass cargo clippy --all-features --all-targets, see:

shuffle.rs.diff
diff --git a/halo2_proofs/examples/shuffle.rs b/halo2_proofs/examples/shuffle.rs
index c482b7b0..9e2a36d3 100644
--- a/halo2_proofs/examples/shuffle.rs
+++ b/halo2_proofs/examples/shuffle.rs
@@ -12,7 +12,7 @@ use halo2_proofs::{
            multiopen::{ProverIPA, VerifierIPA},
            strategy::AccumulatorStrategy,
        },
-        Rotation, VerificationStrategy,
+        VerificationStrategy,
    },
    transcript::{
        Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer,
@@ -63,19 +63,19 @@ impl<const W: usize> MyConfig<W> {
        // Second phase
        let z = meta.advice_column_in(SecondPhase);

-        meta.create_gate("z should start with 1", |meta| {
+        meta.create_gate("z should start with 1", |_| {
            let one = Expression::Constant(F::ONE);

            vec![q_first.expr() * (one - z.cur())]
        });

-        meta.create_gate("z should end with 1", |meta| {
+        meta.create_gate("z should end with 1", |_| {
            let one = Expression::Constant(F::ONE);

            vec![q_last.expr() * (one - z.cur())]
        });

-        meta.create_gate("z should have valid transition", |meta| {
+        meta.create_gate("z should have valid transition", |_| {
            let q_shuffle = q_shuffle.expr();
            let original = original.map(|advice| advice.cur());
            let shuffled = shuffled.map(|advice| advice.cur());

@CeciliaZ030
Copy link
Author

@han0110 Just did clippy but it was with cargo clippy --features halo2curves/reexport --all-targets
Not sure if it's my problem or not but the halo2curves we use in this version has something like this that cause my --all-features fail:

#[cfg(feature = "reexport")]
pub use group;
#[cfg(not(feature = "reexport"))]
use group;

https://github.com/privacy-scaling-explorations/halo2curves/blob/c4dce16378e7b1d4d38e563c1669cdbee1647fb2/src/lib.rs#L21
If I want to have --all-features passed then I had to add halo2curves = { git = 'https://github.com/privacy-scaling-explorations/halo2curves', branch = "main", features = ['reexport']}

Please anyone let me know if I did something wrong. 😥

@han0110
Copy link

han0110 commented Mar 13, 2023

If I want to have --all-features passed then I had to add halo2curves = { git = 'https://github.com/privacy-scaling-explorations/halo2curves', branch = "main", features = ['reexport']}

yeah it's because we have unpinned the halo2curves version recently accidentally I think, and there is a update in halo2curves that have the reexport feature disabled by default, so some imports are missing without adding that feature.

After privacy-scaling-explorations/halo2curves#31 merged it should work without adding that.

@CeciliaZ030
Copy link
Author

@han0110 Thanks for merging my #156 :) Can anyone see if this PR can be merged as well?

@CPerezz
Copy link
Member

CPerezz commented Apr 24, 2023

Will take a look today for sure @CeciliaZ030

Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I really don't like the introduction of the unwraps TBH. But I don't see a way arround.

If others are Ok with this, I'm fine if it gets in. But need @han0110 and @kilic to look at it.

let column_index = query.0.index();
let rotation = query.1 .0;
self.advice[column_index]
[(row as i32 + n + rotation) as usize % n as usize]
.into()
},
&|query| {
let query = self.cs.instance_queries[query.index];
let query = self.cs.instance_queries[query.index.unwrap()];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These unwraps still bother me TBH.
But the overall solution is much better I agree.

Copy link

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just final nitpick, others LGTM!

halo2_proofs/src/plonk/circuit.rs Outdated Show resolved Hide resolved
Copy link

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for addressing all the comments.

@han0110 han0110 merged commit 5a0525d into privacy-scaling-explorations:main Apr 26, 2023
jonathanpwang added a commit to axiom-crypto/halo2 that referenced this pull request Aug 15, 2023
* - Implements `PartialOrd` for `Value<F>`
- Adds a `transpose` method to turn `Value<Result<_>>` into
  `Result<Value<_>>`
- `Expression::identifier()` remove string memory reallocation

* Fix MockProver `assert_verify` panic errors (privacy-scaling-explorations#118)

* fix: Support dynamic lookups in `MockProver::assert_verify`

Since lookups can only be `Fixed` in Halo2-upstream, we need to add
custom suport for the error rendering of dynamic lookups which doesn't
come by default when we rebase to upstream.

This means that now we have to print not only `AdviceQuery` results to
render the `Expression` that is being looked up. But also support
`Instance`, `Advice`, `Challenge` or any other expression types that are
avaliable.

This addresses the rendering issue, renaming also the `table_columns`
variable for `lookup_columns` as the columns do not have the type
`TableColumn` by default as opposite to what happens upstream.

* fix: Don't error and emit empty String for Empty queries

* feat: Add `assert_sarisfied_par` fn to `MockProver`

* fix: Address clippy errors

* chore: Address review comments

* chore: Fix clippy lints

Resolves: privacy-scaling-explorations#116

* Remove partial ordering for value

* Remove transpose

* Parallelize SHPLONK multi-open prover (privacy-scaling-explorations#114)

* feat: parallelize (cpu) shplonk prover

* shplonk: improve `construct_intermediate_sets` using `BTreeSet` and
`BTreeMap` more aggressively

* shplonk: add `Send` and `Sync` to `Query` trait for more parallelization

* fix: ensure the order of the collection of rotation sets is independent
of the values of the opening points

Co-authored-by: Jonathan Wang <[email protected]>

* fix: FailureLocation::find empty-region handling (privacy-scaling-explorations#121)

After working on fixing
privacy-scaling-explorations/zkevm-circuits#1024, a bug was found in the
verification fn of the MockProver which implies that while finding a
FailureLocation, if a Region doesn't contain any rows.

This is fixed by introducing a 2-line solution suggested by @lispc.

Resolves: privacy-scaling-explorations#117

* Feature: Expose Fixed columns & Assembly permutation structs in MockProver instance (privacy-scaling-explorations#123)

* feat: Expose fixed columns in MockProver

* change: Make `Assembly` object public & add getters

* chore: Address leftover TODOs

* Feature to serialize/deserialize KZG params, verifying key, and proving key into uncompressed Montgomery form (privacy-scaling-explorations#111)

* feat: read `VerifyingKey` and `ProvingKey` does not require `params` as
long as we serialize `params.k()`

* feat: add features "serde-raw" and "raw-unchecked" to
serialize/deserialize KZG params, verifying key, and proving key
directly into raw bytes in internal memory format.
So field elements are stored in Montgomery form `a * R (mod p)` and
curve points are stored without compression.

* chore: switch to halo2curves 0.3.1 tag

* feat: add enum `SerdeFormat` for user to select
serialization/deserialization format of curve and field elements

Co-authored-by: Jonathan Wang <[email protected]>

* Add support for Column annotations for MockProver debugging (privacy-scaling-explorations#109)

* feat: Add `name_column` to `Layouter` & `RegionLayouter`

This adds the trait-associated function `name_column` in order to enable
the possibility of the Layouter to store annotations aobut the colums.

This function does nothing for all the trait implementors (V1,
SimpleFloor, Assembly....) except for the `MockProver`. Which is
responsible of storing a map that links within a `Region` index, the
`column::Metadata` to the annotation `String`.

* feta: Update metadata/dbg structs to hold Col->Ann mapping

* feat: Update emitter module to print Column annotations

* feat: Add lookup column annotations

This adds the fn `annotate_lookup_column` for `ConstraintSystem` which
allows to carry annotations for the lookup columns declared for a
circuit within a CS.

* feat: Add Lookup TableColumn annotations

This allows to annotate lookup `TableColumn`s and print it's annotation
within the `assert_satisfied` fn.

This has required to change the `ConstraintSystem::lookup_annotations`
to have keys as `metadata::Column` rather than `usize` as otherwise it's
impossible within the `emitter` scope to distinguish between regular
advice columns (local to the Region) and fixed columns which come from
`TableColumn`s.

* fix: Customly derive PartialEq for metadata::Region

This allows to ignore the annotation map of the metadata::Region so that
is easier to match against `VerifyFailure` errors in tests.

* fix: Update ConstraintNotSatisfied testcase

* fix: Update Debug & Display for VerifyFailure

It was necessary to improve the `prover.verify` output also. To do so,
this required auxiliary types which are obfuscated to any other part of the lib
but that are necessary in order to be able to inject the Column names inside of
the `Column` section itself.
This also required to re-implement manually `Debug` and `Display` for this enum.

This closes zcash#705

* fix: Address clippy & warnings

* fix: Add final comments & polish

* fix: Resolve cherry-pick merge conflics & errors

* chore: Change DebugColumn visibility

* chore: Allow to fetch annotations from metadata

* chore: Fix clippy lints

* chore: Remove comments from code for testing

* feat: Add support for Advice and Instance anns in lookups

* feat: Allow `V1` layouter to annotate columns too

* fix: Support `Constant` & `Selector` for lookup exprs

* chore: Address review comments

* chore: Propagete write! result in `VerifyFailure::Display`

* chore: Address clippy lints

* chore: Move Codecov, wasm-build, Bitrot & doc-tests to push (privacy-scaling-explorations#125)

* chore: Move Codecov, wasm-build, Bitrot & doc-tests to push

This should cut down significantly the CI times on every push done to a
branch for a PR.
Resolves: privacy-scaling-explorations#124

* chore: Add back `push` on CI checks

* fix: Allow to compare `Assembly` structs (privacy-scaling-explorations#126)

This was missing in privacy-scaling-explorations#123 so this PR fixes it.

* Add keccak256 hasher for transcript (#2)

* Add keccak256 hasher for transcript

* Fix keccak256 common point prefix

* Remove unnecessary hasher_* variables

* fix: transcript instantiation in poseidon benchmark loop (privacy-scaling-explorations#128)

* Improve performance of vk & pk keygen and of default `parallelize` chunking size (privacy-scaling-explorations#127)

* Squashed commit of the following:

commit 17e3c4e
Author: Mickey <[email protected]>
Date:   Fri Jul 15 11:10:32 2022 +0800

    speed up generate vk pk with multi-thread

* fix

* Improve performance of vk & pk keygen and of default `parallelize` chunking size.

Reduces proving time on large circuits consistently >=3%.
Builts upon [speed up generate vk pk with multi-thread](privacy-scaling-explorations#88)
Fixes: privacy-scaling-explorations#83

* fix: Force `VerifyFailure` to own the annotations map (privacy-scaling-explorations#131)

* fix: Force `VerifyFailure` to own the annotations map

Since otherwise we can't move the `VerifyFailure` vec's confortably, and
also, we're required to have a lot of lifetime annotations, it was
decided to force the `VerifyFailure` to own the Annotation maps.

This shouldn't be too harmful as it only triggers when testing.

Resolves: privacy-scaling-explorations#130

* chore: Address clippy lints

* feat: call synthesize in `MockProver` multiple times to behave same as real prover

* feat: check advice assignment consistency between different phases

* fix: Support annotations for CellNotAssigned in verify_par (privacy-scaling-explorations#138)

* feat: Add `assert_satisfied_at_rows_par` variant (privacy-scaling-explorations#139)

Resolves: privacy-scaling-explorations#133

* Expose mod `permutation` and re-export `permutation::keygen::Assembly` (privacy-scaling-explorations#149)

* feat: expose mod ule `permutation` and re-export `permutation::keygen::Assembly`

* feat: derive `lone` for `permutation::keygen::Assembly`

* feat: bump MSRV for `inferno`

* feat(MockProver): replace errors by asserts

In MockProver, replace all code that returns an error by an assert that panics instead of returning the error.  This change aims to make it easier to debug circuit code bugs by getting backtraces.

* MockProver test utililities (privacy-scaling-explorations#153)

* test/unwrap_value: escape Value safety in the dev module

* test/mock-prover-values: MockProver exposes the generated columns to tests

* test/mock-prover-values: doc

* mockprover-util: remove unwrap_value

---------

Co-authored-by: Aurélien Nicolas <[email protected]>

* feat: Parallel random blinder poly impl (privacy-scaling-explorations#152)

* feat: Parallelize `commit` blinder poly generator method

Solves the concerns raised in privacy-scaling-explorations#151 related to the performance of the
random poly generator inside of `commit`.

Resolves: privacy-scaling-explorations#151

* chore: add `from_evals` for Polynomial

* chore: add benches for commit_zk serial vs par

* fix: Correct thread_seeds iter size

* fix: Clippy

* chore: apply review suggestions

* fix: Inconsisten num of Scalars generated parallely

This fix from @ed255 fixes an error on the code proposal which was
rounding the num of Scalars to be generated and so, was producing
failures.

Co-authored-by: Edu <[email protected]>

* remove: legacy comments & code

---------

Co-authored-by: Edu <[email protected]>

* change: Migrate workspace to pasta_curves-0.5 (privacy-scaling-explorations#157)

* change: Migrate workspace to pasta_curves-0.5

This ports the majority of the workspace to the `pasta_curves-0.5.0`
leaving some tricky edge-cases that we need to handle carefully.

Resolves: privacy-scaling-explorations#132

* fix: Complete latest trait bounds to compile halo2proofs

* change: Migrate examples & benches to pasta 0.5

* change: Migrate halo2_gadgets to pasta-0.5

* change: Update gadgets outdated code with latest upstream

* fix: Sha3 gadget circuit

* fix: doc tests

* chore: Update merged main

* fix: Apply review suggestions

* fix: pin `halo2curves` version to `0.3.2`

* Extend Circuit trait to take parameters in config (privacy-scaling-explorations#168)

* Extend Circuit trait to take parameters in config

The Circuit trait is extended with the following:
```
pub trait Circuit<F: Field> {
    /// [...]
    type Params: Default;

    fn params(&self) -> Self::Params {
        Self::Params::default()
    }

    fn configure_with_params(meta: &mut ConstraintSystem<F>, params: &Self::Params) -> Self::Config {
        Self::configure(meta)
    }

    fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config;
}
```

This allows runtime parametrization of the circuit configuration.  The extension to the Circuit trait has been designed to minimize the breaking change: existing circuits only need to define the associated `type Params`.

Unfortunately "Associated type defaults" are unstable in Rust, otherwise this would be a non-breaking change.  See rust-lang/rust#29661

* Implement circuit params under feature flag

* Don't overwrite configure method

* Fix doc test

* Allow halo2 constraint names to have non static names (privacy-scaling-explorations#156)

* static ref to String type in Gates, Constraints, VirtualCell, Argument

* 'lookup'.to_string()

* return &str for gate name and constriant_name, also run fmt

* Update halo2_gadgets/Cargo.toml

Co-authored-by: Han <[email protected]>

* upgrade rust-toochain

---------

Co-authored-by: Carlos Pérez <[email protected]>
Co-authored-by: Han <[email protected]>

* Improve halo2 query calls (privacy-scaling-explorations#154)

* return expression from cell

* add example

* selector

* recurse Expression to fill in index

* minimized changes from the original

* backword compatible meta.query_X & challange.expr()

* cargo fmt

* fixed lookup to pass all tests

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* update

Co-authored-by: Brecht Devos <[email protected]>

* add primitives.rs back

* remove example2

* backward compatible meta.query_X & Column.cur(), next(), prev(), at(usize)

* impl Debug & make side effects only when query.index.is_none()

* change impl Debug for Expression instead & revert test in plonk_api

* upgrade rust-toolchain

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

* ran clippy

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

---------

Co-authored-by: Brecht Devos <[email protected]>
Co-authored-by: Han <[email protected]>

* fix: compute `num_chunks` more precisely (privacy-scaling-explorations#172)

* Implement Clone trait for Hash, Absorbing, and Sponge structs (privacy-scaling-explorations#171)

* Revert double-assignment mock prover check

Revert the check introduced in
privacy-scaling-explorations#129 to detect double
assignments with different values, because it breaks some tests in the zkevm
project.

There's a legitimate use case of double assignment with different values, which
is overwriting cells in order to perform negative tests (tests with bad witness
that should not pass the constraints).

Also in the EVM Circuit from the zkevm project we "abuse" the assignment of
cells as a cache: sometimes we assign some cells with a guess value, and later
on we reassign with the correct value.

I believe this check is interesting to have, so we could think of ways to add
it back as an optional feature.

* fix: Fix serialization for VerifyingKey (privacy-scaling-explorations#178)

Now the value returned when the number of selectors is a multiple of 8
is correct.

Resolves: privacy-scaling-explorations#175

* Add more getters to expose internal fields

* add a constructor (privacy-scaling-explorations#164)

* add a constructor

* add more comment

* fix as review

* remove clone

* remove

* no need to use new variable

* change comment

* fix clippy

* rename to from_parts

* remove n declaration

* feat: send sync region (privacy-scaling-explorations#180)

* feat: send / sync region

* Update layout.rs

* update

* lol

* debug

* Update keygen.rs

* Update keygen.rs

* Update keygen.rs

* Update keygen.rs

* thread-safe-region feature flag

* cleanup

* patch dev-graph

* patch non-determinism in mapping creation

* reduce mem usage for vk and pk

* mock proving examples

* swap for hashmap for insertion speed

* reduce update overhead

* replace BTree with Vec

* add benchmarks

* make the benchmarks massive

* patch clippy

* simplify lifetimes

* patch benches

* Update halo2_proofs/src/plonk/permutation/keygen.rs

Co-authored-by: Han <[email protected]>

* Update halo2_proofs/examples/vector-mul.rs

Co-authored-by: Han <[email protected]>

* rm benches

* order once

* patch lints

---------

Co-authored-by: Han <[email protected]>

* Fix `parallelize` workload imbalance (privacy-scaling-explorations#186)

* fix parallelize workload imbalance

* remove the need of unsafe

* implement native shuffle argument and api

* fix: remove nonsense comment

* strictly check shuffle rows

* address doc typos

* move compression into product commitment

* typo

* add shuffle errors for `verify_at_rows_par`

* dedup expression evaluation

* cargo fmt

* fix fields in sanity-checks feature

* Updates halo2_curves dependency to released package (privacy-scaling-explorations#190)

THe package release ressets the version from those inherited by the legacy
halo2curves repo's fork history.

The upstream diff is:
https://github.com/privacy-scaling-explorations/halo2curves/compare/9f5c50810bbefe779ee5cf1d852b2fe85dc35d5e..9a7f726fa74c8765bc7cdab11519cf285d169ecf

* chore: remove monorepo

Go back to having halo2curves and poseidon in separate repos.

* chore: fix clippy and tests

* fix: remove thread-safe-regions feature

`WitnessCollection` in `create_proof` isn't thread-safe.
We removed `Region`s from `SimpleLayouter` anyways.

* fix: rustfmt

* fix: dev-graph

* chore: update lint CI name

* chore: fix clippy

* chore: autoexample = false

turn off examples that use layouter

* chore(CI): separate job for examples

* chore: remove prefetch from asm, not used

* chore: fix asm feature

---------

Co-authored-by: adria0 <nowhere@>
Co-authored-by: Carlos Pérez <[email protected]>
Co-authored-by: adria0.eth <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>
Co-authored-by: kilic <[email protected]>
Co-authored-by: dante <[email protected]>
Co-authored-by: pinkiebell <[email protected]>
Co-authored-by: han0110 <[email protected]>
Co-authored-by: Eduard S <[email protected]>
Co-authored-by: naure <[email protected]>
Co-authored-by: Aurélien Nicolas <[email protected]>
Co-authored-by: CeciliaZ030 <[email protected]>
Co-authored-by: Brecht Devos <[email protected]>
Co-authored-by: Enrico Bottazzi <[email protected]>
Co-authored-by: Ethan-000 <[email protected]>
Co-authored-by: Mamy Ratsimbazafy <[email protected]>
Co-authored-by: kilic <[email protected]>
Co-authored-by: François Garillot <[email protected]>
Velaciela pushed a commit to scroll-tech/halo2 that referenced this pull request Oct 9, 2023
* return expression from cell

* add example

* selector

* recurse Expression to fill in index

* minimized changes from the original

* backword compatible meta.query_X & challange.expr()

* cargo fmt

* fixed lookup to pass all tests

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* update

Co-authored-by: Brecht Devos <[email protected]>

* add primitives.rs back

* remove example2

* backward compatible meta.query_X & Column.cur(), next(), prev(), at(usize)

* impl Debug & make side effects only when query.index.is_none()

* change impl Debug for Expression instead & revert test in plonk_api

* upgrade rust-toolchain

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

* ran clippy

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

---------

Co-authored-by: Brecht Devos <[email protected]>
Co-authored-by: Han <[email protected]>
kunxian-xia added a commit to scroll-tech/halo2 that referenced this pull request Jan 12, 2024
* feat: call synthesize in `MockProver` multiple times to behave same as real prover

* modify previous commit

* Expose mod `permutation` and re-export `permutation::keygen::Assembly` (privacy-scaling-explorations#149)

* feat: expose mod ule `permutation` and re-export `permutation::keygen::Assembly`

* feat: derive `lone` for `permutation::keygen::Assembly`

* feat: bump MSRV for `inferno`

* change: Migrate workspace to pasta_curves-0.5 (privacy-scaling-explorations#157)

* change: Migrate workspace to pasta_curves-0.5

This ports the majority of the workspace to the `pasta_curves-0.5.0`
leaving some tricky edge-cases that we need to handle carefully.

Resolves: privacy-scaling-explorations#132

* fix: Complete latest trait bounds to compile halo2proofs

* change: Migrate examples & benches to pasta 0.5

* change: Migrate halo2_gadgets to pasta-0.5

* change: Update gadgets outdated code with latest upstream

* fix: Sha3 gadget circuit

* fix: doc tests

* chore: Update merged main

* fix: Apply review suggestions

* fix previous commit

* Extend Circuit trait to take parameters in config (privacy-scaling-explorations#168)

* Extend Circuit trait to take parameters in config

The Circuit trait is extended with the following:
```
pub trait Circuit<F: Field> {
    /// [...]
    type Params: Default;

    fn params(&self) -> Self::Params {
        Self::Params::default()
    }

    fn configure_with_params(meta: &mut ConstraintSystem<F>, params: &Self::Params) -> Self::Config {
        Self::configure(meta)
    }

    fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config;
}
```

This allows runtime parametrization of the circuit configuration.  The extension to the Circuit trait has been designed to minimize the breaking change: existing circuits only need to define the associated `type Params`.

Unfortunately "Associated type defaults" are unstable in Rust, otherwise this would be a non-breaking change.  See rust-lang/rust#29661

* Implement circuit params under feature flag

* Don't overwrite configure method

* Fix doc test

* Allow halo2 constraint names to have non static names (privacy-scaling-explorations#156)

* static ref to String type in Gates, Constraints, VirtualCell, Argument

* 'lookup'.to_string()

* return &str for gate name and constriant_name, also run fmt

* Update halo2_gadgets/Cargo.toml

Co-authored-by: Han <[email protected]>

* upgrade rust-toochain

---------

Co-authored-by: Carlos Pérez <[email protected]>
Co-authored-by: Han <[email protected]>

* Improve halo2 query calls (privacy-scaling-explorations#154)

* return expression from cell

* add example

* selector

* recurse Expression to fill in index

* minimized changes from the original

* backword compatible meta.query_X & challange.expr()

* cargo fmt

* fixed lookup to pass all tests

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* Update comments

Co-authored-by: Brecht Devos <[email protected]>

* update

Co-authored-by: Brecht Devos <[email protected]>

* add primitives.rs back

* remove example2

* backward compatible meta.query_X & Column.cur(), next(), prev(), at(usize)

* impl Debug & make side effects only when query.index.is_none()

* change impl Debug for Expression instead & revert test in plonk_api

* upgrade rust-toolchain

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

* ran clippy

* Update halo2_proofs/src/plonk/circuit.rs

Co-authored-by: Han <[email protected]>

---------

Co-authored-by: Brecht Devos <[email protected]>
Co-authored-by: Han <[email protected]>

* Implement Clone trait for Hash, Absorbing, and Sponge structs (privacy-scaling-explorations#171)

* fix: Fix serialization for VerifyingKey (privacy-scaling-explorations#178)

Now the value returned when the number of selectors is a multiple of 8
is correct.

Resolves: privacy-scaling-explorations#175

* Add more getters to expose internal fields

* add a constructor (privacy-scaling-explorations#164)

* add a constructor

* add more comment

* fix as review

* remove clone

* remove

* no need to use new variable

* change comment

* fix clippy

* rename to from_parts

* remove n declaration

* feat: send sync region (privacy-scaling-explorations#180)

* feat: send / sync region

* Update layout.rs

* update

* lol

* debug

* Update keygen.rs

* Update keygen.rs

* Update keygen.rs

* Update keygen.rs

* thread-safe-region feature flag

* cleanup

* patch dev-graph

* patch non-determinism in mapping creation

* reduce mem usage for vk and pk

* mock proving examples

* swap for hashmap for insertion speed

* reduce update overhead

* replace BTree with Vec

* add benchmarks

* make the benchmarks massive

* patch clippy

* simplify lifetimes

* patch benches

* Update halo2_proofs/src/plonk/permutation/keygen.rs

Co-authored-by: Han <[email protected]>

* Update halo2_proofs/examples/vector-mul.rs

Co-authored-by: Han <[email protected]>

* rm benches

* order once

* patch lints

---------

Co-authored-by: Han <[email protected]>

* fix previous commit

* Fix `parallelize` workload imbalance (privacy-scaling-explorations#186)

* fix parallelize workload imbalance

* remove the need of unsafe

* Updates halo2_curves dependency to released package (privacy-scaling-explorations#190)

THe package release ressets the version from those inherited by the legacy
halo2curves repo's fork history.

The upstream diff is:
https://github.com/privacy-scaling-explorations/halo2curves/compare/9f5c50810bbefe779ee5cf1d852b2fe85dc35d5e..9a7f726fa74c8765bc7cdab11519cf285d169ecf

* fix: explicitly define mds diff type (privacy-scaling-explorations#196)

* fix: explicitly define mds diff type

* rm paren

* feat: expose `transcript_repr` of `VerifyingKey` and reduce the trait constraint (privacy-scaling-explorations#200)

* implement native shuffle argument and api

fix: remove nonsense comment

strictly check shuffle rows

address doc typos

move compression into product commitment

typo

add shuffle errors for `verify_at_rows_par`

dedup expression evaluation

cargo fmt

fix fields in sanity-checks feature

* feat: public cells to allow for implementations of custom `Layouter`  (privacy-scaling-explorations#192)

* feat: public cells

* Update mds.rs

* Update mds.rs

* Update single_pass.rs

Co-authored-by: Han <[email protected]>

* bump toolchain to resolve errors

* fix clippy errors for CI run

* rustfmt post clippy

* plz let it be the last lint

* patch clippy lints in gadgets

* clippy lints for sha256 bench

* patch halo2proof benches

* Update assigned.rs

* Update halo2_gadgets/src/poseidon/primitives/mds.rs

Co-authored-by: Han <[email protected]>

* Update halo2_gadgets/src/poseidon/primitives/mds.rs

Co-authored-by: Han <[email protected]>

---------

Co-authored-by: Han <[email protected]>

* Synchronize with upstream (privacy-scaling-explorations#199)

* refactor: add default impl for `SyncDeps` for backward compatability

* feat: pick changes from zcash#728 and changes of flag `test-dev-graph`

* feat: pick changes from zcash#622

* feat: pick changes about mod `circuit` and mod `dev`

* feat: pick rest changes of `halo2_proofs`

* fix: when `--no-default-features`

* ci: sync from upstream, and deduplicate jobs when
push to `main`, and remove always failing job `codecov`.

* fix: make `commit_zk` runnable when `--no-default-features`

* chore: Update rust-toolchain to 1.66 for testing  (privacy-scaling-explorations#208)

* chore: Update rust-toolchain to 1.66 for testing

Note that tests will not compile due to the silent MSRV bump in
`blake2b_simd`.

Hence, we need to use `1.66` as toolchain.

Resolves: privacy-scaling-explorations#207

* change: UIpdate MSRVs in Cargo.toml

* fix: clippy (privacy-scaling-explorations#203)

* fix: clippy

* fmt

* fix: Final clippy complains & adjustments

---------

Co-authored-by: CPerezz <[email protected]>

* Implement Sum and Product for Expression (privacy-scaling-explorations#209)

* Make it Eq to make it easier for tests

* Implement Sum and Product for Expression

* Make it readable

* chore: update poseidon dependency

* fix: compiling bug with feautes=parallel_syn

* feat(MockProver): replace errors by asserts(privacy-scaling-explorations#150)

* boundary offset lost when resolving conflict

* disable multiphase prover

* Sync halo2 lib 0.4.0 merging (#81)

* Use thread pool for assign_regions (#57)

* feat: use rayon threadpool

* feat: add UT for many subregions

* refact: move common struct out to module level

* refact: reuse common configure code

* fix ci errors

---------

Co-authored-by: kunxian xia <[email protected]>

* Move `env_logger` dependency to dev-depdendencies (only for test). (#69)

* sync ff/group 0.13

* fix clippy

* fix clippy

* fmg

* [FEAT] Upgrading table16 for SHA256 (#73)

* upgrade sha256

* fix clippy

* Bus auto (#72)

* bus: expose global offset of regions

* bus-auto: add query_advice and query_fixed function in witness generation

* bus-auto: fix clippy

---------

Co-authored-by: Aurélien Nicolas <[email protected]>

* fix-tob-scroll-21 (#59)

* fix-tob-scroll-21

* expose param field for re-randomization

* enable accessing for table16 (#75)

* chore: update poseidon link

* merge sha256 gadget changes

* Fix the CI errors (#78)

* cargo fmt

* fix clippy error

* Feat: switch to logup scheme for lookup argument  (#71)

* Multi-input mv-lookup. (#49)

* Add mv_lookup.rs

* mv_lookup::prover, mv_lookup::verifier

* Replace lookup with mv_lookup

* replace halo2 with mv lookup

Co-authored-by: ying tong <[email protected]>

* cleanups

Co-authored-by: ying tong <[email protected]>

* ConstraintSystem: setup lookup_tracker

Co-authored-by: Andrija <[email protected]>

* mv_lookup::hybrid_prover

Co-authored-by: Andrija <[email protected]>

* WIP

* mv_multi_lookup: enable lookup caching

Co-authored-by: therealyingtong <[email protected]>

* Rename hybrid_lookup -> lookup

* Chunk lookups using user-provided minimum degree

Co-authored-by: Andrija <[email protected]>

* mv_lookup bench

Co-authored-by: Andrija <[email protected]>

* Introduce counter feature for FFTs and MSMs

Co-authored-by: Andrija <[email protected]>

* Fix off-by-one errors in chunk_lookup

Co-authored-by: Andrija <[email protected]>

* bench wip

* time evaluate_h

* KZG

* more efficient batch inversion

* extended lookup example

* Finalize mv lookup

Author: therealyingtong <[email protected]>

* Remove main/

* Fix according to the comments

* replace scan with parallel grand sum computation

* Revert Cargo.lock

* mv lookup Argument name

* parallel batch invert

---------

Co-authored-by: Andrija <[email protected]>
Co-authored-by: ying tong <[email protected]>
Co-authored-by: therealyingtong <[email protected]>

* fmt

* fix unit test

* fix clippy errors

* add todo in mv_lookup's prover

* fmt and clippy

* fix clippy

* add detailed running time of steps in logup's prover

* fmt

* add more log hooks

* more running time logs

* use par invert

* use sorted-vector to store how many times a table element occurs in input

* par the process to get inputs_inv_sum

* use par

* fix par

* add feature to skip inv sums

* add new feature flag

* fix clippy error

---------

Co-authored-by: Sphere L <[email protected]>
Co-authored-by: Andrija <[email protected]>
Co-authored-by: ying tong <[email protected]>
Co-authored-by: therealyingtong <[email protected]>

* fix some simple building errs

* upgrade pathfinder_simd to newer version as it can't compile on mac m1 pro

* resolve merge conflict

* fmt

* clippy

* more clippy fix

* more lint fix

* fmt

* minor syntax fix

* fix ipa multiopen test failure

* fix clippy warning

* fmt

* fix par scan of log_inv diff

* remove uncessary clone

---------

Co-authored-by: alannotnerd <[email protected]>
Co-authored-by: kunxian xia <[email protected]>
Co-authored-by: Steven <[email protected]>
Co-authored-by: Carlos Pérez <[email protected]>
Co-authored-by: zhenfei <[email protected]>
Co-authored-by: Ho <[email protected]>
Co-authored-by: naure <[email protected]>
Co-authored-by: Aurélien Nicolas <[email protected]>
Co-authored-by: Sphere L <[email protected]>
Co-authored-by: Andrija <[email protected]>
Co-authored-by: ying tong <[email protected]>
Co-authored-by: therealyingtong <[email protected]>

---------

Co-authored-by: han0110 <[email protected]>
Co-authored-by: Velaciela <[email protected]>
Co-authored-by: Carlos Pérez <[email protected]>
Co-authored-by: Eduard S <[email protected]>
Co-authored-by: CeciliaZ030 <[email protected]>
Co-authored-by: Brecht Devos <[email protected]>
Co-authored-by: Enrico Bottazzi <[email protected]>
Co-authored-by: Ethan-000 <[email protected]>
Co-authored-by: dante <[email protected]>
Co-authored-by: Mamy Ratsimbazafy <[email protected]>
Co-authored-by: François Garillot <[email protected]>
Co-authored-by: kilic <[email protected]>
Co-authored-by: Thor <[email protected]>
Co-authored-by: CPerezz <[email protected]>
Co-authored-by: chokermaxx <[email protected]>
Co-authored-by: Zhang Zhuo <[email protected]>
Co-authored-by: alannotnerd <[email protected]>
Co-authored-by: kunxian xia <[email protected]>
Co-authored-by: Steven <[email protected]>
Co-authored-by: Ho <[email protected]>
Co-authored-by: naure <[email protected]>
Co-authored-by: Aurélien Nicolas <[email protected]>
Co-authored-by: Sphere L <[email protected]>
Co-authored-by: Andrija <[email protected]>
Co-authored-by: ying tong <[email protected]>
Co-authored-by: therealyingtong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants