0xPolygonZero / plonky2

Apache License 2.0
771 stars 289 forks source link

Starky proof failing to verify recursively #1631

Open armanthepythonguy opened 6 days ago

armanthepythonguy commented 6 days ago

I am trying to verify a starky proof inside a plonky2 circuit. I have followed the same procedure as per the FibonacciStark.rs file, but I am getting error :-

I have my custom Starky proof, which can be successfully proved and verified with prove and verify functions but fails during recursive verification.

thread 'dense::tests::test_stark_recursive' panicked at src/dense.rs:115:70: called Result::unwrap() on an Err value: Partition containing Wire(Wire { row: 53, column: 40 }) was set twice with different values: 5380601374886916272 != 11172169064086565555 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace test dense::tests::test_stark_recursive ... FAILED

armanthepythonguy commented 6 days ago

Here's some code snippets :-

fn recursive_verifier(stark: DenseStark, proof: StarkProofWithPublicInputs<F,C,D>, inner_config: &StarkConfig) -> Result<()>{

        let circuit_config = CircuitConfig::standard_recursion_config();
        let mut builder = CircuitBuilder::<F, D>::new(circuit_config);

        let mut pw: PartialWitness<F> = PartialWitness::new();
        let degree_bits = proof.proof.recover_degree_bits(inner_config);

        println!("{:?}", degree_bits);

        let pt = add_virtual_stark_proof_with_pis(&mut builder, &stark, inner_config, degree_bits, 0, 0);
        set_stark_proof_with_pis_target(&mut pw, &pt, &proof, builder.zero())?;

        verify_stark_proof_circuit::<F, C, DenseStark, D>(&mut builder, stark, pt, inner_config);

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

Also

let trace = stark.generate_trace(pub_inputs.to_vec());
        println!(
            "Duration to generate trace :- {}",
            start.elapsed().as_millis()
        );

        start = Instant::now();
        let (proof, layer_sign) = stark.prove(pub_inputs.to_vec(), trace, *inputs.last().unwrap());
        println!(
            "Duration to generate proof :- {}",
            start.elapsed().as_millis()
        );
        recursive_verifier(stark, proof, &StarkConfig::standard_fast_config())
Nashtare commented 6 days ago

Hello, can we have access to the code that generated this error, along with the version of plonky2 / starky you used and the command you used? Thank you.

armanthepythonguy commented 6 days ago

Here you can find all the relevant codes, also let me know if you want more details, I will add you as a collaborator to the repo. https://gist.github.com/armanthepythonguy/2e5a7240f82c3fec4207ab6aa1fbd71f

armanthepythonguy commented 6 days ago

Also, I would want to learn more about the constraint degree function used while defining the starky circuits. I have seen many examples where we have used values either 2 or 3, Can you please guide me into the relevance of the constraint degree and if any docs you can share

armanthepythonguy commented 4 days ago

Any updates @Nashtare