Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4e98e1e
feat(batcher): integrate circom verifier [not compiling yet]
JuArce Jun 17, 2025
5d4a24a
feat(batcher): integrate circom verifier [not compiling yet part 2]
JuArce Jun 18, 2025
60b70fd
Fix build
MauroToscano Jun 18, 2025
85e8eac
do not run mod tidy
JuArce Jun 18, 2025
ab6e68b
Fix build 2
MauroToscano Jun 18, 2025
393102e
Change the go get on batcher's builder to the last circom version
maximopalopoli Jun 18, 2025
57d8195
Update go mod and go sum files
maximopalopoli Jun 18, 2025
21c308d
refactor: use a single ffi for gnark and circom verifiers
JuArce Jun 19, 2025
b9cbefe
feat: integrate circom verifier in operator
JuArce Jun 19, 2025
0761b8b
feat: add scripts to generate and send circom proofs
JuArce Jun 19, 2025
c9fedd0
docs: add circom verifier
JuArce Jun 19, 2025
d8fb28d
fix: cargo fmt
JuArce Jun 19, 2025
894f68d
ci: send proofs on e2e test
JuArce Jun 19, 2025
ec9c38a
fix: cargo clippy
JuArce Jun 19, 2025
33dff02
fix: batcher docker path
JuArce Jun 19, 2025
7fadb30
test: update test_some_verifiers_disabled
JuArce Jun 19, 2025
f7f7307
ci: update check proofs verified
JuArce Jun 19, 2025
4d3350f
fix: remove ceremony files
JuArce Jun 23, 2025
ab166e8
chore: update gitignore
JuArce Jun 24, 2025
d434ade
fix: use log.Printf
JuArce Jun 24, 2025
ab25058
refactor: separate ffis from code
JuArce Jun 24, 2025
780354f
fix: add missing new lines
JuArce Jun 24, 2025
f440424
fix: cargo fmt
JuArce Jun 24, 2025
3c017b2
fix(ci): paths to libraries
JuArce Jun 24, 2025
f354ae1
Merge branch 'refs/heads/staging' into 1986-feat-integrate-circom-ver…
JuArce Jun 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ infra/ansible/playbooks/files/**.pem

examples/l2/crates/l2/db
examples/l2/crates/l2/zkvm_programs/sp1/elf/sp1_state_transition_program

# Circom
*.ptau
challenge_0003
response_0003
challenge_phase2_0003
circuit.r1cs
circuit.r1cs.json
circuit.sym
response_phase2_0003
witness.wtns
*.zkey
circuit_cpp/
circuit_js
47 changes: 46 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,29 @@ batcher_send_groth16_bn254_infinite: crates/target/release/aligned ## Send a dif
@mkdir -p scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs
@./crates/cli/send_burst_tasks.sh $(BURST_SIZE) $(START_COUNTER)

batcher_send_circom_groth16_bn128_task: crates/target/release/aligned ## Send a Circom Groth16 BN128 proof to Batcher. Parameters: RPC_URL, NETWORK
@echo "Sending Circom Groth16 BN128 proof to Batcher..."
@cd crates/cli/ && cargo run --release -- submit \
--proving_system CircomGroth16Bn128 \
--proof ../../scripts/test_files/circom_groth16_bn128_script/proof.json \
--public_input ../../scripts/test_files/circom_groth16_bn128_script/public.json \
--vk ../../scripts/test_files/circom_groth16_bn128_script/verification_key.json \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--rpc_url $(RPC_URL) \
--network $(NETWORK)

batcher_send_circom_groth16_bn128_burst: crates/target/release/aligned ## Send a burst of Circom Groth16 BN128 proofs to Batcher. Parameters: RPC_URL, NETWORK, BURST_SIZE
@echo "Sending Circom Groth16 BN128 proof to Batcher..."
@cd crates/cli/ && cargo run --release -- submit \
--proving_system CircomGroth16Bn128 \
--proof ../../scripts/test_files/circom_groth16_bn128_script/proof.json \
--public_input ../../scripts/test_files/circom_groth16_bn128_script/public.json \
--vk ../../scripts/test_files/circom_groth16_bn128_script/verification_key.json \
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
--repetitions $(BURST_SIZE) \
--rpc_url $(RPC_URL) \
--network $(NETWORK)

batcher_send_proof_with_random_address: ## Send a proof with a random address to Batcher. Parameters: RPC_URL, NETWORK, PROOF_TYPE, REPETITIONS
@cd crates/cli/ && ./send_proof_with_random_address.sh

Expand Down Expand Up @@ -762,6 +785,13 @@ generate_gnark_groth16_bn254_ineq_proof: ## Run the gnark_plonk_bn254_script
@echo "Running gnark_groth_bn254_ineq script..."
@go run scripts/test_files/gnark_groth16_bn254_infinite_script/cmd/main.go 1

generate_circom_groth16_bn128_proof: ## Run the circom_groth16_bn128_script
@echo "Running circom_groth16_bn128 script..."
@cd scripts/test_files/circom_groth16_bn128_script && ./generate_proof.sh

generate_circom_groth16_bn128_setup: ## Run the circom_groth16_bn128_script setup
@echo "Running circom_groth16_bn128 script setup..."
@cd scripts/test_files/circom_groth16_bn128_script && ./generate_setup.sh

__CONTRACTS_DEPLOYMENT__: ## ____
deploy_aligned_contracts: ## Deploy Aligned Contracts. Parameters: NETWORK=<mainnet|holesky|sepolia>
Expand Down Expand Up @@ -1097,13 +1127,27 @@ docker_batcher_send_groth16_burst:
--rpc_url $(DOCKER_RPC_URL) \
--max_fee 0.1ether

docker_batcher_send_circom_groth16_bn128_burst:
@echo "Sending Circom Groth16 BN128 task to Batcher..."
docker exec $(shell docker ps | grep batcher | awk '{print $$1}') aligned submit \
--private_key $(DOCKER_PROOFS_PRIVATE_KEY) \
--proving_system CircomGroth16Bn128 \
--proof ./scripts/test_files/circom_groth16_bn128_script/proof.json \
--public_input ./scripts/test_files/circom_groth16_bn128_script/public.json \
--vk ./scripts/test_files/circom_groth16_bn128_script/verification_key.json \
--proof_generator_addr $(PROOF_GENERATOR_ADDRESS) \
--repetitions $(DOCKER_BURST_SIZE) \
--rpc_url $(DOCKER_RPC_URL) \
--max_fee 0.1ether

# Update target as new proofs are supported.
docker_batcher_send_all_proofs_burst:
@$(MAKE) docker_batcher_send_sp1_burst
@$(MAKE) docker_batcher_send_risc0_burst
@$(MAKE) docker_batcher_send_plonk_bn254_burst
@$(MAKE) docker_batcher_send_plonk_bls12_381_burst
@$(MAKE) docker_batcher_send_groth16_burst
@$(MAKE) docker_batcher_send_circom_groth16_bn128_burst

docker_batcher_send_infinite_groth16:
docker exec $(shell docker ps | grep batcher | awk '{print $$1}') \
Expand Down Expand Up @@ -1141,6 +1185,7 @@ docker_verify_proofs_onchain:
'

DOCKER_PROOFS_WAIT_TIME=60
DOCKER_SENT_PROOFS=6

docker_verify_proof_submission_success:
@echo "Verifying proofs were successfully submitted..."
Expand Down Expand Up @@ -1169,7 +1214,7 @@ docker_verify_proof_submission_success:
fi; \
echo "---------------------------------------------------------------------------------------------------"; \
done; \
if [ $$(ls -1 ./aligned_verification_data/*.cbor | wc -l) -ne 5 ]; then \
if [ $$(ls -1 ./aligned_verification_data/*.cbor | wc -l) -ne $(DOCKER_SENT_PROOFS) ]; then \
echo "ERROR: Some proofs were verified successfully, but some proofs are missing in the aligned_verification_data/ directory"; \
exit 1; \
fi; \
Expand Down
7 changes: 7 additions & 0 deletions common/proving_systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
Groth16Bn254
SP1
Risc0
CircomGroth16Bn128
)

func (t *ProvingSystemId) String() string {
Expand All @@ -34,6 +35,8 @@ func ProvingSystemIdFromString(provingSystem string) (ProvingSystemId, error) {
return SP1, nil
case "Risc0":
return Risc0, nil
case "CircomGroth16Bn128":
return CircomGroth16Bn128, nil
}

return 0, fmt.Errorf("unknown proving system: %s", provingSystem)
Expand All @@ -51,6 +54,8 @@ func ProvingSystemIdToString(provingSystem ProvingSystemId) (string, error) {
return "SP1", nil
case Risc0:
return "Risc0", nil
case CircomGroth16Bn128:
return "CircomGroth16Bn128", nil
}

return "", fmt.Errorf("unknown proving system: %d", provingSystem)
Expand Down Expand Up @@ -105,6 +110,8 @@ func (s *ProvingSystemId) UnmarshalCBOR(data []byte) error {
*s = SP1
case "Risc0":
*s = Risc0
case "CircomGroth16Bn128":
*s = CircomGroth16Bn128
}

return nil
Expand Down
11 changes: 10 additions & 1 deletion crates/batcher/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use std::{env, path::PathBuf, process::Command};

const GO_SRC: &str = "./gnark/verifier.go";
const GO_SRC: &str = "./go_verifiers_lib/verifier.go";
const GO_OUT: &str = "libverifier.a";
const GO_LIB: &str = "verifier";

fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

// Fix the missing dependency issue
let mut get_cmd = Command::new("go");
get_cmd.arg("get")
.arg("github.com/yetanotherco/go-circom-prover-verifier/parsers@v0.0.0-20250618185957-f01a8a8ec4a6");

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

// Build library
let mut go_build = Command::new("go");
go_build
.arg("build")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.3
require (
github.com/consensys/gnark v0.12.0
github.com/consensys/gnark-crypto v0.17.0
github.com/yetanotherco/go-circom-prover-verifier v0.0.0-20250618185957-f01a8a8ec4a6
)

require (
Expand All @@ -25,3 +26,5 @@ require (
golang.org/x/sys v0.30.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

require github.com/ethereum/go-ethereum v1.14.0 // indirect
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ github.com/consensys/gnark-crypto v0.17.0/go.mod h1:A2URlMHUT81ifJ0UlLzSlm7TmnE3
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ethereum/go-ethereum v1.14.0/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down Expand Up @@ -44,6 +45,7 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yetanotherco/go-circom-prover-verifier v0.0.0-20250618185957-f01a8a8ec4a6/go.mod h1:A6TUcQ/lvmwAA/Ir8kRMIX5NcIglk8iNKeHF8Nj6Hu0=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ typedef struct ListRef {
const uint8_t *ptr;
uintptr_t len;
} ListRef;


*/
import "C"

import (
"bytes"
"github.com/yetanotherco/go-circom-prover-verifier/parsers"
"github.com/yetanotherco/go-circom-prover-verifier/verifier"
"log"
"unsafe"

Expand Down Expand Up @@ -119,3 +119,30 @@ func verifyGroth16Proof(proofBytesRef C.ListRef, pubInputBytesRef C.ListRef, ver
err = groth16.Verify(proof, verificationKey, pubInput)
return err == nil
}

//export VerifyCircomGroth16ProofBN128
func VerifyCircomGroth16ProofBN128(proofBytesRef C.ListRef, pubInputBytesRef C.ListRef, verificationKeyBytesRef C.ListRef) bool {
proofBytes := listRefToBytes(proofBytesRef)
pubInputBytes := listRefToBytes(pubInputBytesRef)
verificationKeyBytes := listRefToBytes(verificationKeyBytesRef)

proof, err := parsers.ParseProof(proofBytes)
if err != nil {
log.Printf("Could not parse proof: %v", err)
return false
}

public, err := parsers.ParsePublicSignals(pubInputBytes)
if err != nil {
log.Printf("Could not parse public signals: %v", err)
return false
}

vk, err := parsers.ParseVk(verificationKeyBytes)
if err != nil {
log.Printf("Could not parse verification key: %v", err)
return false
}

return verifier.Verify(vk, proof, public)
}
1 change: 1 addition & 0 deletions crates/batcher/src/circom/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod verifier;
20 changes: 20 additions & 0 deletions crates/batcher/src/circom/verifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::ffi::circom_ffi::VerifyCircomGroth16ProofBN128;
use aligned_sdk::common::types::ProvingSystemId;

pub fn verify_circom(
proving_system: &ProvingSystemId,
proof: &Vec<u8>,
public_input: &Vec<u8>,
verification_key: &Vec<u8>,
) -> bool {
let proof = proof.into();
let public_input = public_input.into();
let verification_key = verification_key.into();

match proving_system {
ProvingSystemId::CircomGroth16Bn128 => unsafe {
VerifyCircomGroth16ProofBN128(proof, public_input, verification_key)
},
_ => false,
}
}
9 changes: 9 additions & 0 deletions crates/batcher/src/ffi/circom_ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::ffi::list_ref::ListRef;

extern "C" {
pub fn VerifyCircomGroth16ProofBN128(
proof: ListRef,
public_input: ListRef,
verification_key: ListRef,
) -> bool;
}
19 changes: 19 additions & 0 deletions crates/batcher/src/ffi/gnark_ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::ffi::list_ref::ListRef;

extern "C" {
pub fn VerifyPlonkProofBLS12_381(
proof: ListRef,
public_input: ListRef,
verification_key: ListRef,
) -> bool;
pub fn VerifyPlonkProofBN254(
proof: ListRef,
public_input: ListRef,
verification_key: ListRef,
) -> bool;
pub fn VerifyGroth16ProofBN254(
proof: ListRef,
public_input: ListRef,
verification_key: ListRef,
) -> bool;
}
26 changes: 26 additions & 0 deletions crates/batcher/src/ffi/list_ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct ListRef {
data: *const u8,
len: usize,
}

impl From<Vec<u8>> for ListRef {
fn from(v: Vec<u8>) -> Self {
Self::from(v.as_slice())
}
}

impl From<&Vec<u8>> for ListRef {
fn from(v: &Vec<u8>) -> Self {
Self::from(v.as_slice())
}
}

impl From<&[u8]> for ListRef {
fn from(v: &[u8]) -> Self {
let len = v.len();
let data = v.as_ptr().cast();
ListRef { data, len }
}
}
3 changes: 3 additions & 0 deletions crates/batcher/src/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod circom_ffi;
pub mod gnark_ffi;
mod list_ref;
48 changes: 3 additions & 45 deletions crates/batcher/src/gnark/mod.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
use crate::ffi::gnark_ffi::{
VerifyGroth16ProofBN254, VerifyPlonkProofBLS12_381, VerifyPlonkProofBN254,
};
use aligned_sdk::common::types::ProvingSystemId;

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct ListRef {
data: *const u8,
len: usize,
}

impl From<Vec<u8>> for ListRef {
fn from(v: Vec<u8>) -> Self {
Self::from(v.as_slice())
}
}

impl From<&Vec<u8>> for ListRef {
fn from(v: &Vec<u8>) -> Self {
Self::from(v.as_slice())
}
}

impl From<&[u8]> for ListRef {
fn from(v: &[u8]) -> Self {
let len = v.len();
let data = v.as_ptr().cast();
ListRef { data, len }
}
}

pub fn verify_gnark(
proving_system: &ProvingSystemId,
proof: &Vec<u8>,
Expand All @@ -50,21 +26,3 @@ pub fn verify_gnark(
_ => false,
}
}

extern "C" {
pub fn VerifyPlonkProofBLS12_381(
proof: ListRef,
public_input: ListRef,
verification_key: ListRef,
) -> bool;
pub fn VerifyPlonkProofBN254(
proof: ListRef,
public_input: ListRef,
verification_key: ListRef,
) -> bool;
pub fn VerifyGroth16ProofBN254(
proof: ListRef,
public_input: ListRef,
verification_key: ListRef,
) -> bool;
}
2 changes: 2 additions & 0 deletions crates/batcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ use types::errors::{BatcherError, TransactionSendError};
use crate::config::{ConfigFromYaml, ContractDeploymentOutput};
use crate::telemetry::sender::TelemetrySender;

pub mod circom;
mod config;
mod connection;
mod eth;
mod ffi;
pub mod gnark;
pub mod metrics;
pub mod retry;
Expand Down
Loading
Loading