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

Proof creation crashes #760

Closed
moCello opened this issue Aug 10, 2023 · 0 comments · Fixed by #761
Closed

Proof creation crashes #760

moCello opened this issue Aug 10, 2023 · 0 comments · Fixed by #761
Assignees
Labels
fix:bug Something isn't working

Comments

@moCello
Copy link
Member

moCello commented Aug 10, 2023

Describe the bug

When the Prover of a smaller circuit and without public input has been compiled, the proof generation crashes when attempted with a malicious larger circuit that does have public inputs.

To Reproduce

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 TestSize {
    witnesses: Vec<BlsScalar>,
    sum: BlsScalar,
}

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

impl Circuit for TestSize {
    fn circuit<C>(&self, composer: &mut C) -> Result<(), Error>
    where
        C: Composer,
    {
        let sum = self.witnesses.iter().fold(C::ZERO, |acc, scalar| {
            let w = composer.append_witness(*scalar);
            let constraint = Constraint::new().left(1).a(acc).right(1).b(w);
            composer.gate_add(constraint)
        });

        let expected_sum = composer.append_witness(self.sum);
        composer.assert_equal(sum, expected_sum);

        Ok(())
    }
}

#[test]
fn size() {
    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 TestSize, which only one gate: sum = 0
    let (prover, _verifier) = Compiler::compile::<TestSize>(&pp, LABEL)
        .expect("It should be possible to compile the prover and verifier");

    // Create circuit with more gates
    let pi: Vec<BlsScalar> = [BlsScalar::one(); 5].into();
    let sum = pi.iter().sum();
    let circuit = TestSize::new(pi, sum);
    let result = prover.prove(rng, &circuit).err();
    assert_eq!(
        result,
        Some(dusk_plonk::error::Error::InvalidCircuitSize),
        "proof creation for different sized circuit shouldn't be possible"
    );
}

Expected behaviour

Don't crash

@moCello moCello added the fix:bug Something isn't working label Aug 10, 2023
@moCello moCello self-assigned this Aug 10, 2023
@moCello moCello changed the title Proof creation with unexpected pi Proof creation crashes Aug 11, 2023
@moCello moCello linked a pull request Aug 14, 2023 that will close this issue
moCello added a commit that referenced this issue Aug 14, 2023
This fixes a panic on proof creation when the circuit to prove is
larger than in the provers circuit description

Resolves: #760
moCello added a commit that referenced this issue Aug 14, 2023
This fixes a panic on proof creation when the circuit to prove is
larger than in the provers circuit description

Resolves: #760
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