Skip to content

Commit

Permalink
Make bootloader mode the default (#18)
Browse files Browse the repository at this point in the history
This allows both the argument '--with-bootloader' and '--no-bootloader'.
Both cant be used at the same time.
  • Loading branch information
whichqua authored May 23, 2024
1 parent e4d5968 commit f7bf9d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
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");
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()],
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

0 comments on commit f7bf9d9

Please sign in to comment.