Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Deduplicate code between evm ConstraintBuilder and BaseConstraintBuilder#1318

Merged
leolara merged 12 commits into
mainfrom
leo/unify-constraint-builder
Apr 26, 2023
Merged

Deduplicate code between evm ConstraintBuilder and BaseConstraintBuilder#1318
leolara merged 12 commits into
mainfrom
leo/unify-constraint-builder

Conversation

@leolara

@leolara leolara commented Mar 14, 2023

Copy link
Copy Markdown
Contributor

Description

evm ConstraintBuilder and BaseConstraintBuilder have:

require_zero
require_equal
require_boolean
require_in_set
condition
add_constraints
add_constraint
validate_degree
all with very similar implementation. Deduplicate them

Issue Link

#1202

Type of change

  • Refactor

Contents

  • Created a trait for common code.

Rationale

DRY

How Has This Been Tested?

Run tests.

Notes (TODO?)

  • condition and validate_degree use the state, I don't know what could be the rusty way of making this code common.
  • Perhaps we should rethought the names of the trait and structs, BaseConstraintBuilder seems to be used mostly outside EVM circuit, while ConstraintBuilder is used in the EVM circuit exclusively.

@github-actions github-actions Bot added the crate-zkevm-circuits Issues related to the zkevm-circuits workspace member label Mar 14, 2023
@ed255 ed255 self-requested a review April 13, 2023 11:15

@ed255 ed255 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I added one note about removing a function that I think is duplicated, but otherwise looks very good!

Comment thread zkevm-circuits/src/evm_circuit/util/constraint_builder.rs Outdated
Comment thread zkevm-circuits/src/evm_circuit/util/constraint_builder.rs Outdated
@leolara

leolara commented Apr 18, 2023

Copy link
Copy Markdown
Contributor Author

@ed255 check now, I solved lots of conflicts with main basically

@ed255 ed255 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just one last small comment :P

Comment thread zkevm-circuits/src/exp_circuit.rs Outdated

@ed255 ed255 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! This looks nicer now :)

condition: None,
}
}
pub(crate) trait ConstrainBuilderCommon<F: Field> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub(crate) trait ConstrainBuilderCommon<F: Field> {
pub(crate) trait ConstraintBuilderCommon<F: Field> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I also think that maybe it's time to name ConstraintBuilder and BaseConstraintBuilder in another way. Tbh, I'm not really sure about the best naming, but what about:

ConstraintBuilder -> EvmConstraintBuilder
BaseConstraintBuilder -> BasicConstraintBulder

@ed255 @ChihChengLiang ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, I did not saw your comment about the renaming @leolara!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall LGTM, nice refactor :) only the typo to be fixed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have done the ConstraintBuilder -> EvmConstraintBuilder rename

@leolara leolara enabled auto-merge April 26, 2023 06:21
@leolara leolara added this pull request to the merge queue Apr 26, 2023
@leolara leolara removed this pull request from the merge queue due to a manual request Apr 26, 2023
@leolara leolara enabled auto-merge April 26, 2023 06:34
@leolara leolara added this pull request to the merge queue Apr 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

crate-zkevm-circuits Issues related to the zkevm-circuits workspace member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deduplicate code between evm ConstraintBuilder and BaseConstraintBuilder

4 participants