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

Introduce BoolVar struct #94

Merged
merged 6 commits into from
Aug 9, 2022
Merged

Introduce BoolVar struct #94

merged 6 commits into from
Aug 9, 2022

Conversation

alxiong
Copy link
Contributor

@alxiong alxiong commented Aug 8, 2022

Description

Introducing struct BoolVar whose creation automatically enforces a bool_gate(), distinguishing from normal Variable to avoid repeated checks and make API clearer.

closes: #91


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (main)
  • Linked to GitHub issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the GitHub PR explorer

@alxiong alxiong self-assigned this Aug 8, 2022
Copy link
Contributor

@chancharles92 chancharles92 left a comment

Choose a reason for hiding this comment

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

@alxiong Nice work. There is one subtlety that needs to be addressed though.

plonk/src/circuit/customized/ecc/mod.rs Outdated Show resolved Hide resolved
plonk/src/circuit/customized/ecc/mod.rs Outdated Show resolved Hide resolved
@alxiong alxiong marked this pull request as ready for review August 9, 2022 09:45
@zhenfeizhang
Copy link
Contributor

In general I want to advocate my "circuit ref" idea. For example

struct BoolVar<'a> {
  index: Variable,
  cs: &'a ConstraintSystem
}

On top of overloading operators here are some additional thoughts:

  • to access the variable, we should use an API get_index(&self)->Variable -- i think it is a bit cleaner than into()
    • it makes more sense to me to implement Into/From for Vec<BoolVar> and Variable, in both directions, which are binary (de)composition
  • to create new variables we should use associated function BoolVar::new(cs: &ConstraintSystem, value: bool) rather than Circuit::create_bool_variable(...) and so on...
  • to check variable bound we can simply call bool_var.check_bound(), and we do not need to pass parameters

plonk/src/circuit/customized/ecc/mod.rs Outdated Show resolved Hide resolved
plonk/src/circuit/customized/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@chancharles92 chancharles92 left a comment

Choose a reason for hiding this comment

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

LGTM, we can wait for Zhenfei's approval before merging.

@zhenfeizhang
Copy link
Contributor

LGTM2

@alxiong alxiong merged commit 918d038 into main Aug 9, 2022
@alxiong alxiong deleted the alex/bool-var branch August 9, 2022 15:24
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.

[Constraint] Introducing BoolVariable
3 participants