mirror of
https://github.com/arnaucube/circom-compat.git
synced 2026-01-09 07:21:33 +01:00
Feat: Use pre-calculated ConstraintMatrices (#2)
* feat: add function for calculating the coefficients * fix tests / debug coeffs * feat: use groth16 with configurable matrices * test: add no r1cs test * test: add a test to check matrices values * scaffold of the matrix calculation * feat: correctly load and use matrices in the without_r1cs variant * chore: cargo fmt * chore: cargo fmt / lints * ci: do not double run tests * fix: calculate correctly points at inf * test: use correct abicoder v2 types Co-authored-by: Kobi Gurkan <kobigurk@gmail.com>
This commit is contained in:
committed by
GitHub
parent
4e2c2d39dd
commit
11e6d04f3b
@@ -1,7 +1,4 @@
|
||||
use ark_circom::{
|
||||
ethereum::{Inputs, Proof, VerifyingKey},
|
||||
CircomBuilder, CircomConfig,
|
||||
};
|
||||
use ark_circom::{ethereum, CircomBuilder, CircomConfig};
|
||||
use ark_std::rand::thread_rng;
|
||||
use color_eyre::Result;
|
||||
|
||||
@@ -70,18 +67,59 @@ async fn solidity_verifier() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// We need to implement the conversion from the Ark-Circom's internal Ethereum types to
|
||||
// the ones expected by the abigen'd types. Could we maybe provide a convenience
|
||||
// macro for these, given that there's room for implementation error?
|
||||
abigen!(Groth16Verifier, "./tests/verifier_abi.json");
|
||||
use groth16verifier_mod::{G1Point, G2Point, Proof, VerifyingKey};
|
||||
impl From<ethereum::G1> for G1Point {
|
||||
fn from(src: ethereum::G1) -> Self {
|
||||
Self { x: src.x, y: src.y }
|
||||
}
|
||||
}
|
||||
impl From<ethereum::G2> for G2Point {
|
||||
fn from(src: ethereum::G2) -> Self {
|
||||
// We should use the `.as_tuple()` method which handles converting
|
||||
// the G2 elements to have the second limb first
|
||||
let src = src.as_tuple();
|
||||
Self { x: src.0, y: src.1 }
|
||||
}
|
||||
}
|
||||
impl From<ethereum::Proof> for Proof {
|
||||
fn from(src: ethereum::Proof) -> Self {
|
||||
Self {
|
||||
a: src.a.into(),
|
||||
b: src.b.into(),
|
||||
c: src.c.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<ethereum::VerifyingKey> for VerifyingKey {
|
||||
fn from(src: ethereum::VerifyingKey) -> Self {
|
||||
Self {
|
||||
alfa_1: src.alpha1.into(),
|
||||
beta_2: src.beta2.into(),
|
||||
gamma_2: src.gamma2.into(),
|
||||
delta_2: src.delta2.into(),
|
||||
ic: src.ic.into_iter().map(|i| i.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: Middleware> Groth16Verifier<M> {
|
||||
async fn check_proof<I: Into<Inputs>, P: Into<Proof>, VK: Into<VerifyingKey>>(
|
||||
async fn check_proof<
|
||||
I: Into<ethereum::Inputs>,
|
||||
P: Into<ethereum::Proof>,
|
||||
VK: Into<ethereum::VerifyingKey>,
|
||||
>(
|
||||
&self,
|
||||
proof: P,
|
||||
vk: VK,
|
||||
inputs: I,
|
||||
) -> Result<bool, ContractError<M>> {
|
||||
// convert into the expected format by the contract
|
||||
let proof = proof.into().as_tuple();
|
||||
let vk = vk.into().as_tuple();
|
||||
let proof = proof.into().into();
|
||||
let vk = vk.into().into();
|
||||
let inputs = inputs.into().0;
|
||||
|
||||
// query the contract
|
||||
|
||||
Reference in New Issue
Block a user