From 119f0b0dcdf995aa28b7a14918806d9bdd659c59 Mon Sep 17 00:00:00 2001 From: polydez <155382956+polydez@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:45:10 +0500 Subject: [PATCH] refactor: address review comments --- Cargo.toml | 1 - miden-lib/Cargo.toml | 2 +- miden-lib/build.rs | 16 ++++++++-------- miden-lib/src/transaction/mod.rs | 4 ---- .../kernel_v0.rs} | 0 .../{procedures.rs => procedures/mod.rs} | 8 ++++++-- 6 files changed, 15 insertions(+), 16 deletions(-) rename miden-lib/src/transaction/{procedures_v0.rs => procedures/kernel_v0.rs} (100%) rename miden-lib/src/transaction/{procedures.rs => procedures/mod.rs} (91%) diff --git a/Cargo.toml b/Cargo.toml index 07a8887e8..70d77e61c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,5 @@ miden-stdlib = { version = "0.10", default-features = false } miden-tx = { path = "miden-tx", version = "0.6" } miden-verifier = { version = "0.10", default-features = false } rand = { version = "0.8", default-features = false } -regex = { version = "1.10.6", default-features = false } vm-core = { package = "miden-core", version = "0.10", default-features = false } vm-processor = { package = "miden-processor", version = "0.10", default-features = false } diff --git a/miden-lib/Cargo.toml b/miden-lib/Cargo.toml index 9a12670a8..b2b590c2e 100644 --- a/miden-lib/Cargo.toml +++ b/miden-lib/Cargo.toml @@ -33,4 +33,4 @@ vm-processor = { workspace = true, features = ["testing"] } [build-dependencies] assembly = { workspace = true } miden-stdlib = { workspace = true } -regex = { workspace = true } +regex = { version = "1.10" } diff --git a/miden-lib/build.rs b/miden-lib/build.rs index f5502ff91..7cadfd1d8 100644 --- a/miden-lib/build.rs +++ b/miden-lib/build.rs @@ -22,7 +22,7 @@ const ASM_DIR: &str = "asm"; const ASM_MIDEN_DIR: &str = "miden"; const ASM_NOTE_SCRIPTS_DIR: &str = "note_scripts"; const ASM_TX_KERNEL_DIR: &str = "kernels/transaction"; -const PROCEDURES_V0_RS_FILE: &str = "src/transaction/procedures_v0.rs"; +const KERNEL_V0_RS_FILE: &str = "src/transaction/procedures/kernel_v0.rs"; // PRE-PROCESSING // ================================================================================================ @@ -34,7 +34,7 @@ const PROCEDURES_V0_RS_FILE: &str = "src/transaction/procedures_v0.rs"; fn main() -> Result<()> { // re-build when the MASM code changes println!("cargo:rerun-if-changed=asm"); - println!("cargo:rerun-if-changed={PROCEDURES_V0_RS_FILE}"); + println!("cargo:rerun-if-changed={KERNEL_V0_RS_FILE}"); // Copies the MASM code to the build directory let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); @@ -81,9 +81,9 @@ fn main() -> Result<()> { /// /// The complied files are written as follows: /// -/// - {target_dir}/tx_kernel.masl -> contains kernel library compiled from api.masm. -/// - {target_dir}/tx_kernel.masb -> contains the executable compiled from main.masm. -/// - src/transaction/procedures_v0.rs -> contains the kernel procedures table. +/// - {target_dir}/tx_kernel.masl -> contains kernel library compiled from api.masm. +/// - {target_dir}/tx_kernel.masb -> contains the executable compiled from main.masm. +/// - src/transaction/procedures/kernel_v0.rs -> contains the kernel procedures table. /// /// When the `testing` feature is enabled, the POW requirements for account ID generation are /// adjusted by modifying the corresponding constants in {source_dir}/lib/constants.masm file. @@ -122,7 +122,7 @@ fn compile_tx_kernel(source_dir: &Path, target_dir: &Path) -> Result assembler, )?; - // generate `procedures_v0.rs` file + // generate `kernel_v0.rs` file generate_kernel_proc_hash_file(kernel_lib.clone())?; let output_file = target_dir.join("tx_kernel").with_extension(Library::LIBRARY_EXTENSION); @@ -172,7 +172,7 @@ fn decrease_pow(line: io::Result) -> io::Result { Ok(line) } -/// Generates `procedures_v0.rs` file based on the kernel library +/// Generates `kernel_v0.rs` file based on the kernel library fn generate_kernel_proc_hash_file(kernel: KernelLibrary) -> Result<()> { let (_, module_info, _) = kernel.into_parts(); @@ -215,7 +215,7 @@ fn generate_kernel_proc_hash_file(kernel: KernelLibrary) -> Result<()> { }).collect::>().join("\n"); fs::write( - PROCEDURES_V0_RS_FILE, + KERNEL_V0_RS_FILE, format!( r#"/// This file is generated by build.rs, do not modify diff --git a/miden-lib/src/transaction/mod.rs b/miden-lib/src/transaction/mod.rs index 3976e2151..623d6858d 100644 --- a/miden-lib/src/transaction/mod.rs +++ b/miden-lib/src/transaction/mod.rs @@ -35,10 +35,6 @@ pub use errors::{ mod procedures; -// Include procedure hashes generated in build.rs -#[rustfmt::skip] -mod procedures_v0; - // CONSTANTS // ================================================================================================ diff --git a/miden-lib/src/transaction/procedures_v0.rs b/miden-lib/src/transaction/procedures/kernel_v0.rs similarity index 100% rename from miden-lib/src/transaction/procedures_v0.rs rename to miden-lib/src/transaction/procedures/kernel_v0.rs diff --git a/miden-lib/src/transaction/procedures.rs b/miden-lib/src/transaction/procedures/mod.rs similarity index 91% rename from miden-lib/src/transaction/procedures.rs rename to miden-lib/src/transaction/procedures/mod.rs index 934b45583..14471a593 100644 --- a/miden-lib/src/transaction/procedures.rs +++ b/miden-lib/src/transaction/procedures/mod.rs @@ -1,9 +1,14 @@ use alloc::vec::Vec; +use kernel_v0::KERNEL0_PROCEDURES; use miden_objects::{Digest, Felt, Hasher}; use super::TransactionKernel; +// Include procedure hashes generated in build.rs +#[rustfmt::skip] +mod kernel_v0; + // TRANSACTION KERNEL // ================================================================================================ @@ -15,8 +20,7 @@ impl TransactionKernel { pub const NUM_VERSIONS: usize = 1; /// Array of all available kernels. - pub const PROCEDURES: [&'static [Digest]; Self::NUM_VERSIONS] = - [&super::procedures_v0::KERNEL0_PROCEDURES]; + pub const PROCEDURES: [&'static [Digest]; Self::NUM_VERSIONS] = [&KERNEL0_PROCEDURES]; // PUBLIC ACCESSORS // --------------------------------------------------------------------------------------------