Skip to content

Commit

Permalink
chore!: Make abi field non-optional in CompiledProgram (#856)
Browse files Browse the repository at this point in the history
* chore!: make `abi` non-optional on `CompiledProgram`

* chore!: remove unnecessary move from `read_inputs_from_file`
  • Loading branch information
TomAFrench authored Feb 16, 2023
1 parent 970a34b commit 98acb5a
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crates/nargo/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn generate_circuit_and_witness_to_disk<P: AsRef<Path>>(
program_dir,
PROVER_INPUT_FILE,
Format::Toml,
compiled_program.abi.as_ref().unwrap().clone(),
&compiled_program.abi,
)?;

let (_, solved_witness) =
Expand Down
6 changes: 3 additions & 3 deletions crates/nargo/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn execute_with_path<P: AsRef<Path>>(
&program_dir,
PROVER_INPUT_FILE,
Format::Toml,
compiled_program.abi.as_ref().unwrap().clone(),
&compiled_program.abi,
)?;

execute_program(&compiled_program, &inputs_map)
Expand Down Expand Up @@ -87,7 +87,7 @@ pub(crate) fn extract_public_inputs(
.map(|index| solved_witness[index])
.collect();

let public_abi = compiled_program.abi.as_ref().unwrap().clone().public_abi();
let public_abi = compiled_program.abi.clone().public_abi();

public_abi.decode(&encoded_public_inputs)
}
Expand All @@ -96,7 +96,7 @@ pub(crate) fn solve_witness(
compiled_program: &CompiledProgram,
input_map: &InputMap,
) -> Result<WitnessMap, CliError> {
let abi = compiled_program.abi.as_ref().unwrap().clone();
let abi = compiled_program.abi.clone();
let mut solved_witness =
input_map_to_witness_map(abi, input_map).map_err(|error| match error {
AbiError::UndefinedInput(_) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub fn read_inputs_from_file<P: AsRef<Path>>(
path: P,
file_name: &str,
format: Format,
abi: Abi,
abi: &Abi,
) -> Result<InputMap, CliError> {
let file_path = {
let mut dir_path = path.as_ref().to_path_buf();
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn prove_with_path<P: AsRef<Path>>(
&program_dir,
PROVER_INPUT_FILE,
Format::Toml,
compiled_program.abi.as_ref().unwrap().clone(),
&compiled_program.abi,
)?;

let (_, solved_witness) = execute_program(&compiled_program, &inputs_map)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/nargo/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ pub fn verify_with_path<P: AsRef<Path>>(
let mut public_inputs_map: InputMap = BTreeMap::new();

// Load public inputs (if any) from `VERIFIER_INPUT_FILE`.
let public_abi = compiled_program.abi.clone().unwrap().public_abi();
let public_abi = compiled_program.abi.clone().public_abi();
let num_pub_params = public_abi.num_parameters();
if num_pub_params != 0 {
let current_dir = program_dir;
public_inputs_map =
read_inputs_from_file(current_dir, VERIFIER_INPUT_FILE, Format::Toml, public_abi)?;
read_inputs_from_file(current_dir, VERIFIER_INPUT_FILE, Format::Toml, &public_abi)?;
}

let valid_proof = verify_proof(compiled_program, public_inputs_map, &load_proof(proof_path)?)?;
Expand All @@ -62,7 +62,7 @@ pub(crate) fn verify_proof(
public_inputs_map: InputMap,
proof: &[u8],
) -> Result<bool, CliError> {
let public_abi = compiled_program.abi.unwrap().public_abi();
let public_abi = compiled_program.abi.public_abi();
let public_inputs =
public_abi.encode(&public_inputs_map, false).map_err(|error| match error {
AbiError::UndefinedInput(_) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_abi/src/input_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Format {
pub fn parse(
&self,
input_string: &str,
abi: Abi,
abi: &Abi,
) -> Result<BTreeMap<String, InputValue>, InputParserError> {
match self {
Format::Toml => toml::parse_toml(input_string, abi),
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_abi/src/input_parser/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::collections::BTreeMap;

pub(crate) fn parse_toml(
input_string: &str,
abi: Abi,
abi: &Abi,
) -> Result<BTreeMap<String, InputValue>, InputParserError> {
// Parse input.toml into a BTreeMap.
let data: BTreeMap<String, TomlTypes> = toml::from_str(input_string)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Driver {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CompiledProgram {
pub circuit: Circuit,
pub abi: Option<noirc_abi::Abi>,
pub abi: noirc_abi::Abi,
}

impl Driver {
Expand Down Expand Up @@ -189,7 +189,7 @@ impl Driver {

let blackbox_supported = acvm::default_is_black_box_supported(np_language.clone());
match create_circuit(program, np_language, blackbox_supported, show_ssa, show_output) {
Ok(circuit) => Ok(CompiledProgram { circuit, abi: Some(abi) }),
Ok(circuit) => Ok(CompiledProgram { circuit, abi }),
Err(err) => {
// The FileId here will be the file id of the file with the main file
// Errors will be shown at the call site without a stacktrace
Expand Down

0 comments on commit 98acb5a

Please sign in to comment.