Skip to content

Commit 21c308d

Browse files
committed
refactor: use a single ffi for gnark and circom verifiers
1 parent 57d8195 commit 21c308d

File tree

7 files changed

+39
-101
lines changed

7 files changed

+39
-101
lines changed

crates/batcher/build.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
use std::{env, path::PathBuf, process::Command};
22

3-
const GO_SRC: &str = "./gnark/verifier.go";
3+
const GO_SRC: &str = "./verifiers_ffi/verifier.go";
44
const GO_OUT: &str = "libverifier.a";
55
const GO_LIB: &str = "verifier";
66

7-
const CIRCOM_SRC: &str = "./circom/verifier.go";
8-
const CIRCOM_OUT: &str = "libcircomverifier.a";
9-
const CIRCOM_LIB: &str = "circomverifier";
10-
117
fn main() {
128
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
139

@@ -18,7 +14,7 @@ fn main() {
1814

1915
let _ = get_cmd.output(); // Run but don't fail if it has issues
2016

21-
// Build gnark library
17+
// Build library
2218
let mut go_build = Command::new("go");
2319
go_build
2420
.arg("build")
@@ -29,23 +25,7 @@ fn main() {
2925

3026
go_build.status().expect("Go build failed");
3127

32-
// Build circom library
33-
let mut circom_build = Command::new("go");
34-
circom_build
35-
.arg("build")
36-
.arg("-buildmode=c-archive")
37-
.arg("-o")
38-
.arg(out_dir.join(CIRCOM_OUT))
39-
.arg(CIRCOM_SRC);
40-
41-
let output = circom_build.output().expect("Failed to execute Circom build command");
42-
if !output.status.success() {
43-
eprintln!("Circom build failed: {}", String::from_utf8_lossy(&output.stderr));
44-
panic!("Circom build failed");
45-
}
46-
4728
println!("cargo:rerun-if-changed={}", GO_SRC);
48-
println!("cargo:rerun-if-changed={}", CIRCOM_SRC);
4929
println!(
5030
"cargo:rustc-link-search=native={}",
5131
out_dir.to_str().unwrap()
@@ -56,5 +36,4 @@ fn main() {
5636
}
5737

5838
println!("cargo:rustc-link-lib=static={}", GO_LIB);
59-
println!("cargo:rustc-link-lib=static={}", CIRCOM_LIB);
6039
}

crates/batcher/circom/go.mod

Lines changed: 0 additions & 10 deletions
This file was deleted.

crates/batcher/circom/go.sum

Lines changed: 0 additions & 14 deletions
This file was deleted.

crates/batcher/circom/verifier.go

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.22.3
55
require (
66
github.com/consensys/gnark v0.12.0
77
github.com/consensys/gnark-crypto v0.17.0
8+
github.com/yetanotherco/go-circom-prover-verifier v0.0.0-20250618185957-f01a8a8ec4a6
89
)
910

1011
require (
@@ -25,3 +26,5 @@ require (
2526
golang.org/x/sys v0.30.0 // indirect
2627
rsc.io/tmplfunc v0.0.3 // indirect
2728
)
29+
30+
require github.com/ethereum/go-ethereum v1.14.0 // indirect
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ github.com/consensys/gnark-crypto v0.17.0/go.mod h1:A2URlMHUT81ifJ0UlLzSlm7TmnE3
1111
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
1212
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1313
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14+
github.com/ethereum/go-ethereum v1.14.0/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8=
1415
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
1516
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
1617
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@@ -44,6 +45,7 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
4445
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4546
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
4647
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
48+
github.com/yetanotherco/go-circom-prover-verifier v0.0.0-20250618185957-f01a8a8ec4a6/go.mod h1:A6TUcQ/lvmwAA/Ir8kRMIX5NcIglk8iNKeHF8Nj6Hu0=
4749
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
4850
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
4951
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ typedef struct ListRef {
88
const uint8_t *ptr;
99
uintptr_t len;
1010
} ListRef;
11-
12-
1311
*/
1412
import "C"
1513

1614
import (
1715
"bytes"
16+
"github.com/yetanotherco/go-circom-prover-verifier/parsers"
17+
"github.com/yetanotherco/go-circom-prover-verifier/verifier"
1818
"log"
1919
"unsafe"
2020

@@ -119,3 +119,33 @@ func verifyGroth16Proof(proofBytesRef C.ListRef, pubInputBytesRef C.ListRef, ver
119119
err = groth16.Verify(proof, verificationKey, pubInput)
120120
return err == nil
121121
}
122+
123+
//export VerifyCircomGroth16ProofBN128
124+
func VerifyCircomGroth16ProofBN128(proofBytesRef C.ListRef, pubInputBytesRef C.ListRef, verificationKeyBytesRef C.ListRef) bool {
125+
proofBytes := listRefToBytes(proofBytesRef)
126+
pubInputBytes := listRefToBytes(pubInputBytesRef)
127+
verificationKeyBytes := listRefToBytes(verificationKeyBytesRef)
128+
print("FFI proofBytes: ", unsafe.Pointer(proofBytesRef.ptr), " len: ", len(proofBytes))
129+
print("FFI pubInputBytes: ", unsafe.Pointer(pubInputBytesRef.ptr), " len: ", len(pubInputBytes))
130+
print("FFI verificationKeyBytes: ", unsafe.Pointer(verificationKeyBytesRef.ptr), " len: ", len(verificationKeyBytes))
131+
132+
proof, err := parsers.ParseProof(proofBytes)
133+
if err != nil {
134+
print("FFI ParseProof error: ", err)
135+
return false
136+
}
137+
public, err := parsers.ParsePublicSignals(pubInputBytes)
138+
if err != nil {
139+
print("FFI ParsePublicSignals error: ", err)
140+
return false
141+
}
142+
vk, err := parsers.ParseVk(verificationKeyBytes)
143+
if err != nil {
144+
print("FFI ParseVk error: ", err)
145+
return false
146+
}
147+
148+
is_valid := verifier.Verify(vk, proof, public)
149+
print("FFI is_valid: ", is_valid)
150+
return is_valid
151+
}

0 commit comments

Comments
 (0)