From 82cb088138415c5400dbe12a67fec076af5f6449 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Tue, 6 Aug 2024 16:08:25 -0700 Subject: [PATCH] fix: load miden-stdlib for the blake3 example --- assembly/src/lib.rs | 1 + assembly/src/library/mod.rs | 12 ++++++++++++ miden/src/examples/blake3.rs | 11 ++++++++--- miden/src/tools/mod.rs | 3 +-- stdlib/src/lib.rs | 8 +++++++- stdlib/tests/mem/mod.rs | 2 +- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/assembly/src/lib.rs b/assembly/src/lib.rs index 15f4d51b3..a22b3738a 100644 --- a/assembly/src/lib.rs +++ b/assembly/src/lib.rs @@ -31,6 +31,7 @@ pub mod testing; mod tests; /// Re-exported for downstream crates +pub use vm_core::mast; pub use vm_core::utils; pub use self::{ diff --git a/assembly/src/library/mod.rs b/assembly/src/library/mod.rs index 8028714ca..3888ec8e1 100644 --- a/assembly/src/library/mod.rs +++ b/assembly/src/library/mod.rs @@ -161,6 +161,12 @@ impl Library { } } +impl From for MastForest { + fn from(value: Library) -> Self { + value.mast_forest + } +} + impl Serializable for Library { fn write_into(&self, target: &mut W) { self.write_into_with_options(target, AstSerdeOptions::default()) @@ -495,6 +501,12 @@ impl KernelLibrary { } } +impl From for MastForest { + fn from(value: KernelLibrary) -> Self { + value.library.mast_forest + } +} + impl Serializable for KernelLibrary { fn write_into(&self, target: &mut W) { self.write_into_with_options(target, AstSerdeOptions::default()) diff --git a/miden/src/examples/blake3.rs b/miden/src/examples/blake3.rs index 1f94ade81..6db77685d 100644 --- a/miden/src/examples/blake3.rs +++ b/miden/src/examples/blake3.rs @@ -21,11 +21,16 @@ pub fn get_example(n: usize) -> Example> { n, expected_result ); + let mut host = DefaultHost::default(); + host.load_mast_forest(StdLibrary::default().into()); + + let stack_inputs = + StackInputs::try_from_ints(INITIAL_HASH_VALUE.iter().map(|&v| v as u64)).unwrap(); + Example { program, - stack_inputs: StackInputs::try_from_ints(INITIAL_HASH_VALUE.iter().map(|&v| v as u64)) - .unwrap(), - host: DefaultHost::default(), + stack_inputs, + host, expected_result, num_outputs: 8, } diff --git a/miden/src/tools/mod.rs b/miden/src/tools/mod.rs index 50aec1ad8..70501fbfb 100644 --- a/miden/src/tools/mod.rs +++ b/miden/src/tools/mod.rs @@ -38,8 +38,7 @@ impl Analyze { // fetch the stack and program inputs from the arguments let stack_inputs = input_data.parse_stack_inputs().map_err(Report::msg)?; let mut host = DefaultHost::new(input_data.parse_advice_provider().map_err(Report::msg)?); - let stdlib = StdLibrary::default(); - host.load_mast_forest(stdlib.as_ref().mast_forest().clone()); + host.load_mast_forest(StdLibrary::default().into()); let execution_details: ExecutionDetails = analyze(program.as_str(), stack_inputs, host) .expect("Could not retrieve execution details"); diff --git a/stdlib/src/lib.rs b/stdlib/src/lib.rs index 6b5f5af57..09a723a9b 100644 --- a/stdlib/src/lib.rs +++ b/stdlib/src/lib.rs @@ -2,7 +2,7 @@ extern crate alloc; -use assembly::{library::Library, utils::Deserializable}; +use assembly::{library::Library, mast::MastForest, utils::Deserializable}; // STANDARD LIBRARY // ================================================================================================ @@ -22,6 +22,12 @@ impl From for Library { } } +impl From for MastForest { + fn from(value: StdLibrary) -> Self { + value.0.into() + } +} + impl Default for StdLibrary { fn default() -> Self { let bytes = include_bytes!(concat!(env!("OUT_DIR"), "/assets/std.masl")); diff --git a/stdlib/tests/mem/mod.rs b/stdlib/tests/mem/mod.rs index d6a6d4ea8..7ce4bc80d 100644 --- a/stdlib/tests/mem/mod.rs +++ b/stdlib/tests/mem/mod.rs @@ -31,7 +31,7 @@ fn test_memcopy() { assembler.assemble_program(source).expect("Failed to compile test source."); let mut host = DefaultHost::default(); - host.load_mast_forest(stdlib.as_ref().mast_forest().clone()); + host.load_mast_forest(stdlib.into()); let mut process = Process::new( program.kernel().clone(),