Skip to content

[PROPOSAL] Add Rust/Solana export commands for Groth16#615

Draft
vitorpy wants to merge 1 commit intoiden3:masterfrom
vitorpy:feat/rust-solana-export
Draft

[PROPOSAL] Add Rust/Solana export commands for Groth16#615
vitorpy wants to merge 1 commit intoiden3:masterfrom
vitorpy:feat/rust-solana-export

Conversation

@vitorpy
Copy link

@vitorpy vitorpy commented Dec 22, 2025

Summary

Solana's groth16-solana crate, as well as most Solana ZK applications, use snarkjs for generating proofs. I'm adding, mostly verbatim from groth16-solana JS scripts, native methods to the snarkjs CLI to export Solana-compatible artifacts.

This is a proposal - I'm happy and more than open to take feedback and rework this in a way that's amenable to snarkjs maintainers.

New Commands

  • snarkjs zkey export rustverifier [circuit.zkey] [verifier.rs] (alias: zkerv)

    • Exports Groth16 verification key as a self-contained Rust file with struct definition
  • snarkjs zkey export rustcalldata [public.json] [proof.json] (alias: zkerc)

    • Exports proof elements and public inputs as Rust constants

Implementation Details

The byte transformations follow the conventions established by groth16-solana for compatibility with Solana's alt_bn128 precompiles:

  • G1 points: Each coordinate → little-endian 32 bytes → reverse → 64 bytes total
  • G2 points: Concatenate coordinate pair (64 bytes) → reverse all → 128 bytes total
  • Scalars: Little-endian 32 bytes → reverse → 32 bytes

Test Plan

  • Verify rustverifier output matches existing groth16-solana parse_vk_to_rust.js output
  • Verify generated Rust code compiles
  • Test with groth16-solana verifier
  • All existing tests pass (49/49)

Add two new CLI commands for exporting Groth16 artifacts as Rust code:
- `zkey export rustverifier` - exports verification key as Rust struct
- `zkey export rustcalldata` - exports proof and public inputs as Rust constants

The byte transformations follow groth16-solana conventions for compatibility
with Solana's alt_bn128 precompiles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant