Skip to content

Support recursive feature #26

@moven0831

Description

@moven0831

Problem

Recursive proving features are currently broken. For example, it encounters foreign exceptions when invoking C++ bindings during SRS setup.

Current Status

Tests and related features are commented out:

  • /*pub fn generate_recursive_honk_proof_artifacts(
    proof_bytes: Vec<u8>,
    vk_bytes: Vec<u8>
    ) -> Result<(Vec<String>, Vec<String>), String> {
    Ok(unsafe {
    let proof = acir_proof_as_fields_ultra_honk(&proof_bytes);
    let vk = acir_vk_as_fields_ultra_honk(&vk_bytes);
    // Get the number of public inputs from the third field of the proof
    // by parsing from hex to usize
    let num_public_inputs = usize::from_str_radix(proof[1].trim_start_matches("0x"), 16).unwrap();
    let end_index_for_proof_without_public_inputs = 3 + num_public_inputs;
    // We keep the first 3 fields but remove the following public inputs and keep the rest
    let mut proof_without_public_inputs: Vec<String> = Vec::from(&proof[..3]);
    proof_without_public_inputs.extend_from_slice(&proof[end_index_for_proof_without_public_inputs..]);
    (proof_without_public_inputs, vk)
    })
    }*/
  • /*#[test]
    fn test_ultra_honk_recursive_proving() {
    // Read the JSON manifest of the circuit
    let recursed_circuit_path = get_circuit_path("recursed.json");
    let recursed_circuit_txt = std::fs::read_to_string(&recursed_circuit_path)
    .unwrap_or_else(|_| panic!("Failed to read circuit file at: {:?}", recursed_circuit_path));
    // Parse the JSON manifest into a dictionary
    let recursed_circuit: serde_json::Value = serde_json::from_str(&recursed_circuit_txt).unwrap();
    // Get the bytecode from the dictionary
    let recursed_circuit_bytecode = recursed_circuit["bytecode"].as_str().unwrap();
    setup_srs(String::from(recursed_circuit_bytecode), None, true).unwrap();
    let mut initial_witness = WitnessMap::new();
    // x
    initial_witness.insert(Witness(0), FieldElement::from(5u128));
    // y
    initial_witness.insert(Witness(1), FieldElement::from(25u128));
    let (recursed_proof, recursed_vk) = prove_ultra_honk(recursed_circuit_bytecode, initial_witness, true).unwrap();
    let (proof_as_fields, vk_as_fields, key_hash) = recursion::generate_recursive_honk_proof_artifacts(recursed_proof, recursed_vk).unwrap();
    //println!("proof: {:?}", proof_as_fields);
    //println!("vk: {:?}", vk_as_fields);
    //println!("key_hash: {:?}", key_hash);
    assert_eq!(proof_as_fields.len(), 463);
    assert_eq!(vk_as_fields.len(), 128);
    //assert_eq!(key_hash, "0x25240793a378438025d0dbe8a4e197c93ec663864a5c9b01699199423dab1008");
    // Read the JSON manifest of the circuit
    let recursive_circuit_path = get_circuit_path("recursive.json");
    let recursive_circuit_txt = std::fs::read_to_string(&recursive_circuit_path)
    .unwrap_or_else(|_| panic!("Failed to read circuit file at: {:?}", recursive_circuit_path));
    // Parse the JSON manifest into a dictionary
    let recursive_circuit: serde_json::Value = serde_json::from_str(&recursive_circuit_txt).unwrap();
    // Get the bytecode from the dictionary
    let recursive_circuit_bytecode = recursive_circuit["bytecode"].as_str().unwrap();
    println!("recursive_circuit_bytecode: {:?}", recursive_circuit_bytecode);
    // IMPORTANT: Likely to run into a timeout for the net srs, replace None with a path to a local srs file
    // before running this test
    setup_srs(String::from(recursive_circuit_bytecode), None, true).unwrap();
    let mut initial_witness_recursive = WitnessMap::new();
    let mut index = 0;
    // Verification key
    vk_as_fields.iter().for_each(|v| {
    initial_witness_recursive.insert(Witness(index), FieldElement::try_from_str(v).unwrap());
    index += 1;
    });
    // Proof
    proof_as_fields.iter().for_each(|v| {
    initial_witness_recursive.insert(Witness(index), FieldElement::try_from_str(v).unwrap());
    index += 1;
    });
    // Public inputs
    initial_witness_recursive.insert(Witness(index), FieldElement::from(25u128));
    index += 1;
    // Key hash
    initial_witness_recursive.insert(Witness(index), FieldElement::try_from_str(&key_hash).unwrap());
    let (proof, vk) = prove_ultra_honk(recursive_circuit_bytecode, initial_witness_recursive, true).unwrap();
    let verdict = verify_ultra_honk(proof, vk).unwrap();
    assert!(verdict);
    }*/

Next Steps

Re-enable recursive proving support once bb and noir versions stabilize. There's dev demand for this feature.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions