Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.2.0"
edition = "2024"

[dependencies]
bargo-core = { path = "crates/bargo-core" }
bargo-core = { path = "crates/bargo-core", default-features = false }
color-eyre = "0.6.5"

[dev-dependencies]
Expand All @@ -19,4 +19,7 @@ assert_fs = "1.1"
path-slash = "0.2"

[features]
default = ["cairo", "evm-foundry"]
cairo = ["bargo-core/cairo"]
evm-foundry = ["bargo-core/evm-foundry"]
runner-history-tests = []
52 changes: 35 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ bargo is a Swiss Army knife for circuit proving, verification, smart contract ge
- **[nargo](https://noir-lang.org/docs/getting_started/installation/)** - Noir language toolchain
- **[bb](https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg)** - Barretenberg proving system

### EVM Workflow (Optional)
### EVM Foundry Workflow (Optional, `evm-foundry` feature)
- **[Foundry](https://getfoundry.sh/)** - For Solidity contract deployment
- **Environment Variables**: `RPC_URL`, `PRIVATE_KEY` in `.env` file

### Starknet Workflow (Optional)
### Starknet Workflow (Optional, `cairo` feature)
- **[starkli](https://github.com/xJonathanLEI/starkli)** - Starknet CLI tool
- **[garaga](https://github.com/keep-starknet-strange/garaga)** - Cairo verifier generation
- **Python 3.10+** and **pipx** for garaga installation
Expand All @@ -41,12 +41,12 @@ Currently, Noir developers must juggle multiple tools and remember complex comma
# Current workflow (verbose and error-prone)
nargo check
nargo execute # produce bytecode + witness
bb prove -b target/foo.json -w target/foo.gz -o target/
bb write_vk -b target/foo.json -o target/
bb verify -k target/vk -p target/proof
bb write_vk -b target/foo.json -o target/ -t evm
bb prove -b target/foo.json -w target/foo.gz -o target/ -t evm -k target/vk
bb verify -k target/vk -p target/proof -i target/public_inputs -t evm

# Plus remembering different flags for Solidity generation
bb write_vk --oracle_hash keccak -b target/foo.json -o target/
bb write_vk -b target/foo.json -o target/ -t evm
bb write_solidity_verifier -k target/vk -o contracts/Verifier.sol

# And for Starknet verifier contracts:
Expand All @@ -72,12 +72,12 @@ bargo evm verify
bargo evm gen
bargo evm calldata

# Starknet Workflow
# Starknet Workflow (requires `cairo` feature)
bargo build
bargo cairo prove
bargo cairo verify
bargo cairo gen
bargo cairo data
bargo cairo calldata
```

**How bargo improves on underlying tools:**
Expand All @@ -96,15 +96,17 @@ bargo cairo data
- `bargo rebuild` - Clean and rebuild from scratch
- `bargo doctor` - Check that all required tools are installed

### EVM Commands
### EVM Commands (Core)
- `bargo evm prove` - Generate proof and verification key with Keccak oracle
- `bargo evm verify` - Verify proof locally
- `bargo evm gen` - Generate Solidity verifier contract and Foundry project
- `bargo evm gen` - Generate Solidity verifier contract (Foundry project when enabled)
- `bargo evm calldata` - Generate calldata for on-chain verification

### EVM Commands (Foundry, `evm-foundry` feature)
- `bargo evm deploy` - Deploy verifier contract to EVM networks
- `bargo evm verify-onchain` - Verify proof on-chain

### Starknet Commands
### Starknet Commands (`cairo` feature)
- `bargo cairo prove` - Generate proof and verification key with Starknet oracle
- `bargo cairo verify` - Verify proof locally
- `bargo cairo gen` - Generate Cairo verifier contract using garaga
Expand Down Expand Up @@ -132,6 +134,22 @@ bargo --help
bargo doctor # Check dependencies
```

### Feature Flags

By default, `bargo` enables both the Cairo and Foundry feature sets. To disable them at compile time:

```toml
# Cargo.toml dependency example
bargo = { version = "0.2.0", default-features = false, features = ["cairo"] }
```

```bash
# Building locally
cargo build --no-default-features
cargo build --no-default-features --features cairo
cargo build --no-default-features --features evm-foundry
```

### EVM Setup (Optional)

```bash
Expand Down Expand Up @@ -265,7 +283,7 @@ target/
└── calldata.json

contracts/
├── evm/ # Foundry project with Solidity verifier
├── evm/ # Solidity verifier (Foundry project when enabled)
└── cairo/ # Cairo verifier project
```

Expand Down Expand Up @@ -324,13 +342,13 @@ Error: Command execution failed: bb prove --scheme ultra_honk

### Backend-Specific Errors

#### Cairo Backend Errors
#### Cairo Backend Errors (requires `cairo` feature)
- **Deploy failures**: Issues with Starknet contract deployment
- **Class hash errors**: Problems with contract declaration
- **Garaga integration**: Tool-specific failures during contract generation

#### EVM Backend Errors
- **Foundry integration**: Issues with Solidity compilation or deployment
- **Foundry integration**: Issues with Solidity compilation or deployment (requires `evm-foundry`)
- **Network errors**: Problems connecting to Ethereum networks
- **Contract compilation**: Solidity verifier generation failures

Expand Down Expand Up @@ -365,8 +383,8 @@ Error: Command execution failed: bb prove --scheme ultra_honk
|---------|----------|
| "nargo not found" | Install Noir toolchain: `curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash` |
| "bb not found" | Install Barretenberg: Follow Aztec installation docs |
| "garaga not found" | Install with pip: `pip install garaga==0.18.1` |
| "forge not found" | Install Foundry: `curl -L https://foundry.paradigm.xyz \| bash && foundryup` |
| "garaga not found" | Install with pip: `pip install garaga==0.18.1` (only for `cairo`) |
| "forge not found" | Install Foundry: `curl -L https://foundry.paradigm.xyz \| bash && foundryup` (only for `evm-foundry`) |
| Version compatibility issues | Use `bargo doctor` to check versions and compatibility |
| Missing artifacts | Run prerequisite commands: `bargo build` → `bargo <backend> prove` |
| Network connection issues | Check RPC URLs and network configuration in `.env` |
Expand Down Expand Up @@ -446,4 +464,4 @@ Integration tests use `ScopedDir` guards to prevent race conditions when running

## License

MIT License - see [LICENSE](LICENSE) file for details.
MIT License - see [LICENSE](LICENSE) file for details.
5 changes: 5 additions & 0 deletions crates/bargo-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ which = "4.4"

[dev-dependencies]
tempfile = "3.8"

[features]
default = ["cairo", "evm-foundry"]
cairo = []
evm-foundry = []
14 changes: 9 additions & 5 deletions crates/bargo-core/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

use color_eyre::Result;

use crate::config::{CairoDeployConfig, Config};
use crate::config::Config;

#[cfg(feature = "cairo")]
use crate::config::CairoDeployConfig;

/// Trait for polymorphic backend implementations (Cairo, EVM, etc.)
///
Expand Down Expand Up @@ -43,13 +46,15 @@ pub trait Backend {
#[derive(Debug, Clone)]
pub enum BackendConfig {
/// Cairo/Starknet backend configuration
#[cfg(feature = "cairo")]
CairoDeploy(CairoDeployConfig),
}

/// Backend type identifier for factory function
#[derive(Debug, Clone, Copy)]
pub enum BackendKind {
/// Cairo/Starknet backend
#[cfg(feature = "cairo")]
Cairo,
/// EVM/Ethereum backend
Evm,
Expand All @@ -72,10 +77,9 @@ pub enum BackendKind {
/// backend.generate(&config)?;
/// ```
pub fn backend_for(backend_kind: BackendKind) -> Box<dyn Backend> {
use crate::commands::{cairo, evm};

match backend_kind {
BackendKind::Cairo => Box::new(cairo::backend::CairoBackend::new()),
BackendKind::Evm => Box::new(evm::backend::EvmBackend::new()),
#[cfg(feature = "cairo")]
BackendKind::Cairo => Box::new(crate::commands::cairo::backend::CairoBackend::new()),
BackendKind::Evm => Box::new(crate::commands::evm::backend::EvmBackend::new()),
}
}
2 changes: 2 additions & 0 deletions crates/bargo-core/src/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
//! Legacy direct command execution functions have been removed.

pub mod bb;
#[cfg(feature = "evm-foundry")]
pub mod foundry;
#[cfg(feature = "cairo")]
pub mod garaga;
pub mod nargo;

Expand Down
13 changes: 9 additions & 4 deletions crates/bargo-core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ pub enum Commands {
},

/// Cairo/Starknet operations
#[cfg(feature = "cairo")]
#[command(about = "Generate Cairo verifiers and interact with Starknet")]
Cairo {
#[command(subcommand)]
command: CairoCommands,
},

/// EVM/Foundry operations
/// EVM operations
#[command(about = "Generate Solidity verifiers and interact with EVM networks")]
Evm {
#[command(subcommand)]
Expand All @@ -74,6 +75,7 @@ pub enum Commands {
Doctor,
}

#[cfg(feature = "cairo")]
#[derive(Subcommand)]
pub enum CairoCommands {
/// Generate Cairo verifier contract
Expand Down Expand Up @@ -117,8 +119,8 @@ pub enum CairoCommands {

#[derive(Subcommand)]
pub enum EvmCommands {
/// Generate Solidity verifier contract and Foundry project
#[command(about = "Generate Solidity verifier contract with complete Foundry project setup")]
/// Generate Solidity verifier contract
#[command(about = "Generate Solidity verifier contract (Foundry project setup when enabled)")]
Gen,

/// Generate Keccak oracle proof
Expand All @@ -130,6 +132,7 @@ pub enum EvmCommands {
Verify,

/// Deploy verifier contract to EVM network
#[cfg(feature = "evm-foundry")]
#[command(about = "Deploy verifier contract using Foundry")]
Deploy {
/// Network to deploy to (mainnet or sepolia)
Expand All @@ -138,10 +141,11 @@ pub enum EvmCommands {
},

/// Generate calldata for proof verification
#[command(about = "Generate calldata for proof verification using cast")]
#[command(about = "Generate calldata for proof verification")]
Calldata,

/// Verify proof on-chain
#[cfg(feature = "evm-foundry")]
#[command(about = "Verify proof on EVM network using deployed verifier")]
VerifyOnchain,
}
Expand All @@ -151,6 +155,7 @@ pub enum Backend {
/// Barretenberg backend (EVM/Solidity)
Bb,
/// Starknet backend (Cairo)
#[cfg(feature = "cairo")]
Starknet,
/// All backends
All,
Expand Down
1 change: 1 addition & 0 deletions crates/bargo-core/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn run(cfg: &Config, backend: Backend) -> Result<()> {
println!("{}", info_msg("target/bb/ already clean"));
}
}
#[cfg(feature = "cairo")]
Backend::Starknet => {
if cfg.dry_run {
println!("Would run: rm -rf target/starknet/");
Expand Down
70 changes: 39 additions & 31 deletions crates/bargo-core/src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,53 @@ pub fn run(cfg: &Config) -> Result<()> {
}
}

match which::which("garaga") {
Ok(path) => {
if !cfg.quiet {
println!("✅ garaga: {}", path.display());
#[cfg(feature = "cairo")]
{
match which::which("garaga") {
Ok(path) => {
if !cfg.quiet {
println!("✅ garaga: {}", path.display());
}
}
}
Err(_) => {
if !cfg.quiet {
println!("⚠️ garaga: not found (optional - needed for Cairo features)");
println!(" Install with: pipx install garaga");
println!(" Requires Python 3.10+");
Err(_) => {
if !cfg.quiet {
println!("⚠️ garaga: not found (optional - needed for Cairo features)");
println!(" Install with: pipx install garaga");
println!(" Requires Python 3.10+");
}
}
}
}

match which::which("forge") {
Ok(path) => {
if !cfg.quiet {
println!("✅ forge: {}", path.display());
#[cfg(feature = "evm-foundry")]
{
match which::which("forge") {
Ok(path) => {
if !cfg.quiet {
println!("✅ forge: {}", path.display());
}
}
}
Err(_) => {
if !cfg.quiet {
println!("⚠️ forge: not found (optional - needed for EVM features)");
println!(" Install with: curl -L https://foundry.paradigm.xyz | bash");
println!(" Then run: foundryup");
Err(_) => {
if !cfg.quiet {
println!("⚠️ forge: not found (optional - needed for EVM deploy features)");
println!(" Install with: curl -L https://foundry.paradigm.xyz | bash");
println!(" Then run: foundryup");
}
}
}
}

match which::which("cast") {
Ok(path) => {
if !cfg.quiet {
println!("✅ cast: {}", path.display());
match which::which("cast") {
Ok(path) => {
if !cfg.quiet {
println!("✅ cast: {}", path.display());
}
}
}
Err(_) => {
if !cfg.quiet {
println!("⚠️ cast: not found (optional - needed for EVM features)");
println!(" Install with: curl -L https://foundry.paradigm.xyz | bash");
println!(" Then run: foundryup");
Err(_) => {
if !cfg.quiet {
println!("⚠️ cast: not found (optional - used for on-chain helpers)");
println!(" Install with: curl -L https://foundry.paradigm.xyz | bash");
println!(" Then run: foundryup");
}
}
}
}
Expand All @@ -94,7 +100,9 @@ pub fn run(cfg: &Config) -> Result<()> {
} else {
println!("🚨 Some required dependencies are missing.");
println!(" Core features require: nargo + bb");
#[cfg(feature = "evm-foundry")]
println!(" EVM deployment features also require: forge + cast");
#[cfg(feature = "cairo")]
println!(" Cairo features also require: garaga");
}
}
Expand Down
Loading
Loading