Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bootloader mode the default #18

Merged
merged 12 commits into from
May 23, 2024
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,24 @@ After compiling a Cairo0 program to `program.json`, run:
stone-prover-cli prove program.json
```

### Run and prove one or more programs/PIEs with the Starknet bootloader
### Run and prove one or more programs/PIEs

If you want to prove one or more programs and PIEs by running them with the Starknet bootloader,
you can use the `--with-bootloader` option.
#### Running with the Starknet bootloader

The CLI uses the Cairo bootloader by default to prove one or more programs and PIEs.
You can use the `--with-bootloader`flag to ensure this.

```shell
stone-prover-cli prove --with-bootloader program1.json program2.json pie1.zip
```

#### Running without the Starknet bootloader
You can use the `--no-bootloader` option if you want to run without the Starknet bootloader.

```shell
stone-prover-cli prove --no-bootloader program.json
```

### Verify a proof

If you want to verify the generated proof file, run:
Expand Down
20 changes: 17 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ impl FromStr for Bootloader {
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
pub struct ProveArgs {
#[clap(long = "with-bootloader", default_value_t = false)]
#[clap(long = "with-bootloader", default_value_t = true)]
pub with_bootloader: bool,

#[clap(
long = "no-bootloader",
conflicts_with = "with_bootloader",
default_value_t = false
)]
pub no_bootloader: bool,

#[clap(long = "bootloader-version")]
bootloader: Option<Bootloader>,

Expand All @@ -73,9 +80,16 @@ pub struct ProveArgs {
}

impl ProveArgs {
fn use_bootloader(&self) -> bool {
if self.no_bootloader {
return false;
}
self.with_bootloader
}
pub fn command(mut self) -> ProveCommand {
let mut cmd = Cli::command();
if !self.with_bootloader {
let use_bootloader = self.use_bootloader();
if !use_bootloader {
if self.config.fact_topologies_file.is_some() {
cmd.error(
ErrorKind::ArgumentConflict,
Expand All @@ -102,7 +116,7 @@ impl ProveArgs {
let layout = self.layout.unwrap_or(Layout::StarknetWithKeccak);
let verifier = self.verifier.unwrap_or(Verifier::Stone);

let executable = match self.with_bootloader {
let executable = match use_bootloader {
true => {
let bootloader = match self.bootloader {
Some(version) => version,
Expand Down
26 changes: 20 additions & 6 deletions tests/test_prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::common::cli_in_path;
mod common;

fn invoke_cli(
with_bootloader: bool,
use_bootloader: bool,
executables: &[&Path],
verifier: Option<Verifier>,
prover_config: Option<&Path>,
Expand All @@ -21,8 +21,10 @@ fn invoke_cli(

command.arg("prove");

if with_bootloader {
if use_bootloader {
command.arg("--with-bootloader");
} else {
command.arg("--no-bootloader");
}
for executable in executables {
command.arg(*executable);
Expand Down Expand Up @@ -70,6 +72,18 @@ fn assert_proof_eq(proof: Proof, expected_proof: Proof) {
assert_eq!(proof.proof_hex, expected_proof.proof_hex);
}

#[rstest]
fn assert_conflict_on_usage_of_with_and_no_bootloader(#[from(cli_in_path)] _path: ()) {
let mut command = std::process::Command::new("stone-prover-cli");
odesenfans marked this conversation as resolved.
Show resolved Hide resolved
command.arg("prove");
command.arg("--with-bootloader");
command.arg("--no-bootloader");
let output = command.output().unwrap();
assert!(!output.status.success());
assert!(format!("{output:?}")
.contains("the argument '--with-bootloader' cannot be used with '--no-bootloader'"))
}

#[rstest]
fn execute_and_prove_program(
#[from(cli_in_path)] _path: (),
Expand Down Expand Up @@ -102,7 +116,7 @@ fn execute_and_prove_program(

let result = invoke_cli(
false,
&vec![program.as_path()],
&[program.as_path()],
odesenfans marked this conversation as resolved.
Show resolved Hide resolved
None,
prover_config,
prover_parameters,
Expand Down Expand Up @@ -138,7 +152,7 @@ fn execute_and_prove_program_l1_verifier(#[from(cli_in_path)] _path: ()) {

let result = invoke_cli(
false,
&vec![program.as_path()],
&[program.as_path()],
Some(Verifier::L1),
None,
None,
Expand Down Expand Up @@ -184,7 +198,7 @@ fn execute_and_prove_program_with_bootloader(#[from(cli_in_path)] _path: ()) {

let result = invoke_cli(
true,
&vec![program.as_path()],
&[program.as_path()],
None,
None,
None,
Expand Down Expand Up @@ -217,7 +231,7 @@ fn execute_and_prove_pie_with_bootloader(#[from(cli_in_path)] _path: ()) {

let result = invoke_cli(
true,
&vec![pie.as_path()],
&[pie.as_path()],
None,
None,
None,
Expand Down
Loading