Skip to content

Commit 08d31be

Browse files
committed
Add Cairo backend implementation for Starknet proofs
1 parent 1b1bcd4 commit 08d31be

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//! Cairo backend implementation for Starknet proof systems
2+
//!
3+
//! This module provides a Cairo backend that implements the BackendTrait,
4+
//! wrapping the existing Cairo workflow functions to provide a unified interface.
5+
6+
use color_eyre::Result;
7+
8+
use crate::{backend::Backend, config::Config};
9+
10+
use super::workflow;
11+
12+
/// Cairo backend implementation for Starknet-based proof systems
13+
#[derive(Debug)]
14+
pub struct CairoBackend;
15+
16+
impl CairoBackend {
17+
/// Create a new Cairo backend instance
18+
pub fn new() -> Self {
19+
Self
20+
}
21+
}
22+
23+
impl Backend for CairoBackend {
24+
/// Generate Cairo verifier contract and setup project structure
25+
fn generate(&self, cfg: &Config) -> Result<()> {
26+
workflow::run_gen(cfg)
27+
}
28+
29+
/// Generate proof using Cairo/Starknet proof system
30+
fn prove(&self, cfg: &Config) -> Result<()> {
31+
workflow::run_prove(cfg)
32+
}
33+
34+
/// Verify a generated Cairo proof
35+
fn verify(&self, cfg: &Config) -> Result<()> {
36+
workflow::run_verify(cfg)
37+
}
38+
39+
/// Generate calldata for Cairo proof verification
40+
fn calldata(&self, cfg: &Config) -> Result<()> {
41+
workflow::run_calldata(cfg)
42+
}
43+
44+
/// Deploy Cairo verifier contract to Starknet network
45+
///
46+
/// Cairo deployment is a two-step process:
47+
/// 1. Declare the contract on the network to get a class_hash
48+
/// 2. Deploy an instance of the contract using the class_hash
49+
fn deploy(&self, cfg: &Config, network: Option<&str>) -> Result<()> {
50+
// Use provided network or default to "sepolia"
51+
let network_str = network.unwrap_or("sepolia");
52+
53+
// Step 1: Declare the contract to get class_hash
54+
workflow::run_declare(cfg, network_str)?;
55+
56+
// Step 2: Deploy the contract using the class_hash from declare
57+
workflow::run_deploy(cfg, None)
58+
}
59+
60+
/// Verify proof on-chain using deployed Cairo verifier on Starknet
61+
fn verify_onchain(&self, cfg: &Config, address: Option<&str>) -> Result<()> {
62+
workflow::run_verify_onchain(cfg, address)
63+
}
64+
}
65+
66+
impl Default for CairoBackend {
67+
fn default() -> Self {
68+
Self::new()
69+
}
70+
}

crates/bargo-core/src/commands/cairo/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This module provides a clean, modular interface for Cairo/Starknet operations
44
//! including proof generation, verification, contract management, and deployment.
55
6+
pub mod backend;
67
pub mod bb_operations;
78
pub mod directories;
89
pub mod garaga;

0 commit comments

Comments
 (0)