Skip to content

Add save command to the examples#874

Closed
GraDKh wants to merge 1 commit intodgordon/serialize_prooffrom
gordon/dd_save_command
Closed

Add save command to the examples#874
GraDKh wants to merge 1 commit intodgordon/serialize_prooffrom
gordon/dd_save_command

Conversation

@GraDKh
Copy link
Copy Markdown
Contributor

@GraDKh GraDKh commented Aug 29, 2025

Add save subcommand to example CLI for artifact export

TL;DR

Adds a new save subcommand to the examples CLI that allows exporting circuit artifacts to files.

What changed?

  • Added a new save subcommand to the example CLI that can export:
    • Constraint system binary
    • Public witness values
    • Non-public data values
  • Implemented a helper function write_serialized to handle serialization and file writing
  • Updated the README with documentation for all CLI subcommands, including detailed usage examples for the new save command

How to test?

Run any example with the new save subcommand:

# Save only the constraint system
cargo run --release --example my_circuit -- save --cs-path out/cs.bin

# Save public values and non-public values
cargo run --release --example my_circuit -- save \
    --pub-witness-path out/public.bin \
    --non-pub-data-path out/non_public.bin

# Save all three artifacts
cargo run --release --example my_circuit -- save \
    --cs-path out/cs.bin \
    --pub-witness-path out/public.bin \
    --non-pub-data-path out/non_public.bin

Why make this change?

This change enables developers to export circuit artifacts for external analysis, debugging, or integration with other tools. The ability to save constraint systems and witness data separately provides flexibility for different workflows and testing scenarios.

Copy link
Copy Markdown
Contributor Author

GraDKh commented Aug 29, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@GraDKh GraDKh requested review from jadnohra and pepyakin August 29, 2025 16:29
@GraDKh GraDKh marked this pull request as ready for review August 29, 2025 16:29
@GraDKh GraDKh force-pushed the dgordon/serialize_proof branch from f244472 to c224826 Compare September 1, 2025 07:04
@GraDKh GraDKh force-pushed the gordon/dd_save_command branch from 9d18658 to 0c61270 Compare September 1, 2025 07:04
@GraDKh GraDKh force-pushed the dgordon/serialize_proof branch from c224826 to 709b2fd Compare September 1, 2025 07:11
@GraDKh GraDKh force-pushed the gordon/dd_save_command branch from 0c61270 to 5f45183 Compare September 1, 2025 07:11
Comment thread crates/examples/src/cli.rs
Comment thread crates/examples/README.md Outdated
Comment thread crates/examples/src/cli.rs Outdated
Copy link
Copy Markdown
Contributor

jadnohra commented Sep 1, 2025

@GraDKh Added 3 nits that would actually be nice, assuming you will address them and pre-approving

@GraDKh GraDKh force-pushed the gordon/dd_save_command branch from 5f45183 to 06a3624 Compare September 1, 2025 08:45
Comment on lines +115 to +116
#[command(flatten)]
instance: CommandArgs,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a duplicate command argument flattening issue in the Save command struct. Both params and instance fields have the same type CommandArgs, which will cause clap to register the same argument names twice, resulting in runtime parsing conflicts.

Since both fields serve the same purpose (collecting command arguments), the params field on line 113 should be removed, leaving only the instance field on line 116. This will ensure arguments are properly parsed without conflicts when users run the save command.

/// Save constraint system, public witness, and non-public data to files if paths are provided
Save {
    /// Output path for the constraint system binary
    #[arg(long = "cs-path")]
    cs_path: Option<String>,

    /// Output path for the public witness binary
    #[arg(long = "pub-witness-path")]
    pub_witness_path: Option<String>,

    /// Output path for the non-public data (witness + internal) binary
    #[arg(long = "non-pub-data-path")]
    non_pub_data_path: Option<String>,

    // Remove this duplicate field
    // #[command(flatten)]
    // params: CommandArgs,

    #[command(flatten)]
    instance: CommandArgs,
}

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Copy link
Copy Markdown
Contributor Author

GraDKh commented Sep 1, 2025

Addressed all the comments

@GraDKh GraDKh force-pushed the gordon/dd_save_command branch from 06a3624 to d112b72 Compare September 1, 2025 08:53
Comment on lines +13 to +15
if let Some(parent) = Path::new(path).parent()
&& !parent.as_os_str().is_empty()
{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if let combined with && creates a syntax issue that could lead to unexpected behavior. The current structure:

if let Some(parent) = Path::new(path).parent()
    && !parent.as_os_str().is_empty()
{
    // ...
}

This attempts to use parent in the second condition, but the variable binding from if let doesn't properly extend through the && operator in this context.

Consider restructuring with either nested conditionals:

if let Some(parent) = Path::new(path).parent() {
    if !parent.as_os_str().is_empty() {
        // ...
    }
}

Or with proper parentheses to clarify the intent:

if let Some(parent) = Path::new(path).parent() && (!parent.as_os_str().is_empty()) {
    // ...
}
Suggested change
if let Some(parent) = Path::new(path).parent()
&& !parent.as_os_str().is_empty()
{
if let Some(parent) = Path::new(path).parent() {
if !parent.as_os_str().is_empty()
{

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@jadnohra jadnohra force-pushed the gordon/dd_save_command branch from d112b72 to 5886785 Compare September 1, 2025 22:35
@jadnohra jadnohra force-pushed the dgordon/serialize_proof branch from 709b2fd to 47b98f6 Compare September 1, 2025 22:35
This was referenced Sep 1, 2025
@graphite-app
Copy link
Copy Markdown

graphite-app bot commented Sep 2, 2025

Merge activity

  • Sep 2, 7:12 AM UTC: GraDKh added this pull request to the Graphite merge queue.
  • Sep 2, 7:13 AM UTC: CI is running for this pull request on a draft pull request (#908) due to your merge queue CI optimization settings.
  • Sep 2, 7:20 AM UTC: Merged by the Graphite merge queue via draft PR: #908.

graphite-app bot pushed a commit that referenced this pull request Sep 2, 2025
# Add save subcommand to example CLI for artifact export

### TL;DR

Adds a new `save` subcommand to the examples CLI that allows exporting circuit artifacts to files.

### What changed?

- Added a new `save` subcommand to the example CLI that can export:
    - Constraint system binary
    - Public witness values
    - Non-public data values
- Implemented a helper function `write_serialized` to handle serialization and file writing
- Updated the README with documentation for all CLI subcommands, including detailed usage examples for the new `save` command

### How to test?

Run any example with the new save subcommand:

```
# Save only the constraint system
cargo run --release --example my_circuit -- save --cs-path out/cs.bin

# Save public values and non-public values
cargo run --release --example my_circuit -- save \
    --pub-witness-path out/public.bin \
    --non-pub-data-path out/non_public.bin

# Save all three artifacts
cargo run --release --example my_circuit -- save \
    --cs-path out/cs.bin \
    --pub-witness-path out/public.bin \
    --non-pub-data-path out/non_public.bin
```

### Why make this change?

This change enables developers to export circuit artifacts for external analysis, debugging, or integration with other tools. The ability to save constraint systems and witness data separately provides flexibility for different workflows and testing scenarios.
@graphite-app graphite-app bot closed this Sep 2, 2025
@graphite-app graphite-app bot deleted the gordon/dd_save_command branch September 2, 2025 07:20
lockedloop pushed a commit that referenced this pull request Sep 8, 2025
# Add save subcommand to example CLI for artifact export

### TL;DR

Adds a new `save` subcommand to the examples CLI that allows exporting circuit artifacts to files.

### What changed?

- Added a new `save` subcommand to the example CLI that can export:
    - Constraint system binary
    - Public witness values
    - Non-public data values
- Implemented a helper function `write_serialized` to handle serialization and file writing
- Updated the README with documentation for all CLI subcommands, including detailed usage examples for the new `save` command

### How to test?

Run any example with the new save subcommand:

```
# Save only the constraint system
cargo run --release --example my_circuit -- save --cs-path out/cs.bin

# Save public values and non-public values
cargo run --release --example my_circuit -- save \
    --pub-witness-path out/public.bin \
    --non-pub-data-path out/non_public.bin

# Save all three artifacts
cargo run --release --example my_circuit -- save \
    --cs-path out/cs.bin \
    --pub-witness-path out/public.bin \
    --non-pub-data-path out/non_public.bin
```

### Why make this change?

This change enables developers to export circuit artifacts for external analysis, debugging, or integration with other tools. The ability to save constraint systems and witness data separately provides flexibility for different workflows and testing scenarios.
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.

2 participants