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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions relation/src/gadgets/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ark_ff::PrimeField;

use crate::{
errors::CircuitError,
gates::{CondSelectGate, LogicOrGate},
gates::{CondSelectGate, LogicOrGate, LogicOrOutputGate},
BoolVar, Circuit, PlonkCircuit, Variable,
};

Expand Down Expand Up @@ -120,7 +120,7 @@ impl<F: PrimeField> PlonkCircuit<F> {

let c = self.create_boolean_variable_unchecked(c_val)?;
let wire_vars = &[a.into(), b.into(), 0, 0, c.into()];
self.insert_gate(wire_vars, Box::new(LogicOrGate))?;
self.insert_gate(wire_vars, Box::new(LogicOrOutputGate))?;

Ok(c)
}
Expand Down Expand Up @@ -186,6 +186,32 @@ mod test {
}

fn test_logic_or_helper<F: PrimeField>() -> Result<(), CircuitError> {
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let false_var = circuit.false_var();
let true_var = circuit.true_var();
// Good path
let should_be_true = circuit.logic_or(false_var, true_var)?;
assert!(circuit.witness(should_be_true.into())?.eq(&F::one()));
let should_be_true = circuit.logic_or(true_var, false_var)?;
assert!(circuit.witness(should_be_true.into())?.eq(&F::one()));
let should_be_true = circuit.logic_or(true_var, true_var)?;
assert!(circuit.witness(should_be_true.into())?.eq(&F::one()));
// Error path
let should_be_false = circuit.logic_or(false_var, false_var)?;
assert!(circuit.witness(should_be_false.into())?.eq(&F::zero()));
assert!(circuit.check_circuit_satisfiability(&[]).is_ok());

Ok(())
}
#[test]
fn test_logic_or_gate() -> Result<(), CircuitError> {
test_logic_or_gate_helper::<FqEd254>()?;
test_logic_or_gate_helper::<FqEd377>()?;
test_logic_or_gate_helper::<FqEd381>()?;
test_logic_or_gate_helper::<Fq377>()
}

fn test_logic_or_gate_helper<F: PrimeField>() -> Result<(), CircuitError> {
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let false_var = circuit.false_var();
let true_var = circuit.true_var();
Expand Down
4 changes: 2 additions & 2 deletions relation/src/gates/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ where

/// A gate for computing the logic OR value of 2 variables
#[derive(Clone)]
pub struct LogicOrValueGate;
pub struct LogicOrOutputGate;

impl<F> Gate<F> for LogicOrValueGate
impl<F> Gate<F> for LogicOrOutputGate
where
F: Field,
{
Expand Down