How zkaa-onchain/zkaa-recursive works
Based on our analysis of the file tree and README, this project is a Rust-based command line toolkit called “plonkit” that serves as a zk-SNARK workflow engine for circuits written in the circom DSL. Its purpose is to provide an end‐to‐end solution for generating proofs, verifying them, aggregating recursive proofs, and generating a Solidity verifier smart contract using the plonk proof system. The project integrates with external tools like circom and snarkit2 for circuit compilation and witness generation, and it offers a complete workflow from key setup (trusted SRS generation) to smart contract verification.
Main Components
• CLI Entry Point: Represented by src/bin/main.rs, this is the command line interface that parses user commands and delegates tasks (subcommands such as “prove”, “recursive-prove”, “setup”, etc.).
• Core Engine & Modules: Divide the engine into logical Rust modules such as:
• Circuit Processing: Modules like circom_circuit.rs and r1cs_file.rs that handle circuit representation, loading, and analysis.
• Proof Generation: Modules (e.g., plonk.rs and transpile.rs) that implement proof generation logic.
• Recursive Proof Handling: The “recursive” module manages aggregation of multiple proofs for recursive verification.
• Utility Functions: Module utils.rs, reader.rs, and tests.rs support common functionality and testing.
• Key and Setup Management: Represent the “keys/setup” directory and associated logic for generating/using the SRS (Structured Reference String) for Plonk.
• Test & Validation Infrastructure:
• Test circuits folder and associated shell scripts (e.g., test_poseidon_plonk.sh) that illustrate end-to-end flows.
• Contract Integration: The “test/contract” folder highlighting the Hardhat configuration and Solidity verifier generation.
• External Tools and Dependencies: Include circom and snarkit2 as external executables (with prerequisites noted in the README), as well as the Rust toolchain and dependencies defined in Cargo.toml.
Relationships and Data Flow
• From the main CLI, commands are routed to the Proof Generation Module which:
1. Loads a circuit file (using circom_circuit.rs or r1cs_file.rs).
2. Possibly calls out to external tools to generate a witness (via snarkit2/circom externally).
3. Uses proof generation logic in plonk.rs to create a SNARK proof.
4. Optionally aggregates proofs using the recursive proof module.
• Once a proof is generated, the system exports a verification key (and a Solidity verifier may be generated), with a clear flow from input (circuit and SRS/key files) to output (proof.bin, vk.bin, verifier.sol).
Architectural Patterns and Design Principles
• CLI-driven Workflow: The design is centered around a command-line interface that controls the execution of various subcommands.
• Extensibility: Separate concerns for proof generation, recursive aggregation, and verifier generation indicate a design that allows new subcommands or algorithm enhancements.
• Integration with External Systems: The integration with external circuit compilers (circom) and blockchain contracts (via Hardhat and Solidity) should be depicted.
Detailed Component Relationships
• CLI Layer: Show how commands (prove, recursive-prove, setup, export-verification-key, generate-verifier) are received and routed.
• Data Flow: From user-provided circuit and input files → processed by circuit modules → passed to the proof generation module → outputting proof binaries and verification keys.
• Recursive Component: Clearly mark its role in aggregating individual proofs for more complex verification strategies.
• Testing & Verification: Illustrate the integration tests that verify the entire circuit-to-verifier workflow, connecting test folders with actual build artifacts.
• External Interaction: Mark dependencies on external executables (circom and snarkit2) which are prerequisites before the Rust toolchain kicks in.