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

Support circom proof convert for both BN254 and BLS12-381 #368

Open
vivianjeng opened this issue Mar 14, 2025 · 0 comments
Open

Support circom proof convert for both BN254 and BLS12-381 #368

vivianjeng opened this issue Mar 14, 2025 · 0 comments
Assignees

Comments

@vivianjeng
Copy link
Collaborator

Problem

Now we implemented toEthereumProof and fromEthereumProof

// Only supports bn254 for now
pub fn to_ethereum_proof(proof: Vec<u8>) -> ProofCalldata {

But it only supports Bn254 for now
We can add support for BLS12-381

Discussion: #367 (comment)
Discussion: #361 (comment)

Details

Solution 1 (best)

Convert the proofs in circom-prover with the types: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/snarkjs/index.d.cts
so that the struct becomes

pub struct CircomProof {
    pub a: G1, // each element is BigUint type
    pub b: G2,
    pub c: G1,
    pub protocol: String,
    pub curve: String,
}

// circom-prover
pub struct GenerateProofResult {
    pub proof: CircomProof,
    pub inputs: Vec<BigUint>,
}

// mopro-ffi
pub struct GenerateProofResult {
    pub proof: CircomProof, // convert all BigUint to String
    pub inputs: Vec<String>, // convert all BigUint to String
}

the API becomes

// circom-prover
pub fn prove(
        proof_lib: ProofLib,
        wit_fn: WitnessFn,
        json_input_str: String,
        zkey_path: String,
    ) -> Result<CircomProof> {

pub fn verify(
        proof_lib: ProofLib,
        proof: CircomProof // merge proof and public_signals
        zkey_path: String,
    ) -> Result<bool> {

We have handled all BN254 and BLS12-381 convert in https://github.com/zkmopro/mopro/blob/main/circom-prover/src/prover/ethereum.rs
Then it should support these 2 curves to convert to CircomProof
Just need to update the mopro-ffi and test-e2e types

Solution 2 (short term, not recommended)

add support for toEthereumProof with

pub fn to_ethereum_proof(proof: Vec<u8>) -> ProofCalldata {
let deserialized_proof = deserialize_proof::<Bn254>(proof);

deserialize/serialize BLS12-381

Acceptance criteria

Support for both BN254 and BLS12-381 that the proof needs to be

  1. readable (like toEthereumProof)
  2. verifiable (in verify_circom_proof)
  3. exportable (with uniffi)

Next steps (optional)

If choose Solution 1, and we can remove all toEthereumProof, fromEthereumProof, toEthereumInputs, fromEthereumInputs

@vivianjeng vivianjeng mentioned this issue Mar 14, 2025
@KimiWu123 KimiWu123 self-assigned this Mar 14, 2025
@KimiWu123 KimiWu123 moved this to In progress in Mopro Kanban Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

No branches or pull requests

2 participants