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

Circuit creation should fail when circuit is different from prover circuit description #762

Open
moCello opened this issue Aug 14, 2023 · 0 comments · May be fixed by #824
Open

Circuit creation should fail when circuit is different from prover circuit description #762

moCello opened this issue Aug 14, 2023 · 0 comments · May be fixed by #824
Assignees
Labels
fix:bug Something isn't working

Comments

@moCello
Copy link
Member

moCello commented Aug 14, 2023

Describe the bug
When creating a circuit that is valid in itself but differs from the circuit from the circuit description by adding public inputs to the constraints, the proof creation is successful.

To Reproduce
if applicable add a minimum reproducible example

use dusk_plonk::prelude::*;
use rand::rngs::StdRng;
use rand::SeedableRng;

const CAPACITY: usize = 1 << 4;
const LABEL: &[u8] = b"check_public_inputs";

#[derive(Default)]
pub struct TestPI {
    public: Vec<BlsScalar>,
    sum: BlsScalar,
}

impl TestPI {
    pub fn new(public: Vec<BlsScalar>, sum: BlsScalar) -> Self {
        Self { public, sum }
    }
}

impl Circuit for TestPI {
    fn circuit<C>(&self, composer: &mut C) -> Result<(), Error>
    where
        C: Composer,
    {
        // this circuit will always have the same amount of gates but different
        // amount of public inputs, depending on the struct data
        let mut sum = C::ZERO;
        for i in 0..2 {
            let constraint = match i < self.public.len() {
                true => Constraint::new()
                    .left(1)
                    .a(sum)
                    .right(1)
                    .b(C::ONE)
                    .public(self.public[i]),
                false => Constraint::new().left(1).a(sum).right(1).b(C::ONE),
            };
            sum = composer.gate_add(constraint);
        }
        let expected_sum = composer.append_witness(self.sum);
        composer.assert_equal(sum, expected_sum);

        Ok(())
    }
}

#[test]
fn public_inputs() {
    let rng = &mut StdRng::seed_from_u64(0x10b);
    let pp = PublicParameters::setup(CAPACITY, rng)
        .expect("Creation of public parameter shouldn't fail");

    // compiling the default version of TestPI, which has no pi
    let (prover, _verifier) = Compiler::compile::<TestPI>(&pp, LABEL)
        .expect("It should be possible to compile the prover and verifier");

    // Create circuit with public inputs
    let pi: Vec<BlsScalar> = [BlsScalar::one(); 2].into();
    let sum = BlsScalar::from(4);
    let circuit = TestPI::new(pi, sum);
    let result = prover.prove(rng, &circuit);
    assert_eq!(
        result,
        Err(Error::PublicInputNotFound { index: 0 }),
        "proof creation for different sized circuit shouldn't be possible"
    );
}

Expected behaviour
This is a minor bug since a Verifier, that doesn't expect public input, won't verify a proof that needs public input. Nevertheless, the proof creation shouldn't be possible for a circuit that doesn't match the circuit description of the Prover.

@moCello moCello added the fix:bug Something isn't working label Aug 14, 2023
moCello added a commit that referenced this issue Aug 16, 2023
@moCello moCello self-assigned this Nov 2, 2023
@moCello moCello linked a pull request May 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant