Skip to content

Commit

Permalink
fix: load miden-stdlib for the blake3 example
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbinth committed Aug 6, 2024
1 parent fb1c280 commit 82cb088
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions assembly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
12 changes: 12 additions & 0 deletions assembly/src/library/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ impl Library {
}
}

impl From<Library> for MastForest {
fn from(value: Library) -> Self {
value.mast_forest
}
}

impl Serializable for Library {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.write_into_with_options(target, AstSerdeOptions::default())
Expand Down Expand Up @@ -495,6 +501,12 @@ impl KernelLibrary {
}
}

impl From<KernelLibrary> for MastForest {
fn from(value: KernelLibrary) -> Self {
value.library.mast_forest
}
}

impl Serializable for KernelLibrary {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.write_into_with_options(target, AstSerdeOptions::default())
Expand Down
11 changes: 8 additions & 3 deletions miden/src/examples/blake3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ pub fn get_example(n: usize) -> Example<DefaultHost<MemAdviceProvider>> {
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,
}
Expand Down
3 changes: 1 addition & 2 deletions miden/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 7 additions & 1 deletion stdlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

extern crate alloc;

use assembly::{library::Library, utils::Deserializable};
use assembly::{library::Library, mast::MastForest, utils::Deserializable};

// STANDARD LIBRARY
// ================================================================================================
Expand All @@ -22,6 +22,12 @@ impl From<StdLibrary> for Library {
}
}

impl From<StdLibrary> 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"));
Expand Down
2 changes: 1 addition & 1 deletion stdlib/tests/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 82cb088

Please sign in to comment.