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

fix NonNativeAdditionGenerator bug #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

qope
Copy link

@qope qope commented May 3, 2023

The NonNativeAdditionGenerator does not take into account the case when a + b = modulus.

For example, the following test will fail:

#[cfg(test)]
mod tests {
    use crate::gadgets::nonnative::CircuitBuilderNonNative;
    use plonky2::{
        field::{secp256k1_base::Secp256K1Base, types::Field},
        iop::witness::PartialWitness,
        plonk::{
            circuit_builder::CircuitBuilder,
            circuit_data::CircuitConfig,
            config::{GenericConfig, PoseidonGoldilocksConfig},
        },
    };

    #[test]
    fn test_add_to_zero() {
        const D: usize = 2;
        type C = PoseidonGoldilocksConfig;
        type F = <C as GenericConfig<D>>::F;
        let config = CircuitConfig::standard_ecc_config();

        let pw = PartialWitness::<F>::new();
        let mut builder = CircuitBuilder::<F, D>::new(config);

        let a = Secp256K1Base::ONE;
        let b = Secp256K1Base::NEG_ONE;

        let a_t = builder.constant_nonnative(a);
        let b_t = builder.constant_nonnative(b);
        let c_t = builder.add_nonnative(&a_t, &b_t);

        let zero_t = builder.constant_nonnative(Secp256K1Base::ZERO);

        builder.connect_nonnative(&c_t, &zero_t);

        let data = builder.build::<C>();
        let proof = data.prove(pw).unwrap();
        data.verify(proof).unwrap();
    }
}

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.

1 participant