feat(circom): add optional Garaga Starknet calldata helper - #723
feat(circom): add optional Garaga Starknet calldata helper#723rukafe0x wants to merge 7 commits into
Conversation
Expose generate_circom_groth16_garaga_calldata behind the optional garaga feature. Parses SnarkJS proof.json, public.json, and verification_key.json, then calls Garaga v1.1.0 get_groth16_calldata_felt to return Starknet felts as decimal strings. Includes golden fixtures from Garaga v1.1.0 SnarkJS BN254 examples, a garaga-calldata-tests workspace crate, fixture generator binary, and Circom adapter documentation for starknet.dart usage outside Mopro.
Expose generate_circom_groth16_garaga_calldata_from_proof_result so mobile apps can build Starknet calldata directly from generate_circom_proof output using proof_result.inputs instead of a separate SnarkJS public.json file. Co-authored-by: Cursor <cursoragent@cursor.com>
Nested mod declarations under circom.rs require helpers in src/circom/. Co-authored-by: Cursor <cursoragent@cursor.com>
Cursor/garaga calldata helper 1c80
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds optional Garaga v1.1.0 support for converting Circom/SnarkJS BN254 Groth16 proof results into Starknet calldata, with feature-gated APIs, conversion helpers, fixtures, golden tests, regeneration tooling, and documentation. ChangesGaraga calldata integration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant CalldataAPI
participant SnarkJSParser
participant GaragaConverter
participant garaga_rs
Caller->>CalldataAPI: Submit proof result and verification key JSON
CalldataAPI->>SnarkJSParser: Parse and validate verification key
CalldataAPI->>GaragaConverter: Convert proof inputs and verification key
GaragaConverter->>garaga_rs: Generate Starknet calldata
garaga_rs-->>CalldataAPI: Return calldata felts
CalldataAPI-->>Caller: Return decimal felt strings
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cli/src/template/init/src/circom/circom_garaga.rs`:
- Around line 73-85: Validate the parsed public-input count against vk.n_public
immediately after parse_snarkjs_vk_json in both calldata APIs at
cli/src/template/init/src/circom/circom_garaga.rs lines 73-85 and 99-107,
returning MoproError::CircomError when inputs exceed the VK capacity before
calling to_groth16_proof or to_groth16_vk. Add regression tests covering
oversized public inputs for both APIs.
In `@cli/src/template/init/src/circom/garaga_convert.rs`:
- Around line 7-9: Update parse_biguint and the public_inputs_to_biguint
conversion flow to validate public-input values against the BN254 scalar-field
order before constructing the Garaga proof or calling get_groth16_calldata_felt.
Preserve existing decimal parsing errors, while returning an appropriate error
for values outside the scalar field; keep coordinate validation bounded to the
BN254 base field as already required.
In `@cli/src/template/init/src/circom/snarkjs_types.rs`:
- Around line 36-42: Allow zero-public-input proofs by removing the non-empty
validation from parse_snarkjs_public_json in
cli/src/template/init/src/circom/snarkjs_types.rs lines 36-42, and update the
public-input conversion in cli/src/template/init/src/circom/garaga_convert.rs
lines 34-42 to convert an empty slice into an empty Vec<BigUint>; leave
enforcement of input-count equality to the API layer against the verification
key’s n_public.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e6dbd06d-f337-455b-8df5-3f1fee1b572d
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (18)
Cargo.tomlcli/src/init/circom.rscli/src/init/write_toml.rscli/src/template/circom/lib.rscli/src/template/init/src/circom.rscli/src/template/init/src/circom/circom_garaga.rscli/src/template/init/src/circom/garaga_convert.rscli/src/template/init/src/circom/snarkjs_types.rscli/src/template/init/test-vectors/circom/garaga/bn254/README.mdcli/src/template/init/test-vectors/circom/garaga/bn254/expected_garaga_calldata.jsoncli/src/template/init/test-vectors/circom/garaga/bn254/proof.jsoncli/src/template/init/test-vectors/circom/garaga/bn254/public.jsoncli/src/template/init/test-vectors/circom/garaga/bn254/verification_key.jsondocs/docs/adapters/circom.mdgaraga-calldata-tests/Cargo.tomlgaraga-calldata-tests/src/bin/gen_garaga_calldata_fixture.rsgaraga-calldata-tests/src/circom/mod.rsgaraga-calldata-tests/src/lib.rs
…ecks. Validate public-input count field bounds (aicoderabbit suggestion) and fix rustfmt/clippy warnings.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
garaga-calldata-tests/src/lib.rs (1)
45-82: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate fixture-loading logic vs.
gen_garaga_calldata_fixture.rs.
load_fixture_proof_resultreimplements the identical SnarkJS→CircomProofResultmapping (including z-coordinate fallbacks) that also exists ingaraga-calldata-tests/src/bin/gen_garaga_calldata_fixture.rs::load_proof_result. Two independent copies of this mapping risk silently diverging, which would undermine the golden-test guarantee since the fixture generator and the test consumer could disagree on how a proof is parsed.Consider extracting this into a shared test-utility function reused by both the test module and the fixture-generation binary.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@garaga-calldata-tests/src/lib.rs` around lines 45 - 82, Extract the SnarkJS-to-CircomProofResult mapping from load_fixture_proof_result and the binary’s load_proof_result into a shared test utility, preserving the existing proof field construction and z-coordinate fallbacks. Update both callers to reuse that single helper so fixture generation and consumption cannot diverge.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/docs/adapters/circom.md`:
- Around line 395-398: Update the Flutter snippet surrounding
generateCircomGroth16GaragaCalldata to define vkJson before use by showing how
to load verification_key.json in Dart, or explicitly accept it as an input to
the example; ensure the snippet is copy-paste runnable.
---
Nitpick comments:
In `@garaga-calldata-tests/src/lib.rs`:
- Around line 45-82: Extract the SnarkJS-to-CircomProofResult mapping from
load_fixture_proof_result and the binary’s load_proof_result into a shared test
utility, preserving the existing proof field construction and z-coordinate
fallbacks. Update both callers to reuse that single helper so fixture generation
and consumption cannot diverge.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 43d64666-58cc-4905-87a8-c2d43853cab0
📒 Files selected for processing (12)
cli/src/main.rscli/src/template/circom/lib.rscli/src/template/init/src/circom.rscli/src/template/init/src/circom/circom_garaga.rscli/src/template/init/src/circom/garaga_convert.rscli/src/template/init/src/circom/snarkjs_types.rscli/src/template/init/test-vectors/circom/garaga/bn254/README.mddocs/docs/adapters/circom.mdgaraga-calldata-tests/build.rsgaraga-calldata-tests/src/bin/gen_garaga_calldata_fixture.rsgaraga-calldata-tests/src/circom/mod.rsgaraga-calldata-tests/src/lib.rs
💤 Files with no reviewable changes (2)
- cli/src/template/init/src/circom/snarkjs_types.rs
- cli/src/main.rs
🚧 Files skipped from review as they are similar to previous changes (3)
- garaga-calldata-tests/src/circom/mod.rs
- cli/src/template/init/src/circom.rs
- garaga-calldata-tests/src/bin/gen_garaga_calldata_fixture.rs
Summary
Adds an optional Circom helper to format Groth16 proofs as Starknet verifier calldata via Garaga
get_groth16_calldata_felt, so apps can prove on-device and produce on-chain calldata without a backend. This is intentionally a side helper on the Circom template , not part of mopro-ffi core, so non-Starknet / non-Circom users stay unaffected unless they enable the featureCloses #646
Changes
generate_circom_groth16_garaga_calldata— from SnarkJSproof.json/public.json/verification_key.jsongenerate_circom_groth16_garaga_calldata_from_proof_result— from in-appCircomProofResult+ VK JSON (recommended)garaga_rsv1.1.0, BN254 only)Cargo.tomlwiring: optionalgaraga_rs+garagafeaturestarknet.dartusage notes indocs/docs/adapters/circom.mdgaraga-calldata-testsworkspace crateUsage (sketch)