Skip to content

Commit

Permalink
chore: improve types in acvm-backend-barretenberg (#2516)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Sep 1, 2023
1 parent 2668ac2 commit 92af05a
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 120 deletions.
35 changes: 16 additions & 19 deletions crates/acvm_backend_barretenberg/src/bb/contract.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use super::{assert_binary_exists, get_binary_path, CliShimError};

/// VerifyCommand will call the barretenberg binary
Expand All @@ -9,9 +11,9 @@ use super::{assert_binary_exists, get_binary_path, CliShimError};
/// remaining logic that is missing.
pub(crate) struct ContractCommand {
pub(crate) verbose: bool,
pub(crate) path_to_crs: String,
pub(crate) path_to_vk: String,
pub(crate) path_to_contract: String,
pub(crate) crs_path: PathBuf,
pub(crate) vk_path: PathBuf,
pub(crate) contract_path: PathBuf,
}

impl ContractCommand {
Expand All @@ -22,11 +24,11 @@ impl ContractCommand {
command
.arg("contract")
.arg("-c")
.arg(self.path_to_crs)
.arg(self.crs_path)
.arg("-k")
.arg(self.path_to_vk)
.arg(self.vk_path)
.arg("-o")
.arg(self.path_to_contract);
.arg(self.contract_path);

if self.verbose {
command.arg("-v");
Expand All @@ -46,30 +48,25 @@ impl ContractCommand {
fn contract_command() {
use tempfile::tempdir;

let path_to_1_mul = "./src/1_mul.bytecode";
let bytecode_path = PathBuf::from("./src/1_mul.bytecode");

let temp_directory = tempdir().expect("could not create a temporary directory");
let temp_directory_path = temp_directory.path();
let path_to_crs = temp_directory_path.join("crs");
let path_to_vk = temp_directory_path.join("vk");
let path_to_contract = temp_directory_path.join("contract");
let crs_path = temp_directory_path.join("crs");
let vk_path = temp_directory_path.join("vk");
let contract_path = temp_directory_path.join("contract");

let write_vk_command = super::WriteVkCommand {
verbose: true,
path_to_bytecode: path_to_1_mul.to_string(),
path_to_vk_output: path_to_vk.to_str().unwrap().to_string(),
bytecode_path,
vk_path_output: vk_path.clone(),
is_recursive: false,
path_to_crs: path_to_crs.to_str().unwrap().to_string(),
crs_path: crs_path.clone(),
};

assert!(write_vk_command.run().is_ok());

let contract_command = ContractCommand {
verbose: true,
path_to_vk: path_to_vk.to_str().unwrap().to_string(),
path_to_crs: path_to_crs.to_str().unwrap().to_string(),
path_to_contract: path_to_contract.to_str().unwrap().to_string(),
};
let contract_command = ContractCommand { verbose: true, vk_path, crs_path, contract_path };

assert!(contract_command.run().is_ok());
drop(temp_directory);
Expand Down
19 changes: 9 additions & 10 deletions crates/acvm_backend_barretenberg/src/bb/gates.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::path::PathBuf;

use super::{assert_binary_exists, get_binary_path};

/// GatesCommand will call the barretenberg binary
/// to return the number of gates needed to create a proof
/// for the given bytecode.
pub(crate) struct GatesCommand {
pub(crate) path_to_crs: String,
pub(crate) path_to_bytecode: String,
pub(crate) crs_path: PathBuf,
pub(crate) bytecode_path: PathBuf,
}

impl GatesCommand {
Expand All @@ -14,9 +16,9 @@ impl GatesCommand {
let output = std::process::Command::new(get_binary_path())
.arg("gates")
.arg("-c")
.arg(self.path_to_crs)
.arg(self.crs_path)
.arg("-b")
.arg(self.path_to_bytecode)
.arg(self.bytecode_path)
.output()
.expect("Failed to execute command");

Expand Down Expand Up @@ -55,16 +57,13 @@ impl GatesCommand {
fn gate_command() {
use tempfile::tempdir;

let path_to_1_mul = "./src/1_mul.bytecode";
let bytecode_path = PathBuf::from("./src/1_mul.bytecode");

let temp_directory = tempdir().expect("could not create a temporary directory");
let temp_directory_path = temp_directory.path();
let path_to_crs = temp_directory_path.join("crs");
let crs_path = temp_directory_path.join("crs");

let gate_command = GatesCommand {
path_to_crs: path_to_crs.to_str().unwrap().to_string(),
path_to_bytecode: path_to_1_mul.to_string(),
};
let gate_command = GatesCommand { crs_path, bytecode_path };

let output = gate_command.run();
assert_eq!(output, 2775);
Expand Down
34 changes: 18 additions & 16 deletions crates/acvm_backend_barretenberg/src/bb/prove.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use super::{assert_binary_exists, get_binary_path, CliShimError};

/// ProveCommand will call the barretenberg binary
Expand All @@ -9,11 +11,11 @@ use super::{assert_binary_exists, get_binary_path, CliShimError};
/// The proof will be written to the specified output file.
pub(crate) struct ProveCommand {
pub(crate) verbose: bool,
pub(crate) path_to_crs: String,
pub(crate) crs_path: PathBuf,
pub(crate) is_recursive: bool,
pub(crate) path_to_bytecode: String,
pub(crate) path_to_witness: String,
pub(crate) path_to_proof: String,
pub(crate) bytecode_path: PathBuf,
pub(crate) witness_path: PathBuf,
pub(crate) proof_path: PathBuf,
}

impl ProveCommand {
Expand All @@ -24,13 +26,13 @@ impl ProveCommand {
command
.arg("prove")
.arg("-c")
.arg(self.path_to_crs)
.arg(self.crs_path)
.arg("-b")
.arg(self.path_to_bytecode)
.arg(self.bytecode_path)
.arg("-w")
.arg(self.path_to_witness)
.arg(self.witness_path)
.arg("-o")
.arg(self.path_to_proof);
.arg(self.proof_path);

if self.verbose {
command.arg("-v");
Expand All @@ -54,22 +56,22 @@ impl ProveCommand {
fn prove_command() {
use tempfile::tempdir;

let path_to_1_mul = "./src/1_mul.bytecode";
let path_to_1_mul_witness = "./src/witness.tr";
let bytecode_path = PathBuf::from("./src/1_mul.bytecode");
let witness_path = PathBuf::from("./src/witness.tr");

let temp_directory = tempdir().expect("could not create a temporary directory");
let temp_directory_path = temp_directory.path();

let path_to_crs = temp_directory_path.join("crs");
let path_to_proof = temp_directory_path.join("1_mul").with_extension("proof");
let crs_path = temp_directory_path.join("crs");
let proof_path = temp_directory_path.join("1_mul").with_extension("proof");

let prove_command = ProveCommand {
verbose: true,
path_to_crs: path_to_crs.to_str().unwrap().to_string(),
crs_path,
bytecode_path,
witness_path,
is_recursive: false,
path_to_bytecode: path_to_1_mul.to_string(),
path_to_witness: path_to_1_mul_witness.to_string(),
path_to_proof: path_to_proof.to_str().unwrap().to_string(),
proof_path,
};

let proof_created = prove_command.run();
Expand Down
44 changes: 23 additions & 21 deletions crates/acvm_backend_barretenberg/src/bb/verify.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::path::PathBuf;

use super::{assert_binary_exists, get_binary_path};

/// VerifyCommand will call the barretenberg binary
/// to verify a proof
pub(crate) struct VerifyCommand {
pub(crate) verbose: bool,
pub(crate) path_to_crs: String,
pub(crate) crs_path: PathBuf,
pub(crate) is_recursive: bool,
pub(crate) path_to_proof: String,
pub(crate) path_to_vk: String,
pub(crate) proof_path: PathBuf,
pub(crate) vk_path: PathBuf,
}

impl VerifyCommand {
Expand All @@ -18,11 +20,11 @@ impl VerifyCommand {
command
.arg("verify")
.arg("-c")
.arg(self.path_to_crs)
.arg(self.crs_path)
.arg("-p")
.arg(self.path_to_proof)
.arg(self.proof_path)
.arg("-k")
.arg(self.path_to_vk);
.arg(self.vk_path);

if self.verbose {
command.arg("-v");
Expand All @@ -43,43 +45,43 @@ fn verify_command() {

use crate::bb::{ProveCommand, WriteVkCommand};

let path_to_1_mul = "./src/1_mul.bytecode";
let path_to_1_mul_witness = "./src/witness.tr";
let bytecode_path = PathBuf::from("./src/1_mul.bytecode");
let witness_path = PathBuf::from("./src/witness.tr");

let temp_directory = tempdir().expect("could not create a temporary directory");
let temp_directory_path = temp_directory.path();

let path_to_crs = temp_directory_path.join("crs");
let path_to_proof = temp_directory_path.join("1_mul").with_extension("proof");
let path_to_vk = temp_directory_path.join("vk");
let crs_path = temp_directory_path.join("crs");
let proof_path = temp_directory_path.join("1_mul").with_extension("proof");
let vk_path_output = temp_directory_path.join("vk");

let write_vk_command = WriteVkCommand {
verbose: true,
path_to_bytecode: path_to_1_mul.to_string(),
path_to_crs: path_to_crs.to_str().unwrap().to_string(),
bytecode_path: bytecode_path.clone(),
crs_path: crs_path.clone(),
is_recursive: false,
path_to_vk_output: path_to_vk.to_str().unwrap().to_string(),
vk_path_output: vk_path_output.clone(),
};

let vk_written = write_vk_command.run();
assert!(vk_written.is_ok());

let prove_command = ProveCommand {
verbose: true,
path_to_crs: path_to_crs.to_str().unwrap().to_string(),
crs_path: crs_path.clone(),
is_recursive: false,
path_to_bytecode: path_to_1_mul.to_string(),
path_to_witness: path_to_1_mul_witness.to_string(),
path_to_proof: path_to_proof.to_str().unwrap().to_string(),
bytecode_path,
witness_path,
proof_path: proof_path.clone(),
};
prove_command.run().unwrap();

let verify_command = VerifyCommand {
verbose: true,
path_to_crs: path_to_crs.to_str().unwrap().to_string(),
crs_path,
is_recursive: false,
path_to_proof: path_to_proof.to_str().unwrap().to_string(),
path_to_vk: path_to_vk.to_str().unwrap().to_string(),
proof_path,
vk_path: vk_path_output,
};

let verified = verify_command.run();
Expand Down
26 changes: 14 additions & 12 deletions crates/acvm_backend_barretenberg/src/bb/write_vk.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::path::PathBuf;

use super::{assert_binary_exists, get_binary_path, CliShimError};

/// WriteCommand will call the barretenberg binary
/// to write a verification key to a file
pub(crate) struct WriteVkCommand {
pub(crate) verbose: bool,
pub(crate) path_to_crs: String,
pub(crate) crs_path: PathBuf,
pub(crate) is_recursive: bool,
pub(crate) path_to_bytecode: String,
pub(crate) path_to_vk_output: String,
pub(crate) bytecode_path: PathBuf,
pub(crate) vk_path_output: PathBuf,
}

impl WriteVkCommand {
Expand All @@ -18,11 +20,11 @@ impl WriteVkCommand {
command
.arg("write_vk")
.arg("-c")
.arg(self.path_to_crs)
.arg(self.crs_path)
.arg("-b")
.arg(self.path_to_bytecode)
.arg(self.bytecode_path)
.arg("-o")
.arg(self.path_to_vk_output);
.arg(self.vk_path_output);

if self.verbose {
command.arg("-v");
Expand All @@ -46,19 +48,19 @@ impl WriteVkCommand {
fn write_vk_command() {
use tempfile::tempdir;

let path_to_1_mul = "./src/1_mul.bytecode";
let bytecode_path = PathBuf::from("./src/1_mul.bytecode");

let temp_directory = tempdir().expect("could not create a temporary directory");
let temp_directory_path = temp_directory.path();
let path_to_crs = temp_directory_path.join("crs");
let path_to_vk = temp_directory_path.join("vk");
let crs_path = temp_directory_path.join("crs");
let vk_path_output = temp_directory_path.join("vk");

let write_vk_command = WriteVkCommand {
verbose: true,
path_to_bytecode: path_to_1_mul.to_string(),
path_to_crs: path_to_crs.to_str().unwrap().to_string(),
bytecode_path,
crs_path,
is_recursive: false,
path_to_vk_output: path_to_vk.to_str().unwrap().to_string(),
vk_path_output,
};

let vk_written = write_vk_command.run();
Expand Down
Loading

0 comments on commit 92af05a

Please sign in to comment.