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

Bug fixed. logic_or should use LogicOrValueGate #115

Merged
merged 2 commits into from
Aug 24, 2022
Merged

Bug fixed. logic_or should use LogicOrValueGate #115

merged 2 commits into from
Aug 24, 2022

Conversation

mrain
Copy link
Contributor

@mrain mrain commented Aug 24, 2022

Description

closes: #114


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
Copy link
Contributor

alxiong commented Aug 24, 2022

I don't understand, why is there a LogicOrValueGate in the first place? that seems equivalent to LogicOrGate?

impl<F> Gate<F> for LogicOrGate
where
    F: Field,
{
    fn name(&self) -> &'static str {
        "Logic OR Gate"
    }
    fn q_lc(&self) -> [F; GATE_WIDTH] {
        [F::one(), F::one(), F::zero(), F::zero()]
    }
    fn q_mul(&self) -> [F; N_MUL_SELECTORS] {
        [-F::one(), F::zero()]
    }
    fn q_c(&self) -> F {
        -F::one()
    }
}

impl<F> Gate<F> for LogicOrValueGate
where
    F: Field,
{
    fn name(&self) -> &'static str {
        "Logic OR Value Gate"
    }
    fn q_lc(&self) -> [F; GATE_WIDTH] {
        [F::one(), F::one(), F::zero(), F::zero()]
    }
    fn q_mul(&self) -> [F; N_MUL_SELECTORS] {
        [-F::one(), F::zero()]
    }
    fn q_o(&self) -> F {
        F::one()
    }
}

basically LogicOrGate: a+b-ab-1 =0 and LogicOrValueGate: a+b-ab=1, they are the same.

@chancharles92
Copy link
Contributor

I remember we used to have APIs c = logic_or(a, b) and logic_or_gate(c, a, b): the first return a bool variable c that's the logic_or of the inputs; the 2nd API enforces c = a or b. So what's the LogicOrValueGate?

@mrain
Copy link
Contributor Author

mrain commented Aug 24, 2022

I don't understand, why is there a LogicOrValueGate in the first place? that seems equivalent to LogicOrGate?
basically LogicOrGate: a+b-ab-1 =0 and LogicOrValueGate: a+b-ab=1, they are the same.

Not really the same. For LogicOrValueGate is a+b-ab=output, that's q_o not q_c

I remember we used to have APIs c = logic_or(a, b) and logic_or_gate(c, a, b): the first return a bool variable c that's the logic_or of the inputs; the 2nd API enforces c = a or b. So what's the LogicOrValueGate?

We only have APIs c = logic_or(a, b) and logic_or_gate(a, b). Later one is a hard constraint that a or b must be true.
LogicOrGate corresponds to the later constraint. And LogicOrValueGate is computing the logic or of two input wires.

@chancharles92
Copy link
Contributor

chancharles92 commented Aug 24, 2022

@mrain Is there a better name for LogicOrValueGate and LogicOrGate? How about LogicOrOutputGate and LogicOrConstantGate?

@mrain
Copy link
Contributor Author

mrain commented Aug 24, 2022

@mrain Is there a better name for LogicOrValueGate and LogicOrGate? How about LogicOrOutputGate and LogicOrConstantGate?

What about LogicOrGate and LogicOrOutputGate? That's clear enough to me.
WDYT @alxiong

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

@mrain mrain merged commit bcd92b2 into main Aug 24, 2022
@mrain mrain deleted the chengyu/cmp branch August 24, 2022 18:36
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.

Failed test for comparison gate
3 participants