Skip to content

Small changes for EVM circuit updates#54

Merged
CPerezz merged 3 commits into
privacy-ethereum:mainfrom
Brechtpd:lazy-eval
May 5, 2022
Merged

Small changes for EVM circuit updates#54
CPerezz merged 3 commits into
privacy-ethereum:mainfrom
Brechtpd:lazy-eval

Conversation

@Brechtpd

@Brechtpd Brechtpd commented Apr 1, 2022

Copy link
Copy Markdown

For privacy-ethereum/zkevm-circuits#417

  • Lazy evaluation in MockProver: More rows need to be checked again, but because a lot of expressions are disabled by selectors, big parts of expressions can simply be skipped when the selector is zero.
  • Column index is made public
  • An expression identifier is added to make is possible to easily verify if expressions calculate the same thing

Comment thread halo2_proofs/src/dev.rs Outdated
Comment thread halo2_proofs/src/plonk/circuit.rs Outdated

@han0110 han0110 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. Only got a question on docs.

Comment on lines +733 to +736
/// Identifier for this expression. Expressions with identical identifiers
/// do the same calculation (but the expressions don't need to be exactly equal
/// in how they are composed e.g. `1 + 2` and `2 + 1` can have the same identifier).
pub fn identifier(&self) -> String {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

... but the expressions don't need to be exactly equal in how they are composed e.g. 1 + 2 and 2 + 1 can have the same identifier

At first glance at the docs I thought this method helps to organize expression to make 1 + 2 and 2 + 1 have the same identifier, but it seems not. Does this aim to info developer to use more identical expression as possible (to reuse stored expression as much as possible)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I had some naive code to try and do the reorganization, but chose to remove it for now because it didn't really work well enough and didn't make any difference. I think it's not super easy to do this well elegantly (or at least I haven't found one yet, but haven't really tried much to be honest). But yeah the goal is indeed that this identifier can directly be used to detect expressions that are interchangeable (so in our use case to reuse stored expressions when possible).

So for now the docs share how the function could behave in the future, and so e.g. should not be used to compare expressions if strict equality is required.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see, I also tried once to normalize expression, but I found it's really ugly (use some kinds of map as key of map) and not sure if it works, can feel that it's not easy to do.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since HashMap in std rust now relies on hashbrown which is pretty damn fast.
Have we tried to store as ID the map key containing ([values, involved], Expression::Type)? With arrays we can check quickly with contains and similar things. Same in Iterators.

Expression::Type here simply means that for any set of inputs (independent of the order), if we perform the same op we will get the same result. (So we don't need to store the result in the keys and only in the values).

Is there anything painful on using HashMap?

@CPerezz CPerezz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Brilliant work as always @Brechtpd

Just left some comments with ideas :)

Also, seems that rustdoc is complaining for intra_doc_links lint.

halo2_gadgets/src/lib.rs#L7

lint `broken_intra_doc_links` has been renamed to `rustdoc::broken_intra_doc_links`

Comment on lines +733 to +736
/// Identifier for this expression. Expressions with identical identifiers
/// do the same calculation (but the expressions don't need to be exactly equal
/// in how they are composed e.g. `1 + 2` and `2 + 1` can have the same identifier).
pub fn identifier(&self) -> String {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since HashMap in std rust now relies on hashbrown which is pretty damn fast.
Have we tried to store as ID the map key containing ([values, involved], Expression::Type)? With arrays we can check quickly with contains and similar things. Same in Iterators.

Expression::Type here simply means that for any set of inputs (independent of the order), if we perform the same op we will get the same result. (So we don't need to store the result in the keys and only in the values).

Is there anything painful on using HashMap?

@Brechtpd

Copy link
Copy Markdown
Author

Also, seems that rustdoc is complaining for intra_doc_links lint.

halo2_gadgets/src/lib.rs#L7

lint `broken_intra_doc_links` has been renamed to `rustdoc::broken_intra_doc_links`

I renamed them in https://github.com/appliedzkp/halo2/pull/44/files, but I think that is straight from halo2 upstream so I'm not sure why they were not renamed there already. I don't know if there's some version difference for something.

@CPerezz

CPerezz commented May 3, 2022

Copy link
Copy Markdown

@Brechtpd any plans to try #54 (comment) ?

Or should we merge directly?

@Brechtpd

Brechtpd commented May 3, 2022

Copy link
Copy Markdown
Author

@Brechtpd any plans to try #54 (comment) ?

Or should we merge directly?

I would prefer to merge it as is. It's not easy to get something that catches all similar expressions. I do have something that tries to make more of an effort, but at least currently it doesn't make a difference. I would prefer to postpone a better method to a later PR.

@CPerezz CPerezz merged commit 9992785 into privacy-ethereum:main May 5, 2022
ChihChengLiang pushed a commit that referenced this pull request Aug 18, 2022
* Lazy evaluation + Make column index public

* Feedback
mratsim pushed a commit to taikoxyz/halo2 that referenced this pull request Jan 16, 2024
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.

4 participants