diff --git a/crates/nargo_cli/src/cli/fs/keys.rs b/crates/nargo_cli/src/cli/fs/keys.rs index 7890f68a9b4..bbb84876913 100644 --- a/crates/nargo_cli/src/cli/fs/keys.rs +++ b/crates/nargo_cli/src/cli/fs/keys.rs @@ -1,9 +1,9 @@ -use super::{create_named_dir, load_hex_data, write_to_file}; +use super::{create_named_dir, load_hex_data, program::checksum_acir, write_to_file}; use crate::{ constants::{ACIR_CHECKSUM, PK_EXT, VK_EXT}, errors::CliError, }; -use acvm::{acir::circuit::Circuit, hash_constraint_system}; +use acvm::acir::circuit::Circuit; use std::path::{Path, PathBuf}; pub(crate) fn save_key_to_dir>( @@ -30,11 +30,10 @@ pub(crate) fn fetch_pk_and_vk>( ) -> Result<(Vec, Vec), CliError> { let acir_hash_path = circuit_build_path.as_ref().with_extension(ACIR_CHECKSUM); - let expected_acir_hash = load_hex_data(acir_hash_path.clone())?; + let expected_acir_checksum = load_hex_data(acir_hash_path.clone())?; + let new_acir_checksum = checksum_acir(circuit); - let new_acir_hash = hash_constraint_system(circuit); - - if new_acir_hash[..] != expected_acir_hash { + if new_acir_checksum[..] != expected_acir_checksum { return Err(CliError::MismatchedAcir(acir_hash_path)); } @@ -64,7 +63,7 @@ mod tests { use super::fetch_pk_and_vk; use crate::cli::fs::{ keys::save_key_to_dir, - program::{hash_acir, save_acir_hash_to_dir}, + program::{checksum_acir, save_acir_checksum_to_dir}, }; use acvm::acir::circuit::Circuit; use tempdir::TempDir; @@ -81,7 +80,7 @@ mod tests { save_key_to_dir(&pk, circuit_name, &circuit_build_path, true).unwrap(); save_key_to_dir(&vk, circuit_name, &circuit_build_path, false).unwrap(); - save_acir_hash_to_dir(hash_acir(&circuit), circuit_name, &circuit_build_path); + save_acir_checksum_to_dir(checksum_acir(&circuit), circuit_name, &circuit_build_path); circuit_build_path.push(circuit_name); let loaded_keys = fetch_pk_and_vk(&circuit, circuit_build_path, true, true).unwrap(); diff --git a/crates/nargo_cli/src/cli/fs/program.rs b/crates/nargo_cli/src/cli/fs/program.rs index 447be9a8f4f..f327c81f609 100644 --- a/crates/nargo_cli/src/cli/fs/program.rs +++ b/crates/nargo_cli/src/cli/fs/program.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use acvm::{acir::circuit::Circuit, hash_constraint_system}; +use acvm::{acir::circuit::Circuit, checksum_constraint_system}; use noirc_driver::{CompiledContract, CompiledProgram}; use crate::{constants::ACIR_CHECKSUM, errors::CliError}; @@ -34,16 +34,16 @@ fn save_build_artifact_to_file, T: ?Sized + serde::Serialize>( circuit_path } -pub(crate) fn hash_acir(circuit: &Circuit) -> [u8; 32] { - hash_constraint_system(circuit) +pub(crate) fn checksum_acir(circuit: &Circuit) -> [u8; 4] { + checksum_constraint_system(circuit).to_be_bytes() } -pub(crate) fn save_acir_hash_to_dir>( - acir_hash: [u8; 32], +pub(crate) fn save_acir_checksum_to_dir>( + acir_checksum: [u8; 4], hash_name: &str, hash_dir: P, ) -> PathBuf { let hash_path = hash_dir.as_ref().join(hash_name).with_extension(ACIR_CHECKSUM); - write_to_file(hex::encode(acir_hash).as_bytes(), &hash_path); + write_to_file(hex::encode(acir_checksum).as_bytes(), &hash_path); hash_path } diff --git a/crates/nargo_cli/src/cli/preprocess_cmd.rs b/crates/nargo_cli/src/cli/preprocess_cmd.rs index eab66a91122..05f6edd60a4 100644 --- a/crates/nargo_cli/src/cli/preprocess_cmd.rs +++ b/crates/nargo_cli/src/cli/preprocess_cmd.rs @@ -8,7 +8,7 @@ use crate::{constants::TARGET_DIR, errors::CliError}; use super::fs::{ keys::save_key_to_dir, - program::{hash_acir, read_program_from_file, save_acir_hash_to_dir}, + program::{checksum_acir, read_program_from_file, save_acir_checksum_to_dir}, }; use super::NargoConfig; @@ -38,16 +38,16 @@ pub(crate) fn run(args: PreprocessCommand, config: NargoConfig) -> Result<(), Cl pub(crate) struct PreprocessedData { pub(crate) proving_key: Vec, pub(crate) verification_key: Vec, - pub(crate) program_hash: [u8; 32], + pub(crate) program_checksum: [u8; 4], } impl From<&Circuit> for PreprocessedData { fn from(circuit: &Circuit) -> Self { let backend = crate::backends::ConcreteBackend; let (proving_key, verification_key) = backend.preprocess(circuit); - let program_hash = hash_acir(circuit); + let program_checksum = checksum_acir(circuit); - PreprocessedData { proving_key, verification_key, program_hash } + PreprocessedData { proving_key, verification_key, program_checksum } } } @@ -58,7 +58,7 @@ pub(crate) fn save_preprocess_data>( ) -> Result<(PathBuf, PathBuf), CliError> { // Save a checksum of the circuit to compare against during proving and verification. // If hash doesn't match then the circuit has been updated and keys are stale. - save_acir_hash_to_dir(data.program_hash, key_name, &preprocess_dir); + save_acir_checksum_to_dir(data.program_checksum, key_name, &preprocess_dir); let pk_path = save_key_to_dir(&data.proving_key, key_name, &preprocess_dir, true)?; let vk_path = save_key_to_dir(&data.verification_key, key_name, preprocess_dir, false)?;