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

create precompiles for zksaas Circom verifiers #654

Open
2 tasks
shekohex opened this issue May 20, 2024 · 1 comment
Open
2 tasks

create precompiles for zksaas Circom verifiers #654

shekohex opened this issue May 20, 2024 · 1 comment
Assignees

Comments

@shekohex
Copy link
Contributor

shekohex commented May 20, 2024

Create a precompile for the following verifiers:

  • Circom:
    fn verify(public_inp_bytes: &[u8], proof_bytes: &[u8], vk_bytes: &[u8]) -> Result<bool, Error> {
    let public_input_field_elts = match super::to_field_elements::<Fr>(public_inp_bytes) {
    Ok(v) => v,
    Err(e) => {
    log::error!("Failed to convert public input bytes to field elements: {e:?}",);
    return Err(e);
    },
    };
    let vk = match ArkVerifyingKey::deserialize_compressed(vk_bytes) {
    Ok(v) => v,
    Err(e) => {
    log::error!("Failed to deserialize verifying key: {e:?}");
    return Err(e.into());
    },
    };
    let proof = match Proof::decode(proof_bytes).and_then(|v| v.try_into()) {
    Ok(v) => v,
    Err(e) => {
    log::error!("Failed to deserialize proof: {e:?}");
    return Err(e);
    },
    };
    let res = match verify_groth16(&vk, &public_input_field_elts, &proof) {
    Ok(v) => v,
    Err(e) => {
    log::error!("Failed to verify proof: {e:?}");
    return Err(e);
    },
    };
    Ok(res)
  • Arkworks:
    impl<E: Pairing> super::InstanceVerifier for ArkworksVerifierGroth16<E> {
    fn verify(public_inp_bytes: &[u8], proof_bytes: &[u8], vk_bytes: &[u8]) -> Result<bool, Error> {
    let public_input_field_elts = super::to_field_elements::<E::ScalarField>(public_inp_bytes)?;
    let vk = VerifyingKey::<E>::deserialize_compressed(vk_bytes)?;
    let proof = Proof::<E>::deserialize_compressed(proof_bytes)?;
    let res = verify_groth16::<E>(&vk, &public_input_field_elts, &proof)?;
    Ok(res)
    }
    }
@salman01zp salman01zp self-assigned this May 20, 2024
@drewstone
Copy link
Contributor

drewstone commented May 20, 2024

If we want the fastest, most performant groth16 verify function we should actually explore this first instead of adding these precompiles. Specifically, we only right now use the groth16 verify for zkSaaS blueprint. If we deploy this blueprint we should want it using https://github.com/paritytech/arkworks-extensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not Started 🕧
Development

No branches or pull requests

3 participants