Skip to content

Commit

Permalink
feat(cli): improve cargo prove new (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctian1 authored Oct 11, 2024
2 parents 613f577 + 359ca92 commit 8c0c542
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ jobs:
- name: Run cargo prove new
run: |
cargo prove new fibonacci --version dev
cargo prove new fibonacci --version dev --evm
- name: Build program and run script
run: |
Expand Down Expand Up @@ -297,7 +297,7 @@ jobs:
low-memory:
name: Low Memory
strategy:
strategy:
matrix:
mem_limit: [16, 32, 64]
runs-on:
Expand Down Expand Up @@ -353,16 +353,22 @@ jobs:
include:
- name: "Ubuntu 24.04 (x86_64)"
runner: "ubuntu-24.04"
template: evm
- name: "Ubuntu 22.04 (x86_64)"
runner: "ubuntu-22.04"
template: bare
- name: "Ubuntu 20.04 (x86_64)"
runner: "ubuntu-20.04"
template: evm
- name: "macOS Monterey (x86_64)"
runner: "macos-12"
template: evm
- name: "macOS Ventura (x86_64)"
runner: "macos-13"
template: bare
- name: "macOS Sonoma (ARM64)"
runner: "macos-14"
template: evm

runs-on: "${{ matrix.runner }}"
steps:
Expand All @@ -379,7 +385,7 @@ jobs:
- name: "Create SP1 project from template"
run: |
cargo prove new hello
cargo prove new --${{ matrix.template }} hello
- name: "Build SP1 project"
run: |
Expand Down
24 changes: 9 additions & 15 deletions book/generating-proofs/proof-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,20 @@ client.prove(&pk, stdin).run().unwrap();
## Compressed

The compressed prover mode generates STARK proofs that have constant size. Use this in settings where you
care about **verification cost / proof size**. This is useful for applications where you want to recursively verify SP1 proofs within SP1 (see the [proof aggregation](../writing-programs/proof-aggregation.md) section).
care about **verification cost / proof size**, but not onchain verification. Compressed proofs are also useful because they can be cheaply recursively verified within SP1 itself (see the [proof aggregation](../writing-programs/proof-aggregation.md) section).

```rust,noplayground
let client = ProverClient::new();
client.prove(&pk, stdin).compressed().run().unwrap();
```

## Groth16 (testnet only)
## Groth16

<div class="warning">
WARNING: Groth16 proofs are currently only verifiable on testnets & are not production-ready
</div>
> WARNING: The Groth16 prover requires around 64GB of RAM and only has prebuilt circuit artifacts on official releases of SP1. We recommend using the prover network to generate these proofs.
<div class="warning">
WARNING: The Groth16 prover requires around 64GB of RAM and are only guaranteed to work on official releases of SP1. We recommend using the prover network to generate these proofs.
</div>
The Groth16 prover mode generate a SNARK proof that is ~260 bytes large and can be verified onchain for around ~270k gas. Groth16 proofs take about ~30s longer to generate over a compressed proof.

The Groth16 prover mode generate a SNARK proof with extremely small proof size and low verification cost.
This mode generates proofs that can be verified onchain for around ~270k gas.
The trusted setup for the Groth16 circuit keys uses the [Aztec Ignition ceremony](https://github.com/AztecProtocol/ignition-verification) + entropy contributions from members of the Succinct team.

```rust,noplayground
let client = ProverClient::new();
Expand All @@ -46,12 +41,11 @@ client.prove(&pk, stdin).groth16().run().unwrap();

## PLONK

<div class="warning">
WARNING: The PLONK prover requires around 64GB of RAM and are only guaranteed to work on official releases of SP1. We recommend using the prover network to generate these proofs.
</div>
> WARNING: The PLONK prover requires around 64GB of RAM and only has prebuilt circuit artifacts on official releases of SP1. We recommend using the prover network to generate these proofs.
The Groth16 and PLONK prover modes generate a SNARK proof with extremely small proof size and low verification cost.
This mode generates proofs that can be verified onchain for around ~300k gas.
The PLONK prover mode generate a SNARK proof that is ~868 bytes large and can also be verified onchain for around ~300k gas. Plonk proofs take about ~1m30s longer to generate over a compressed proof.

PLONK does not require a trusted setup.

```rust,noplayground
let client = ProverClient::new();
Expand Down
46 changes: 35 additions & 11 deletions crates/cli/src/commands/new.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
use anyhow::Result;
use clap::Parser;
use std::{fs, path::Path, process::Command};
use clap::{Args, Parser};
use std::{
fs,
path::Path,
process::{Command, Stdio},
};
use yansi::Paint;

#[derive(Args)]
#[group(required = true, multiple = false)]
struct TemplateType {
/// Use the `bare` template which includes just a program and script.
#[arg(long)]
bare: bool,

/// Use the `evm` template which includes Solidity smart contracts for onchain integration.
#[arg(long)]
evm: bool,
}

#[derive(Parser)]
#[command(name = "new", about = "Setup a new project that runs inside the SP1.")]
pub struct NewCmd {
/// The name of the project.
name: String,

/// Whether to create the project with template EVM contracts.
#[arg(long, action)]
evm: bool,
/// The template to use for the project.
#[command(flatten)]
template: TemplateType,

/// Version of sp1-project-template to use (branch or tag).
#[arg(long, default_value = "main")]
Expand All @@ -32,16 +48,24 @@ impl NewCmd {
println!(" \x1b[1m{}\x1b[0m {}", Paint::green("Cloning"), TEMPLATE_REPOSITORY_URL);

// Clone the repository with the specified version.
let output = Command::new("git")
let mut command = Command::new("git");

command
.arg("clone")
.arg("--branch")
.arg(&self.version)
.arg(TEMPLATE_REPOSITORY_URL)
.arg(root.as_os_str())
.arg("--recurse-submodules")
.arg("--depth=1")
.output()
.expect("failed to execute command");
.arg("--depth=1");

if self.template.evm {
command.arg("--recurse-submodules").arg("--shallow-submodules");
}

// Stream output to stdout.
command.stdout(Stdio::inherit()).stderr(Stdio::inherit());

let output = command.output().expect("failed to execute command");
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
return Err(anyhow::anyhow!("failed to clone repository: {}", stderr));
Expand All @@ -50,7 +74,7 @@ impl NewCmd {
// Remove the .git directory.
fs::remove_dir_all(root.join(".git"))?;

if self.evm {
if self.template.evm {
// Check if the user has `foundry` installed.
if Command::new("foundry").arg("--version").output().is_err() {
println!(
Expand Down

0 comments on commit 8c0c542

Please sign in to comment.