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

Remove the dependency on VirtualCells to query cells from columns #144

Closed
Brechtpd opened this issue Feb 10, 2023 · 10 comments
Closed

Remove the dependency on VirtualCells to query cells from columns #144

Brechtpd opened this issue Feb 10, 2023 · 10 comments
Labels
enhancement New feature or request

Comments

@Brechtpd
Copy link

Some discussion here: privacy-scaling-explorations/zkevm-circuits#1115 (comment)

It's pretty inconvenient to have to go through a mutable VirtualCells object to be able to query Expressions from columns. When building a circuits we only care about the column, the relative offset and the phase. This is just simple data that does not depend on any internal circuit data in VirtualCells. The requirement to query from VirtualCells is only there because it's used to set the query index, but that is something that can be done just as well when these expressions are submitted to halo2.

@CPerezz CPerezz moved this to 🆕 Product Backlog Items in zkEVM Community Edition Feb 23, 2023
@CPerezz CPerezz added the enhancement New feature or request label Feb 23, 2023
@CPerezz
Copy link
Member

CPerezz commented Feb 23, 2023

I like this TBH.

Indeed I just feel that we should have some sepparated entity that makes is easier to simply obtain expressions. Have you considered any solution design specifically?

@naure
Copy link

naure commented Feb 23, 2023

(reposting this comment).

TL;DR:

  • The ConstraintSystem could expose the query_* methods directly.
  • The constraints could be given by a method ConstraintSystem::add_gate.

@naure
Copy link

naure commented Feb 23, 2023

About the functionality of queried_cells and queried_selectors. Some options are:

  1. Drop it. This will break MockProver and require changes there. This should not break anything else because it is private to the crate.
  2. Or discover queried_cells in add_gate by walking down the Expression trees.
  3. Or with a function ConstraintSystem::start_gate(…) that returns a &mut VirtualCells (no closures).

@Brechtpd
Copy link
Author

Brechtpd commented Feb 23, 2023

We have some WIP code here: taikoxyz#1.

This currently exposes some extra functions on the Column type to query Expressions using just the column and some rotation, and then we set the query index when the expression gets submitted to halo2 in create_gate. For backward compatibility the old API will still work.

I'm not sure if this will be sufficient to be as flexible as possible with Expressions, but it's a start and should be easy to add additional API calls if necessary.

@naure
Copy link

naure commented Feb 23, 2023

Yes that makes a lot of sense, better than query_* methods.

What do you think about the ability to submit gates without a closure? ConstraintSystem::add_gate

@Brechtpd
Copy link
Author

Brechtpd commented Feb 23, 2023

Would maybe be cleaner, but because some other abstraction (like the ConstraintBuilder) should already be used to collect all constraints I'm not sure if it's worth changing. That helper object will simply submits all constraints in a single create_gate call or whatever the API is so doesn't really impact how circuits are or can be written.

@naure
Copy link

naure commented Feb 23, 2023

Agree, moving the queries out is the important bit.

Do you intend to return a Query, or Expression(Query)?

The difference is that the query is what the synthesis needs in order to assign a cell (with a rotation abstraction instead of hard-coded offsets). So we would want it available. Then Expression can be obtained by an expr method. So:

column.cur() -> Query
    Or
column.query(offset) -> Query

query.expr() -> Expression

@Brechtpd
Copy link
Author

Just the Expression, which basically is the same data as Query I think with the query index still set to None. I think ideally expressions on the app side would actually be Querys but but that would need too many changes. So I guess you should have all the data you need to be able to so this on the app side, unless you really need it on the halo2 side?

@naure
Copy link

naure commented Feb 23, 2023

If ConstraintBuilder returns Query, this is easily wrapped into Expression::Advice(query), depending which one the app wants at this place. But the reverse is not true, an Expression cannot always be unwrapped into query.

@han0110
Copy link

han0110 commented May 18, 2023

Resolved by #154

@han0110 han0110 closed this as completed May 18, 2023
@han0110 han0110 moved this from 🆕 Product Backlog Items to ✅ Done in zkEVM Community Edition May 18, 2023
iquerejeta pushed a commit to input-output-hk/halo2 that referenced this issue May 8, 2024
…-hk/dev-feature/gl-96-gen-point-witness

Generalize the point-witnessing part of the Ecc Chip

This is part of the SOW task of generalizing the Ecc Chip to Pluto.

Generalize the point check in `halo2_gadgets::ecc::chip::witness_point` to arbitrary curves $y^2=x^3+ax+b$, where $a = 0.$
iquerejeta pushed a commit to input-output-hk/halo2 that referenced this issue May 8, 2024
…-hk/dev-feature/98-gen-fbsm

Generalize fbsm part of Ecc Chip

# Project Context

Part of the SOW task of generalizing the Ecc Chip to Pluto.

This builds on top of privacy-scaling-explorations#144.

The corresponding Galois internal issue is [Galois#98](https://gitlab-ext.galois.com/iog-midnight/halo2/-/issues/98).

# Issue Description

This issue is concerned with generalizing the fixed-base scalar-mul (fbsm) part of the Ecc Chip to arbitrary curves.

Besides generalizing all of the types, and adding tests for all supported curves, the major technical task is to generalize the canonicity check on the windowed scalar decomposition: this canonicity check ensures that the decomposition of the scalar into 3-bit windows is correct. This is a "range check" type task, similar to existing range checks in variable-base scalar mul.

See the Halo 2 Book [chapter on fbsm](http://localhost:3000/design/gadgets/ecc/fixed-base-scalar-mul.html) for details.

# Notes to Reviewers

* The canonicity check is generalized in ["Generalize canonicity check using 3-high-low decomp"](input-output-hk/galois_recursion@f8d2927) (with corresponding book updates in ["[book] fbsm: generalize, and document simplified canonicity check"](560a7d3b9af6df3031584acce4d80c119388df60)). This is the second example application of the [$K$-high-low decomp](privacy-scaling-explorations#114), and again we see a bunch of complex, bespoke range checking being replaced by a conceptually simple use of the decomp gadget :)

* The fbsm works by precomputing a table of multiples of a fixed base, and then using the values to improve the efficiency (constraint complexity / proof burden) of multiplying the fixed base by scalars. This precomputation is very expensive, already taking 1+ hours for Pallas. For Pluto/Eris the precomputation time jumps to 17+ hours, which makes running the tests impractical. However, in a later PR (privacy-scaling-explorations#147), we cache the precomputation for the test bases to disk, which reduces the test time to a few minutes.

* This PR includes a simple custom gate, that replaces the more complex custom gate for the old canonicity check. The new custom gate should be replaced by calls to the [gen arith gate](input-output-hk/galois_recursion#58) once that's available.
iquerejeta pushed a commit to input-output-hk/halo2 that referenced this issue May 8, 2024
…-hk/dev-feature/53-gen-eccc

Implement Ecc Chip for Pluto ... and Vesta and Eris

# Project Context

This issue corresponds to the Milestone 3 updated SOW task "New: Extend EccChip to support Pluto". There is no corresponding GitHub issue, since this is the Pluto/Eris analog of supporting Pallas, which was the starting state. However, the work for this issue overlaps significantly with SOW task "zcash#578: Extend EccChip to support ~~Vesta~~ Eris" ([zcash#578](zcash#578)), since it seems easiest to just generalize to all curves at the same time. So, while we only need to ensure Pluto support for Milestone 3, the strategy we're using also gives Eris and Vesta support "for free".

This builds on top of privacy-scaling-explorations#145 directly, depends directly on privacy-scaling-explorations#143 and privacy-scaling-explorations#144 as well, and is the culmination of generalization work that started at a lower level with privacy-scaling-explorations#101, privacy-scaling-explorations#107, and privacy-scaling-explorations#114. 

The corresponding Galois internal issue is [Galois#53](https://gitlab-ext.galois.com/iog-midnight/halo2/-/issues/53).

# Issue Description

Generalize the Ecc Chip to arbitrary curves, allowing any assumptions that apply to all of Pallas, Vesta, Pluto, and Eris. This work is broken up into several subtasks, concerned with updating the major components of the Ecc Chip ([vbsm](privacy-scaling-explorations#143), [fbsm](privacy-scaling-explorations#145), and [point witnessing](privacy-scaling-explorations#144)), along with the final work here of updating the full Ecc Chip to use all of the updated components, have tests for all curves, and provide instantiations for all curves.

Behind the scenes there are various traits associated with the vbsm and fbsm generalizations, but the final Ecc Chip interface exposes `EccCurve` and `EccField` as the traits required for curves and fields used with Ecc Chip (and of course these traits are implemented for Pallas, Vesta, Pluto, Eris, and their fields).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

4 participants