| Crates.io | samaharam |
| lib.rs | samaharam |
| version | 0.2.0 |
| created_at | 2025-12-20 10:07:28.739844+00 |
| updated_at | 2025-12-20 20:02:38.706444+00 |
| description | Scalable heterogeneous zero-knowledge proof aggregation for EVM chains |
| homepage | |
| repository | https://github.com/ronnakamoto/samaharam |
| max_upload_size | |
| id | 1996296 |
| size | 373,972 |
സമാഹാരം (samahāram) — Malayalam for "aggregation" or "collection"
Samaharam is a high-performance Rust library for aggregating heterogeneous zero-knowledge proofs into a single proof for efficient on-chain verification on EVM chains.
.ptau ceremony files directlyuse samaharam::{Bn254, client::{AggregationClient, ProofRequest}, config::Srs};
use std::sync::Arc;
// Initialize with SRS (parse from .ptau file)
let srs = Arc::new(Srs::<Bn254>::from_ptau("pot12_final.ptau")?);
let mut client = AggregationClient::new(srs)?;
// Register the circuit verification key
let vk = ...; // Load your verification key
let circuit_id = client.register_circuit("payment_circuit", vk);
// Submit proofs (e.g. from snarkjs)
// proof_data is the JSON output from snarkjs
client.submit(ProofRequest {
circuit_type: "payment_circuit".to_string(),
proof_data: proof_bytes,
public_inputs: vec![input1, input2],
})?;
// Aggregate
let result = client.aggregate_external()?;
println!("Aggregated {} proofs", result.proof_count);
// Generate Solidity Verifier
let sol_code = result.generate_solidity_verifier()?;
std::fs::write("SamaharamVerifier.sol", sol_code)?;
Currently, Samaharam supports Groth16 proofs generated by snarkjs/circom.
use samaharam::adapters::{SnarkjsProof, ExternalProof};
// Load proof from snarkjs JSON output
let proof = SnarkjsProof::from_json(json_data)?;
// Convert to internal accumulator instances
let instances = proof.to_accumulator_instances()?;
| Module | Description |
|---|---|
crypto::kzg |
KZG polynomial commitments with Pippenger MSM |
crypto::accumulator |
Proof folding with multi-pairing optimization |
adapters |
Import Groth16 proofs from snarkjs |
solidity::generator |
Generate Solidity verifier contracts |
client |
Ergonomic high-level API |
Samaharam generates a highly optimized Solidity verifier that uses the BN254 precompiles.
// Optimized KZG pairing check (~45k gas)
function verifyKzg(
uint256[2] calldata adjustedCommitment,
uint256[2] calldata combinedQuotient
) external view returns (bool);
Verification Logic: The verifier checks the pairing equation: $$e(A, G_2) \cdot e(-Q, \tau G_2) = 1$$
Where:
Samaharam reduces on-chain verification costs by using Batched KZG. The aggregated proof size is constant regardless of the number of inputs.
| Verification Method | Pairings | Approx. Gas | Savings (vs 3 proofs) |
|---|---|---|---|
| Samaharam KZG | 2 | ~45,000 | ~93% |
| Standard Groth16 | 4 per proof | ~200,000+ | 0% |
Note: Gas costs are estimates based on standard BN254 precompile costs.
| Operation | Optimization |
|---|---|
| Multi-scalar multiplication | Pippenger's bucket method with adaptive window |
| Proof verification | Multi-pairing with shared final exponentiation |
See docs/SECURITY.md for:
This software is provided "as is", without warranty of any kind, express or implied. The author(s) of this crate (github.com/ronnakamoto) shall not be held responsible for any damages, losses, or liabilities arising from the use of this software. Use at your own risk.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.