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

[TASK] PLONK check_membership_if_enabled gadget #163

Closed
lazovicff opened this issue Feb 8, 2022 · 0 comments · Fixed by #169
Closed

[TASK] PLONK check_membership_if_enabled gadget #163

lazovicff opened this issue Feb 8, 2022 · 0 comments · Fixed by #169

Comments

@lazovicff
Copy link
Contributor

lazovicff commented Feb 8, 2022

check_membership_if_enabled is very similar to check_membership, except it takes in one more variable enabled:

fn check_public_set_membership_enabled<F, P>(
    composer: &mut StandardComposer<F, P>,
    set: &Vec<F>,
    member: Variable,
    enabled: Variable,
) -> Variable
where
    F: PrimeField,
    P: TEModelParameters<BaseField = F>,
{
    // Compute all differences between `member` and set elements
    let mut diffs = Vec::new();
    for x in set.iter() {
        let diff = composer.arithmetic_gate(|gate| {
	        gate.witness(member, member, None)
		        .add(F::zero(), F::one())
		        .pi(-*x)
        });
        diffs.push(diff);
    }
    
    // Accumulate the product of all differences
    let mut accumulator = composer.add_witness_to_circuit_description(F::one());
    for diff in diffs {
        accumulator =
	    composer.arithmetic_gate(|gate| gate.witness(accumulator, diff, None).mul(F::one()));
    }
    
    accumulator = composer.arithmetic_gate(|gate| gate.witness(accumulator, enabled, None).mul(F::one()));
    composer.is_zero_with_output(accumulator)
}
@lazovicff lazovicff linked a pull request Feb 23, 2022 that will close this issue
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 a pull request may close this issue.

1 participant